Struct toc

Struct toc

Placement in the overall structure

Module
machine
Time of creation
Task 4 (partly predefined)
Files
toc.h toc.inc toc.asm toc.c

Description

The toc struct is used to save the values of the non-volatile registers in case of a coroutine switch.

The initialization, saving and restoring of the registers is handled by the toc_settle(), toc_go and toc_switch functions.

Struct elements

void *rbx, *r12, *r13, *r14, *r15, *rbp, *rsp;

Functions

void toc_settle (struct toc* regs, void* tos, void (*kickoff)(void*, void*, void*, void*, void*, void*, void*), void* object);
This function prepares the struct toc for the first activation. To do this, register contents (toc) and stack (tos) must be initialized so that on the first activation the execution starts with the function kickoff, which in turn must find the pointer object as the seventh parameter on the stack (with x86_64 the first six parameters are passed via registers).
void toc_go (struct toc* regs);
This function loads the non-volatile processor registers with the contents of the struct regs.
void toc_switch (struct toc* regs_now, struct toc* regs_then);
This function performs a context switch. To do this, the current register values in regs_now must be saved and replaced by the values of regs_then.

Notes

The template contains the files toc.h and toc.inc, which define the struct toc for the use from C/C++ and assembler functions. You should not change anything in these files.

The function toc_settle can be implemented in C, for toc_go and toc_switch assembler is needed.
You will get more information about the assignment and the implementation of toc_settle, toc_go and toc_switch in the next exercise.