Trying to get myself more acquainted with bootloaders and x86 encoding/system programming. Am I correct in thinking that the use of a NOP before a OEM parameter block would be done so the first executed instruction was aligned to an even byte in memory?
I think I counted this correctly, with the OEM block being 41 bytes. If NOP was not there the first instruction executed would be 43 bytes after but is instead 44 bytes.
If not then any ideas? Reading the bootloader code from MikeOS which states:
jmp short bootloader_start ; Jump past disk description section
nop ; Pad out before disk description
OEMLabel db "MIKEBOOT" ; Disk label
BytesPerSector dw 512 ; Bytes per sector
SectorsPerCluster db 1 ; Sectors per cluster
ReservedForBoot dw 1 ; Reserved sectors for boot record
NumberOfFats db 2 ; Number of copies of the FAT
RootDirEntries dw 224 ; Number of entries in root dir
LogicalSectors dw 2880 ; Number of logical sectors
MediumByte db 0F0h ; Medium descriptor byte
SectorsPerFat dw 9 ; Sectors per FAT
SectorsPerTrack dw 18 ; Sectors per track (36/cylinder)
Sides dw 2 ; Number of sides/heads
HiddenSectors dd 0 ; Number of hidden sectors
LargeSectors dd 0 ; Number of LBA sectors
DriveNo dw 0 ; Drive No: 0
Signature db 41 ; Drive signature: 41 for floppy
VolumeID dd 00000000h ; Volume ID: any number
VolumeLabel db "MIKEOS "; Volume Label: any 11 chars
FileSystem db "FAT12 " ; File system type: don't change!
NOP is here because the BIOS Parameter Block (BPB) must have definite placement (yes, alignment aware). NOP is inserted in case the first instruction is short jump, so that totally there should be 3 bytes. If you use near jump, there won't be NOP in that place.
You may ask, if the NOP may be replaced by any other byte? The answer is "no". According to an official FAT documentation NOP must be there in the case of short jump used. And many programs rely on that fact to detect that this is the FAT12 file system.
Yoda wrote:NOP is here because the BIOS Parameter Block (BPB) must have definite placement (yes, alignment aware). NOP is inserted in case the first instruction is short jump, so that totally there should be 3 bytes. If you use near jump, there won't be NOP in that place.
You may ask, if the NOP may be replaced by any other byte? The answer is "no". According to an official FAT documentation NOP must be there in the case of short jump used. And many programs rely on that fact to detect that this is the FAT12 file system.