[Sovled] Problem with 32 bit interrupt handling in C.
-
- Member
- Posts: 40
- Joined: Tue Jul 16, 2019 8:40 pm
[Sovled] Problem with 32 bit interrupt handling in C.
Hey again guys,
Well I decided to redo some of the HAL interface and the kernel but, now when I try to use interrupts it fails. With a triple fault, not sure why. Would someone please take a look at the code? To see if you guys can figure it out. I've been doing this for a few days and I must have made a stupid mistake without spotting it. Not sure which file that mistake could be in though. I would like to know why it keeps triple faulting when I use interrupts though.
Project Link boot32-barebones (Development Branch) : https://github.com/psimonson/boot32-bar ... evelopment
PS: The development branch is the one I'm working on. Also everything I modified is in the kernel directory, somewhere in there is where the problem is.
Thanks in advance,
Philip
Well I decided to redo some of the HAL interface and the kernel but, now when I try to use interrupts it fails. With a triple fault, not sure why. Would someone please take a look at the code? To see if you guys can figure it out. I've been doing this for a few days and I must have made a stupid mistake without spotting it. Not sure which file that mistake could be in though. I would like to know why it keeps triple faulting when I use interrupts though.
Project Link boot32-barebones (Development Branch) : https://github.com/psimonson/boot32-bar ... evelopment
PS: The development branch is the one I'm working on. Also everything I modified is in the kernel directory, somewhere in there is where the problem is.
Thanks in advance,
Philip
Last edited by psimonson1988 on Thu Dec 03, 2020 6:31 pm, edited 1 time in total.
Re: Problem with 32 bit interrupt handling in C.
"Here's my repository, pls debug"? That's new levels of not SSCCE...
Every good solution is obvious once you've found it.
Re: Problem with 32 bit interrupt handling in C.
Hahaha! I wish I had thought of that... would have have saved me loads of time!Solar wrote:"Here's my repository, pls debug"? That's new levels of not SSCCE...
Seriously though, my source code is available for anyone who wants to have a go debugging my mess
CuriOS: A single address space GUI based operating system built upon a fairly pure Microkernel/Nanokernel. Download latest bootable x86 Disk Image: https://github.com/h5n1xp/CuriOS/blob/main/disk.img.zip
Discord:https://discord.gg/zn2vV2Su
Discord:https://discord.gg/zn2vV2Su
Re: Problem with 32 bit interrupt handling in C.
So, what debugging hae you done so far?
(Hint - single-stepping under a debugger can be very instructive.)
(Hint - single-stepping under a debugger can be very instructive.)
-
- Member
- Posts: 40
- Joined: Tue Jul 16, 2019 8:40 pm
Re: Problem with 32 bit interrupt handling in C.
Are there any tutorials on how to debug a kernel in QEMU or could you help guide me if you've got the time? Because so far the only debugging I've done is on normal applications. Not sure how to debug a kernel in QEMU. Please help and thanks.
Re: Problem with 32 bit interrupt handling in C.
Your issue is that you have no assembly in your kernel or HAL at all.
Skylight: https://github.com/austanss/skylight
I make stupid mistakes and my vision is terrible. Not a good combination.
NOTE: Never respond to my posts with "it's too hard".
I make stupid mistakes and my vision is terrible. Not a good combination.
NOTE: Never respond to my posts with "it's too hard".
Re: Problem with 32 bit interrupt handling in C.
Did you miss the various bits of inline assembly code? What is missing that you think is necessary?rizxt wrote:Your issue is that you have no assembly in your kernel or HAL at all.
Re: Problem with 32 bit interrupt handling in C.
Literally, the Wiki states that you can't make an interrupt handler in C using just inline assembly.
Skylight: https://github.com/austanss/skylight
I make stupid mistakes and my vision is terrible. Not a good combination.
NOTE: Never respond to my posts with "it's too hard".
I make stupid mistakes and my vision is terrible. Not a good combination.
NOTE: Never respond to my posts with "it's too hard".
Re: Problem with 32 bit interrupt handling in C.
I can't find that statement, but it's obviously false. The only thing I can find on the subject shows you precisely how you could use inline assembler for this purpose or, even simpler, how to use "__attribute__((interrupt))".
It's true that the OP's interrupt handlers won't work correctly as they are written, because they don't include an "iret" instruction, but as the end with an infinite loop this would not cause the triple fault.
It's true that the OP's interrupt handlers won't work correctly as they are written, because they don't include an "iret" instruction, but as the end with an infinite loop this would not cause the triple fault.
Re: Problem with 32 bit interrupt handling in C.
https://wiki.osdev.org/Interrupt_Servic ... he_Problemiansjack stupidly wrote: I can't find that statement
Skylight: https://github.com/austanss/skylight
I make stupid mistakes and my vision is terrible. Not a good combination.
NOTE: Never respond to my posts with "it's too hard".
I make stupid mistakes and my vision is terrible. Not a good combination.
NOTE: Never respond to my posts with "it's too hard".
Re: Problem with 32 bit interrupt handling in C.
I still can't find that statement, just an example of how not to do it.
Re: Problem with 32 bit interrupt handling in C.
It results in a triple fault because ebp is pushed but never popped... CPU pops important registers back from the stack and since the stack is corrupted it faults.
Skylight: https://github.com/austanss/skylight
I make stupid mistakes and my vision is terrible. Not a good combination.
NOTE: Never respond to my posts with "it's too hard".
I make stupid mistakes and my vision is terrible. Not a good combination.
NOTE: Never respond to my posts with "it's too hard".
Re: Problem with 32 bit interrupt handling in C.
So, as shown further down in that article, you either use inline assembler to insert the correct instructions or you use the directive. It's not the way I would do it, as I'm not a fan of inline assembler, but it can be done.
In this case, as the interrupt routine never tried to return, it's unlikely to be the cause of the triple fault.
In this case, as the interrupt routine never tried to return, it's unlikely to be the cause of the triple fault.
-
- Member
- Posts: 797
- Joined: Fri Aug 26, 2016 1:41 pm
- Libera.chat IRC: mpetch
Re: Problem with 32 bit interrupt handling in C.
As Ianjacks point out there is the __attribute__((interrupt)) that was introduced in GCC 7+. Unfortunately it has some restrictions that may be a problem for some kind of interrupts. If you want reliable access to the state of *all* the registers as they were before the interrupt was called - you can't. There is a mechanism that does work on old and new GCC and that is to write the entry point to an interrupt in pure basic inline assembly at global scope and then have that call into C code. That can be found here: https://stackoverflow.com/a/43311525/3857942 . You can then create C macros to generate these stubs for a large number of entries for ISRs and IRQs. Although the sample code doesn't pass a parameter to the handlers that can be added. That code in the answer was meant as a simplification and meant to show how this can be done.