Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
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.
[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
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.
thanks for the reply.
well, i really dont understand cylinder header that i'm hearing from others. I'm having a hard time understanding the locations of what must be passed around. can you run my code?
lol wrote:thanks for the reply.
well, i really dont understand cylinder header that i'm hearing from others. I'm having a hard time understanding the locations of what must be passed around.
As previously suggested, look up the required parameters for int 13h. It expects certain pieces of information to be passed in certain registers; if you don't know what those are, you're not going to be able to proceed any further. Also google CHS addressing and LBA addressing if you need to understand how to address a particular sector on a disk. CHS is obsolete and generally only useful if you want to boot from a floppy disk (also obsolete), but it's worth knowing anyway.
can you run my code?
Given that it's incomplete, that would be pointless.
Those who understand Unix are doomed to copy it, poorly.
Try to be more careful when establishing what is needed. Read the Int 13h Function 2 carefully. The provided code most probably is not even issuing the correct BIOS call; try to see why. Additionally, you should be using sector 2, head 0, cylinder 0. Read more up on CHS and converting LBA to CHS here.
All of these issues can be resolved by reading the information more carefully.
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}