Hangs on Real Machine and in Bochs?

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
Jubbens

Hangs on Real Machine and in Bochs?

Post 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
User avatar
Neo
Member
Member
Posts: 842
Joined: Wed Oct 18, 2006 9:01 am

Re:Hangs on Real Machine and in Bochs?

Post by Neo »

Why don't you try writing something from you bootloader first?
Only Human
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:Hangs on Real Machine and in Bochs?

Post 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 ?
User avatar
bubach
Member
Member
Posts: 1224
Joined: Sat Oct 23, 2004 11:00 pm
Location: Sweden
Contact:

Re:Hangs on Real Machine and in Bochs?

Post 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
"Simplicity is the ultimate sophistication."
http://bos.asmhackers.net/ - GitHub
B.E

Re:Hangs on Real Machine and in Bochs?

Post 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.
Jubbens

Re:Hangs on Real Machine and in Bochs?

Post by Jubbens »

That BIOS call sets CF on error....but what would give me 0x09? How do I test it?
B.E

Re:Hangs on Real Machine and in Bochs?

Post by B.E »

the bios returns the error code in ah
AR

Re:Hangs on Real Machine and in Bochs?

Post 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.
Jubbens

Re:Hangs on Real Machine and in Bochs?

Post 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.
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:Hangs on Real Machine and in Bochs?

Post 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)
B.E

Re:Hangs on Real Machine and in Bochs?

Post by B.E »

You could something on the display when ah is non zero.
Jubbens

Re:Hangs on Real Machine and in Bochs?

Post 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.
B.E

Re:Hangs on Real Machine and in Bochs?

Post 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
Jubbens

Re:Hangs on Real Machine and in Bochs?

Post 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"?
AR

Re:Hangs on Real Machine and in Bochs?

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