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

IRQs and ISRs for the SH4's CPU. More...

Modules

 Exception Codes
 IRQ exception code values.
 
 Exception type offsets
 Offsets within exception types.
 

Files

file  irq.h
 Interrupt and exception handling.
 

Data Structures

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

Macros

#define REG_BYTE_CNT   256 /* Currently really 228 */
 The number of bytes required to save thread context.
 
#define CONTEXT_PC(c)   ((c).pc)
 Fetch the program counter from an irq_context_t.
 
#define CONTEXT_FP(c)   ((c).r[14])
 Fetch the frame pointer from an irq_context_t.
 
#define CONTEXT_SP(c)   ((c).r[15])
 Fetch the stack pointer from an irq_context_t.
 
#define CONTEXT_RET(c)   ((c).r[0])
 Fetch the return value from an irq_context_t.
 
#define TIMER_IRQ   EXC_TMU0_TUNI0
 The value of the timer IRQ.
 

Typedefs

typedef uint32_t irq_t
 The type of an interrupt identifier.
 
typedef void(* irq_handler) (irq_t source, irq_context_t *context, void *data)
 The type of an IRQ handler.
 

Functions

int irq_inside_int (void)
 Are we inside an interrupt handler?
 
void irq_force_return (void)
 Pretend like we just came in from an interrupt and force a context switch back to the "current" context.
 
int irq_set_handler (irq_t source, irq_handler hnd, void *data)
 Set or remove an IRQ handler.
 
irq_handler irq_get_handler (irq_t source)
 Get the address of the current handler for the IRQ type.
 
int trapa_set_handler (irq_t code, irq_handler hnd, void *data)
 Set or remove a handler for a trapa code.
 
int irq_set_global_handler (irq_handler hnd, void *data)
 Set a global exception handler.
 
irq_handler irq_get_global_handler (void)
 Get the global exception handler.
 
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, uint32_t *args, int usermode)
 Fill a newly allocated context block for usage with supervisor or user mode.
 
int irq_disable (void)
 Disable interrupts.
 
void irq_enable (void)
 Enable all interrupts.
 
void irq_restore (int v)
 Restore IRQ state.
 
int irq_init (void)
 Initialize interrupts.
 
void irq_shutdown (void)
 Shutdown interrupts, restoring the state to how it was before irq_init() was called.
 

Detailed Description

IRQs and ISRs for the SH4's CPU.

Macro Definition Documentation

◆ CONTEXT_FP

#define CONTEXT_FP (   c)    ((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)    ((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)    ((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)    ((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 /* Currently really 228 */

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

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

◆ TIMER_IRQ

#define TIMER_IRQ   EXC_TMU0_TUNI0

The value of the timer IRQ.

Typedef Documentation

◆ irq_handler

typedef void(* irq_handler) (irq_t source, irq_context_t *context, void *data)

The type of an IRQ handler.

Parameters
sourceThe IRQ that caused the handler to be called.
contextThe CPU's context.

◆ irq_t

typedef uint32_t irq_t

The type of an interrupt identifier.

Function Documentation

◆ irq_create_context()

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

Fill a newly allocated context block for usage with supervisor or user mode.

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.
usermode1 to run the routine in user mode, 0 for supervisor.

◆ irq_disable()

int irq_disable ( void  )

Disable interrupts.

This function will disable interrupts, but will leave exceptions enabled.

Returns
The state of IRQs before calling the function. This can be used to restore this state later on with irq_restore().

Referenced by g2_lock().

◆ irq_enable()

void irq_enable ( void  )

Enable all interrupts.

This function will enable ALL interrupts, including external ones.

◆ irq_force_return()

void irq_force_return ( void  )

Pretend like we just came in from an interrupt and force a context switch back to the "current" context.

Warning
Make sure you've called irq_set_context() before doing this!

◆ 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.

◆ irq_get_global_handler()

irq_handler irq_get_global_handler ( void  )

Get the global exception handler.

Returns
The global exception handler set with irq_set_global_handler(), or NULL if none is set.

◆ irq_get_handler()

irq_handler irq_get_handler ( irq_t  source)

Get the address of the current handler for the IRQ type.

Parameters
sourceThe IRQ type to look up.
Returns
A pointer to the procedure to handle the exception.

◆ irq_init()

int irq_init ( void  )

Initialize interrupts.

Return values
0On success (no error conditions defined).

◆ irq_inside_int()

int irq_inside_int ( void  )

Are we inside an interrupt handler?

Return values
1If interrupt handling is in progress.
0If normal processing is in progress.

◆ irq_restore()

void irq_restore ( int  v)

Restore IRQ state.

This function will restore the interrupt state to the value specified. This should correspond to a value returned by irq_disable().

Parameters
vThe IRQ state to restore. This should be a value returned by irq_disable().

Referenced by g2_unlock().

◆ 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.

◆ irq_set_global_handler()

int irq_set_global_handler ( irq_handler  hnd,
void *  data 
)

Set a global exception handler.

This function sets a global catch-all handler for all exception types.

Note
The specific handler will still be called for the exception if one is set. If not, setting one of these will stop the unhandled exception error.
Parameters
hndA pointer to the procedure to handle the exception.
dataA pointer that will be passed along to the callback.
Return values
0On success (no error conditions defined).

◆ irq_set_handler()

int irq_set_handler ( irq_t  source,
irq_handler  hnd,
void *  data 
)

Set or remove an IRQ handler.

Passing a NULL value for hnd will remove the current handler, if any.

Parameters
sourceThe IRQ type to set the handler for (see Exception Codes).
hndA pointer to a procedure to handle the exception.
dataA pointer that will be passed along to the callback.
Return values
0On success.
-1If the source is invalid.

◆ irq_shutdown()

void irq_shutdown ( void  )

Shutdown interrupts, restoring the state to how it was before irq_init() was called.

◆ trapa_set_handler()

int trapa_set_handler ( irq_t  code,
irq_handler  hnd,
void *  data 
)

Set or remove a handler for a trapa code.

Parameters
codeThe value passed to the trapa opcode.
hndA pointer to the procedure to handle the trap.
dataA pointer that will be passed along to the callback.
Return values
0On success.
-1If the code is invalid (greater than 0xFF).