IRQs and ISRs for the SH4's CPU.
More...
|
file | irq.h |
| Interrupt and exception handling.
|
|
|
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_t * | irq_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.
|
|
IRQs and ISRs for the SH4's CPU.
◆ CONTEXT_FP
#define CONTEXT_FP |
( |
|
c | ) |
((c).r[14]) |
Fetch the frame pointer from an irq_context_t.
- Parameters
-
c | The 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
-
c | The 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
-
c | The 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
-
c | The 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
The value of the timer IRQ.
◆ irq_handler
The type of an IRQ handler.
- Parameters
-
source | The IRQ that caused the handler to be called. |
context | The CPU's context. |
◆ irq_t
The type of an interrupt identifier.
◆ 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
-
context | The IRQ context to fill in. |
stack_pointer | The value to set in the stack pointer. |
routine | The address of the program counter for the context. |
args | Any arguments to set in the registers. This cannot be NULL, and must have enough values to fill in up to the architecture maximum. |
usermode | 1 to run the routine in user mode, 0 for supervisor. |
◆ irq_disable()
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()
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()
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()
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()
Get the address of the current handler for the IRQ type.
- Parameters
-
source | The IRQ type to look up. |
- Returns
- A pointer to the procedure to handle the exception.
◆ irq_init()
Initialize interrupts.
- Return values
-
0 | On success (no error conditions defined). |
◆ irq_inside_int()
int irq_inside_int |
( |
void |
| ) |
|
Are we inside an interrupt handler?
- Return values
-
1 | If interrupt handling is in progress. |
0 | If 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
-
v | The IRQ state to restore. This should be a value returned by irq_disable(). |
Referenced by g2_unlock().
◆ irq_set_context()
Switch out contexts (for interrupt return).
This function will set the processor state that will be restored when the exception returns.
- Parameters
-
regbank | The 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
-
hnd | A pointer to the procedure to handle the exception. |
data | A pointer that will be passed along to the callback. |
- Return values
-
0 | On success (no error conditions defined). |
◆ irq_set_handler()
Set or remove an IRQ handler.
Passing a NULL value for hnd will remove the current handler, if any.
- Parameters
-
source | The IRQ type to set the handler for (see Exception Codes). |
hnd | A pointer to a procedure to handle the exception. |
data | A pointer that will be passed along to the callback. |
- Return values
-
0 | On success. |
-1 | If 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()
Set or remove a handler for a trapa code.
- Parameters
-
code | The value passed to the trapa opcode. |
hnd | A pointer to the procedure to handle the trap. |
data | A pointer that will be passed along to the callback. |
- Return values
-
0 | On success. |
-1 | If the code is invalid (greater than 0xFF). |