StuBS
|
Low-Level functionality required for context switching. More...
Classes | |
struct | Context |
Structure for saving the CPU context when switching coroutines. More... | |
Functions | |
void | prepareContext (void *tos, Context &context, void(*kickoff)(void *), void *param1=nullptr) |
Prepares a context for its first activation. | |
void | context_switch (Context *current, Context *next) |
Executes the context switch. | |
void | context_launch (Context *next) |
Launch context switching. | |
Low-Level functionality required for context switching.
void context_launch | ( | Context * | next | ) |
Launch context switching.
To start context switching, the current context (from the boot-routines) is thrown away and the prepared register values within the given next
context replace it.
This function must be implemented in assembler in the file context.asm
(why?). It must be declared as extern "C"
, so assembler functions are not C++ name mangled.
next | Pointer to the structure that the next context will be read from |
Executes the context switch.
For a clean context switch, the current register values must be stored in the given context struct. Subsequently, these values must be restored accordingly from the next
context struct.
This function must be implemented in assembler in the file context.asm
(why?). It must be declared as extern "C"
, so assembler functions are not C++ name mangled.
current | Pointer to the structure that the current context will be stored in |
next | Pointer to the structure that the next context will be read from |
void prepareContext | ( | void * | tos, |
Context & | context, | ||
void(*)(void *) | kickoff, | ||
void * | param1 = nullptr ) |
Prepares a context for its first activation.
To allow the execution to start in Thread::kickoff during the first activation, the stack must be initialized such that it contains all the information required. This is, most importantly, the function to be called (typically the respective implementation of Thread::kickoff) and any parameters required by this function.
Additionally to the stack, the initial context is setup in a way that context_switch and context_launch can work with it.
prepareContext()
can be implemented in the high-level programming language C++ (in file context.cc
).
tos | Pointer to the top of stack (= address of first byte beyond the memory reserved for the stack) |
context | Reference to the Context structure to be filled |
kickoff | Pointer to the Thread::kickoff function |
param1 | first parameter for Thread::kickoff function |