PIC not working

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
Alula
Posts: 2
Joined: Thu Feb 06, 2025 6:07 am

PIC not working

Post by Alula »

https://github.com/ApplePieCodes/lithium
Acording to my irq0, my OS should be printing Tick and Tock when the irq0 is triggered. It doesn't seem too.
Octocontrabass
Member
Member
Posts: 5695
Joined: Mon Mar 25, 2013 7:01 pm

Re: PIC not working

Post by Octocontrabass »

What is the value of RFLAGS when you expect the first IRQ0 to arrive?
sebihepp
Member
Member
Posts: 197
Joined: Tue Aug 26, 2008 11:24 am
GitHub: https://github.com/sebihepp

Re: PIC not working

Post by sebihepp »

The problem with your code on github is that you create idt_table_desc on the stack in function idt_reload() - once the function returns, the stack get overwritten by following functions and when the cpu is reading that descriptor later it gets garbage (random values based on which time it reads your descriptor).
Octocontrabass
Member
Member
Posts: 5695
Joined: Mon Mar 25, 2013 7:01 pm

Re: PIC not working

Post by Octocontrabass »

sebihepp wrote: Thu Feb 06, 2025 11:30 amwhen the cpu is reading that descriptor later
The CPU won't read that descriptor later so it's not a problem.
MichaelPetch
Member
Member
Posts: 813
Joined: Fri Aug 26, 2016 1:41 pm
Libera.chat IRC: mpetch

Re: PIC not working

Post by MichaelPetch »

Octocontrabass wrote: Thu Feb 06, 2025 11:19 am What is the value of RFLAGS when you expect the first IRQ0 to arrive?
Octo is correct in asking this. If you use the QEMU monitor you can do `info registers` while your kernel is in an infnite loop. If bit 9 in RFLAGS isn't set then interrupts are off and you won't receive them.

Upon looking at the code you don't actually enable interrupts. After you setup your interrupt handlers/idt you can use this to enable them

Code: Select all

__asm__ ("sti" ::: "memory");
Note: Your code will end up in a deadlock situation if an interrupt occurs during writing to the display using the `twrite_*` functions. There is a spinlock in the`twrite_*` functions that prevents multiple threads updating the display simultaneously. If you interrupt a `twrite_*` function and your interrupt tries to write to the display with a `twrite_*` function it will wait forever on the lock associated with display updates.
Alula
Posts: 2
Joined: Thu Feb 06, 2025 6:07 am

Re: PIC not working

Post by Alula »

The asm ("sti") fixed it!
Post Reply