Why these codes aren't work?

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.
Post Reply
SmartBoy

Why these codes aren't work?

Post by SmartBoy »

Hello ..

finally , the first try to write boot sector load kernel :) i wrote it using NASM and this is my code :

The boot sector :

Code: Select all

; The boot sector

jmp 07C0h:load
      
load:   
   mov   ax,0x100
   mov es,ax ; don't forget this agian !
   mov bx,0
   mov ah,2
   mov al,1
   mov ch,0
   mov cl,2
   mov dh,0
   mov dl,0
   int 13h
   
   jc print_err    ; Oh , error ok try again !
   
   jmp 0x100:0 ; Woooooooooooow , Load the kernel
   
print_err:
   mov    ah,0Eh
   mov    bx,07h
   mov    al,'e'
   int    10h
   jmp      load

times 510-($-$$) db 0
dw 0AA55h
the kernel

Code: Select all

; I want it in C :(
; However , it's kernel :)
; Just print Hello .

[BITS 16]
ORG 0

mov ax,0x100
mov ds,ax
mov es,ax
mov ax,0x9000
mov ss,ax
mov sp,0xffff

mov    ah,0Eh
mov    bx,07h
mov    al,'H'
int    10h

mov    ah,0Eh
mov    bx,07h
mov    al,'e'
int    10h

mov    ah,0Eh
mov    bx,07h
mov    al,'l'
int    10h

mov    ah,0Eh
mov    bx,07h
mov    al,'l'
int    10h

mov    ah,0Eh
mov    bx,07h
mov    al,'o'
int    10h

mov    ah,0Eh
mov    bx,07h
mov    al,'!'
int    10h
i make the image using this command : "cat boot.bin kernel.bin | dd of=image bs=512 conv=notrunc"

and try the image using qemu , but it's don't work , i mean it's don't load the kernel and print Hello! . Why ? ???

Sorry for my bad English :-[
killedbydeath

Re:Why these codes isn't work?

Post by killedbydeath »

First of all don't make an image.
Assemble both your files and
dd if=boot.bin of=/dev/fd0 (or /dev/sd0 if you have SCSI)
then
dd if=kernel.bin obs=512 seek=1 of=/dev/fd0
also,

setup a stack in the bootloader and push ax into stack before you use it as a parameter in int 13h. then pop it off the stack and point your data segment to address 0x100
so before you do jmp 0x100:0 make a
mov ds,ax ; DS=0x100
BUT MAKE SURE THAT AX=0x100 if you're not sure with your stack
just do a mov ax,0x100 before you fill in ds. (that helped me solve a similar problem once ;D)
Best Regards
B.E

Re:Why these codes aren't work?

Post by B.E »

Also with the boot loader you havn't spefied the starting address of where everything is. Moreover you do not have the line

Code: Select all

[ ORG 0x7C00 ]
It may also be this line. What is the point of it.

Code: Select all

jmp 07C0h:load
if you realy want it, try

Code: Select all

jmp load
Post Reply