Boot loader explanation?
Posted: Sun Sep 13, 2009 6:12 am
I found this tutorial about boot loaders, located at http://inglorion.net/documents/tutorial ... ootsector/, but it left me with some questions:
Here's the bootloader source. I've commented every action with what I gather from the tutorial it does. Please do let me know if I assume wrong somewhere.
However, I know I don't understand the following:
Thanks in advance.
Here's the bootloader source. I've commented every action with what I gather from the tutorial it does. Please do let me know if I assume wrong somewhere.
However, I know I don't understand the following:
- The"xor bx, bx" command
- Why CL is set to 1
- Why DH is set to 0
Code: Select all
[BITS 16] ;tell the assembler that its a 16 bit code
[ORG 0x7C00] ;Origin, tell the assembler that where the code will
;be in memory after it is been loaded
; Kernel info
KERNEL_START equ 1 ; Disk block where kernel starts
KERNEL_SIZE equ 1 ; Kernel size in disk blocks
KERNEL_SEGMENT equ 1000h ; Segment where kernel will be loaded
; Load kernel
mov ax, 200h + KERNEL_SIZE ; Set AH to 2 (OPcode to read), and AL to KERNEL_SIZE
push word KERNEL_SEGMENT ; Send KERNEL_SEGMENT to stack
pop es ; Retrieve KERNEL_SEGMENT from stack and store in ES,
; which is where "int 13h" will look for the segment to read from.
xor bx, bx ; I don't understand this, but since BX is the offset,
; I assume this somehow sets BX = 0?
mov cx, KERNEL_START + 1 ; Set CH = KERNEL_START, Set CL = 1 (Why?)
mov dx, 0 ; Set head = 0 (Why?), Set drive number = 0 (Floppy A)
int 13h ; Invoke BIOS to OPcode(2:Read), flag if error.
jnc ok ; Jump to ok: if not carry flag
jmp $ ; Infinite loop if carry flag
ok:
jmp KERNEL_SEGMENT:0 ; Jump to Kernel, located at 1000h with offset 0
TIMES 510 - ($ - $$) db 0 ; Fill the rest of sector with 0
DW 0xAA55 ; Add boot signature at the end of bootloader