KallistiOS git master
Independent SDK for the Sega Dreamcast
Loading...
Searching...
No Matches
trap.h
Go to the documentation of this file.
1/* KallistiOS ##version##
2
3 arch/dreamcast/include/arch/trap.h
4 Copyright (C) 2024 Falco Girgis
5
6*/
7
8/** \file
9 \brief Interrupt and exception handling.
10 \ingroup traps
11
12 This file contains various definitions and declarations related to handling
13 trap events, as are invoked through the `TRAPA` instruction.
14
15 \author Falco Girgis
16
17 \see arch/irq.h, dc/asic.h
18
19 \todo
20 - state management, propagation
21 - TRAPA instruction inline ASM
22 - document reserved TRAP codes
23*/
24
25#ifndef __ARCH_TRAP_H
26#define __ARCH_TRAP_H
27
28#include <stdint.h>
29
30#include <sys/cdefs.h>
31__BEGIN_DECLS
32
33/** \cond */ /* Forward declarations */
34struct irq_context;
35typedef struct irq_context irq_context_t;
36/** \endcond */
37
38/** \defgroup traps Traps
39 \brief API for managing TRAPA events and handlers.
40 \ingroup system
41
42 This API provides methods for setting and getting the installed handler for
43 a particular `TRAPA` code.
44
45 `TRAPA` is an SH4 instruction which simply takes a code (0-255) and fires
46 an exception event which transfers execution to the kernel so that it can
47 then be handled in software.
48
49 @{
50*/
51
52/** Type for a code passed to the `TRAPA` instruction. */
53typedef uint8_t trapa_t;
54
55/** \defgroup irq_trapa_handler Handlers
56 \brief API for managing TRAPA handlers
57
58 This API allows for the setting and retrieving of a handler associated with
59 a particular `TRAPA` value.
60
61 @{
62*/
63
64/** The type of a TRAPA handler
65
66 \param trap The IRQ that caused the handler to be called.
67 \param context The CPU's context.
68 \param data Arbitrary userdata associated with the handler.
69*/
70typedef void (*trapa_handler)(trapa_t trap, irq_context_t *context, void *data);
71
72/** Set or remove a handler for a trapa code.
73
74 \param trap The value passed to the trapa opcode.
75 \param hnd A pointer to the procedure to handle the trap.
76 \param data A pointer that will be passed along to the callback.
77
78 \retval 0 On success.
79
80 \sa trapa_get_handler()
81*/
82int trapa_set_handler(trapa_t trap, trapa_handler hnd, void *data);
83
84/** Get an existing TRAPA handler.
85
86 \param trap The value passed to the trapa opcode.
87 \param data A pointer to a void* which will be filled in with
88 the handler's userdata, or NULL if not interested.
89
90 \return A pointer to the procedure to handle the TRAP code.
91
92 \sa trapa_set_handler()
93*/
95
96/** @} */
97
98/** @} */
99
100__END_DECLS
101
102#endif /* __ARCH_TRAP_H */
int trapa_set_handler(trapa_t trap, trapa_handler hnd, void *data)
Set or remove a handler for a trapa code.
void(* trapa_handler)(trapa_t trap, irq_context_t *context, void *data)
The type of a TRAPA handler.
Definition trap.h:70
trapa_handler trapa_get_handler(trapa_t trap, void **data)
Get an existing TRAPA handler.
uint8_t trapa_t
Type for a code passed to the TRAPA instruction.
Definition trap.h:53
Architecture-specific structure for holding the processor state.
Definition irq.h:86