开发者

Question about the bootloader

I am following the brokenthorn operating development series to study about bootloader. In this page , these are the three line of code :

bits    16  ; We are still in 16 bit Real Mode
org     0x7c00  ; We are loaded by BIOS at 0x7C00
start:      jmp loader ; jump over OEM block

In second line He loaded the bios at 7c00 in floppy. why not on 0000? I checked at Where to store the bootloader on a floppy image?. Here also the same thing has given. But the reason has not explained. Can anybody explain this to me please? Thanks in advance.

EDIT : I am getting confused because in the same site in a later tutorial the codes are :

bits    16  ; we are in 16 bit real mode

org  0   ; we will set regisers later

start:  jmp main ; jump to start of bootloader

and then in main

main:

     ;----------------------------------------------------
     ; code located at 0000:7C00, adjust segment registers
     ;---------------------------------------------开发者_高级运维-------

          cli           ; disable interrupts
          mov     ax, 0x07C0    ; setup registers to point to our segment
          mov     ds, ax
          mov     es, ax
          mov     fs, ax
          mov     gs, ax

Now here why he used org 0? And then why he copied the address to all the registers? Sorry if this is a foolish question. I am very new to assembly programming and just started to read about the bootloaders.


I think you might be conflating two different things. The bootloader lives at the beginning of the floppy (which is I guess where you get the 0000 from), but the BIOS copies it into memory at address 7c00 before it runs it.

The 'org' tells the assembler that that's where the code is going to run from, after it's been copied.


Here it says:

BIOS developer team decided 0x7C00 because:

  1. They wanted to leave as much room as possible for the OS to load itself within the 32KiB.
  2. 8086/8088 used 0x0 - 0x3FF for interrupts vector, and BIOS data area was after it.
  3. The boot sector was 512 bytes, and stack/data area for boot program needed more 512 bytes.
  4. So, 0x7C00, the last 1024B of 32KiB was chosen.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜