s-matyukevich / raspberry-pi-os

Learning operating system development using Linux kernel and Raspberry Pi
MIT License
12.98k stars 1.28k forks source link

[Lesson04] Raspberry Pi 4 interrupts not working after first call to timer_tick() #255

Closed archaro closed 1 year ago

archaro commented 1 year ago

I followed the advice given in issue #237 and was able to get my project behaving properly on a pi4, with the timer ticking nicely.

However, I've run into an odd problem with the scheduler. Using most of the code from Lesson04 I have built a primitive scheduler in my project, and things are now behaving strangely. Here is some output with helpful debugging printf()s:

Current Exception Level is: 1
Enabling interrupt 97
EnableRegister: ff84110c
About to call enable_irq()...
Calling switch_to()...
1234512345123451234512In handle_irq()...
In timer_tick()....
About to call enable_irq()...
Calling switch_to()...
abcdeabcdeabcdeabcdeabcdeabcd[...]

As you can see, everything is just peachy until timer_tick() is called by the interrupt handler. Thereafter, it seems that even though interrupts are re-enabled, the interrupt handler never gets called again. My handle_irq() function is using the fix described by @maxstreitberger in issue #237, and my timer_tick() function and enable_irq() assembler function are identical to those in Lesson04.

I'm very confused!

archaro commented 1 year ago

Ah, the wisdom of the rubber duck.

In handle_interrupt(), I had:

  switch (irq) {
    case (SYSTEM_TIMER_IRQ_1):
      handle_timer_irq();
      put32(GICC_EOIR, irq_ack_reg);
      break;

and what I actually needed was:

  switch (irq) {
    case (SYSTEM_TIMER_IRQ_1):
      put32(GICC_EOIR, irq_ack_reg);
      handle_timer_irq();
      break;

Order matters!