Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
928 views
in Technique[技术] by (71.8m points)

assembly - How does the bios know what type of BPB is present?

If I want my bootloader to boot from a usb stick, I have to include a BPB. The usb stick is running in floppy emulation mode. As seen here, there are many different BPB versions. How does the bios know what type of BPB is present? GRUB 0.97 seem to be using yet another BPB format ?

I can pad my bootloader from offset 0xb a little, and then it will also work. Is there a standard/common size to use? I am not using any filesystem on my USB, just raw.

I guess I need the BPB because the bios tries to update some on the values, which overwrite some of the code. Since every BPB seems a little different, how can the bios know where to update what value?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Not all BIOS implementations care if you have a BPB. The general format for the BPB with the beginning of an MBR boot sector is below:

bits 16
org 0                   ; BIOS will load the MBR to this location.

    bootStart:
            jmp     _start
            nop
            osType      db  'MSDOS6.0'
            bpb
            bps         dw  512
            spc         db  8
            rs          dw  1
            fats        db  2
            re          dw  512
            ss          dw  0
            media       db  0xf8
            spfat       dw  0xc900
            spt         dw  0x3f00
            heads       dw  0x1000
            hidden      dw  0x3f00, 0
            ls          dw  0x5142,0x0600
            pdn         db  0x80
            cheads          db  0
            sig         db  0x29
            serialno    dw  0xce13, 0x4630
            label       db  'NO NAME'
            fattype     db  "FAT32"

    _start:
                                ; set up the registers
            mov     ax, 0x07c0
            mov     ds, ax
            mov     fs, ax
            mov     gs, ax
            mov     ax, 0x0700
            mov     es, ax

The fields are always in the same place.. The way that the system, if it cares about the BPB, verifies it is simply by parsing it.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...