Page 1 of 1

PIC not working

Posted: Thu Feb 06, 2025 6:15 am
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.

Re: PIC not working

Posted: Thu Feb 06, 2025 11:19 am
by Octocontrabass
What is the value of RFLAGS when you expect the first IRQ0 to arrive?

Re: PIC not working

Posted: Thu Feb 06, 2025 11:30 am
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).

Re: PIC not working

Posted: Thu Feb 06, 2025 11:45 am
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.

Re: PIC not working

Posted: Thu Feb 06, 2025 4:14 pm
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.

Re: PIC not working

Posted: Thu Feb 06, 2025 4:57 pm
by Alula
The asm ("sti") fixed it!