1 #ifndef SDI_INTERRUPT_H
2 #define SDI_INTERRUPT_H
7 Versionstring: $VER: SDI_interrupt.h 1.1 (25.04.2006)
10 Project page: http://www.sf.net/projects/sditools/
11 Description: defines to hide compiler specific interrupt and
14 1.0 17.05.05 : inspired by the SDI_#?.h files made by Jens Langner
15 and Dirk Stöcker I created files to handle interrupt
16 and handler functions in an API compatible way.
17 1.1 25.04.06 : fixed MakeInterrupt() and MakeHandler() macro. (geit)
18 WIP 23.08.13 : ported to AROS. WARNING: FOR ABIv1 ONLY!
23 ** This is PD (Public Domain). This means you can do with it whatever you want
24 ** without any restrictions. I only ask you to tell me improvements, so I may
25 ** fix the main line of this files as well.
27 ** To keep confusion level low: When changing this file, please note it in
28 ** above history list and indicate that the change was not made by myself
29 ** (e.g. add your name or nick name).
31 ** Find the latest version of this file at:
32 ** http://cvs.sourceforge.net/viewcvs.py/sditools/sditools/headers/
34 ** Guido Mersmann <geit@gmx.de>
38 #include "SDI_compiler.h"
41 ** The INTERRUPTPROTO macro is for creating interrupts functions and the
42 ** HANDLERPROTO macro is for handler type setup like used by the
45 ** The usage is simular to the DISPATCHERPROTO macro provided by SDI_hook.h.
47 ** It gets the function name as argument. To supply this function for use by
48 ** an interrupt structure or handler argument, use the ENTRY macro, which also
49 ** gets the function name as argument. There is also a MakeInterrupt and a
50 ** MakeHandler macro for easy structure setup.
54 ** We create a handler function for the input.device.
56 ** HANDLERPROTO( handlerfunc, ULONG, struct InputEvent *inputevent, APTR userdata)
58 ** ... Modify/parse input stream here
60 ** return( (ULONG) inputevent );
62 ** MakeHandler( handlerstruct, handlerfunc, "TestHandler", &our_user_data);
64 ** As you can see usage is as simple as using SDI hooks. To create interrupt
65 ** use INTERRUPTPROTO and MakeInterrupt. Internally both macros are identically.
67 ** There are also functions to create more specific interrupt and handler
68 ** structures. By default type is NT_INTERRUPT and priority is 0.
70 ** MakeHandlerType - additional argument for type
71 ** MakeHandlerPri - additional argument for pri
72 ** MakeHandlerTypePri - additional arguments for type and pri
75 ** Notes: Since the interrupt structure is used for handlers and also foreign
76 ** handlers are using this structure I keeped the arguments definition
83 #ifndef SDI_TRAP_LIB /* avoid defining this twice */
85 #include <proto/alib.h>
86 #include <emul/emulregs.h>
88 #define SDI_TRAP_LIB 0xFF00 /* SDI prefix to reduce conflicts */
90 struct SDI_EmulLibEntry
98 #define INTERRUPTPROTO(name, ret, obj, data) \
99 SAVEDS ASM ret name( obj, data); \
100 static ret Trampoline_##name(void) {return name(( obj) REG_A0, \
102 static const struct SDI_EmulLibEntry Gate_##name = {SDI_TRAP_LIB, 0, \
103 (APTR) Trampoline_##name}; \
104 SAVEDS ASM ret name( obj, data)
106 #define HANDLERPROTO(name, ret, obj, data) \
107 SAVEDS ASM ret name( obj, data); \
108 static ret Trampoline_##name(void) {return name(( obj) REG_A0, \
110 static const struct SDI_EmulLibEntry Gate_##name = {SDI_TRAP_LIB, 0, \
111 (APTR) Trampoline_##name}; \
112 SAVEDS ASM ret name( obj, data)
114 #define ENTRY(func) (APTR)&Gate_##func
116 #elif defined(__AROS__)
118 /* This is the same prototype for both Cause() and
119 * AddIntServer() functions
121 #define INTERRUPTPROTO(name, ret, obj, data) \
122 ret name(obj, data, struct ExecBase *SysBase); \
123 AROS_UFH5(int, name##_wrapper, \
124 AROS_UFHA(APTR, is_Data, A1), \
125 AROS_UFHA(APTR, is_Code, A5), \
126 AROS_UFHA(struct ExecBase *, sysBase, A6), \
127 AROS_UFHA(APTR, mask, D1), \
128 AROS_UFHA(APTR, custom, A0)) \
129 { AROS_USERFUNC_INIT \
130 name(custom, is_Data, sysBase ); return 0; \
131 AROS_USERFUNC_EXIT } \
132 ret name(obj, data, struct ExecBase *SysBase)
136 #define INTERRUPTPROTO(name, ret, obj, data) \
137 SAVEDS ASM ret name(REG(a0, obj), REG(a1, data))
138 #define HANDLERPROTO(name, ret, obj, data) \
139 SAVEDS ASM ret name(REG(a0, obj), REG(a1, data))
141 #define ENTRY(func) (APTR)func
143 #endif /* __MORPHOS__ */
145 /* some structure creating macros for easy and more specific usage */
147 #define MakeInterrupt( name, func, title, isdata ) \
148 static struct Interrupt name = {{ NULL, NULL, NT_INTERRUPT, 0, (STRPTR) title}, (APTR) isdata, (void (*)()) ENTRY(func) }
150 #define MakeInterruptPri( name, func, title, isdata, pri ) \
151 static struct Interrupt name = {{ NULL, NULL, NT_INTERRUPT, pri, (STRPTR) title}, (APTR) isdata, (void (*)()) ENTRY(func) }
153 #define MakeInterruptType( name, func, title, isdata, type ) \
154 static struct Interrupt name = {{ NULL, NULL, type, 0, (STRPTR) title}, (APTR) isdata, (void (*)()) ENTRY(func) }
156 #define MakeInterruptTypePri( name, func, title, isdata, type, pri ) \
157 static struct Interrupt name = {{ NULL, NULL, type, pri, (STRPTR) title}, (APTR) isdata, (void (*)()) ENTRY(func) }
159 #define MakeHandler( name, func, title, isdata ) \
160 static struct Interrupt name = {{ NULL, NULL, NT_INTERRUPT, 0, (STRPTR) title}, (APTR) isdata, (void (*)()) ENTRY(func) }
162 #define MakeHandlerPri( name, func, title, isdata, pri ) \
163 static struct Interrupt name = {{ NULL, NULL, NT_INTERRUPT, pri, (STRPTR) title}, (APTR) isdata, (void (*)()) ENTRY(func) }
165 #define MakeHandlerType( name, func, title, isdata, type ) \
166 static struct Interrupt name = {{ NULL, NULL, type, 0, (STRPTR) title}, (APTR) isdata, (void (*)()) ENTRY(func) }
168 #define MakeHandlerTypePri( name, func, title, isdata, type, pri ) \
169 static struct Interrupt name = {{ NULL, NULL, type, pri, (STRPTR) title}, (APTR) isdata, (void (*)()) ENTRY(func) }
172 #endif /* SDI_INTERRUPT_H */