Bochs keeps restarting

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
kutkloon7
Member
Member
Posts: 98
Joined: Fri Jan 04, 2013 6:56 pm

Bochs keeps restarting

Post by kutkloon7 »

Hello!

I am following the series on OSdev by Brokenthorn (probably like many people here), and I've ran into some trouble. When I try to install the GDT and switch to protected mode as explained in the 8th installment, Bochs keeps restarting, so I suppose I've ran into a triple fault.

After a bit of trying and rewriting my code I was tired, so I tried to assemble and run Brokenthorn's example code. It turns out Bochs behaves exactly the same way when I compile the provided example code! I have no idea what to do now. Could there be a fault in my stage 1 bootloader (seems unlikely), is it because I have a newer version of Bochs? How does the provided example code run for you guys? I could upload the floppy image or the flat binary somewhere if anyone thinks it will help.

BTW, I run win XP and have Bochs 2.6.2. The last lines of the Bochs logfile are:
  • 00014919114i[BIOS ] Booting from 0000:7c00
    00015991904e[CPU0 ] fetch_raw_descriptor: GDT: index (f) 1 > limit (0)
    00015991904e[CPU0 ] interrupt(): gate descriptor is not valid sys seg (vector=0x0d)
    00015991904e[CPU0 ] interrupt(): gate descriptor is not valid sys seg (vector=0x08)
    00015991904i[CPU0 ] CPU is in protected mode (active)
    00015991904i[CPU0 ] CS.mode = 16 bit
    00015991904i[CPU0 ] SS.mode = 16 bit
    00015991904i[CPU0 ] EFER = 0x00000000
    00015991904i[CPU0 ] | EAX=60000011 EBX=0000000f ECX=0009000f EDX=00000000
    00015991904i[CPU0 ] | ESP=0000ffff EBP=00000000 ESI=000e0538 EDI=000000c0
    00015991904i[CPU0 ] | IOPL=0 id vip vif ac vm RF nt of df if tf sf zf af PF cf
    00015991904i[CPU0 ] | SEG sltr(index|ti|rpl) base limit G D
    00015991904i[CPU0 ] | CS:3000( 0004| 0| 0) 00030000 0000ffff 0 0
    00015991904i[CPU0 ] | DS:0000( 0005| 0| 0) 00000000 0000ffff 0 0
    00015991904i[CPU0 ] | SS:9000( 0005| 0| 0) 00090000 0000ffff 0 0
    00015991904i[CPU0 ] | ES:0000( 0005| 0| 0) 00000000 0000ffff 0 0
    00015991904i[CPU0 ] | FS:0000( 0005| 0| 0) 00000000 0000ffff 0 0
    00015991904i[CPU0 ] | GS:0000( 0005| 0| 0) 00000000 0000ffff 0 0
    00015991904i[CPU0 ] | EIP=00000084 (00000084)
    00015991904i[CPU0 ] | CR0=0x60000011 CR2=0x00000000
    00015991904i[CPU0 ] | CR3=0x00000000 CR4=0x00000000
    00015991904i[CPU0 ] 0x0000000000000084>> jmp far 0008:0589 : EA89050800
    00015991904e[CPU0 ] exception(): 3rd (13) exception with no resolution, shutdown status is 00h, resetting
    00015991904i[SYS ] bx_pc_system_c::Reset(HARDWARE) called
Thanks in advance! I hope someone can help me.

BTW: Now reading this topic on this forum. Someone suggests that a IDT should be loaded. In the Brokenthorn tutorial, this is not yet done. It is not explicitly mentioned, but I suppose that the provided example code should assemble and run without errors.
User avatar
Jezze
Member
Member
Posts: 395
Joined: Thu Jul 26, 2007 1:53 am
Libera.chat IRC: jfu
Contact:

Re: Bochs keeps restarting

Post by Jezze »

Im writing this from my phone and i havent used bochs but I think you are getting a page fault 0xd. Have you set up a proper page fault handler? That would make it easier for you to figure out what address that causes it.
Fudge - Simplicity, clarity and speed.
http://github.com/Jezze/fudge/
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Bochs keeps restarting

Post by Combuster »

I think you are getting a page fault 0xd
Nope, nope, nope. The log makes it obvious that paging is off.

The error is printed in the log as such:
GDT: index (f) 1 > limit (0)
As in, the GDT has not been properly set up and has a limit of zero


Looking at the actual page, it becomes apparent that the problem starts off with
CS:3000
i.e. your code is stored and running at 0x00030000 and not at the 0x00000500 used by the tutorial. You then try to load the GDT from the location it's not actually loaded, resulting in an offset and length of zero.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
kutkloon7
Member
Member
Posts: 98
Joined: Fri Jan 04, 2013 6:56 pm

Re: Bochs keeps restarting

Post by kutkloon7 »

I feel a little bit stupid I haven't thought of that :oops:

If I have time tonight I'll try to get it working. Big thanks :wink:

Edit: It seems that simply changing org 0x0500 to org 0x0000 (or just removing the org directive) and changing ds to 0x3000, doesn't solve the problem. I just get approximately the same error.
  • 00030938265i[BIOS ] Booting from 0000:7c00
    00032038299e[CPU0 ] check_cs(0x0008): not a valid code segment !
    00032038299e[CPU0 ] interrupt(): gate descriptor is not valid sys seg (vector=0x0d)
    00032038299e[CPU0 ] interrupt(): gate descriptor is not valid sys seg (vector=0x08)
    00032038299i[CPU0 ] CPU is in protected mode (active)
    00032038299i[CPU0 ] CS.mode = 16 bit
    00032038299i[CPU0 ] SS.mode = 16 bit
    ...
    00032038299i[CPU0 ] 0x0000000000000087>> jmp far 0008:008c : EA8C000800
    00032038299e[CPU0 ] exception(): 3rd (13) exception with no resolution, shutdown status is 00h, resetting
    00032038299i[SYS ] bx_pc_system_c::Reset(HARDWARE) called
Just the second line is really different (except for the different data segment, and slightly different instruction pointer, which is because I had to add some commands because 0x3000 is harder to load then 0).
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Bochs keeps restarting

Post by Combuster »

jmp far 0008:008c : EA8C000800
0x0000008c isn't the same as 0x0003008c, and the same probably goes for the GDT.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
kutkloon7
Member
Member
Posts: 98
Joined: Fri Jan 04, 2013 6:56 pm

Re: Bochs keeps restarting

Post by kutkloon7 »

Thanks for your help. I'm quite confused though, I can't get it to work. I'm going to read some tutorials on the GDT, I don't feel I understand the topic well enough. I hope to make some progress and post an update in a few days.
kutkloon7
Member
Member
Posts: 98
Joined: Fri Jan 04, 2013 6:56 pm

Re: Bochs keeps restarting

Post by kutkloon7 »

If I load the stage 2 bootloader on 0000:0500h, everything works fine. Because this is done in all the sources/tutorials I checked, I will be doing this too.

I don't know, but I feel like it should be possible to load my stage 2 bootloader at 3000:0000h as I did before... But then my GDT becomes corrupted (my guess is that there's something wrong with a pointer to or in the GDT descriptor).
Post Reply