Page 1 of 1
kernel troubles
Posted: Tue Nov 05, 2002 6:24 pm
by elias
ive finally got my boot loader ot boot off the disk. the onyl prob is my test kernl prints out junk. wats wrong with my code?
boot loader code:
[ORG 7C00h]
jmp start
start:
push cs
pop ds
mov ax, 0000h
mov ss, ax
mov sp, 7BEFh
mov ah, 02h
mov al, 01h
mov ch, 00h
mov cl, 02h
mov dh, 00h
mov bx, 0800h
mov es, bx
mov bx, 0000h
int 13h
jmp 0800h:0000h
times 472 db 0
sig1 db 55h
sig2 db 0xAA
kernle code:
[ORG 0]
jmp print
msg db 'kernel succesfully loaded', 0
print:
mov ah, 0Eh
lea si, [msg]
str_loop:
lodsb
cmp al, 0
jz end
int 10h
jmp str_loop
end:
ret
Re:kernel troubles
Posted: Tue Nov 05, 2002 6:48 pm
by PlayOS
Hi,
To put it simply you should compare your code with mine and see the differences:
Boot.asm
Code: Select all
[ORG 7C00h]
jmp start
start:
mov ax, cs
mov ds, ax
mov ax, 0000h
mov ss, ax
mov sp, 7BFEh
mov ah, 02h
mov al, 01h
mov ch, 00h
mov cl, 02h
mov dh, 00h
mov bx, 0800h
mov es, bx
mov bx, 0000h
int 13h
jmp 0800h:0000h
times 510-($-$$) db 0
sig dw 0xaa55
Kernel.asm
Code: Select all
[ORG 0]
mov ax, 0800h
mov ds, ax
mov es, ax
call print
jmp $
msg db 'kernel succesfully loaded', 0
print:
mov ah, 0Eh
mov si, msg
str_loop:
lodsb
cmp al, 0
je end
int 10h
jmp str_loop
end:
ret
Some changes were not needed, but I done them for more clarification. This definately works running in bochs.
Hope this helps.
Re:kernel troubles
Posted: Wed Nov 06, 2002 8:12 am
by elias
so basically my only prob was lack of a data segment?
Re:kernel troubles
Posted: Wed Nov 06, 2002 8:27 am
by PlayOS
Basically, Yes.
Re:kernel troubles
Posted: Wed Nov 06, 2002 6:42 pm
by elias
i tried your code, but now nothing is printed instead of junk. shouldnt org be 8000h cuz thats where the kernel is loaded? and also, should the ds and es be at 8000h isntead of 0800h? ive tried these changes, but they also dont work.
Re:kernel troubles
Posted: Wed Nov 06, 2002 6:43 pm
by elias
i also forgot to add, is the ss and sp still be set, and work for all code in real mode? since the boot sector set it?
Re:kernel troubles
Posted: Wed Nov 06, 2002 6:50 pm
by Tom
if in real mode try this code:
; NOTE: There might be a bug in this code that prints 1 extra
; junk character at the end.
mov si, msg ; Print msg
print:
lodsb ; AL=memory contents at DS:SI
cmp al, 0 ; If AL=0 then hang
je hang
mov ah, 0Eh ; Print AL
mov bx, 7
int 10h
jmp print ; Print next character
Re:kernel troubles
Posted: Wed Nov 06, 2002 8:18 pm
by PlayOS
Because you never leave real mode the segment that you are in is 0x800 (0x8000 is the absolute physical address) so this is where you must stay, there are many other combinations of seg:offset that would be correct but this is where you explicitly loaded it to and you have org 0 so this is the only place that would work without changing your org.
You may need to CLD right before the print loop, as the DF flag may be incorrectly set. This worked on my machine running in bochs so the code definately works. Try putting CLD in just after mov si, msg.
And yes your stack will remain in effect until you explicitly change it.
hope this helps.