Page 1 of 1
Hangs on Real Machine and in Bochs?
Posted: Mon Apr 18, 2005 8:00 pm
by Jubbens
I wrote a simple "Hello World" bootloader and kernel. I've tried it in Bochs and on a real machine, but in both cases it reads the floppy but hangs before it prints the message. Bochsout doesn't provide any clues, except these lines:
00077417008e[HD ] device set to 0 which does not exist
00077417301e[HD ] device set to 1 which does not exist
But I don't suppose that matters much. Here's the bootloader and the kernel is attached. Compiled with FASM (no errors) and floppy'd with
partcopy boot.bin 0 200 -f0
partcopy kernel.bin 200 400 -f0
Code: Select all
; Bootloader
; _______________
; Set this up as our bootloader
org 0x7C00
use16
dw 0x55AA
; Load the second sector into RAM at 0x1000:0x0000 (64KB)
mov dl,0x00
mov bx,0x1000
mov es,bx
mov bx,0x0000
mov ch,0x01
mov cl,0x02
mov dh,0x01
mov al,0x01
mov cl,0x02
mov ah,0x02
int 0x13
; Set the kernel as our data segment
mov ax, 0x1000
mov ds, ax
; Jump to the kernel
jmp 0x1000:0x000
; Fill up the sector
times 512-($-$$)-2 db 0
Re:Hangs on Real Machine and in Bochs?
Posted: Mon Apr 18, 2005 9:28 pm
by Neo
Why don't you try writing something from you bootloader first?
Re:Hangs on Real Machine and in Bochs?
Posted: Tue Apr 19, 2005 1:12 am
by Pype.Clicker
at least, it doesn't come with "running in bogus memory", so it has (at least) managed to load something at the given location. I would say that's almost a miracle considering you didn't even bothered with checking return code from the BIOS loadsectors.
Also, without an 'ORG 0' statement, your kernel is might not locate its data properly.
0:500 looks like an odd location for the stack. You know the Bios data area isn't far from there. What about using e.g. 0:0x8000 instead ?
Re:Hangs on Real Machine and in Bochs?
Posted: Tue Apr 19, 2005 4:07 am
by bubach
Part of the problem may be that you don't use partcopy with the correct syntax:
USAGE:
PARTCOPY source source_offset length destination {destination_offset}
So what you want to do (for the kernel) is something like:
partcopy kernel.bin 0 500 -f0 200
where you replace 500 with the size of kernel.bin
Re:Hangs on Real Machine and in Bochs?
Posted: Tue Apr 19, 2005 4:51 am
by B.E
Pype.Clicker is right. Test the return value
It is likely that you get a 09h(ddata boundary error) error code. If so just change the segment so it is'nt x000h.
Re:Hangs on Real Machine and in Bochs?
Posted: Tue Apr 19, 2005 4:30 pm
by Jubbens
That BIOS call sets CF on error....but what would give me 0x09? How do I test it?
Re:Hangs on Real Machine and in Bochs?
Posted: Tue Apr 19, 2005 9:05 pm
by B.E
the bios returns the error code in ah
Re:Hangs on Real Machine and in Bochs?
Posted: Tue Apr 19, 2005 9:26 pm
by AR
Code: Select all
; Fill up the sector
times 512-($-$$)-2 db 0
Your boot signature has somehow ended up at the start instead of the end, unless FASM has some really weird assembling method the "dw 0x55AA" should be at the end not the start, I don't know what opcode 0x55AA is but that may be the problem.
Re:Hangs on Real Machine and in Bochs?
Posted: Tue Apr 19, 2005 9:37 pm
by Jubbens
Tried telling the kernel where it is.....no luck.
Tried moving boot sig to end...........no luck.
Tried fixing partcopy syntax.............no luck.
Thanks for the suggestions everyone. I guess the next step is seeing what int 13 returned as an error code in ah.
Re:Hangs on Real Machine and in Bochs?
Posted: Wed Apr 20, 2005 1:52 am
by Pype.Clicker
my guess would then be that you're reading the wrong sector (and i'm not going to lookup RBIL for you to check out in what register is track, head, sector, etc.)
I suggest you read the sectors right at 0xB8000:0 to see what you're actually loading (or use "xp 0x10000" in bochs debugger)
Re:Hangs on Real Machine and in Bochs?
Posted: Wed Apr 20, 2005 2:16 am
by B.E
You could something on the display when ah is non zero.
Re:Hangs on Real Machine and in Bochs?
Posted: Wed Apr 20, 2005 4:58 pm
by Jubbens
I added the following to my bootloader after the int 13 call:
Code: Select all
mov byte [strg1],ah
mov si,[strg1]
call print
strg1: db "", 0
It dumps "S " to the screen. The hex equivalent for that is 0x53. That's not on the return table for this interrupt.
S = 0x53 = Not on table
[space] = 0x20 = controller failue
http://www.ctyme.com/intr/rb-0606.htm#Table234
So what's going on here? I know I did something wrong.
Re:Hangs on Real Machine and in Bochs?
Posted: Wed Apr 20, 2005 8:47 pm
by B.E
Code: Select all
mov byte [strg1],ah
mov si,[strg1]
call print
strg1: db "", 0
change the line
strg1: db "", 0
to:
strg1: db " ", 0
and change the line
mov si,[strg1]
to:
mov si,strg1
Re:Hangs on Real Machine and in Bochs?
Posted: Thu Apr 21, 2005 9:16 pm
by Jubbens
I revised the code according to B.E, but nothing was printed. I turned it back to the original way and It did the "S " thing again. Then I looked in bochout.txt, and it contained about 5000 lines of
LOCK prefix unallowed (op1=0xd5, attr=0x1, mod=0x0, nnn=0)
the file was 40MB! But what does it mean by "lock prefix"?
Re:Hangs on Real Machine and in Bochs?
Posted: Thu Apr 21, 2005 11:01 pm
by AR
lock is an instruction to prevent other CPUs from accessing RAM whilst the current CPU is for one instruction (on an SMP system), that would imply that you've jumped into rubbish.
And of course B.E's fixes print nothing, there isn't anything in the quotes to be printed... If you want to print something then you'll have to actually put something in the string.