开发者

booting from a disk/cd/usb

How can I boot my small console from a disk/cd/usb, with the following configuration:

  1. The m开发者_JAVA技巧edia that I want to use will be completely raw i.e no filesystem on it.
  2. When I insert the media in my system or assume that its already inserted, I want to make it boot my own small OS.

The procedure that I want to use is that when my system starts, it boots from the disk/cd/usb, and starts my OS. For now imagine that the OS is going to be a hello world program. I actually want to see how the real world OS implement themselves.


A bootloader must be 512 bytes. No less no more. And it must end with the standard PC boot signature: 0xAA55.

Also note a PC boots in 16 bits mode. You need to load your kernel or secondstage bootloader from that code into memory, and then jump to that code (and maybe switch the CPU to 32 bits protected mode).

For instance (nasm):

BITS 16

; Your assembly code here (510 bytes max)...
jmp $

; Fills the remaining space with 0
times 510 - ( $ - $$ ) db  0

; Boot signature
dw 0xAA55


Thas the job of a boot loader. The bootloader should be present in the first 512 bytes of a HardDisk. This location is called MBR(Master boot record)

  1. When bios loads it checks if the media contains the MBR. it verifies the MBR signature 0xAA55 which should be present as the last 2 bytes of MBR.

  2. Then the Bios loads the BootLoader into RAM at address 0x7C00

  3. Then the boot loader is the one who actually loads the kernal into memory, by reading the filesystem.

  4. usually you cannot fit in all the code in 512 bytes, so there will be a secondory boot loader.

  5. secondary bootloader will be loaded by your primary bootloader.

  6. secondary boot loader loads IDT and GDT (Interupt vector table and Global descriptor table). Enables A20 gate to move into protected mode.

  7. secondary boot loader loads the 32 bit kernel from disk into memory, then jumps to the kernel code

For more information you can download Linux kernel v0.01 (First version). Look how it is done. to my surprise the code to read the File system + the code to move into protected mode is fit into 512 bytes of code.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜