Weird task switching bug

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
yucarp
Member
Member
Posts: 39
Joined: Fri Dec 05, 2025 5:19 pm
Libera.chat IRC: yucarp

Weird task switching bug

Post by yucarp »

When I load and change the cr3 register the stack pointer suddenly increases by 0x120. That eventually causes a memory spill and triple fault. Commenting the mov %r11, %cr3 makes it work fine but stack pointer goes to random places when I remove the comment. Any clues what causes this?
Attachments
mmu.c
(6.21 KiB) Downloaded 33 times
irq.asm
(1.61 KiB) Downloaded 30 times
task.c
(2.13 KiB) Downloaded 26 times
yucarp
Member
Member
Posts: 39
Joined: Fri Dec 05, 2025 5:19 pm
Libera.chat IRC: yucarp

Re: Weird task switching bug

Post by yucarp »

This bug has to do with the APIC timer, when setting the timer correct the bug was fixed
User avatar
savoita
Posts: 11
Joined: Fri Aug 29, 2025 11:12 am

Re: Weird task switching bug

Post by savoita »

Can you elaborate on what you mean by "setting the timer right" ? Might be useful for others in the future.
Be kind.
yucarp
Member
Member
Posts: 39
Joined: Fri Dec 05, 2025 5:19 pm
Libera.chat IRC: yucarp

Re: Weird task switching bug

Post by yucarp »

Ah, my bad... So I was measuring time with TSC but it was giving unaligned values (for example 13241). Instead I aligned the time (for example 13000) and it works perfectly.
Octocontrabass
Member
Member
Posts: 6249
Joined: Mon Mar 25, 2013 7:01 pm

Re: Weird task switching bug

Post by Octocontrabass »

How did that change fix the bug? It sounds an awful lot like the bug is still there and you've only made it less likely to occur.
Post Reply