OSDev.org

The Place to Start for Operating System Developers
It is currently Fri Mar 29, 2024 8:34 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Exception handling code causes triple fault
PostPosted: Sat Jun 23, 2018 3:46 pm 
Offline
Member
Member
User avatar

Joined: Fri Apr 08, 2016 5:03 am
Posts: 132
Location: atapio.cpp - why won't you work :(
Hi :)

I finally decided to add a kernel panic screen to my OS instead of just printing out the error when I realized that I wasn't actually catching any exceptions (tested with a divide by zero code) :shock:

Instead, I would get a triple fault and reboot. All other interrupts seem to work (keyboard, syscalls, PIT, etc...) but my exception code doesn't seem to work :/

This is the code, every exception related ISR push their ID on the stack and an optional zero to keep the stack integrity when there is no additional code and calls it:
Code:
_asm_fault_handler:
    pusha
    push %ds
    push %es
    push %fs
    push %gs
    mov $0x10, %ax
    mov %ax, %ds
    mov %ax, %es
    mov %ax, %fs
    mov %ax, %gs
    movl %esp, %eax
    push %eax
    movl _fault_handler, %eax
    call *%eax
    pop %eax
    pop %gs
    pop %fs
    pop %es
    pop %ds
    popa
    add $8, %esp
    iret


I know it's a bit late in the development of my OS that I find out about this but I hope someone can help figure whats wrong :)

_________________
My github page: https://github.com/AlexandreRouma
Meme-deving since 420 Bc !
YouTube: https://www.youtube.com/channel/UCyJnOD ... C8Y7pccc6A
Twitter: https://twitter.com/WhatsTheGeekYT


Top
 Profile  
 
 Post subject: Re: Exception handling code causes triple fault
PostPosted: Sat Jun 23, 2018 4:03 pm 
Offline
Member
Member

Joined: Thu Apr 26, 2018 11:21 pm
Posts: 49
Are the entries for these specified in the IDT with an interrupt gate? I use an interrupt gate for all types of interrupts and exceptions because it ensures the IF flag is disabled immediately, so interrupts can't interrupt interrupts....

Also, exception handlers should probably do a check to see if the exception is in user code or kernel code (based on bottom 2 bits of IRET stack -> CS). If it's in kernel code you just call your standard text output functions and then HLT for the effect of a panic in text mode (and interrupts should also be disabled at that point)


Top
 Profile  
 
 Post subject: Re: Exception handling code causes triple fault
PostPosted: Sat Jun 23, 2018 4:38 pm 
Offline
Member
Member
User avatar

Joined: Fri Apr 08, 2016 5:03 am
Posts: 132
Location: atapio.cpp - why won't you work :(
rwosdev wrote:
Are the entries for these specified in the IDT with an interrupt gate? I use an interrupt gate for all types of interrupts and exceptions because it ensures the IF flag is disabled immediately, so interrupts can't interrupt interrupts....

Also, exception handlers should probably do a check to see if the exception is in user code or kernel code (based on bottom 2 bits of IRET stack -> CS). If it's in kernel code you just call your standard text output functions and then HLT for the effect of a panic in text mode (and interrupts should also be disabled at that point)


Yeah, they are all specified, the divide by zero exception for example is:

Code:
encodeIdtEntry(&_IDT[8 * 0x00], (uint32_t)&_isr0, 0x08, INT_GATE);


And I'm still running everything in ring 0 lol, but thanks for the advice :)

_________________
My github page: https://github.com/AlexandreRouma
Meme-deving since 420 Bc !
YouTube: https://www.youtube.com/channel/UCyJnOD ... C8Y7pccc6A
Twitter: https://twitter.com/WhatsTheGeekYT


Top
 Profile  
 
 Post subject: Re: Exception handling code causes triple fault
PostPosted: Sun Jun 24, 2018 10:11 am 
Offline
Member
Member
User avatar

Joined: Fri Apr 08, 2016 5:03 am
Posts: 132
Location: atapio.cpp - why won't you work :(
UPDATE !

This was apparently a error on my part when I tried to convert the NASM tutorial I was following to GAS ^^

This is the now working code:
Code:
isr_common_stub:
    pusha
    push %ds
    push %es
    push %fs
    push %gs
    movw $0x10,%ax
    movw %ax,%ds
    movw %ax,%es
    movw %ax,%fs
    movw %ax,%gs
    movl %esp,%eax
    pushl %eax
    movl $_fault_handler, %eax
    call *%eax
    popl %eax
    popl %gs
    popl %fs
    popl %es
    popl %ds
    popa
    addl $8,%esp
    iret

_________________
My github page: https://github.com/AlexandreRouma
Meme-deving since 420 Bc !
YouTube: https://www.youtube.com/channel/UCyJnOD ... C8Y7pccc6A
Twitter: https://twitter.com/WhatsTheGeekYT


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot] and 161 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group