1

I have been following the Operating System development tutorial on http://www.brokenthorn.com. Right now I'm trying to setup the BIOS parameter block with this code:

jmp loader
bpbName db "NubOS",0,0,0
bpbBytesPerSector:      DW 512
bpbSectorsPerCluster:   DB 1
bpbReservedSectors:     DW 1
bpbNumberOfFATs:        DB 2
bpbRootEntries:         DW 224
bpbTotalSectors:        DW 2880
bpbMedia:               DB 0xF0
bpbSectorsPerFAT:       DW 9
bpbSectorsPerTrack:     DW 18
bpbHeadsPerCylinder:    DW 2
bpbHiddenSectors:       DD 0
bpbTotalSectorsBig:     DD 0
bsDriveNumber:          DB 0
bsUnused:               DB 0
bsExtBootSignature:     DB 0x29
bsSerialNumber:         DD 0xa0a1a2a3
bsVolumeLabel:          DB "MOS FLOPPY "
bsFileSystem:           DB "FAT12   "

However, when I try to open the disk using the ImDisk driver for virtual floppies, it says that the drive needs to be formatted. Is the code I'm using correct?

Hudson Worden
  • 2,263
  • 8
  • 30
  • 45
  • 1
    You are just missing the 3 bytes right before the above as @hobbs said. This is, btw, described in the [official doc from Microsoft - fatgen103.doc](http://msdn.microsoft.com/en-us/library/windows/hardware/gg463084.aspx). – Alexey Frunze May 05 '12 at 00:19
  • I do have the three byte jump maybe I should put it in the question. – Hudson Worden May 05 '12 at 14:25
  • 1
    How about the rest of it? Did you actually write the FAT sectors? – Hans Passant May 05 '12 at 14:31
  • No, I suppose that is the answer then. – Hudson Worden May 05 '12 at 14:32
  • Try a short jump: sector begins with `jmp short loader`, followed by `nop`, then go `bpbName` through `bsFileSystem`, then `loader:` and all your code and then the last 2 bytes of the 512-byte sector being 0x55 and 0xAA. These two must be at offsets 510 and 511 respectively. – Alexey Frunze May 05 '12 at 14:42
  • @Alex thank you so much it worked. If you put that in the answers I will make that the answer. Is there a reference that tells you how big instructions are? – Hudson Worden May 05 '12 at 19:19
  • Answer added. For instructions themselves the most definitive references are the CPU manuals from Intel and AMD. For the FAT and FAT-compatible bootsectors see the Microsoft's doc (mentioned above). They actually list both options (short jmp+nop and normal jmp), but there may be a bug somewhere (not in your code) and only the first (most common) is recognized. – Alexey Frunze May 05 '12 at 19:26

3 Answers3

2

You're missing the 3-byte jump instruction before the BPB. The bytes-per-sector word should be at offset 0x0b relative to the beginning of the disk, not at 0x08. The jump will go to the bootloader code which is after the BPB (and if the jump is short enough that it only requires two bytes, it's followed by a nop).

If a machine will never be booted from the disk, you can put any arbitrary values in those first three bytes, but it's traditional to have a jump anyway, that goes to a piece of code that prints something like This disk is not bootable and then halts the machine.

hobbs
  • 223,387
  • 19
  • 210
  • 288
2

Try a short jump: the sector begins with jmp short loader, followed by nop, then go bpbName through bsFileSystem, then loader: and all your code and then the last 2 bytes of the 512-byte sector being 0x55 and 0xAA. These two must be at offsets 510 and 511 respectively.

Alexey Frunze
  • 61,140
  • 12
  • 83
  • 180
1

You can find a complete implementation of a FAt12 driver in assembly here: Simple Operating System with Fat 12 Driver.

halfer
  • 19,824
  • 17
  • 99
  • 186
Hossein
  • 24,202
  • 35
  • 119
  • 224