Page 1 of 1

Triple fault in boot, Brokenthorn tutorials

Posted: Sat Sep 06, 2008 8:40 pm
by Troy Martin
I'm using parts of the Brokenthorn OSDev tutorials to write my own kernel in assembly. My OS starts to boot, but will crash after my "Loading kernel sectors....................." message with a triple fault. It happens in both Virtual PC and Bochs. Halp!

I've attached the .zip. Assemble k_main.asm and boot.asm with NASM. The bootloader expects the assembled k_main.asm to be called tboskrnl.sys.

Re: Triple fault in boot, Brokenthorn tutorials

Posted: Sun Sep 07, 2008 12:40 am
by neon
Add org 0x500 to the top of your k_main.asm file. This is where the bootloader loads your kernel image to.

Running it through Bochs, it seems its getting to your kernel just fine. Adding the above fixed it for me. (Although it did triple fault afterwords inside of your kernel...thats a different problem though)

If you are still unable to get it to work, can you please post the command line you use to assemble your kernel?

Re: Triple fault in boot, Brokenthorn tutorials

Posted: Sun Sep 07, 2008 9:04 am
by Troy Martin
Hehe, thanks neon. I'm a bit of an idiot.

It triple faults somewhere after the kernel starts, but before the LoadingMsg is printed. That's still in real mode though...

I use nasm -o tboskrnl.sys k_main.asm to assemble it with the latest version of NASM. I grabbed some of the code from the tutorial "Preparing for the kernel Part 1", just so you know.

Re: Triple fault in boot, Brokenthorn tutorials

Posted: Sun Sep 07, 2008 9:12 am
by inflater
Try this:

Replace "main" with this:

...

Code: Select all

main:
mov ax,cs         ; AX = your code segment
mov ds,ax         ;make ds equal
mov es,ax         ;same for ES
xor ax,ax           ;AX = 0000
mov ss,ax          ;SS = 0
mov sp,7C00h     ;SS:SP = 0:7C00, should be enough for the pmode switch
It's triplefaulting in rmode? :shock: I think the DS was set incorrectly, maybe that was the culprit why the loadingmsg didnt print.
BTW I think you'll not succeed in "read_kbd", since you don't have a valid IDT... ;) Maybe that is the culprit, too.

//EDIT: I've debugged your code, it seems to triplefault after the mov cr0,eax and jmp far. Disassembled code shows "selector 8 > GDT size limit".vGDT may be bad, but I think the A20 switching code is too small...
You're right, it doesnt display the msg after all... bootloader problem?

Re: Triple fault in boot, Brokenthorn tutorials

Posted: Sun Sep 07, 2008 9:40 am
by Troy Martin
I did some looking around, and different sites have different GDT values. I'd like to see some of your values and test them out.

Re: Triple fault in boot, Brokenthorn tutorials

Posted: Sun Sep 07, 2008 9:53 am
by neon
Commenting the call to read_kbd seems to fix it for me...Worked fine in both Bochs and Virtual PC.

I am thinking inflater is right. If any interrupt is triggered in protected mode it will surely triple fault without a valid IDT. I would recommend creating a new IDT and remapping the PIC before attempting to develop the keyboard driver.

Also, your GDT is fine :)

With regards to your A20 code, Bochs enables A20 by default so if you run into problems with other systems you may need to use another more portable method.

Re: Triple fault in boot, Brokenthorn tutorials

Posted: Sun Sep 07, 2008 10:12 am
by Troy Martin
I'm only using I/O ports for the keyboard driver, so how does that affect anything?

Also, tried that, still dies somewhere.

Re: Triple fault in boot, Brokenthorn tutorials

Posted: Sun Sep 07, 2008 10:57 am
by neon
Ah, your right. I think I found a problem though... You are mixing 16 bit and 32 bit code.

Move %include "k_studio.h" and your msg_name_ver varable inside of a 32 bit code section. ie:

Code: Select all

bits 32
%include "k_stdio.asm"
msg_name_ver db "TBOS version 0.2.1", 0x0D, 0x0A, 0
kernel:
Try this, in addition to the org 0x500 posted earlier.

Re: Triple fault in boot, Brokenthorn tutorials

Posted: Sun Sep 07, 2008 1:31 pm
by Troy Martin
Woohooo! Works now! I did a little once-over of the stdio routines to make some more checks, and I noticed that you used LF and not CRLF as a newline. Very *n?x of you. :)

EDIT: Contrary to what was said about my read_kbd routine, it's stable with no alterations! The only thing is I need to advance the cursor when the letter is typed out!