Task Switching in 64bit

2k Views Asked by At

In x86, you can use the TSS for task switching between running processes, however, it is recommended to use only one TSS (as you have to) and perform software task switching, especially if you want to port the kernel to other hardware which don't have TSS's.

In x86-64 (64 bit), there is no TSS (e.g. it doesn't do anything like in x86), so, how would someone go about doing task switching without it (since before, you would use at least one)?

2

There are 2 best solutions below

0
On BEST ANSWER

You would do it the same way you would do it on any other platform: you store the contents of the appropriate registers:

  • the stack pointer
  • the instruction pointer
  • whichever general-purpose registers are appropriate for the architecture
  • any other state you need to maintain (FPU/MMX/SSE registers, etc.)

for the task you're switching away from, and restore the same for the task you're switching to.

Often this is done by pushing all the state onto the stack you're switching from, and popping it off the stack you're switching to. This way, only the stack pointer needs to be passed around or managed by the kernel to track what's waiting in the background.

0
On

Actually, it seems there is a TSS in 64 bit mode, it just isn't used for hardware context switching; instead, it is just used to specify the kernel's stack if and when a transfer to a higher privilege level occurs.

You will still have to use software context switching, for changing control between different tasks, however.