Aufgabe 4: Kontextwechsel
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... | |
Detailed Description
Low-Level functionality required for context switching.
Class Documentation
struct StackPointer |
Function Documentation
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
).
- Parameters
-
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
- Returns
- Pointer to the latest data (which will be
pop
ped first) on the prepared stack
- Todo:
- Implement Function (and helper functions, if required)
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.
- Parameters
-
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
- Todo:
- Implement Method