KallistiOS git master
Independent SDK for the Sega Dreamcast
Loading...
Searching...
No Matches
Context

Thread execution state and accessors More...

Data Structures

struct  irq_context_t
 Architecture-specific structure for holding the processor state. More...
 

Macros

#define REG_BYTE_CNT   256
 The number of bytes required to save thread context.
 

Functions

void irq_set_context (irq_context_t *regbank)
 Switch out contexts (for interrupt return).
 
irq_context_tirq_get_context (void)
 Get the current IRQ context.
 
void irq_create_context (irq_context_t *context, uint32_t stack_pointer, uint32_t routine, const uint32_t *args, bool usermode)
 Fill a newly allocated context block.
 

Register Accessors

Convenience macros for accessing context registers

#define CONTEXT_PC(c)
 Fetch the program counter from an irq_context_t.
 
#define CONTEXT_FP(c)
 Fetch the frame pointer from an irq_context_t.
 
#define CONTEXT_SP(c)
 Fetch the stack pointer from an irq_context_t.
 
#define CONTEXT_RET(c)
 Fetch the return value from an irq_context_t.
 

Detailed Description

Thread execution state and accessors

This API includes the structure and accessors for a thread's context state, which contains the registers that are stored and loaded upon thread context switches, which are passed back to interrupt handlers.

Macro Definition Documentation

◆ CONTEXT_FP

#define CONTEXT_FP ( c)
Value:
((c).r[14])

Fetch the frame pointer from an irq_context_t.

Parameters
cThe context to read from.
Returns
The frame pointer value.

◆ CONTEXT_PC

#define CONTEXT_PC ( c)
Value:
((c).pc)

Fetch the program counter from an irq_context_t.

Parameters
cThe context to read from.
Returns
The program counter value.

◆ CONTEXT_RET

#define CONTEXT_RET ( c)
Value:
((c).r[0])

Fetch the return value from an irq_context_t.

Parameters
cThe context to read from.
Returns
The return value.

◆ CONTEXT_SP

#define CONTEXT_SP ( c)
Value:
((c).r[15])

Fetch the stack pointer from an irq_context_t.

Parameters
cThe context to read from.
Returns
The stack pointer value.

◆ REG_BYTE_CNT

#define REG_BYTE_CNT   256

The number of bytes required to save thread context.

This should include all general CPU registers, FP registers, and status regs (even if not all of these are actually used).

Note
On the Dreamcast, we need 228 bytes for all of that, but we round it up to a nicer number for sanity.

Function Documentation

◆ irq_create_context()

void irq_create_context ( irq_context_t * context,
uint32_t stack_pointer,
uint32_t routine,
const uint32_t * args,
bool usermode )

Fill a newly allocated context block.

The given parameters will be passed to the called routine (up to the architecture maximum). For the Dreamcast, this maximum is 4.

Parameters
contextThe IRQ context to fill in.
stack_pointerThe value to set in the stack pointer.
routineThe address of the program counter for the context.
argsAny arguments to set in the registers. This cannot be NULL, and must have enough values to fill in up to the architecture maximum.
usermodetrue to run the routine in user mode, false for supervisor.

◆ irq_get_context()

irq_context_t * irq_get_context ( void )

Get the current IRQ context.

This will fetch the processor context prior to the exception handling during an IRQ service routine.

Returns
The current IRQ context.
See also
irq_set_context()

◆ irq_set_context()

void irq_set_context ( irq_context_t * regbank)

Switch out contexts (for interrupt return).

This function will set the processor state that will be restored when the exception returns.

Parameters
regbankThe values of all registers to be restored.
See also
irq_get_context()