KallistiOS git master
Independent SDK for the Sega Dreamcast
Loading...
Searching...
No Matches
IRQ context handling

API for handling IRQ contexts 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

static void irq_create_context (irq_context_t *context, uintptr_t stack_pointer, uintptr_t routine, const uintptr_t *args)
 Fill a newly allocated context block.
 
static void irq_set_context (irq_context_t *cxt)
 Switch out contexts (for interrupt return).
 
static irq_context_t * irq_get_context (void)
 Get the current IRQ context.
 

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

API for handling IRQ contexts

Thread execution state and accessors

This API provides functions to create a new IRQ context, get a pointer to the current context, or set the context that will be used when returning from an exception.

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.

Referenced by catchnull(), and on_break().

◆ 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()

static void irq_create_context ( irq_context_t * context,
uintptr_t stack_pointer,
uintptr_t routine,
const uintptr_t * args )
inlinestatic

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.

References arch_irq_create_context().

◆ irq_get_context()

static irq_context_t * irq_get_context ( void )
inlinestatic

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()

References arch_irq_get_context().

◆ irq_set_context()

static void irq_set_context ( irq_context_t * cxt)
inlinestatic

Switch out contexts (for interrupt return).

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

Parameters
cxtThe IRQ context to restore.
See also
irq_get_context()

References arch_irq_set_context(), and cxt.