7 Versionstring: $VER: SDI_hook.h 1.15 (30.04.2006)
8 Author: SDI & Jens Langner
10 Project page: http://www.sf.net/projects/sditools/
11 Description: defines to hide compiler specific hook stuff
13 1.0 21.06.02 : based on the work made for freeciv and YAM with
14 additional texts partly taken from YAM_hook.h changes made
15 by Jens Langner, largely reworked the mechanism
16 1.1 07.10.02 : added HOOKPROTONP and HOOKPROTONONP requested by Jens
17 1.2 18.10.02 : reverted to old MorphOS-method for GCC
18 1.3 08.02.04 : modified to get it compatible to AmigaOS4
19 1.4 17.02.04 : modified to get compatible to latest SDI_compiler.h changes
20 1.5 02.03.04 : added UNUSED define to OS4 hook specification so that the
21 compiler can ignore some warnings.
22 1.6 02.03.04 : added (APTR) casts to MorphOS prototype definition to
23 reduce compiler warnings.
24 1.7 04.07.04 : removed static from all DISPATCHERPROTO definitions as there
25 may be dispatchers that are of course non static.
26 1.8 07.04.05 : added MakeHookWithData (Sebastian Bauer)
27 1.9 08.04.05 : changed MorphOS hooks to use HookEntry (Ilkka Lehtoranta)
28 1.10 16.05.05 : simplified and fixed for vbcc/MorphOS (Frank Wille)
29 1.11 17.05.05 : changed cast in DISPATCHERPROTO from (void(*)()) to APTR
30 cause SDI version of the EmulLibEntry uses APTR for easy
32 Added #ifndef SDI_TRAP_LIB to avoid double defines when
33 combining with SDI_interrupt.h or SDI_misc.h (Guido
35 1.12 18.05.05 : DISPATCHERPROTO wasn't working, because of the missing REG_Ax
36 definitions. Added include <emul/emulregs.h> (Guido Mersmann)
37 1.13 11.12.05 : fixed a minor typo in the PPC HOOKPROTONP macro.
39 1.14 20.04.06 : unified static of MorphOs with non-MorphOS vesion
40 1.15 30.04.06 : modified to get it compatible to AROS. (Guido Mersmann)
44 ** This is PD (Public Domain). This means you can do with it whatever you want
45 ** without any restrictions. I only ask you to tell me improvements, so I may
46 ** fix the main line of this files as well.
48 ** To keep confusion level low: When changing this file, please note it in
49 ** above history list and indicate that the change was not made by myself
50 ** (e.g. add your name or nick name).
52 ** Find the latest version of this file at:
53 ** http://cvs.sourceforge.net/viewcvs.py/sditools/sditools/headers/
55 ** Jens Langner <Jens.Langner@light-speed.de> and
56 ** Dirk Stöcker <soft@dstoecker.de>
59 #include "SDI_compiler.h"
62 ** Hook macros to handle the creation of Hooks/Dispatchers for different
63 ** Operating System versions.
64 ** Currently AmigaOS and MorphOS is supported.
66 ** For more information about hooks see include file <utility/hooks.h> or
67 ** the relevant descriptions in utility.library autodocs.
71 ** Creates a hook with the name "TestHook" that calls a corresponding
72 ** function "TestFunc" that will be called with a pointer "text"
73 ** (in register A1) and returns a long.
75 ** HOOKPROTONHNO(TestFunc, LONG, STRPTR text)
80 ** MakeHook(TestHook, TestFunc);
82 ** Every function that is created with HOOKPROTO* must have a MakeHook() or
83 ** MakeStaticHook() to create the corresponding hook. Best is to call this
84 ** directly after the hook function. This is required by the GCC macros.
86 ** The naming convention for the Hook Prototype macros is as followed:
88 ** HOOKPROTO[NH][NO][NP]
90 ** NoHook | NoParameter
93 ** So a plain HOOKPROTO() creates you a Hook function that requires
94 ** 4 parameters, the "name" of the hookfunction, the "obj" in REG_A2,
95 ** the "param" in REG_A1 and a "hook" in REG_A0. Usually you will always
96 ** use NH, as the hook structure itself is nearly never required.
98 ** The DISPATCHERPROTO macro is for MUI dispatcher functions. It gets the
99 ** functionname as argument. To supply this function for use by MUI, use
100 ** The ENTRY macro, which also gets the function name as argument.
103 #if defined(__PPC__) || defined(__AROS__)
104 #define HOOKPROTO(name, ret, obj, param) static SAVEDS ret \
105 name(struct Hook *hook, obj, param)
106 #define HOOKPROTONO(name, ret, param) static SAVEDS ret \
107 name(struct Hook *hook, UNUSED APTR obj, param)
108 #define HOOKPROTONP(name, ret, obj) static SAVEDS ret \
109 name(struct Hook *hook, obj, UNUSED APTR param)
110 #define HOOKPROTONONP(name, ret) static SAVEDS ret \
111 name(struct Hook *hook, UNUSED APTR obj, UNUSED APTR param)
112 #define HOOKPROTONH(name, ret, obj, param) static SAVEDS ret \
113 name(UNUSED struct Hook *hook, obj, param)
114 #define HOOKPROTONHNO(name, ret, param) static SAVEDS ret \
115 name(UNUSED struct Hook *hook, UNUSED APTR obj, param)
116 #define HOOKPROTONHNP(name, ret, obj) static SAVEDS ret \
117 name(UNUSED struct Hook *hook, obj, UNUSED APTR param)
118 #define HOOKPROTONHNONP(name, ret) static SAVEDS ret name(void)
120 #define HOOKPROTO(name, ret, obj, param) static SAVEDS ASM ret \
121 name(REG(a0, struct Hook *hook), REG(a2, obj), REG(a1, param))
122 #define HOOKPROTONO(name, ret, param) static SAVEDS ASM ret \
123 name(REG(a0, struct Hook *hook), REG(a1, param))
124 #define HOOKPROTONP(name, ret, obj) static SAVEDS ASM ret \
125 name(REG(a0, struct Hook *hook), REG(a2, obj))
126 #define HOOKPROTONONP(name, ret) static SAVEDS ASM ret \
127 name(REG(a0, struct Hook *hook))
128 #define HOOKPROTONH(name, ret, obj, param) static SAVEDS ASM ret \
129 name(REG(a2, obj), REG(a1, param))
130 #define HOOKPROTONHNO(name, ret, param) static SAVEDS ASM ret \
132 #define HOOKPROTONHNP(name, ret, obj) static SAVEDS ASM ret \
134 #define HOOKPROTONHNONP(name, ret) static SAVEDS ret name(void)
139 #ifndef SDI_TRAP_LIB /* avoid defining this twice */
140 #include <proto/alib.h>
141 #include <emul/emulregs.h>
143 #define SDI_TRAP_LIB 0xFF00 /* SDI prefix to reduce conflicts */
145 struct SDI_EmulLibEntry
153 #define MakeHook(hookname, funcname) struct Hook hookname = {{NULL, NULL}, \
154 (HOOKFUNC)HookEntry, (HOOKFUNC)funcname, NULL}
155 #define MakeHookWithData(hookname, funcname, data) struct Hook hookname = \
156 {{NULL, NULL}, (HOOKFUNC)HookEntry, (HOOKFUNC)funcname, (APTR)data}
157 #define MakeStaticHook(hookname, funcname) static struct Hook hookname = \
158 {{NULL, NULL}, (HOOKFUNC)HookEntry, (HOOKFUNC)funcname, NULL}
159 #define DISPATCHERPROTO(name) \
161 static ULONG name(struct IClass * cl, Object * obj, Msg msg); \
162 static ULONG Trampoline_##name(void) {return name((struct IClass *) \
163 REG_A0, (Object *) REG_A2, (Msg) REG_A1);} \
164 const struct SDI_EmulLibEntry Gate_##name = {SDI_TRAP_LIB, 0, \
165 (APTR) Trampoline_##name}; \
166 static ULONG name(struct IClass * cl, Object * obj, Msg msg)
167 #define ENTRY(func) (APTR)&Gate_##func
169 #else /* !__MORPHOS__ */
170 #define MakeHook(hookname, funcname) struct Hook hookname = {{NULL, NULL}, \
171 (HOOKFUNC)funcname, NULL, NULL}
172 #define MakeHookWithData(hookname, funcname, data) struct Hook hookname = \
173 {{NULL, NULL}, (HOOKFUNC)funcname, NULL, (APTR)data}
174 #define MakeStaticHook(hookname, funcname) static struct Hook hookname = \
175 {{NULL, NULL}, (HOOKFUNC)funcname, NULL, NULL}
176 #define ENTRY(func) (APTR)func
178 #if defined(__AROS__)
179 #define DISPATCHERPROTO(name) IPTR \
180 name( struct IClass * cl, Object * obj, Msg msg)
182 #define DISPATCHERPROTO(name) SAVEDS ASM ULONG name(REG(a0, \
183 struct IClass * cl), REG(a2, Object * obj), REG(a1, Msg msg))
188 #define InitHook(hook, orighook, data) ((hook)->h_Entry = (orighook).h_Entry,\
189 (hook)->h_SubEntry = (orighook).h_SubEntry,(hook)->h_Data = (APTR)(data))
191 #endif /* SDI_HOOK_H */