Triple fault in boot, Brokenthorn tutorials

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
User avatar
Troy Martin
Member
Member
Posts: 1686
Joined: Fri Apr 18, 2008 4:40 pm
Location: Langley, Vancouver, BC, Canada
Contact:

Triple fault in boot, Brokenthorn tutorials

Post 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.
Attachments
os.zip
The troublesome OS...
(6.16 KiB) Downloaded 83 times
Image
Image
Solar wrote:It keeps stunning me how friendly we - as a community - are towards people who start programming "their first OS" who don't even have a solid understanding of pointers, their compiler, or how a OS is structured.
I wish I could add more tex
User avatar
neon
Member
Member
Posts: 1567
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Re: Triple fault in boot, Brokenthorn tutorials

Post 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?
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
User avatar
Troy Martin
Member
Member
Posts: 1686
Joined: Fri Apr 18, 2008 4:40 pm
Location: Langley, Vancouver, BC, Canada
Contact:

Re: Triple fault in boot, Brokenthorn tutorials

Post 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.
Image
Image
Solar wrote:It keeps stunning me how friendly we - as a community - are towards people who start programming "their first OS" who don't even have a solid understanding of pointers, their compiler, or how a OS is structured.
I wish I could add more tex
User avatar
inflater
Member
Member
Posts: 1309
Joined: Thu Sep 28, 2006 10:32 am
Location: Slovakia
Contact:

Re: Triple fault in boot, Brokenthorn tutorials

Post 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?
My web site: http://inflater.wz.cz (Slovak)
Derrick operating system: http://derrick.xf.cz (Slovak and English :P)
User avatar
Troy Martin
Member
Member
Posts: 1686
Joined: Fri Apr 18, 2008 4:40 pm
Location: Langley, Vancouver, BC, Canada
Contact:

Re: Triple fault in boot, Brokenthorn tutorials

Post 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.
Image
Image
Solar wrote:It keeps stunning me how friendly we - as a community - are towards people who start programming "their first OS" who don't even have a solid understanding of pointers, their compiler, or how a OS is structured.
I wish I could add more tex
User avatar
neon
Member
Member
Posts: 1567
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Re: Triple fault in boot, Brokenthorn tutorials

Post 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.
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
User avatar
Troy Martin
Member
Member
Posts: 1686
Joined: Fri Apr 18, 2008 4:40 pm
Location: Langley, Vancouver, BC, Canada
Contact:

Re: Triple fault in boot, Brokenthorn tutorials

Post 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.
Image
Image
Solar wrote:It keeps stunning me how friendly we - as a community - are towards people who start programming "their first OS" who don't even have a solid understanding of pointers, their compiler, or how a OS is structured.
I wish I could add more tex
User avatar
neon
Member
Member
Posts: 1567
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Re: Triple fault in boot, Brokenthorn tutorials

Post 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.
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
User avatar
Troy Martin
Member
Member
Posts: 1686
Joined: Fri Apr 18, 2008 4:40 pm
Location: Langley, Vancouver, BC, Canada
Contact:

Re: Triple fault in boot, Brokenthorn tutorials

Post 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!
Image
Image
Solar wrote:It keeps stunning me how friendly we - as a community - are towards people who start programming "their first OS" who don't even have a solid understanding of pointers, their compiler, or how a OS is structured.
I wish I could add more tex
Post Reply