Loading kernel from a bootsector
Posted: Tue Jan 14, 2014 9:41 pm
Hi guys. I'm creating a bootloader in NASM and I'm very new to this stuff. I had my friends and the internet help me in creating it but I'm really lost and confused. I made a kernel.asm file and a bootsector.asm file. I should be able to load my kernel file to the bootsector file. However, it doesn't load.
Here is my code:
I'm sure my load and reset functions are implemented well. I think there is something wrong in my .read function. I'm really confused.
Any answer would be very helpful.
Here is my code:
Code: Select all
[BITS 16]
[ORG 0x7C00]
mov [bootdrv], dl ;put drive number
;disable interrupt, set stack, enable interrupt
cli
mov ax, 0x9000
mov ss, ax
mov sp, 0
sti
...
*some code here nothing to do with loading
...
.load_kernel:
call read_kernel ; Load stuff from the bootdrive
jmp dword KERNEL_SEGMENT:0
read_kernel:
push ds
.reset:
mov ax, 0 ;reset disk
mov dl, [bootdrv] ;drive to reset
int 13h
jc .reset ;try again if fail
pop ds
.read:
push es ; save ES if there's something important in it
; load the "kernel" at KERNEL_SEGMENT:0
mov ax, KERNEL_SEGMENT
mov es, ax
xor bx, bx
; your kernel will have 512 bytes (1 sector) for now
mov al, 0x1
; get the saved drive number back to DL
mov dl, [bootdrv]
mov dh, 0x0 ; head 0
mov cl, 0x2 ; start reading from 2nd sector
; read
int 0x13
pop es ; restore ES
retn ; return and continue after call instruction
; fill up to 510 bytes with zeroes and ...
times 510-($-$$) db 0
; place the boot signature on the end
dw 0xAA55
Any answer would be very helpful.