twizzler-operating-system / twizzler

The Twizzler Operating System
BSD 3-Clause "New" or "Revised" License
62 stars 13 forks source link

Fix handling of aarch64 system state when switching threads #164

Closed PandaZ3D closed 6 months ago

PandaZ3D commented 6 months ago

Two small issues were addressed here that prevented user threads from being switched back and forth. One was that certain system registers were not being saved (e.g. the user thread local storage register). We save system registers upon thread entry to handle an exception, and during a context switch between threads. We take inspiration from FreeBSD for the latter, and save the user thread local storage variables there.

Another was the context switch code for aarch64 assumed that it was called as a subroutine which assumed the return address of the caller was saved in the link register. At the end of the routine, the code would call ret. The issue was that the compiler would inline this function, making our assumptions incorrect and causing an infinite loop. We fixed this by not inlining the context switch code with the inline(never) macro.

The only other change was to comment out the enumeration of NVMe from within the Pager since unlike the Device Manager, it crashes if no NVMe controller is found. The current virt device (aarch64) emulated supports NVMe, but the option is not enabled. It seems unnecessary for the Pager to require this functionality so I opted to comment it out.

With these changes, the ARM port now reaches the user prompt printed by the init program waiting for user input. The actual user input processing requires an interrupt driven serial device to place bytes in the console among other things which is future work.

Summary