I'm working on adding multitasking to my OS and so far my scheduler is coming along okay, but I'm having problems with understanding a specific concept related to context switching.
So, my scheduler crashes (i386) when the thread list looks like this:
Code: Select all
[Sun Feb 16 15:43:12 2025] [CPU0] [DBG ] [TASK:SCHED] Reschedule thread 0x54e810 to back of queue (owned by 'init')
[Sun Feb 16 15:43:12 2025] [CPU0] [DBG ] [TASK:SCHED] New thread list:
[Sun Feb 16 15:43:12 2025] [CPU0] [DBG ] [TASK:SCHED] Thread 0x54e1c0 - owned by process 'kthread2' (pid 2 prio 2)
[Sun Feb 16 15:43:12 2025] [CPU0] [DBG ] [TASK:SCHED] Thread 0x54df40 - owned by process 'kthread' (pid 1 prio 2)
[Sun Feb 16 15:43:12 2025] [CPU0] [DBG ] [TASK:SCHED] Thread 0x54e810 - owned by process 'init' (pid 0 prio 3)
However, when I switch to kthread from kthread2, the entire system triple faults - I quickly tracked this down to be because of ESP being no longer valid when switching to kthread's page directory. But this makes total sense - kthread2 had a stack allocated in its page directory AFTER kthread was created.
The weird part is this approach works on x86_64 (targeting both architectures) - it just doesn't care. I'm really confused because I can't find any information for this (or I'm just bad at looking
