StuBS
|
Low-Level functionality required for context switching. More...
Classes | |
struct | StackPointer |
Structure for saving the stack pointer when switching coroutines. More... | |
Functions | |
void * | prepareContext (void *tos, void(*kickoff)(void *), void *param1=nullptr) |
Prepares a context for its first activation. More... | |
void | context_switch (StackPointer ¤t, StackPointer &next) |
Executes the context switch. More... | |
void | context_go (StackPointer &next) |
Executes a thread for the very first time. More... | |
Low-Level functionality required for context switching.
struct StackPointer |
void * prepareContext | ( | void * | tos, |
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.
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) |
kickoff | Pointer to the Thread::kickoff function |
param1 | first parameter for Thread::kickoff function |
pop
ped first) on the prepared stack void context_switch | ( | StackPointer & | current, |
StackPointer & | next | ||
) |
Executes the context switch.
For a clean context switch, the current register values must be stored to the currently active stack and the stack pointer must be stored to the current
StackPointer structure. Subsequently, these values must be restored accordingly from the next
stack.
This function must be implemented in assembler in the file context.asm
. It must be declared as extern "C"
, as assembler functions are not C++ name mangled.
current | Pointer to the structure that the current stack pointer will be stored in |
next | Pointer to the structure that the next stack pointer will be read from |
void context_go | ( | StackPointer & | next | ) |
Executes a thread for the very first time.
For a clean startup, the current register values must be restored accordingly from the next
stack.
This function must be implemented in assembler in the file context.asm
. It must be declared as extern "C"
, as assembler functions are not C++ name mangled.
next | Pointer to the structure that the next stack pointer will be read from |