From 07e6d51b5648cbee998cdf49a808d938335adee9 Mon Sep 17 00:00:00 2001 From: mazze Date: Mon, 25 Aug 2014 16:35:34 +0000 Subject: [PATCH] Test bed for SDI headers. git-svn-id: https://svn.aros.org/svn/aros/trunk/AROS@49532 fb15a70f-31f2-0310-bbcc-cdcc74a49acc --- test/sdi/README | 131 ++++++ test/sdi/SDI_compiler.h | 243 +++++++++++ test/sdi/SDI_hook.h | 314 +++++++++++++++ test/sdi/SDI_interrupt.h | 156 +++++++ test/sdi/SDI_lib.h | 199 +++++++++ test/sdi/SDI_misc.h | 121 ++++++ test/sdi/SDI_stdarg.h | 108 +++++ test/sdi/examples/hooks/example_hookuse.c | 86 ++++ test/sdi/examples/hooks/makefile.mos | 58 +++ test/sdi/examples/hooks/makefile.os3 | 59 +++ test/sdi/examples/hooks/makefile.os4 | 59 +++ test/sdi/examples/libraries/example_lib.c | 604 ++++++++++++++++++++++++++++ test/sdi/examples/libraries/makefile.mos | 58 +++ test/sdi/examples/libraries/makefile.os3 | 59 +++ test/sdi/examples/libraries/makefile.os4 | 59 +++ test/sdi/examples/misc/example_miscuse.c | 105 +++++ test/sdi/examples/misc/makefile.mos | 58 +++ test/sdi/examples/misc/makefile.os3 | 59 +++ test/sdi/examples/misc/makefile.os4 | 59 +++ test/sdi/examples/varargs/example_varargs.c | 66 +++ test/sdi/examples/varargs/makefile.mos | 59 +++ test/sdi/examples/varargs/makefile.os3 | 59 +++ test/sdi/examples/varargs/makefile.os4 | 59 +++ 23 files changed, 2838 insertions(+) create mode 100644 test/sdi/README create mode 100644 test/sdi/SDI_compiler.h create mode 100644 test/sdi/SDI_hook.h create mode 100644 test/sdi/SDI_interrupt.h create mode 100644 test/sdi/SDI_lib.h create mode 100644 test/sdi/SDI_misc.h create mode 100644 test/sdi/SDI_stdarg.h create mode 100755 test/sdi/examples/hooks/example_hookuse.c create mode 100644 test/sdi/examples/hooks/makefile.mos create mode 100644 test/sdi/examples/hooks/makefile.os3 create mode 100644 test/sdi/examples/hooks/makefile.os4 create mode 100644 test/sdi/examples/libraries/example_lib.c create mode 100644 test/sdi/examples/libraries/makefile.mos create mode 100644 test/sdi/examples/libraries/makefile.os3 create mode 100644 test/sdi/examples/libraries/makefile.os4 create mode 100644 test/sdi/examples/misc/example_miscuse.c create mode 100644 test/sdi/examples/misc/makefile.mos create mode 100644 test/sdi/examples/misc/makefile.os3 create mode 100644 test/sdi/examples/misc/makefile.os4 create mode 100755 test/sdi/examples/varargs/example_varargs.c create mode 100644 test/sdi/examples/varargs/makefile.mos create mode 100644 test/sdi/examples/varargs/makefile.os3 create mode 100644 test/sdi/examples/varargs/makefile.os4 diff --git a/test/sdi/README b/test/sdi/README new file mode 100644 index 0000000000..91e4ca4e10 --- /dev/null +++ b/test/sdi/README @@ -0,0 +1,131 @@ +Short: SDI headers - A set of C macro/defines to make amiga development easier. +Kurz: SDI Headers - Ein Bündel von C Makros/Defines um Amiga Entwicklungen einfacher zu machen +Author: mail@jens-maus.de (Jens Maus), soft@dstoecker.de (Dirk Stöcker) +Uploader: mail@jens-maus.de (Jens Maus) +Version: 1.6 (14.07.2005) +Type: dev/c +Replaces: dev/c/SDI_headers.lha +Architecture: ppc-morphos >= 1.4.2; m68k-amigaos >= 2.1.0; ppc-amigaos >= 4.0.0 + +ABOUT +----- +One may ask, what are these "SDI headers" all about? So let me try to +explain the idea behind those additional headerfiles first: + +The so-called "SDI headers" are a set of freely available and freely usable +C-language header files which provide different sets of macros and defines +to make the live of developers much more comfortable when it comes to +dealing with hooks, compiler specific specialities or if one have to keep C +sources compatible over different AmigaOS-like platforms. + +In fact, by using the SDI headers a developer might keep his sources simple +and compatible to AmigaOS3, AmigaOS4 and also MorphOS much more easier, than +with having to clutter them with tones of #ifdef statements just because +these platforms use different approaches for the same path. + +WHY? +---- +Now you may ask why? The answer is quite easy. Because if you have followed +recent development pathes of AmigaOS3 and its successors AmigaOS4 and +MorphOS, you might have noticed that many parts of the original AmigaOS +API/SDK have been changed. On one hand the API changed because OS4 and +MorphOS are now PPC based, but also because of the senseless "fight" between +those Amiga-based platforms, it is much harder these days for a developer +willing to support all of these platforms at once. +Here is where the SDI headers can clearly help. They release much of the pain +when it comes to deal with Hooks, compiler differences and platform +specialities. + +DIFFERENT PURPOSES +------------------ +Currently the "SDI headers" consist of 4 different header files which were +developed because of different purposes: + +SDI_compiler.h - This header file carries compiler independent defines and + macros to allow developers to keep sources compatible to + different compilers and make sources in all more transparent + to compilers. + +SDI_hook.h - Dealing with Amiga-hooks was always a bit tricky and hard, + but in using this header file Hook can be defined in a very + easy and Amiga-platform independent fashion. + +SDI_lib.h - Since AmigaOS4 a new library system has been introduced + which comes with a different fashion of dealing with + shared libraries. This header file allows to keep sources + compatible to the old scheme by using different types + of macros making it transparent for AmigaOS3 and MorphOS + as well. + +SDI_stdarg.h - Unfortunatly variable argument list functions has always + been a bit tricky and especially since we are on the PPC + now, developers have to be more careful in how to use + variable argument list functions. However, this header + file allows to use a simple set of macros to generate a + AmigaOS3/AmigaOS4 and MorphOS compatible variable + argument list function. + +SDI_interrupt.h- Dealing with Amiga-interrupts was always a bit tricky and + hard, but in using this header file interrupts and handler + can be defined in a very easy and Amiga-platform + independent fashion. + +SDI_misc.h - This file contains miscellaneous function definitions which + may be required during development like the PutChProc() for + RawDoFmt(). + + +So you see. The SDI headers are a global players and if you use the whole +set of these headers your sources can be much easier maintainable than +they are already. Just have a look at the included examples! + +USAGE +----- +There is nothing really special about these headers and their usage. All +header files in the "includes" subdirectory of this distributions should be +perfectly commented and can be directly included in any sources. +However, for a better understanding we have worked out some examples which +should illustrate how the SDI headers have to be used and how they are able +to simplify parts of a source code, especially if this source has to be +compatible to many different AmigaOS like platforms. + +ARE THEY SERIOUSLY USED YET? +---------------------------- +Of course these headers are not only "theoretical stuff". In fact they are +currently used in the following well-known Amiga-based projects: + +YAM (Yet Another Mailer) - http://yam.ch/ +NList MUI classes - http://sf.net/p/nlist-classes +MUI (Magic User Interface) - http://muidev.de/ +Freeciv (Amiga port) +XAD library + +.. and many unknown ones :) + +So if you are interested in looking into "real" working source code and not +only into the supplied example code, please feel free to have a look at +the source code of the above projects (if it is freely available of course). + +UPDATES +------- +The latest brand of these headers can be viewed and downloaded from the +following URL: + + http://sf.net/p/adtools/code/HEAD/tree/trunk/sdi/ + +COPYRIGHT +--------- +The header files and sources of the SDI headers and its examples are fully +public domain. They can be reproduced and altered in any way. All we +(the authors) request is that if you find a bug or better way to deal +with something please send us a comment or hint about it so that we can +integrate this stuff in future versions. +Please share the public domain idea to make development for all us small +Amiga developer group easier and so painful in future. + +AUTHORS +------- +The main/original authors of the SDI headers are: + +Jens Maus +Dirk Stöcker diff --git a/test/sdi/SDI_compiler.h b/test/sdi/SDI_compiler.h new file mode 100644 index 0000000000..531c29737d --- /dev/null +++ b/test/sdi/SDI_compiler.h @@ -0,0 +1,243 @@ +#ifndef SDI_COMPILER_H +#define SDI_COMPILER_H + +/* Includeheader + + Name: SDI_compiler.h + Versionstring: $VER: SDI_compiler.h 1.35 (03.03.2011) + Authors: Dirk Stoecker, Jens Maus + Distribution: PD + Project page: http://sf.net/p/adtools/code/HEAD/tree/trunk/sdi/ + Description: defines to hide compiler stuff + Id: $Id$ + URL: $URL: svn://svn.code.sf.net/p/adtools/code/trunk/sdi/SDI_compiler.h $ + + 1.1 25.06.98 : created from data made by Gunter Nikl + 1.2 17.11.99 : added VBCC + 1.3 29.02.00 : fixed VBCC REG define + 1.4 30.03.00 : fixed SAVEDS for VBCC + 1.5 29.07.00 : added #undef statements (needed e.g. for AmiTCP together + with vbcc) + 1.6 19.05.01 : added STACKEXT and Dice stuff + 1.7 16.06.01 : added MorphOS specials and VARARGS68K + 1.8 21.09.02 : added MorphOS register stuff + 1.9 26.09.02 : added OFFSET macro. Thanks Frank Wille for suggestion + 1.10 18.10.02 : reverted to old MorphOS-method for GCC + 1.11 09.11.02 : added REGARGS define to MorphOS section + 1.12 18.01.04 : some adaptions for AmigaOS4 compatibility + 1.13 17.02.04 : changed ASM macros to be a simple define and added + INTERRUPT, CHIP and FAR + 1.14 02.03.04 : added UNUSED which can be used to specify a function parameter + or variable as "unused" which will not cause any compiler warning. + 1.15 02.03.04 : added special INLINE define for gcc > 3.0 version + 1.17 07.03.04 : changed INLINE definition of gcc <= 2.95.3 to be static aswell. + 1.18 21.06.04 : added USED and USED_VAR attribute to allow placing a + __attribute__((used)) to a function and a variable, taking care of + different compiler versions. + 1.19 04.07.04 : register specification for variables is not supported on MorphOS, + so we modified the REG() macro accordingly. + 1.20 28.02.05 : correct INLINE for VBCC. + 1.21 28.02.05 : cleanup __GCC__ case. + 1.22 16.05.05 : changed the vbcc/REG() macro. + added missing vbcc/VARARGS68K define. + moved morphos SDI_EmulLib Stuff into compilers.h. I know it's not + compiler specific, (Guido Mersmann) + 1.23 30.04.06 : modified to get it compatible to AROS. (Guido Mersmann) + 1.24 06.05.06 : __linearvarargs is only valid for vbcc and PPC, so I moved VARARGS68K + to prevent problems with 68K and i86 targets. (Guido Mersmann) + 1.25 21.06.07 : added NEAR to be usable for __near specification for SAS/C + 1.26 14.10.07 : added DEPRECATED macro which defaults to __attribute__((deprecated)) + for GCC compiles. + 1.27 20.03.09 : applied some changes and fixes to get the header more usable + for an AROS compilation. (Pavel Fedin) + 1.28 25.03.09 : added missing IPTR definition to make SDI_compiler.h more compatible + to AROS. (Pavel Fedin) + 1.29 25.03.09 : fixed the IPTR definition and also the use of the __M68000__ define. + 1.30 26.03.09 : fixed the IPTR definition by only defining it for non AROS targets. + 1.31 29.03.09 : added VARARGS68K definition for AROS. + 1.32 28.05.09 : added STACKED definition for non-AROS targets. + 1.33 03.06.10 : added missing SIPTR definition to make SDI_compiler.h more compatible + to AROS. + 1.34 26.07.10 : adapted IPTR and SIPTR definitions as the latest MorphOS SDK already + contains them. (tboeckel) + 1.35 03.03.11 : fixed AROS macros for m68k (Jason McMullan) + +*/ + +/* +** This is PD (Public Domain). This means you can do with it whatever you want +** without any restrictions. I only ask you to tell me improvements, so I may +** fix the main line of this files as well. +** +** To keep confusion level low: When changing this file, please note it in +** above history list and indicate that the change was not made by myself +** (e.g. add your name or nick name). +** +** Find the latest version of this file at: +** http://sf.net/p/adtools/code/HEAD/tree/trunk/sdi/ +** +** Jens Maus +** Dirk Stoecker +*/ + +/* Some SDI internal header */ + +#undef ASM +#undef REG +#undef LREG +#undef CONST +#undef SAVEDS +#undef INLINE +#undef REGARGS +#undef STDARGS +#undef OFFSET +#undef INTERRUPT +#undef CHIP +#undef FAR +#undef NEAR +#undef UNUSED +#undef USED +#undef USED_VAR +#undef DEPRECATED + +/* first "exceptions" */ + +#if defined(__MAXON__) + #define STDARGS + #define STACKEXT + #define REGARGS + #define SAVEDS + #define INLINE inline +/*************************************************************************/ +#elif defined(__VBCC__) + #define STDARGS + #define STACKEXT + #define REGARGS + #define INLINE static + #define OFFSET(p,m) __offsetof(struct p,m) + + #if defined(__PPC__) + #define VARARGS68K __linearvarargs + #define REG(reg,arg) arg + #else + #define REG(reg,arg) __reg(#reg) arg + #endif +/*************************************************************************/ +#elif defined(__STORM__) + #define STDARGS + #define STACKEXT + #define REGARGS + #define INLINE inline +/*************************************************************************/ +#elif defined(__SASC) + #define ASM __asm +/*************************************************************************/ +#elif defined(__GNUC__) + #define UNUSED __attribute__((unused)) /* for functions, variables and types */ + #define USED __attribute__((used)) /* for functions only! */ + #define DEPRECATED __attribute__((deprecated)) + #if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ > 0) + #define USED_VAR USED /* for variables only! */ + #define INLINE static __inline __attribute__((always_inline)) + #endif + /* we have to distinguish between AmigaOS4 and MorphOS */ + #if (defined(_M68000) || defined(__M68000) || defined(__mc68000)) && !defined(__AROS__) + #define REG(reg,arg) arg __asm(#reg) + #define LREG(reg,arg) register REG(reg,arg) + #else + #define REG(reg,arg) arg + #define SAVEDS + #define STDARGS + #define REGARGS + #define STACKEXT + #if defined(__MORPHOS__) + #define VARARGS68K __attribute__((varargs68k)) + #endif + #if defined(__AROS__) + #define VARARGS68K __stackparm + #endif + #define INTERRUPT + #define CHIP + #endif + #define FAR + #define NEAR +#elif defined(_DCC) + #define REG(reg,arg) __##reg arg + #define STACKEXT __stkcheck + #define STDARGS __stkargs + #define INLINE static +#endif + +/* then "common" ones */ + +#if !defined(ASM) + #define ASM +#endif +#if !defined(REG) + #define REG(reg,arg) register __##reg arg +#endif +#if !defined(LREG) + #define LREG(reg,arg) register arg +#endif +#if !defined(CONST) + #define CONST const +#endif +#if !defined(SAVEDS) + #define SAVEDS __saveds +#endif +#if !defined(INLINE) + #define INLINE static __inline +#endif +#if !defined(REGARGS) + #define REGARGS __regargs +#endif +#if !defined(STDARGS) + #define STDARGS __stdargs +#endif +#if !defined(STACKEXT) + #define STACKEXT __stackext +#endif +#if !defined(VARARGS68K) + #define VARARGS68K +#endif +#if !defined(OFFSET) + #define OFFSET(structName, structEntry) \ + ((char *)(&(((struct structName *)0)->structEntry))-(char *)0) +#endif +#if !defined(INTERRUPT) + #define INTERRUPT __interrupt +#endif +#if !defined(CHIP) + #define CHIP __chip +#endif +#if !defined(FAR) + #define FAR __far +#endif +#if !defined(NEAR) + #define NEAR __near +#endif +#if !defined(UNUSED) + #define UNUSED +#endif +#if !defined(USED) + #define USED +#endif +#if !defined(USED_VAR) + #define USED_VAR +#endif +#if !defined(DEPRECATED) + #define DEPRECATED +#endif +#if !defined(__AROS__) && !defined(__MORPHOS__) && !defined(IPTR) + #define IPTR ULONG +#endif +#if !defined(__AROS__) && !defined(__MORPHOS__) && !defined(SIPTR) + #define SIPTR LONG +#endif +#if !defined(__AROS__) && !defined(STACKED) + #define STACKED +#endif + +/*************************************************************************/ + +#endif /* SDI_COMPILER_H */ diff --git a/test/sdi/SDI_hook.h b/test/sdi/SDI_hook.h new file mode 100644 index 0000000000..7b51ebe1de --- /dev/null +++ b/test/sdi/SDI_hook.h @@ -0,0 +1,314 @@ +#ifndef SDI_HOOK_H +#define SDI_HOOK_H + +/* Includeheader + + Name: SDI_hook.h + Versionstring: $VER: SDI_hook.h 1.26 (17.10.2012) + Authors: Dirk Stoecker, Jens Maus + Distribution: PD + Project page: http://sf.net/p/adtools/code/HEAD/tree/trunk/sdi/ + Description: defines to hide compiler specific hook stuff + Id: $Id$ + URL: $URL: svn://svn.code.sf.net/p/adtools/code/trunk/sdi/SDI_hook.h $ + + 1.0 21.06.02 : based on the work made for freeciv and YAM with + additional texts partly taken from YAM_hook.h changes made + by Jens Langner, largely reworked the mechanism + 1.1 07.10.02 : added HOOKPROTONP and HOOKPROTONONP requested by Jens + 1.2 18.10.02 : reverted to old MorphOS-method for GCC + 1.3 08.02.04 : modified to get it compatible to AmigaOS4 + 1.4 17.02.04 : modified to get compatible to latest SDI_compiler.h changes + 1.5 02.03.04 : added UNUSED define to OS4 hook specification so that the + compiler can ignore some warnings. + 1.6 02.03.04 : added (APTR) casts to MorphOS prototype definition to + reduce compiler warnings. + 1.7 04.07.04 : removed static from all DISPATCHERPROTO definitions as there + may be dispatchers that are of course non static. + 1.8 07.04.05 : added MakeHookWithData (Sebastian Bauer) + 1.9 08.04.05 : changed MorphOS hooks to use HookEntry (Ilkka Lehtoranta) + 1.10 16.05.05 : simplified and fixed for vbcc/MorphOS (Frank Wille) + 1.11 17.05.05 : changed cast in DISPATCHERPROTO from (void(*)()) to APTR + cause SDI version of the EmulLibEntry uses APTR for easy + usage. + Added #ifndef SDI_TRAP_LIB to avoid double defines when + combining with SDI_interrupt.h or SDI_misc.h (Guido + Mersmann) + 1.12 18.05.05 : DISPATCHERPROTO wasn't working, because of the missing REG_Ax + definitions. Added include (Guido Mersmann) + 1.13 11.12.05 : fixed a minor typo in the PPC HOOKPROTONP macro. + (Jens Langner) + 1.14 20.04.06 : unified static of MorphOs with non-MorphOS vesion + 1.15 30.04.06 : modified to get it compatible to AROS. (Guido Mersmann) + 1.16 06.10.06 : added new DISPATCHER() macro and separated it from the + DISPATCHERPROTO() definition. Now the DISPATCHERPROTO() should + only be used to get the correct prototype and the plain + DISPATCHER() for defining the dispatcher itself. + 1.17 14.07.08 : added "_" to all UNUSED variable specifications to make sure + a user does not use those definition on accident. + 1.18 20.03.09 : modified macros to be somewhat more compatible for an AROS + usage (Pavel Fedin) + 1.19 25.03.09 : fixed the DISPATCHERPROTO() macros for x86_64 AROS. + 1.20 26.03.09 : fixed m68k define checks. + 1.21 19.05.09 : added SDISPATCHER() to generate a static dispatcher. + 1.22 24.06.10 : fixed AROS macros (Matthias Rustler). + 1.23 12.08.10 : added missing proto/alib.h include for AROS + 1.24 03.03.11 : fixed AROS macros for m68k (Jason McMullan) + 1.25 18.07.12 : added crosscall macros for functions with 1 and 2 parameters. + These macros are to be used in case i.e. PPC code is to be called + from m68k code. The function pointer must be passed with ENTRY(). + 1.26 17.10.12 : added crosscall macros for functions with 1 and 2 parameters but + no return value. +*/ + +/* +** This is PD (Public Domain). This means you can do with it whatever you want +** without any restrictions. I only ask you to tell me improvements, so I may +** fix the main line of this files as well. +** +** To keep confusion level low: When changing this file, please note it in +** above history list and indicate that the change was not made by myself +** (e.g. add your name or nick name). +** +** Find the latest version of this file at: +** http://sf.net/p/adtools/code/HEAD/tree/trunk/sdi/ +** +** Jens Maus +** Dirk Stoecker +*/ + +#include "SDI_compiler.h" + +/* +** Hook macros to handle the creation of Hooks/Dispatchers for different +** Operating System versions. +** Currently AmigaOS, AROS, and MorphOS are supported. +** +** For more information about hooks see include file or +** the relevant descriptions in utility.library autodocs. +** +** Example: +** +** Creates a hook with the name "TestHook" that calls a corresponding +** function "TestFunc" that will be called with a pointer "text" +** (in register A1) and returns a long. +** +** HOOKPROTONHNO(TestFunc, LONG, STRPTR text) +** { +** Printf(text); +** return 0; +** } +** MakeHook(TestHook, TestFunc); +** +** Every function that is created with HOOKPROTO* must have a MakeHook() or +** MakeStaticHook() to create the corresponding hook. Best is to call this +** directly after the hook function. This is required by the GCC macros. +** +** The naming convention for the Hook Prototype macros is as followed: +** +** HOOKPROTO[NH][NO][NP] +** ^^ ^^ ^^ +** NoHook | NoParameter +** NoObject +** +** So a plain HOOKPROTO() creates you a Hook function that requires +** 4 parameters, the "name" of the hookfunction, the "obj" in REG_A2, +** the "param" in REG_A1 and a "hook" in REG_A0. Usually you will always +** use NH, as the hook structure itself is nearly never required. +** +** The DISPATCHERPROTO macro is for MUI dispatcher functions. It gets the +** functionname as argument. To supply this function for use by MUI, use +** The ENTRY macro, which also gets the function name as argument. +*/ + +#if !defined(__AROS__) && (defined(_M68000) || defined(__M68000) || defined(__mc68000)) + #define HOOKPROTO(name, ret, obj, param) static SAVEDS ASM ret \ + name(REG(a0, struct Hook *hook), REG(a2, obj), REG(a1, param)) + #define HOOKPROTONO(name, ret, param) static SAVEDS ASM ret \ + name(REG(a0, struct Hook *hook), REG(a1, param)) + #define HOOKPROTONP(name, ret, obj) static SAVEDS ASM ret \ + name(REG(a0, struct Hook *hook), REG(a2, obj)) + #define HOOKPROTONONP(name, ret) static SAVEDS ASM ret \ + name(REG(a0, struct Hook *hook)) + #define HOOKPROTONH(name, ret, obj, param) static SAVEDS ASM ret \ + name(REG(a2, obj), REG(a1, param)) + #define HOOKPROTONHNO(name, ret, param) static SAVEDS ASM ret \ + name(REG(a1, param)) + #define HOOKPROTONHNP(name, ret, obj) static SAVEDS ASM ret \ + name(REG(a2, obj)) + #define HOOKPROTONHNONP(name, ret) static SAVEDS ret name(void) +#else + /* NOTE: This is fine for AROS, since HookEntry will handle stack params + */ + #define HOOKPROTO(name, ret, obj, param) static SAVEDS ret \ + name(struct Hook *hook, obj, param) + #define HOOKPROTONO(name, ret, param) static SAVEDS ret \ + name(struct Hook *hook, UNUSED APTR _obj, param) + #define HOOKPROTONP(name, ret, obj) static SAVEDS ret \ + name(struct Hook *hook, obj, UNUSED APTR _param) + #define HOOKPROTONONP(name, ret) static SAVEDS ret \ + name(struct Hook *hook, UNUSED APTR _obj, UNUSED APTR _param) + #define HOOKPROTONH(name, ret, obj, param) static SAVEDS ret \ + name(UNUSED struct Hook *_hook, obj, param) + #define HOOKPROTONHNO(name, ret, param) static SAVEDS ret \ + name(UNUSED struct Hook *_hook, UNUSED APTR _obj, param) + #define HOOKPROTONHNP(name, ret, obj) static SAVEDS ret \ + name(UNUSED struct Hook *_hook, obj, UNUSED APTR _param) + #define HOOKPROTONHNONP(name, ret) static SAVEDS ret name(void) +#endif + +#ifdef __MORPHOS__ + + #ifndef SDI_TRAP_LIB /* avoid defining this twice */ + #include + #include + + #define SDI_TRAP_LIB 0xFF00 /* SDI prefix to reduce conflicts */ + + struct SDI_EmulLibEntry + { + UWORD Trap; + UWORD pad; + APTR Func; + }; + #endif + + #define MakeHook(hookname, funcname) struct Hook hookname = {{NULL, NULL}, \ + (HOOKFUNC)HookEntry, (HOOKFUNC)funcname, NULL} + #define MakeHookWithData(hookname, funcname, data) struct Hook hookname = \ + {{NULL, NULL}, (HOOKFUNC)HookEntry, (HOOKFUNC)funcname, (APTR)data} + #define MakeStaticHook(hookname, funcname) static struct Hook hookname = \ + {{NULL, NULL}, (HOOKFUNC)HookEntry, (HOOKFUNC)funcname, NULL} + #define DISPATCHERPROTO(name) ULONG name(struct IClass * cl, Object * obj, \ + Msg msg); \ + extern const struct SDI_EmulLibEntry Gate_##name + #define DISPATCHER(name) \ + struct IClass; \ + ULONG name(struct IClass * cl, Object * obj, Msg msg); \ + static ULONG Trampoline_##name(void) {return name((struct IClass *) \ + REG_A0, (Object *) REG_A2, (Msg) REG_A1);} \ + const struct SDI_EmulLibEntry Gate_##name = {SDI_TRAP_LIB, 0, \ + (APTR) Trampoline_##name}; \ + ULONG name(struct IClass * cl, Object * obj, Msg msg) + #define SDISPATCHER(name) \ + struct IClass; \ + static ULONG name(struct IClass * cl, Object * obj, Msg msg); \ + static ULONG Trampoline_##name(void) {return name((struct IClass *) \ + REG_A0, (Object *) REG_A2, (Msg) REG_A1);} \ + static const struct SDI_EmulLibEntry Gate_##name = {SDI_TRAP_LIB, 0, \ + (APTR) Trampoline_##name}; \ + static ULONG name(struct IClass * cl, Object * obj, Msg msg) + #define CROSSCALL1(name, ret, type1, param1) \ + static STDARGS SAVEDS ret name(type1 param1); \ + static ret Trampoline_##name(void) \ + { \ + ULONG *stk = (ULONG *)REG_A7; \ + type1 param1 = (type1)stk[1]; \ + return name(param1); \ + } \ + static const struct SDI_EmulLibEntry Gate_##name = {SDI_TRAP_LIB, 0, \ + (APTR) Trampoline_##name}; \ + static STDARGS SAVEDS ret name(type1 param1, type2 param2) + #define CROSSCALL1NR(name, type1, param1) \ + static STDARGS SAVEDS void name(type1 param1); \ + static void Trampoline_##name(void) \ + { \ + ULONG *stk = (ULONG *)REG_A7; \ + type1 param1 = (type1)stk[1]; \ + name(param1); \ + } \ + static const struct SDI_EmulLibEntry Gate_##name = {SDI_TRAP_LIB, 0, \ + (APTR) Trampoline_##name}; \ + static STDARGS SAVEDS void name(type1 param1) + #define CROSSCALL2(name, ret, type1, param1, type2, param2) \ + static STDARGS SAVEDS ret name(type1 param1, type2 param2); \ + static ret Trampoline_##name(void) \ + { \ + ULONG *stk = (ULONG *)REG_A7; \ + type1 param1 = (type1)stk[1]; \ + type2 param2 = (type2)stk[2]; \ + return name(param1, param2); \ + } \ + static const struct SDI_EmulLibEntry Gate_##name = {SDI_TRAP_LIB, 0, \ + (APTR) Trampoline_##name}; \ + static STDARGS SAVEDS ret name(type1 param1, type2 param2) + #define CROSSCALL2NR(name, type1, param1, type2, param2) \ + static STDARGS SAVEDS void name(type1 param1, type2 param2); \ + static void Trampoline_##name(void) \ + { \ + ULONG *stk = (ULONG *)REG_A7; \ + type1 param1 = (type1)stk[1]; \ + type2 param2 = (type2)stk[2]; \ + name(param1, param2); \ + } \ + static const struct SDI_EmulLibEntry Gate_##name = {SDI_TRAP_LIB, 0, \ + (APTR) Trampoline_##name}; \ + static STDARGS SAVEDS void name(type1 param1, type2 param2) + #define ENTRY(func) (APTR)&Gate_##func + +#elif defined(__AROS__) + #include + + #define MakeHook(hookname, funcname) struct Hook hookname = {{NULL, NULL}, \ + (HOOKFUNC)HookEntry, (HOOKFUNC)funcname, NULL} + #define MakeHookWithData(hookname, funcname, data) struct Hook hookname = \ + {{NULL, NULL}, (HOOKFUNC)HookEntry, (HOOKFUNC)funcname, (APTR)data} + #define MakeStaticHook(hookname, funcname) static struct Hook hookname = \ + {{NULL, NULL}, (HOOKFUNC)HookEntry, (HOOKFUNC)funcname, NULL} + #define DISPATCHERPROTO(name) \ + IPTR name(struct IClass * cl, Object * obj, Msg msg); \ + AROS_UFP3(IPTR, Gate_##name, \ + AROS_UFPA(struct IClass *, cl, A0), \ + AROS_UFPA(Object *, obj, A2), \ + AROS_UFPA(Msg, msg, A1)) + #define DISPATCHERx(x,name) \ + x IPTR name(struct IClass * cl, Object * obj, Msg msg); \ + x AROS_UFH3(IPTR, Gate_##name, \ + AROS_UFHA(struct IClass *, cl, A0), \ + AROS_UFHA(Object *, obj, A2), \ + AROS_UFHA(Msg, msg, A1)) \ + { AROS_USERFUNC_INIT \ + return name(cl, obj, msg); \ + AROS_USERFUNC_EXIT \ + } \ + x IPTR name(struct IClass * cl, Object * obj, Msg msg) + #define DISPATCHER(name) DISPATCHERx(,name) + #define SDISPATCHER(name) DISPATCHERx(static,name) + #define CROSSCALL1(name, ret, type1, param1) \ + static STDARGS SAVEDS ret Gate_##name(type1 param1) + #define CROSSCALL1NR(name, type1, param1) \ + static STDARGS SAVEDS void Gate_##name(type1 param1) + #define CROSSCALL2(name, ret, type1, param1, type2, param2) \ + static STDARGS SAVEDS ret Gate_##name(type1 param1, type2 param2) + #define CROSSCALL2NR(name, type1, param1, type2, param2) \ + static STDARGS SAVEDS void Gate_##name(type1 param1, type2 param2) + #define ENTRY(func) (APTR)Gate_##func + +#else /* !__MORPHOS__ && !__AROS__*/ + + #define MakeHook(hookname, funcname) struct Hook hookname = {{NULL, NULL}, \ + (HOOKFUNC)funcname, NULL, NULL} + #define MakeHookWithData(hookname, funcname, data) struct Hook hookname = \ + {{NULL, NULL}, (HOOKFUNC)funcname, NULL, (APTR)data} + #define MakeStaticHook(hookname, funcname) static struct Hook hookname = \ + {{NULL, NULL}, (HOOKFUNC)funcname, NULL, NULL} + #define DISPATCHERPROTO(name) SAVEDS ASM IPTR name(REG(a0, \ + struct IClass * cl), REG(a2, Object * obj), REG(a1, Msg msg)) + #define DISPATCHER(name) DISPATCHERPROTO(name) + #define SDISPATCHER(name) static DISPATCHERPROTO(name) + #define CROSSCALL1(name, ret, type1, param1) \ + static STDARGS SAVEDS ret name(type1 param1) + #define CROSSCALL1NR(name, type1, param1) \ + static STDARGS SAVEDS void name(type1 param1) + #define CROSSCALL2(name, ret, type1, param1, type2, param2) \ + static STDARGS SAVEDS ret name(type1 param1, type2 param2) + #define CROSSCALL2NR(name, type1, param1, type2, param2) \ + static STDARGS SAVEDS void name(type1 param1, type2 param2) + #define ENTRY(func) (APTR)func + +#endif + +#define InitHook(hook, orighook, data) ((hook)->h_Entry = (orighook).h_Entry,\ + (hook)->h_SubEntry = (orighook).h_SubEntry,(hook)->h_Data = (APTR)(data)) + +#endif /* SDI_HOOK_H */ diff --git a/test/sdi/SDI_interrupt.h b/test/sdi/SDI_interrupt.h new file mode 100644 index 0000000000..45ed500a24 --- /dev/null +++ b/test/sdi/SDI_interrupt.h @@ -0,0 +1,156 @@ +#ifndef SDI_INTERRUPT_H +#define SDI_INTERRUPT_H + +/* Includeheader + + Name: SDI_interrupt.h + Versionstring: $VER: SDI_interrupt.h 1.1 (25.04.2006) + Author: Guido Mersmann + Distribution: PD + Project page: http://sf.net/p/adtools/code/HEAD/tree/trunk/sdi/ + Description: defines to hide compiler specific interrupt and + handler stuff + Id: $Id$ + URL: $URL: svn://svn.code.sf.net/p/adtools/code/trunk/sdi/SDI_interrupt.h $ + + 1.0 17.05.05 : inspired by the SDI_#?.h files made by Jens Langner + and Dirk Stöcker I created files to handle interrupt + and handler functions in an API compatible way. + 1.1 25.04.06 : fixed MakeInterrupt() and MakeHandler() macro. (geit) + +*/ + +/* +** This is PD (Public Domain). This means you can do with it whatever you want +** without any restrictions. I only ask you to tell me improvements, so I may +** fix the main line of this files as well. +** +** To keep confusion level low: When changing this file, please note it in +** above history list and indicate that the change was not made by myself +** (e.g. add your name or nick name). +** +** Find the latest version of this file at: +** http://sf.net/p/adtools/code/HEAD/tree/trunk/sdi/ +** +** Guido Mersmann +** +*/ + +#include "SDI_compiler.h" + +/* +** The INTERRUPTPROTO macro is for creating interrupts functions and the +** HANDLERPROTO macro is for handler type setup like used by the +** input.device. +** +** The usage is simular to the DISPATCHERPROTO macro provided by SDI_hook.h. +** +** It gets the function name as argument. To supply this function for use by +** an interrupt structure or handler argument, use the ENTRY macro, which also +** gets the function name as argument. There is also a MakeInterrupt and a +** MakeHandler macro for easy structure setup. +** +** Example: +** +** We create a handler function for the input.device. +** +** HANDLERPROTO( handlerfunc, ULONG, struct InputEvent *inputevent, APTR userdata) +** { +** ... Modify/parse input stream here +** ... +** return( (ULONG) inputevent ); +** } +** MakeHandler( handlerstruct, handlerfunc, "TestHandler", &our_user_data); +** +** As you can see usage is as simple as using SDI hooks. To create interrupt +** use INTERRUPTPROTO and MakeInterrupt. Internally both macros are identically. +** +** There are also functions to create more specific interrupt and handler +** structures. By default type is NT_INTERRUPT and priority is 0. +** +** MakeHandlerType - additional argument for type +** MakeHandlerPri - additional argument for pri +** MakeHandlerTypePri - additional arguments for type and pri +** +** +** Notes: Since the interrupt structure is used for handlers and also foreign +** handlers are using this structure I keeped the arguments definition +** on the user side. +** +*/ + +#ifdef __MORPHOS__ + +#ifndef SDI_TRAP_LIB /* avoid defining this twice */ + + #include + #include + + #define SDI_TRAP_LIB 0xFF00 /* SDI prefix to reduce conflicts */ + + struct SDI_EmulLibEntry + { + UWORD Trap; + UWORD pad; + APTR Func; + }; +#endif + + #define INTERRUPTPROTO(name, ret, obj, data) \ + SAVEDS ASM ret name( obj, data); \ + static ret Trampoline_##name(void) {return name(( obj) REG_A0, \ + (data) REG_A1);} \ + static const struct SDI_EmulLibEntry Gate_##name = {SDI_TRAP_LIB, 0, \ + (APTR) Trampoline_##name}; \ + SAVEDS ASM ret name( obj, data) + + #define HANDLERPROTO(name, ret, obj, data) \ + SAVEDS ASM ret name( obj, data); \ + static ret Trampoline_##name(void) {return name(( obj) REG_A0, \ + (data) REG_A1);} \ + static const struct SDI_EmulLibEntry Gate_##name = {SDI_TRAP_LIB, 0, \ + (APTR) Trampoline_##name}; \ + SAVEDS ASM ret name( obj, data) + + #define ENTRY(func) (APTR)&Gate_##func + +#else + + #define INTERRUPTPROTO(name, ret, obj, data) \ + SAVEDS ASM ret name(REG(a0, obj), REG(a1, data)) + #define HANDLERPROTO(name, ret, obj, data) \ + SAVEDS ASM ret name(REG(a0, obj), REG(a1, data)) + + #define ENTRY(func) (APTR)func + +#endif /* __MORPHOS__ */ + +/* some structure creating macros for easy and more specific usage */ + +#define MakeInterrupt( name, func, title, isdata ) \ + static struct Interrupt name = {{ NULL, NULL, NT_INTERRUPT, 0, (STRPTR) title}, (APTR) isdata, (void (*)()) ENTRY(func) } + +#define MakeInterruptPri( name, func, title, isdata, pri ) \ + static struct Interrupt name = {{ NULL, NULL, NT_INTERRUPT, pri, (STRPTR) title}, (APTR) isdata, (void (*)()) ENTRY(func) } + +#define MakeInterruptType( name, func, title, isdata, type ) \ + static struct Interrupt name = {{ NULL, NULL, type, 0, (STRPTR) title}, (APTR) isdata, (void (*)()) ENTRY(func) } + +#define MakeInterruptTypePri( name, func, title, isdata, type, pri ) \ + static struct Interrupt name = {{ NULL, NULL, type, pri, (STRPTR) title}, (APTR) isdata, (void (*)()) ENTRY(func) } + +#define MakeHandler( name, func, title, isdata ) \ + static struct Interrupt name = {{ NULL, NULL, NT_INTERRUPT, 0, (STRPTR) title}, (APTR) isdata, (void (*)()) ENTRY(func) } + +#define MakeHandlerPri( name, func, title, isdata, pri ) \ + static struct Interrupt name = {{ NULL, NULL, NT_INTERRUPT, pri, (STRPTR) title}, (APTR) isdata, (void (*)()) ENTRY(func) } + +#define MakeHandlerType( name, func, title, isdata, type ) \ + static struct Interrupt name = {{ NULL, NULL, type, 0, (STRPTR) title}, (APTR) isdata, (void (*)()) ENTRY(func) } + +#define MakeHandlerTypePri( name, func, title, isdata, type, pri ) \ + static struct Interrupt name = {{ NULL, NULL, type, pri, (STRPTR) title}, (APTR) isdata, (void (*)()) ENTRY(func) } + + +#endif /* SDI_INTERRUPT_H */ + diff --git a/test/sdi/SDI_lib.h b/test/sdi/SDI_lib.h new file mode 100644 index 0000000000..a93e4693f6 --- /dev/null +++ b/test/sdi/SDI_lib.h @@ -0,0 +1,199 @@ +#ifndef SDI_LIB_H +#define SDI_LIB_H + +/* Includeheader + + Name: SDI_lib.h + Versionstring: $VER: SDI_lib.h 1.12 (01.04.2014) + Author: Jens Maus + Distribution: PD + Project page: http://sf.net/p/adtools/code/HEAD/tree/trunk/sdi/ + Description: defines to hide OS specific library function definitions + Id: $Id$ + URL: $URL: svn://svn.code.sf.net/p/adtools/code/trunk/sdi/SDI_lib.h $ + + 1.0 09.05.04 : initial version which allows to hide OS specific shared + library function definition like it has been introduced with + the new interface based library system in AmigaOS4. + 1.1 13.05.04 : replaced the LIBENTRY() macro with some more sophisticated + LFUNC_ macros which allow to maintain varargs library functions + in a much easier manner. + 1.2 22.05.04 : removed the anyway not required SAVEDS and ASM statements + from the LIBFUNC macro for OS4. Also removed the LIBFUNC + statement in the 68k LIBPROTOVA() macro so that no registers + can be used in there (which should be the default). + 1.3 04.07.04 : added empty LIBFUNC define for MorphOS which was missing. + 1.4 05.10.04 : added missing LIBFUNC call to OS3/MOS interface + 1.5 19.05.05 : fixed some documentation glitches (Guido Mersmann) + 1.6 08.06.05 : swapped LIBFUNC and ret within the prototype, because + c standard says attributes first and vbcc want them like + this. (Guido Mersmann) + changed the documentation to explain that LIBFUNC must be + set first. (Guido Mersmann) + 1.7 11.12.05 : adapted all macros to be somewhat more compatible to also + OS3 and MorphOS. Now in the real use case (codesets.library) + it required a fundamental rework of the macros. (Jens Langner) + 1.8 28.02.06 : removed "##" in front of the OS3 __VARARGS__ usage as they + causing errors on GCC >= 3.x. + 1.9 15.03.09 : fixed some missing function prototype in LIBPROTOVA() + 1.10 30.04.09 : added approriate LIBPROTOVA() definition for OS3 and MorphOS + to at least make the functions known. The same pattern as for + LIBSTUBVA() will be used now (Thore Böckelmann) + 1.11 04.05.09 : reverted the faulty LIBPROTOVA() definition to its previous + version (Thore Böckelmann) + 1.12 01.04.14 : removed the necessity of stub functions for AmigaOS4 (Thore + Böckelmann) +*/ + +/* +** This is PD (Public Domain). This means you can do with it whatever you want +** without any restrictions. I only ask you to tell me improvements, so I may +** fix the main line of this files as well. +** +** To keep confusion level low: When changing this file, please note it in +** above history list and indicate that the change was not made by myself +** (e.g. add your name or nick name). +** +** Find the latest version of this file at: +** http://sf.net/p/adtools/code/HEAD/tree/trunk/sdi/ +** +** Jens Maus +** Dirk Stöcker +*/ + +#include "SDI_compiler.h" + +/* +** Library function macros to handle the definition/usage for different +** Operating System versions. +** Currently special library function handling for AmigaOS version 4 is +** supported +** +** Example: +** +** Defines a library jump function "TestFunc" with a ULONG return value and +** which is called by the corresponding library vector of a shared library. +** +** LIBPROTO(TestFunc, ULONG, REG(a6, UNUSED __BASE_OR_IFACE), REG(a0, char *text)) +** { +** Printf(text); +** return 0; +** } +** +** Please note the use of the LIBPROTO macro which defines this function +** automatically as a function which is directly called from within a shared +** library. For AmigaOS4 the library interface pointer is passed as a variable +** named "self" to the function. For all other systems the library base pointer +** is passed. +** Since this macro contains compiler attributes it must be called first, even +** if some compiler allow attributes and result type mixed, other do not and we +** want to keep the stuff compiler independent. +** +** If you now require to have some OS/compiler independent prototype +** definition please use the following statement: +** +** LIBPROTO(TestFunc, ULONG, REG(a6, UNUSED __BASE_OR_IFACE), REG(a0, char *text)); +** +** This will ensure that you get a proper prototype for the same function +** where this macro will automatically take care that a LIBSTUB_* stub +** function will also automatically defined as required if you are generating +** a shared library for MorphOS. +** +** So if you then want to add this function to a library interface please +** use the LFUNC_* macros to generate your library function vector +** like this example one: +** +** #define libvector LFUNC_FAS(SomeFunc) \ +** LFUNC_FA_(TestFunc) \ +** LFUNC_VA_(VarargsFunc) +** +** This way you can then easily put the "libvector" define in your real +** library function vector of your shared library instead of having to +** specify each function with surrounded "#ifdef" defines. These macros +** will then also take automatically care that the varargs functions +** will only be specified on OS versions where these functions are now +** real functions, like with AmigaOS4. +** +** Stub functions are needed for MorphOS only and usually look like this: +** +** LIBSTUB(TestFunc, ULONG) +** { +** __BASE_OR_IFACE = (__BASE_OR_IFACE_TYPE)REG_A6; +** return CALL_LFUNC(TestFunc, (char *)REG_A0); +** } +** +** The CALL_LFUNC macro must be used to internally call one of the public +** library functions without going through the interface/jump table. +** The CALL_LFUNC_NP macro does the same job for functions without further +** parameters, except the implicit interface/base pointer. +** +** By using this schema a developer might ensure full source code backward +** compatibility to AmigaOS3 without having to introduce dozens of #ifdef +** statements in his code. +*/ + +#ifdef LIBFUNC +#undef LIBFUNC +#endif + +#if defined(__amigaos4__) + #define LIBFUNC + #if !defined(__cplusplus) && \ + (__STDC_VERSION__ >= 199901L || __GNUC__ >= 3 || \ + (__GNUC__ == 2 && __GNUC_MINOR__ >= 95)) + #define LIBPROTO(name, ret, ...) \ + LIBFUNC ret LIB_##name(__VA_ARGS__) + #define LIBPROTOVA(name, ret, ...) \ + LIBFUNC ret VARARGS68K LIB_##name(__VA_ARGS__) + #define LIBSTUB(name, ret, ...) + #define CALL_LFUNC_NP(name, ...) LIB_##name(__BASE_OR_IFACE_VAR) + #define CALL_LFUNC(name, ...) LIB_##name(__BASE_OR_IFACE_VAR, __VA_ARGS__) + #endif + #define LFUNC_FAS(name) LIB_##name + #define LFUNC_VAS(name) LIB_##name + #define LFUNC_FA_(name) ,LIB_##name + #define LFUNC_VA_(name) ,LIB_##name + #define LFUNC(name) LIB_##name +#elif defined(__MORPHOS__) + #define LIBFUNC + #if !defined(__cplusplus) && \ + (__STDC_VERSION__ >= 199901L || __GNUC__ >= 3 || \ + (__GNUC__ == 2 && __GNUC_MINOR__ >= 95)) + #define LIBPROTO(name, ret, ...) \ + LIBFUNC ret LIBSTUB_##name(void); \ + LIBFUNC ret LIB_##name(__VA_ARGS__) + #define LIBPROTOVA(name, ret, ...) + #define LIBSTUB(name, ret, ...) \ + LIBFUNC ret LIBSTUB_##name(void) + #define CALL_LFUNC_NP(name, ...) LIB_##name(__BASE_OR_IFACE_VAR) + #define CALL_LFUNC(name, ...) LIB_##name(__BASE_OR_IFACE_VAR, __VA_ARGS__) + #endif + #define LFUNC_FAS(name) LIBSTUB_##name + #define LFUNC_VAS(name) + #define LFUNC_FA_(name) ,LIBSTUB_##name + #define LFUNC_VA_(name) + #define LFUNC(name) LIBSTUB_##name +#else + #define LIBFUNC SAVEDS ASM + #if !defined(__cplusplus) && \ + (__STDC_VERSION__ >= 199901L || __GNUC__ >= 3 || \ + (__GNUC__ == 2 && __GNUC_MINOR__ >= 95)) + #define LIBPROTO(name, ret, ...) \ + LIBFUNC ret LIB_##name(__VA_ARGS__) + #define LIBPROTOVA(name, ret, ...) + #define LIBSTUB(name, ret, ...) + #define CALL_LFUNC_NP(name, ...) LIB_##name(__BASE_OR_IFACE_VAR) + #define CALL_LFUNC(name, ...) LIB_##name(__BASE_OR_IFACE_VAR, __VA_ARGS__) + #endif + #define LFUNC_FAS(name) LIB_##name + #define LFUNC_VAS(name) + #define LFUNC_FA_(name) ,LIB_##name + #define LFUNC_VA_(name) + #define LFUNC(name) LIB_##name +#endif + +#if !defined(LIBPROTO) || !defined(LIBPROTOVA) + #error "OS or compiler is not yet supported by SDI_lib.h" +#endif + +#endif /* SDI_LIB_H */ diff --git a/test/sdi/SDI_misc.h b/test/sdi/SDI_misc.h new file mode 100644 index 0000000000..5680139780 --- /dev/null +++ b/test/sdi/SDI_misc.h @@ -0,0 +1,121 @@ +#ifndef SDI_MISC_H +#define SDI_MISC_H + +/* Includeheader + + Name: SDI_misc.h + Versionstring: $VER: SDI_misc.h 1.0 (17.05.2005) + Author: Guido Mersmann + Distribution: PD + Project page: http://sf.net/p/adtools/code/HEAD/tree/trunk/sdi/ + Description: defines to hide compiler specific function stuff. + This header is ment to keep all minor functions + like PutChProc() used by RawDoFMT(). + Id: $Id$ + URL: $URL: svn://svn.code.sf.net/p/adtools/code/trunk/sdi/SDI_misc.h $ + + 1.0 17.05.05 : inspired by the SDI_#?.h files made by Jens Langner + and Dirk Stöcker I created this file to handle rawdofmt() + functions. +*/ + +/* +** This is PD (Public Domain). This means you can do with it whatever you want +** without any restrictions. I only ask you to tell me improvements, so I may +** fix the main line of this files as well. +** +** To keep confusion level low: When changing this file, please note it in +** above history list and indicate that the change was not made by myself +** (e.g. add your name or nick name). +** +** Find the latest version of this file at: +** http://sf.net/p/adtools/code/HEAD/tree/trunk/sdi/ +** +** Guido Mersmann +** +*/ + +#include "SDI_compiler.h" + +/* +** Function macros to handle the creation of functions for different +** Operating System versions. +** Currently AmigaOS and MorphOS is supported. +** +** Currently the following macros are available: +** +** PUTCHARPROTO +** +** When using RawDoFmt() from exec.library you need this function to +** store the output created by the function. +** +** For more information about RawDoFmt() take a look into the +** relevant descriptions in exec.library autodocs. +** +** Example: +** +** struct SPrintfStream +** { +** char *Target; +** ULONG TargetSize; +** }; +** +** PUTCHARPROTO( SPrintf_DoChar, char c, struct SPrintfStream *s ) +** { +** *(s->Target++) = c; +** } +** +** ULONG SPrintf(char *format, char *target, ULONG *args) +** { +** struct SPrintfStream s; +** +** s.Target = target; +** +** RawDoFmt( format, args, ENTRY( SPrintf_DoChar), &s); +** +** return( s.Target - target); +** } +** +** As you can see usage within RawDoFmt() requires using the ENTRY() +** macro. +** +*/ + +#ifdef __MORPHOS__ + +#ifndef SDI_TRAP_LIB /* avoid defining this twice */ + + #include + #include + + #define SDI_TRAP_LIB 0xFF00 /* SDI prefix to reduce conflicts */ + + struct SDI_EmulLibEntry + { + UWORD Trap; + UWORD pad; + APTR Func; + }; + +#endif + + #define PUTCHARPROTO(name, chr, buffer) \ + SAVEDS ASM void name( chr, buffer); \ + static void Trampoline_##name(void) { name(( chr) REG_D0, \ + (buffer) REG_A3);} \ + static const struct SDI_EmulLibEntry Gate_##name = {SDI_TRAP_LIB, 0, \ + (APTR) Trampoline_##name}; \ + SAVEDS ASM void name( chr, buffer) + + #define ENTRY(func) (APTR)&Gate_##func + +#else + + #define PUTCHARPROTO(name, chr, buffer) \ + SAVEDS ASM void name(REG(d0, chr), REG(a3, buffer)) + + #define ENTRY(func) (APTR)func + +#endif /* __MORPHOS__ */ + +#endif /* SDI_MISC_H */ diff --git a/test/sdi/SDI_stdarg.h b/test/sdi/SDI_stdarg.h new file mode 100644 index 0000000000..12871689ee --- /dev/null +++ b/test/sdi/SDI_stdarg.h @@ -0,0 +1,108 @@ +#ifndef SDI_STDARG_H +#define SDI_STDARG_H + +/* Includeheader + + Name: SDI_stdarg.h + Versionstring: $VER: SDI_stdarg.h 1.1 (06.06.2014) + Author: Jens Maus + Distribution: PD + Project page: http://sf.net/p/adtools/code/HEAD/tree/trunk/sdi/ + Description: defines to hide OS specific variable arguments + function definitions + Id: $Id$ + URL: $URL: svn://svn.code.sf.net/p/adtools/code/trunk/sdi/SDI_stdarg.h $ + + 1.0 05.07.2004 : initial version + 1.1 06.06.2014 : added a type cast to VA_ARG() result + +*/ + +/* +** This is PD (Public Domain). This means you can do with it whatever you want +** without any restrictions. I only ask you to tell me improvements, so I may +** fix the main line of this files as well. +** +** To keep confusion level low: When changing this file, please note it in +** above history list and indicate that the change was not made by myself +** (e.g. add your name or nick name). +** +** Find the latest version of this file at: +** http://sf.net/p/adtools/code/HEAD/tree/trunk/sdi/ +** +** Jens Maus +** Dirk Stöcker +*/ + +#include "SDI_compiler.h" + +/* +** Variable arguments function macros to allow specification of the +** variable arguments typical functions like va_list/va_start/va_end in +** an operating system independent fashion. +** +** With help of the following macro definition a developer might define +** variable arguments functions for different types of operating +** system implementations without having to clutter the sources with +** multiple "#ifdef" defines just because all of these operating systems +** come with different varable arguments support functions. +** +** Example: +** +** Instead of using the standard va_list, va_start and va_end functions +** of , a developer might specify the following sprintf() +** function to make it automatically compatible with AmigaOS3, AmigaOS4 +** and also MorphOS. +** +** int VARARGS68K sprintf(char *buf, char *fmt, ...) +** { +** VA_LIST args; +** +** VA_START(args, fmt); +** RawDoFmt(fmt, VA_ARG(args, void *), NULL, buf); +** VA_END(args); +** +** return(strlen(buf)); +** } +** +** Please note the uppercase letters of the macros in contrast to the +** official varargs functions specified in . +** +** By using this schema a developer might ensure full source code backward +** compatibility to AmigaOS3 without having to introduce dozens of #ifdef +** statements in his code. +*/ + +#include + +#ifdef VA_LIST +#undef VA_LIST +#endif +#ifdef VA_START +#undef VA_START +#endif +#ifdef VA_ARG +#undef VA_ARG +#endif +#ifdef VA_END +#undef VA_END +#endif + +#if defined(__amigaos4__) + #define VA_LIST va_list + #define VA_START(va, start) va_startlinear((va), (start)) + #define VA_ARG(va, type) va_getlinearva((va), type) + #define VA_END(va) va_end((va)) +#elif defined(__MORPHOS__) + #define VA_LIST va_list + #define VA_START(va, start) va_start((va), (start)) + #define VA_ARG(va, type) (type)((va)->overflow_arg_area) + #define VA_END(va) va_end((va)) +#else + #define VA_LIST va_list + #define VA_START(va, start) va_start((va), (start)) + #define VA_ARG(va, type) (type)(va) + #define VA_END(va) va_end((va)) +#endif + +#endif /* SDI_STDARG_H */ diff --git a/test/sdi/examples/hooks/example_hookuse.c b/test/sdi/examples/hooks/example_hookuse.c new file mode 100755 index 0000000000..fb9cdab1d6 --- /dev/null +++ b/test/sdi/examples/hooks/example_hookuse.c @@ -0,0 +1,86 @@ +/* Example source + + Name: example_hookuse.c + Versionstring: $VER: example_hookuse.c 1.0 (06.10.2004) + Author: Jens Langner + Distribution: PD + Description: shows how the SDI_hook.h header include are used + + 1.0 06.10.04 : initial version showing how the SDI_hook.h header have to be + used if one wants to keep the sources platform independent + throughout all common AmigaOS compatible platforms like OS3, + OS4 and MorphOS. + + + Please note that this example is just for educational purposes and wasn't + checked for complete correctness. However, it should compile and probably also + work as expected. But please note that its purpose is to show how the hook + macros make it very easy to deal with hooks and also keep the sources simple + and platform independent through OS3, OS4 and MorphOS. + + Feel free to comment and submit any suggestions directly to + Jens.Langner@light-speed.de + +*/ + +#include +#include + +#include +#include +#include + +#include "SDI_hook.h" + +/******************************************************************************/ +/* Own hook definitions */ +/******************************************************************************/ + +// The following hook is just an example hook where we use the object +// for printing out some minor text. Do you see how easy it is to use hooks and +// how great it is to use SDI_hook.h to automatically keep your sources compatible +// to all common AmigaOS platforms? +HOOKPROTONHNP(HelloFunc, LONG, char *txt) +{ + printf("'%s' which returns ", txt); + + return -10; +} +MakeStaticHook(HelloHook, HelloFunc); + +/******************************************************************************/ +/* The main entry point to just illustrate how the hook is called */ +/******************************************************************************/ + +struct Library *UtilityBase; +#if defined(__amigaos4__) +struct UtilityIFace *IUtility; +#define GETINTERFACE(iface, base) (iface = (APTR)GetInterface((struct Library *)(base), "main", 1L, NULL)) +#define DROPINTERFACE(iface) { DropInterface((APTR)(iface)); iface = NULL; } +#else +#define GETINTERFACE(iface, base) TRUE +#define DROPINTERFACE(iface) +#endif + +int main(void) +{ + LONG ret = 0; + + if((UtilityBase = OpenLibrary("utility.library", 37))) + { + if(GETINTERFACE(IUtility, UtilityBase)) + { + printf("Hello! I am a "); + + ret = CallHook(&HelloHook, "portable Hook"); + + printf("%ld\n", ret); + + DROPINTERFACE(IUtility); + } + + CloseLibrary(UtilityBase); + } + + return 0; +} diff --git a/test/sdi/examples/hooks/makefile.mos b/test/sdi/examples/hooks/makefile.mos new file mode 100644 index 0000000000..72237f4769 --- /dev/null +++ b/test/sdi/examples/hooks/makefile.mos @@ -0,0 +1,58 @@ +# +# $Id: makefile.mos,v 1.2 2005/06/08 06:54:25 damato Exp $ +# +# :ts=4 +# + +CC = ppc-morphos-gcc + +.c.o: + @echo "Compiling $<" + @$(CC) -c $(CFLAGS) -o $*.o $< + +########################################################################### + +NAME = hellohook +VERSION = 51 + +########################################################################### + +WARNINGS = \ + -Wall -W -Wshadow -Wpointer-arith -Wsign-compare -Wmissing-prototypes \ + -Wundef -Wbad-function-cast -Wmissing-declarations + +CPU = -mcpu=604e -mmultiple +OPTIONS = -DNDEBUG -D__USE_INLINE__ +OPTIMIZE = -O3 -fomit-frame-pointer -fstrength-reduce -finline-functions +DEBUG = -g + +########################################################################### + +CFLAGS = -noixemul $(WARNINGS) $(OPTIMIZE) $(DEBUG) $(CPU) $(OPTIONS) -I. \ + -I../../includes +LFLAGS = -L. + +########################################################################### + +OBJS = \ + example_hookuse.o \ + +LIBS = + +########################################################################### + +all: $(NAME) + +$(NAME): $(OBJS) + @echo "Linking $@" + @$(CC) -o $@.debug $(CFLAGS) $(LFLAGS) $(OBJS) $(LIBS) + @ppc-morphos-strip -R.comment -o $@ $@.debug + +########################################################################### + +example_hookuse.o : example_hookuse.c + +########################################################################### + +clean: + -rm *.o *.debug $(NAME) diff --git a/test/sdi/examples/hooks/makefile.os3 b/test/sdi/examples/hooks/makefile.os3 new file mode 100644 index 0000000000..301bf422c2 --- /dev/null +++ b/test/sdi/examples/hooks/makefile.os3 @@ -0,0 +1,59 @@ +# +# $Id: makefile.os3,v 1.2 2005/06/08 06:54:25 damato Exp $ +# +# :ts=4 +# + +CC = m68k-amigaos-gcc + +.c.o: + @echo "Compiling $<" + @$(CC) -c $(CFLAGS) -o $*.o $< + +########################################################################### + +NAME = hellohook +VERSION = 51 + +########################################################################### + +WARNINGS = \ + -Wall -W -Wshadow -Wpointer-arith -Wsign-compare -Wmissing-prototypes \ + -Wundef -Wbad-function-cast -Wmissing-declarations + +CPU = -m68020-60 -msoft-float +OPTIONS = -DNDEBUG -D__USE_INLINE__ +OPTIMIZE = -O3 -fomit-frame-pointer -fstrength-reduce -finline-functions +DEBUG = -g + +########################################################################### + +CFLAGS = -noixemul $(WARNINGS) $(OPTIMIZE) $(DEBUG) $(CPU) $(OPTIONS) -I. \ + -I../../includes +LFLAGS = -L. + +########################################################################### + +OBJS = \ + example_hookuse.o \ + +LIBS = \ + -lc + +########################################################################### + +all: $(NAME) + +$(NAME): $(OBJS) + @echo "Linking $@" + @$(CC) -o $@.debug $(CFLAGS) $(LFLAGS) $(OBJS) $(LIBS) + @m68k-amigaos-strip -R.comment -o $@ $@.debug + +########################################################################### + +example_hookuse.o : example_hookuse.c + +########################################################################### + +clean: + -rm *.o *.debug $(NAME) diff --git a/test/sdi/examples/hooks/makefile.os4 b/test/sdi/examples/hooks/makefile.os4 new file mode 100644 index 0000000000..f8e99d9111 --- /dev/null +++ b/test/sdi/examples/hooks/makefile.os4 @@ -0,0 +1,59 @@ +# +# $Id: makefile.os4,v 1.2 2005/06/08 06:54:25 damato Exp $ +# +# :ts=4 +# + +CC = ppc-amigaos-gcc + +.c.o: + @echo "Compiling $<" + @$(CC) -c $(CFLAGS) -o $*.o $< + +########################################################################### + +NAME = hellohook +VERSION = 51 + +########################################################################### + +WARNINGS = \ + -Wall -W -Wshadow -Wpointer-arith -Wsign-compare -Wmissing-prototypes \ + -Wundef -Wbad-function-cast -Wmissing-declarations + +CPU = -mcpu=604e -mmultiple +OPTIONS = -DNDEBUG -D__USE_INLINE__ +OPTIMIZE = -O3 -fomit-frame-pointer -fstrength-reduce -finline-functions +DEBUG = -g + +########################################################################### + +CFLAGS = $(WARNINGS) $(OPTIMIZE) $(DEBUG) $(CPU) $(OPTIONS) -I. \ + -I../../includes +LFLAGS = -L. + +########################################################################### + +OBJS = \ + example_hookuse.o \ + +LIBS = \ + -lc -lm + +########################################################################### + +all: $(NAME) + +$(NAME): $(OBJS) + @echo "Linking $@" + @$(CC) -o $@.debug $(CFLAGS) $(LFLAGS) $(OBJS) $(LIBS) + @ppc-amigaos-strip -R.comment -o $@ $@.debug + +########################################################################### + +example_hookuse.o : example_hookuse.c + +########################################################################### + +clean: + -rm *.o *.debug $(NAME) diff --git a/test/sdi/examples/libraries/example_lib.c b/test/sdi/examples/libraries/example_lib.c new file mode 100644 index 0000000000..c992a1e2e7 --- /dev/null +++ b/test/sdi/examples/libraries/example_lib.c @@ -0,0 +1,604 @@ +/* Example source + + Name: example_lib.c + Versionstring: $VER: example_lib.c 1.2 (21.06.2007) + Author: Jens Langner + Distribution: PD + Description: shows how the SDI_lib.h header include can be used + + 1.0 05.10.04 : initial version showing how the SDI_lib.h headers can help + when used for maintaining AmigaOS compatible shared library + interfaces upon compatible operating systems like AmigaOS3, + AmigaOS4 and MorphOS. + + 1.1 20.06.07 : moved LIBFUNC to be first in line acording to changes in + SDI_lib.h. (Guido Mersmann) + + 1.2 21.06.07 : added missing libvector to MorphOS/AmigaOS3 libvectors[] + (Guido Mersmann) + + Please note that this example is just for educational purposes and wasn't + checked for complete correctness. However, it should compile and probably also + work as expected. But please note that its purpose is to show how a shared + library can held platform independent over all different available AmigaOS + platforms like OS3, OS4 and MorphOS. + + Feel free to comment and submit any suggestions directly to + Jens.Langner@light-speed.de + +*/ + +#include +#include +#include +#include + +#include + +#ifdef __amigaos4__ +#include +#endif + +#include +#include +#include + +#include +#include + +#define VERSION 1 +#define REVISION 3 +#define DATE "01.04.2014" +#define VERS "example.library 1.3" +#define VSTRING "example.library 1.3 01.04.2014)\r\n" +#define VERSTAG "\0$VER: example.library 1.3 01.04.2014)" + +static const char UserLibName[] = "example.library"; +static const char UserLibID[] = "\0$VER: example.library 1.3 01.04.2014)"; + +#if defined(__MORPHOS__) +struct ExecBase *SysBase; +#endif + +/******************************************************************************/ +/* >> User defineable library functions start here << */ +/* The following section should illustrate how the SDI_lib.h macros make it */ +/* possible to easily maintain a typical Amiga shared library interface if */ +/* compatibility over all common (OS3/OS4, MorphOS) is required */ +/******************************************************************************/ + +/******************************************************************************/ +/* Local Structures & Prototypes */ +/******************************************************************************/ + +struct LibraryHeader +{ + struct Library libBase; + struct Library *sysBase; + ULONG segList; +}; + +#if defined(__amigaos4__) +#define __BASE_OR_IFACE_TYPE struct ExampleIFace * +#define __BASE_OR_IFACE_VAR IExample +#else +#define __BASE_OR_IFACE_TYPE struct LibraryHeader * +#define __BASE_OR_IFACE_VAR ExampleBase +#endif +#define __BASE_OR_IFACE __BASE_OR_IFACE_TYPE __BASE_OR_IFACE_VAR + +// first the prototypes of all our public library functions +LIBPROTO(SayHelloOS4, char *, REG(a6, UNUSED __BASE_OR_IFACE)); +LIBPROTO(SayHelloOS3, char *, REG(a6, UNUSED __BASE_OR_IFACE)); +LIBPROTO(SayHelloMOS, char *, REG(a6, UNUSED __BASE_OR_IFACE)); +LIBPROTO(Uppercase, char *, REG(a6, UNUSED __BASE_OR_IFACE), REG(a0, char *txt)); +LIBPROTO(SPrintfA, char *, REG(a6, UNUSED __BASE_OR_IFACE), REG(a0, char *buf), REG(a1, char *format), REG(a2, APTR args)); +LIBPROTOVA(SPrintf, char *, REG(a6, UNUSED __BASE_OR_IFACE), REG(a0, char *buf), REG(a1, char *format), ...); + +// let us now create the libvector. +// Please note that the start of the vectors has to be always the "LFUNC_FAS" +// macro +#define libvector LFUNC_FAS(SayHelloOS4) \ + LFUNC_FA_(SayHelloOS3) \ + LFUNC_FA_(SayHelloMOS) \ + LFUNC_FA_(Uppercase) \ + LFUNC_FA_(SPrintfA) \ + LFUNC_VA_(SPrintf) + +// Now the real implementations of the library functions above like in +// a normal AmigaOS shared library follow +LIBPROTO(SayHelloOS4, char *, REG(a6, UNUSED __BASE_OR_IFACE)) +{ + return "Hello AmigaOS4!!!"; +} + +LIBPROTO(SayHelloOS3, char *, REG(a6, UNUSED __BASE_OR_IFACE)) +{ + return "Hello AmigaOS3!!!"; +} + +LIBPROTO(SayHelloMOS, char *, REG(a6, UNUSED __BASE_OR_IFACE)) +{ + return "Hello MorphOS!!!"; +} + +LIBPROTO(Uppercase, char *, REG(a6, UNUSED __BASE_OR_IFACE), REG(a0, char *txt)) +{ + char *p = txt; + + while(p) + { + *p = toupper(*p); + p++; + } + + return txt; +} + +LIBPROTO(SPrintfA, char *, REG(a6, UNUSED __BASE_OR_IFACE), REG(a0, char *buf), REG(a1, char *format), REG(a2, APTR args)) +{ + RawDoFmt(fmt, args, NULL, buf); + + return(buf); +} + +#if defined(__amigaos4__) +// for AmigaOS4 varargs functions are separate entries in the interface structure and +// hence must be defined as separate functions +LIBPROTOVA(SPrintf, char *, REG(a6, UNUSED __BASE_OR_IFACE), REG(a0, char *buf), REG(a1, char *format), ...) +{ + char *ret; + VA_LIST args; + + VA_START(args, format); + // the SPrintf function will be call via the interface + ret = SPrintfA(buf, format, VA_ARG(args, ULONG)); + VA_END(args); + + return(ret); +} +#elif defined(__MORPHOS__) +// define stub functions for all functions in the jump table which take the +// parameters from the emulated 68k registers. The parameters don't need to +// be specified again, because these are really functions taking no direct +// parameters. Only the type of the returned value is required. +LIBSTUB(SayHelloOS4, char *) +{ + __BASE_OR_IFACE = (__BASE_OR_IFACE_TYPE)REG_A6; + return CALL_LFUNC_NP(SayHelloOS4); +} + +LIBSTUB(SayHelloOS3, char *) +{ + __BASE_OR_IFACE = (__BASE_OR_IFACE_TYPE)REG_A6; + return CALL_LFUNC_NP(SayHelloOS3); +} + +LIBSTUB(SayHelloMOS, char *) +{ + __BASE_OR_IFACE = (__BASE_OR_IFACE_TYPE)REG_A6; + return CALL_LFUNC_NP(SayHelloMOS); +} + +LIBSTUB(Uppercase, char *) +{ + __BASE_OR_IFACE = (__BASE_OR_IFACE_TYPE)REG_A6; + return CALL_LFUNC(Uppercase, (char *)REG_A0); +} + +LIBSTUB(SPrintfA, char *) +{ + __BASE_OR_IFACE = (__BASE_OR_IFACE_TYPE)REG_A6; + return CALL_LFUNC(SprintfA, (char)REG_A0, (char *)REG_A1, (APTR)REG_A2); +} +#endif + +/******************************************************************************/ +/* Starting from here starts the "standard" Amiga library initialization. */ +/* All the above should have illustrated enough how "easy" it is to use the */ +/* SDI_lib.h header file and how it can help in developing a shared library */ +/* for multiple AmigaOS compatible platforms. */ +/******************************************************************************/ + +#if defined(__amigaos4__) + +LIBFUNC static struct LibraryHeader * LibInit (struct LibraryHeader *base, BPTR librarySegment, struct ExecIFace *pIExec); +LIBFUNC static BPTR LibExpunge (struct LibraryManagerInterface *Self); +LIBFUNC static struct LibraryHeader * LibOpen (struct LibraryManagerInterface *Self, ULONG version); +LIBFUNC static BPTR LibClose (struct LibraryManagerInterface *Self); + +#elif defined(__MORPHOS__) + +LIBFUNC static struct LibraryHeader * LibInit (struct LibraryHeader *base, BPTR librarySegment, struct ExecBase *sb); +LIBFUNC static BPTR LibExpunge(void); +LIBFUNC static struct LibraryHeader * LibOpen (void); +LIBFUNC static BPTR LibClose (void); +LIBFUNC static LONG LibNull (void); + +#else + +LIBFUNC static struct LibraryHeader * LibInit (REG(a0, BPTR Segment), REG(d0, struct LibraryHeader *lh), REG(a6, struct ExecBase *sb)); +LIBFUNC static BPTR LibExpunge (REG(a6, struct LibraryHeader *base)); +LIBFUNC static struct LibraryHeader * LibOpen (REG(a6, struct LibraryHeader *base)); +LIBFUNC static BPTR LibClose (REG(a6, struct LibraryHeader *base)); +LIBFUNC static LONG LibNull (void); + +#endif + +/******************************************************************************/ +/* Dummy entry point and LibNull() function all in one */ +/******************************************************************************/ + +#if defined(__amigaos4__) +int _start(void) +#else +int Main(void) +#endif +{ + return RETURN_FAIL; +} + +#if !defined(__amigaos4__) +LIBFUNC static LONG LibNull(VOID) +{ + return(0); +} +#endif + +/******************************************************************************/ +/* Local data structures */ +/******************************************************************************/ + +#if defined(__amigaos4__) +/* ------------------- OS4 Manager Interface ------------------------ */ +STATIC ULONG LibObtain(struct LibraryManagerInterface *Self) +{ + return(Self->Data.RefCount++); +} + +STATIC ULONG LibRelease(struct LibraryManagerInterface *Self) +{ + return(Self->Data.RefCount--); +} + +STATIC CONST APTR LibManagerVectors[] = +{ + (APTR)LibObtain, + (APTR)LibRelease, + (APTR)NULL, + (APTR)NULL, + (APTR)LibOpen, + (APTR)LibClose, + (APTR)LibExpunge, + (APTR)NULL, + (APTR)-1 +}; + +STATIC CONST struct TagItem LibManagerTags[] = +{ + {MIT_Name, (ULONG)"__library"}, + {MIT_VectorTable, (ULONG)LibManagerVectors}, + {MIT_Version, 1}, + {TAG_DONE, 0} +}; + +/* ------------------- Library Interface(s) ------------------------ */ + +STATIC CONST APTR LibVectors[] = +{ + (APTR)LibObtain, + (APTR)LibRelease, + (APTR)NULL, + (APTR)NULL, + (APTR)libvector, + (APTR)-1 +}; + +STATIC CONST struct TagItem MainTags[] = +{ + {MIT_Name, (ULONG)"main"}, + {MIT_VectorTable, (ULONG)LibVectors}, + {MIT_Version, 1}, + {TAG_DONE, 0} +}; + + +STATIC CONST ULONG LibInterfaces[] = +{ + (ULONG)LibManagerTags, + (ULONG)MainTags, + (ULONG)0 +}; + +/* --------------------- m68k Library stubs ------------------------ */ + +STATIC ULONG stub_OpenPPC(ULONG *regarray) +{ + struct Library *Base = (struct Library *) regarray[REG68K_A6/4]; + struct ExtendedLibrary *ExtLib = (struct ExtendedLibrary *) ((ULONG)Base + Base->lib_PosSize); + struct LibraryManagerInterface *Self = (struct LibraryManagerInterface *) ExtLib->ILibrary; + + return (ULONG) Self->Open(0); +} +struct EmuTrap stub_Open = { TRAPINST, TRAPTYPE, stub_OpenPPC }; + +STATIC ULONG stub_ClosePPC(ULONG *regarray) +{ + struct Library *Base = (struct Library *) regarray[REG68K_A6/4]; + struct ExtendedLibrary *ExtLib = (struct ExtendedLibrary *) ((ULONG)Base + Base->lib_PosSize); + struct LibraryManagerInterface *Self = (struct LibraryManagerInterface *) ExtLib->ILibrary; + + return (ULONG) Self->Close(); +} +struct EmuTrap stub_Close = { TRAPINST, TRAPTYPE, stub_ClosePPC }; + +STATIC ULONG stub_ExpungePPC(ULONG *regarray) +{ + return 0UL; +} +struct EmuTrap stub_Expunge = { TRAPINST, TRAPTYPE, stub_ExpungePPC }; + +STATIC ULONG stub_ReservedPPC(ULONG *regarray) +{ + return 0UL; +} +struct EmuTrap stub_Reserved = { TRAPINST, TRAPTYPE, stub_ReservedPPC }; + +STATIC ULONG stub_SayHelloOS4PPC(ULONG *regarray) +{ + struct Library *Base = (struct Library *) regarray[REG68K_A6/4]; + struct ExtendedLibrary *ExtLib = (struct ExtendedLibrary *) ((ULONG)Base + Base->lib_PosSize); + struct LibraryManagerInterface *Self = (struct LibraryManagerInterface *) ExtLib->ILibrary; + + return (char *)Self->SayHelloOS4(); +} +struct EmuTrap stub_SayHelloOS4 = { TRAPINST, TRAPTYPE, stub_SayHelloOS4PPC }; + +STATIC ULONG stub_SayHelloOS3PPC(ULONG *regarray) +{ + struct Library *Base = (struct Library *) regarray[REG68K_A6/4]; + struct ExtendedLibrary *ExtLib = (struct ExtendedLibrary *) ((ULONG)Base + Base->lib_PosSize); + struct LibraryManagerInterface *Self = (struct LibraryManagerInterface *) ExtLib->ILibrary; + + return (char *)Self->SayHelloOS3(); +} +struct EmuTrap stub_SayHelloOS3 = { TRAPINST, TRAPTYPE, stub_SayHelloOS3PPC }; + +STATIC ULONG stub_SayHelloMOSPPC(ULONG *regarray) +{ + struct Library *Base = (struct Library *) regarray[REG68K_A6/4]; + struct ExtendedLibrary *ExtLib = (struct ExtendedLibrary *) ((ULONG)Base + Base->lib_PosSize); + struct LibraryManagerInterface *Self = (struct LibraryManagerInterface *) ExtLib->ILibrary; + + return (char *)Self->SayHelloMOS(); +} +struct EmuTrap stub_SayHelloMOS = { TRAPINST, TRAPTYPE, stub_SayHelloMOSPPC }; + +STATIC ULONG stub_UppercasePPC(ULONG *regarray) +{ + struct Library *Base = (struct Library *) regarray[REG68K_A6/4]; + struct ExtendedLibrary *ExtLib = (struct ExtendedLibrary *) ((ULONG)Base + Base->lib_PosSize); + struct LibraryManagerInterface *Self = (struct LibraryManagerInterface *) ExtLib->ILibrary; + + return (char *)Self->Uppercase( + (char *)regarray[8] + ); +} +struct EmuTrap stub_Uppercase = { TRAPINST, TRAPTYPE, stub_UppercasePPC }; + +STATIC ULONG stub_SPrintfAPPC(ULONG *regarray) +{ + struct Library *Base = (struct Library *) regarray[REG68K_A6/4]; + struct ExtendedLibrary *ExtLib = (struct ExtendedLibrary *) ((ULONG)Base + Base->lib_PosSize); + struct LibraryManagerInterface *Self = (struct LibraryManagerInterface *) ExtLib->ILibrary; + + return (char *)Self->SPrintfA( + (char *)regarray[8], + (char *)regarray[9], + (APTR)regarray[10] + ); +} +struct EmuTrap stub_SPrintfA = { TRAPINST, TRAPTYPE, stub_SPrintfAPPC }; + +STATIC ULONG VecTable68K[] = +{ + (ULONG)&stub_Open, + (ULONG)&stub_Close, + (ULONG)&stub_Expunge, + (ULONG)&stub_Reserved, + (ULONG)&stub_SayHelloOS4, + (ULONG)&stub_SayHelloOS3, + (ULONG)&stub_SayHelloMOS, + (ULONG)&stub_Uppercase, + (ULONG)&stub_SprintfA, + (ULONG)-1 +}; + +/* ----------------------- LibCreate Tags -------------------------- */ + +STATIC CONST struct TagItem LibCreateTags[] = +{ + {CLT_DataSize, (ULONG)(sizeof(struct LibraryHeader))}, + {CLT_InitFunc, (ULONG)LibInit}, + {CLT_Interfaces, (ULONG)LibInterfaces}, + {CLT_Vector68K, (ULONG)VecTable68K}, + {TAG_DONE, 0} +}; + +#else + +STATIC CONST APTR LibVectors[] = +{ + #ifdef __MORPHOS__ + (APTR)FUNCARRAY_32BIT_NATIVE, + #endif + (APTR)LibOpen, + (APTR)LibClose, + (APTR)LibExpunge, + (APTR)LibNull, + (APTR)libvector, + (APTR)-1 +}; + +STATIC CONST ULONG LibInitTab[] = +{ + sizeof(struct LibraryHeader), + (ULONG)LibVectors, + (ULONG)NULL, + (ULONG)LibInit +}; + +#endif + +/* ------------------- ROM Tag ------------------------ */ +static const USED_VAR struct Resident ROMTag = +{ + RTC_MATCHWORD, + (struct Resident *)&ROMTag, + (struct Resident *)&ROMTag + 1, + #if defined(__amigaos4__) + RTF_AUTOINIT|RTF_NATIVE, // The Library should be set up according to the given table. + #elif defined(__MORPHOS__) + RTF_AUTOINIT|RTF_PPC, + #else + RTF_AUTOINIT, + #endif + VERSION, + NT_LIBRARY, + 0, + (APTR)UserLibName, + VSTRING, + #if defined(__amigaos4__) + (APTR)LibCreateTags // This table is for initializing the Library. + #else + (APTR)LibInitTab + #endif +}; + +#if defined(__MORPHOS__) +/* + * To tell the loader that this is a new emulppc elf and not + * one for the ppc.library. + * ** IMPORTANT ** + */ +ULONG USED_VAR __amigappc__=1; +ULONG USED_VAR __abox__=1; + +#endif /* __MORPHOS */ + +/******************************************************************************/ +/* Standard Library Functions, all of them are called in Forbid() state. */ +/******************************************************************************/ + +#ifndef __amigaos4__ +#define DeleteLibrary(LIB) \ + FreeMem((STRPTR)(LIB)-(LIB)->lib_NegSize, (ULONG)((LIB)->lib_NegSize+(LIB)->lib_PosSize)) +#endif + +#if defined(__amigaos4__) +static struct LibraryHeader * LibInit(struct LibraryHeader *base, BPTR librarySegment, struct ExecIFace *pIExec) +{ + struct ExecBase *sb = (struct ExecBase *)pIExec->Data.LibBase; + IExec = pIExec; +#elif defined(__MORPHOS__) +static struct LibraryHeader * LibInit(struct LibraryHeader *base, BPTR librarySegment, struct ExecBase *sb) +{ +#else +LIBFUNC static struct LibraryHeader * LibInit(REG(a0, BPTR librarySegment), REG(d0, struct LibraryHeader *base), REG(a6, struct ExecBase *sb)) +{ +#endif + + SysBase = (APTR)sb; + + base->libBase.lib_Node.ln_Type = NT_LIBRARY; + base->libBase.lib_Node.ln_Pri = 0; + base->libBase.lib_Node.ln_Name = (char *)UserLibName; + base->libBase.lib_Flags = LIBF_CHANGED | LIBF_SUMUSED; + base->libBase.lib_Version = VERSION; + base->libBase.lib_Revision = REVISION; + base->libBase.lib_IdString = (char *)UserLibID; + + base->segList = librarySegment; + base->sysBase = (APTR)SysBase; + + return(base); +} + +#if defined(__amigaos4__) +static BPTR LibExpunge(struct LibraryManagerInterface *Self) +{ + struct LibraryHeader *base = (struct LibraryHeader *)Self->Data.LibBase; +#elif defined(__MORPHOS__) +static BPTR LibExpunge(void) +{ + struct LibraryHeader *base = (struct LibraryHeader*)REG_A6; +#else +LIBFUNC static BPTR LibExpunge(REG(a6, struct LibraryHeader *base)) +{ +#endif + BPTR rc; + + if(base->libBase.lib_OpenCnt > 0) + { + base->libBase.lib_Flags |= LIBF_DELEXP; + return(0); + } + + SysBase = (APTR)base->sysBase; + rc = base->segList; + + Remove((struct Node *)base); + DeleteLibrary(&base->libBase); + + return(rc); +} + +#if defined(__amigaos4__) +static struct LibraryHeader *LibOpen(struct LibraryManagerInterface *Self, ULONG version) +{ + struct LibraryHeader *base = (struct LibraryHeader *)Self->Data.LibBase; +#elif defined(__MORPHOS__) +static struct LibraryHeader *LibOpen(void) +{ + struct LibraryHeader *base = (struct LibraryHeader*)REG_A6; +#else +LIBFUNC static struct LibraryHeader * LibOpen(REG(a6, struct LibraryHeader *base)) +{ +#endif + + base->libBase.lib_Flags &= ~LIBF_DELEXP; + base->libBase.lib_OpenCnt++; + + return base; +} + +#if defined(__amigaos4__) +static BPTR LibClose(struct LibraryManagerInterface *Self) +{ + struct LibraryHeader *base = (struct LibraryHeader *)Self->Data.LibBase; +#elif defined(__MORPHOS__) +static BPTR LibClose(void) +{ + struct LibraryHeader *base = (struct LibraryHeader *)REG_A6; +#else +LIBFUNC static BPTR LibClose(REG(a6, struct LibraryHeader *base)) +{ +#endif + + if(base->libBase.lib_OpenCnt > 0 && + --base->libBase.lib_OpenCnt == 0) + { + if(base->libBase.lib_Flags & LIBF_DELEXP) + { + #if defined(__amigaos4__) + return LibExpunge(Self); + #elif defined(__MORPHOS__) + return LibExpunge(); + #else + return LibExpunge(base); + #endif + } + } + + return 0; +} diff --git a/test/sdi/examples/libraries/makefile.mos b/test/sdi/examples/libraries/makefile.mos new file mode 100644 index 0000000000..3bf88f6f99 --- /dev/null +++ b/test/sdi/examples/libraries/makefile.mos @@ -0,0 +1,58 @@ +# +# $Id: makefile.mos,v 1.2 2005/06/08 06:54:25 damato Exp $ +# +# :ts=4 +# + +CC = ppc-morphos-gcc + +.c.o: + @echo "Compiling $<" + @$(CC) -c $(CFLAGS) -o $*.o $< + +########################################################################### + +NAME = example.library +VERSION = 51 + +########################################################################### + +WARNINGS = \ + -Wall -W -Wshadow -Wpointer-arith -Wsign-compare -Wmissing-prototypes \ + -Wundef -Wbad-function-cast -Wmissing-declarations + +CPU = -mcpu=604e -mmultiple +OPTIONS = -DNDEBUG -D__USE_INLINE__ +OPTIMIZE = -O3 -fomit-frame-pointer -fstrength-reduce -finline-functions +DEBUG = -g + +########################################################################### + +CFLAGS = $(WARNINGS) $(OPTIMIZE) $(DEBUG) $(CPU) $(OPTIONS) -I. \ + -I../../includes +LFLAGS = -L. + +########################################################################### + +OBJS = \ + example_lib.o \ + +LIBS = -lstring + +########################################################################### + +all: $(NAME) + +$(NAME): $(OBJS) + @echo "Linking $@" + @$(CC) -o $@.debug $(CFLAGS) $(LFLAGS) -nostdlib -nostartfiles $(OBJS) $(LIBS) + @ppc-morphos-strip -R.comment -o $@ $@.debug + +########################################################################### + +example_lib.o : example_lib.c + +########################################################################### + +clean: + -rm *.o *.debug *.library diff --git a/test/sdi/examples/libraries/makefile.os3 b/test/sdi/examples/libraries/makefile.os3 new file mode 100644 index 0000000000..9248082484 --- /dev/null +++ b/test/sdi/examples/libraries/makefile.os3 @@ -0,0 +1,59 @@ +# +# $Id: makefile.os3,v 1.2 2005/06/08 06:54:25 damato Exp $ +# +# :ts=4 +# + +CC = m68k-amigaos-gcc + +.c.o: + @echo "Compiling $<" + @$(CC) -c $(CFLAGS) -o $*.o $< + +########################################################################### + +NAME = example.library +VERSION = 51 + +########################################################################### + +WARNINGS = \ + -Wall -W -Wshadow -Wpointer-arith -Wsign-compare -Wmissing-prototypes \ + -Wundef -Wbad-function-cast -Wmissing-declarations + +CPU = -m68020-60 -msoft-float +OPTIONS = -DNDEBUG -D__USE_INLINE__ +OPTIMIZE = -O3 -fomit-frame-pointer -fstrength-reduce -finline-functions +DEBUG = -g + +########################################################################### + +CFLAGS = $(WARNINGS) $(OPTIMIZE) $(DEBUG) $(CPU) $(OPTIONS) -I. \ + -I../../includes +LFLAGS = -L. + +########################################################################### + +OBJS = \ + example_lib.o \ + +LIBS = \ + -lc + +########################################################################### + +all: $(NAME) + +$(NAME): $(OBJS) + @echo "Linking $@" + @$(CC) -o $@.debug $(CFLAGS) $(LFLAGS) -nostdlib -nostartfiles $(OBJS) $(LIBS) + @m68k-amigaos-strip -R.comment -o $@ $@.debug + +########################################################################### + +example_lib.o : example_lib.c + +########################################################################### + +clean: + -rm *.o *.debug *.library diff --git a/test/sdi/examples/libraries/makefile.os4 b/test/sdi/examples/libraries/makefile.os4 new file mode 100644 index 0000000000..cd6d8b566b --- /dev/null +++ b/test/sdi/examples/libraries/makefile.os4 @@ -0,0 +1,59 @@ +# +# $Id: makefile.os4,v 1.2 2005/06/08 06:54:25 damato Exp $ +# +# :ts=4 +# + +CC = ppc-amigaos-gcc + +.c.o: + @echo "Compiling $<" + @$(CC) -c $(CFLAGS) -o $*.o $< + +########################################################################### + +NAME = example.library +VERSION = 51 + +########################################################################### + +WARNINGS = \ + -Wall -W -Wshadow -Wpointer-arith -Wsign-compare -Wmissing-prototypes \ + -Wundef -Wbad-function-cast -Wmissing-declarations + +CPU = -mcpu=604e -mmultiple +OPTIONS = -DNDEBUG -D__USE_INLINE__ +OPTIMIZE = -O3 -fomit-frame-pointer -fstrength-reduce -finline-functions +DEBUG = -g + +########################################################################### + +CFLAGS = $(WARNINGS) $(OPTIMIZE) $(DEBUG) $(CPU) $(OPTIONS) -I. \ + -I../../includes +LFLAGS = -L. + +########################################################################### + +OBJS = \ + example_lib.o \ + +LIBS = \ + -lc + +########################################################################### + +all: $(NAME) + +$(NAME): $(OBJS) + @echo "Linking $@" + @$(CC) -o $@.debug $(CFLAGS) $(LFLAGS) -nostdlib -nostartfiles $(OBJS) $(LIBS) + @ppc-amigaos-strip -R.comment -o $@ $@.debug + +########################################################################### + +example_lib.o : example_lib.c + +########################################################################### + +clean: + -rm *.o *.debug *.library diff --git a/test/sdi/examples/misc/example_miscuse.c b/test/sdi/examples/misc/example_miscuse.c new file mode 100644 index 0000000000..da34ebf87a --- /dev/null +++ b/test/sdi/examples/misc/example_miscuse.c @@ -0,0 +1,105 @@ +/* Example source + + Name: example_miscuse.c + Versionstring: $VER: example_miscuse.c 1.0 (17.05.2005) + Author: Guido Mersmann + Distribution: PD + Description: shows how the SDI_misc.h header includes are used + + 1.0 17.05.04 : initial version showing how the SDI_misc.h header have to be + used if one wants to keep the sources platform independent + throughout all common AmigaOS compatible platforms like OS3, + OS4 and MorphOS. + + + Please note that this example is just for educational purposes and wasn't + checked for complete correctness. However, it should compile and probably also + work as expected. But please note that its purpose is to show how the misc + macros make it very easy to deal with those functions and also keep the + sources simple and platform independent through OS3, OS4 and MorphOS. + + Feel free to comment and submit any suggestions directly to + Guido Mersmann + +*/ + +#include +#include + +#include +#include +#include + +#include "SDI_misc.h" + + +/* +** +**This structure keeps our internal sprintf vars during RawDoFmt() +** +*/ + +struct SPrintfStream +{ + char *Target; + ULONG TargetSize; /* Obsolete in this example, but useful when + dealing with size limited streams */ +}; + +/* +** SPrintf_DoChar +** +** The following function is just an example where we use the object +** for composing some minor text. Do you see how easy it is to use and +** how great it is to use SDI_misc.h to automatically keep your sources +** compatible to all common AmigaOS platforms? +** +*/ + +PUTCHARPROTO( SPrintf_DoChar, char c, struct SPrintfStream *s ) +{ + *(s->Target++) = c; +} + +/* +** +** SPrintf +** +** Here you can see how the function is used by the ENTRY() function. +** +*/ + +ULONG SPrintf( char *format, char *target, ULONG *args ); +ULONG SPrintf( char *format, char *target, ULONG *args ) +{ +struct SPrintfStream s; + + s.Target = target; + + RawDoFmt( format, args, ENTRY( SPrintf_DoChar ), &s); + + return( s.Target - target ); +} + +/* +** +** The main entry point +** +*/ + +int main(void) +{ + char buf[0x80]; /* storage for keeping the SPrintf result string */ + ULONG args[2]; /* storage for keeping the SPrintf arguments */ + + args[0] = (ULONG) "result"; + args[1] = (ULONG) "PUTCHARPROTO macro"; + + SPrintf("I am the %s of using SPrintf() with the new %s!", buf, args); + + printf("%s\n", buf); /* just a simple printf to output and add the \n */ + +return( 0); +} + + diff --git a/test/sdi/examples/misc/makefile.mos b/test/sdi/examples/misc/makefile.mos new file mode 100644 index 0000000000..3ca9d50ba1 --- /dev/null +++ b/test/sdi/examples/misc/makefile.mos @@ -0,0 +1,58 @@ +# +# $Id: makefile.mos,v 1.1 2005/06/08 06:54:25 damato Exp $ +# +# :ts=4 +# + +CC = ppc-morphos-gcc + +.c.o: + @echo "Compiling $<" + @$(CC) -c $(CFLAGS) -o $*.o $< + +########################################################################### + +NAME = hellomisc +VERSION = 51 + +########################################################################### + +WARNINGS = \ + -Wall -W -Wshadow -Wpointer-arith -Wsign-compare -Wmissing-prototypes \ + -Wundef -Wbad-function-cast -Wmissing-declarations + +CPU = -mcpu=604e -mmultiple +OPTIONS = -DNDEBUG -D__USE_INLINE__ +OPTIMIZE = -O3 -fomit-frame-pointer -fstrength-reduce -finline-functions +DEBUG = -g + +########################################################################### + +CFLAGS = -noixemul $(WARNINGS) $(OPTIMIZE) $(DEBUG) $(CPU) $(OPTIONS) -I. \ + -I../../includes +LFLAGS = -L. + +########################################################################### + +OBJS = \ + example_miscuse.o \ + +LIBS = + +########################################################################### + +all: $(NAME) + +$(NAME): $(OBJS) + @echo "Linking $@" + @$(CC) -o $@.debug $(CFLAGS) $(LFLAGS) $(OBJS) $(LIBS) + @ppc-morphos-strip -R.comment -o $@ $@.debug + +########################################################################### + +example_miscuse.o : example_miscuse.c + +########################################################################### + +clean: + -rm *.o *.debug $(NAME) diff --git a/test/sdi/examples/misc/makefile.os3 b/test/sdi/examples/misc/makefile.os3 new file mode 100644 index 0000000000..97406a765f --- /dev/null +++ b/test/sdi/examples/misc/makefile.os3 @@ -0,0 +1,59 @@ +# +# $Id: makefile.os3,v 1.1 2005/06/08 06:54:25 damato Exp $ +# +# :ts=4 +# + +CC = m68k-amigaos-gcc + +.c.o: + @echo "Compiling $<" + @$(CC) -c $(CFLAGS) -o $*.o $< + +########################################################################### + +NAME = hellomisc +VERSION = 51 + +########################################################################### + +WARNINGS = \ + -Wall -W -Wshadow -Wpointer-arith -Wsign-compare -Wmissing-prototypes \ + -Wundef -Wbad-function-cast -Wmissing-declarations + +CPU = -m68020-60 -msoft-float +OPTIONS = -DNDEBUG -D__USE_INLINE__ +OPTIMIZE = -O3 -fomit-frame-pointer -fstrength-reduce -finline-functions +DEBUG = -g + +########################################################################### + +CFLAGS = -noixemul $(WARNINGS) $(OPTIMIZE) $(DEBUG) $(CPU) $(OPTIONS) -I. \ + -I../../includes +LFLAGS = -L. + +########################################################################### + +OBJS = \ + example_miscuse.o \ + +LIBS = \ + -lc + +########################################################################### + +all: $(NAME) + +$(NAME): $(OBJS) + @echo "Linking $@" + @$(CC) -o $@.debug $(CFLAGS) $(LFLAGS) $(OBJS) $(LIBS) + @m68k-amigaos-strip -R.comment -o $@ $@.debug + +########################################################################### + +example_miscuse.o : example_miscuse.c + +########################################################################### + +clean: + -rm *.o *.debug $(NAME) diff --git a/test/sdi/examples/misc/makefile.os4 b/test/sdi/examples/misc/makefile.os4 new file mode 100644 index 0000000000..3a4bb6aa86 --- /dev/null +++ b/test/sdi/examples/misc/makefile.os4 @@ -0,0 +1,59 @@ +# +# $Id: makefile.os4,v 1.1 2005/06/08 06:54:25 damato Exp $ +# +# :ts=4 +# + +CC = ppc-amigaos-gcc + +.c.o: + @echo "Compiling $<" + @$(CC) -c $(CFLAGS) -o $*.o $< + +########################################################################### + +NAME = hellomisc +VERSION = 51 + +########################################################################### + +WARNINGS = \ + -Wall -W -Wshadow -Wpointer-arith -Wsign-compare -Wmissing-prototypes \ + -Wundef -Wbad-function-cast -Wmissing-declarations + +CPU = -mcpu=604e -mmultiple +OPTIONS = -DNDEBUG -D__USE_INLINE__ +OPTIMIZE = -O3 -fomit-frame-pointer -fstrength-reduce -finline-functions +DEBUG = -g + +########################################################################### + +CFLAGS = $(WARNINGS) $(OPTIMIZE) $(DEBUG) $(CPU) $(OPTIONS) -I. \ + -I../../includes +LFLAGS = -L. + +########################################################################### + +OBJS = \ + example_miscuse.o \ + +LIBS = \ + -lc -lm + +########################################################################### + +all: $(NAME) + +$(NAME): $(OBJS) + @echo "Linking $@" + @$(CC) -o $@.debug $(CFLAGS) $(LFLAGS) $(OBJS) $(LIBS) + @ppc-amigaos-strip -R.comment -o $@ $@.debug + +########################################################################### + +example_miscuse.o : example_miscuse.c + +########################################################################### + +clean: + -rm *.o *.debug $(NAME) diff --git a/test/sdi/examples/varargs/example_varargs.c b/test/sdi/examples/varargs/example_varargs.c new file mode 100755 index 0000000000..e3f76ed35a --- /dev/null +++ b/test/sdi/examples/varargs/example_varargs.c @@ -0,0 +1,66 @@ +/* Example source + + Name: example_varargs.c + Versionstring: $VER: example_varargs.c 1.0 (06.10.2004) + Author: Jens Langner + Distribution: PD + Description: shows how the SDI_stdarg.h header include are used + + 1.0 06.10.04 : initial version showing how the SDI_stdarg.h header have to be + used if one wants to keep the sources platform independent + throughout all common AmigaOS compatible platforms like OS3, + OS4 and MorphOS, because all of those systems have a slightly + different way to deal with variable argument functions. + + + Please note that this example is just for educational purposes and wasn't + checked for complete correctness. However, it should compile and probably also + work as expected. But please note that its purpose is to show how the varargs + macros make it very easy to deal with variable argument based functions and also + keep the sources simple and platform independent through OS3, OS4 and MorphOS. + + Feel free to comment and submit any suggestions directly to + Jens.Langner@light-speed.de + +*/ + +#include + +#include +#include +#include + +#include "SDI_stdarg.h" + +/******************************************************************************/ +/* Example of a variable argument based function which is automatically */ +/* compatible to varargs definitions of AmigaOS3, AmigaOS4 and MorphOS... */ +/******************************************************************************/ + +static int STDARGS VARARGS68K MySPrintf(char *buf, char *fmt, ...) +{ + VA_LIST args; + + VA_START(args, fmt); + RawDoFmt(fmt, VA_ARG(args, void *), NULL, buf); + VA_END(args); + + return(strlen(buf)); +} + +/******************************************************************************/ +/* The main entry point to just illustrate how the varargs function is called */ +/******************************************************************************/ + +int main(void) +{ + char buf[256]; + char *type = "portable varargs"; + LONG ret; + + ret = MySPrintf(buf, "This is a '%s' function", type); + + printf("%s returning %d\n", buf, ret); + + return 0; +} diff --git a/test/sdi/examples/varargs/makefile.mos b/test/sdi/examples/varargs/makefile.mos new file mode 100644 index 0000000000..4e66a884ad --- /dev/null +++ b/test/sdi/examples/varargs/makefile.mos @@ -0,0 +1,59 @@ +# +# $Id: makefile.mos,v 1.2 2005/06/08 06:54:25 damato Exp $ +# +# :ts=4 +# + +CC = ppc-morphos-gcc + +.c.o: + @echo "Compiling $<" + @$(CC) -c $(CFLAGS) -o $*.o $< + +########################################################################### + +NAME = hello_varargs +VERSION = 51 + +########################################################################### + +WARNINGS = \ + -Wall -W -Wshadow -Wpointer-arith -Wsign-compare -Wmissing-prototypes \ + -Wundef -Wbad-function-cast -Wmissing-declarations + +CPU = -mcpu=604e -mmultiple +OPTIONS = -DNDEBUG -D__USE_INLINE__ +OPTIMIZE = -O3 -fomit-frame-pointer -fstrength-reduce -finline-functions +DEBUG = -g + +########################################################################### + +CFLAGS = -noixemul $(WARNINGS) $(OPTIMIZE) $(DEBUG) $(CPU) $(OPTIONS) -I. \ + -I../../includes +LFLAGS = -L. + +########################################################################### + +OBJS = \ + example_varargs.o \ + +LIBS = \ + -lstring + +########################################################################### + +all: $(NAME) + +$(NAME): $(OBJS) + @echo "Linking $@" + @$(CC) -o $@.debug $(CFLAGS) $(LFLAGS) $(OBJS) $(LIBS) + @ppc-morphos-strip -R.comment -o $@ $@.debug + +########################################################################### + +example_varargs.o : example_varargs.c + +########################################################################### + +clean: + -rm *.o *.debug $(NAME) diff --git a/test/sdi/examples/varargs/makefile.os3 b/test/sdi/examples/varargs/makefile.os3 new file mode 100644 index 0000000000..52fcf74e1f --- /dev/null +++ b/test/sdi/examples/varargs/makefile.os3 @@ -0,0 +1,59 @@ +# +# $Id: makefile.os3,v 1.2 2005/06/08 06:54:25 damato Exp $ +# +# :ts=4 +# + +CC = m68k-amigaos-gcc + +.c.o: + @echo "Compiling $<" + @$(CC) -c $(CFLAGS) -o $*.o $< + +########################################################################### + +NAME = hello_varargs +VERSION = 51 + +########################################################################### + +WARNINGS = \ + -Wall -W -Wshadow -Wpointer-arith -Wsign-compare -Wmissing-prototypes \ + -Wundef -Wbad-function-cast -Wmissing-declarations + +CPU = -m68020-60 -msoft-float +OPTIONS = -DNDEBUG -D__USE_INLINE__ +OPTIMIZE = -O3 -fomit-frame-pointer -fstrength-reduce -finline-functions +DEBUG = -g + +########################################################################### + +CFLAGS = -noixemul $(WARNINGS) $(OPTIMIZE) $(DEBUG) $(CPU) $(OPTIONS) -I. \ + -I../../includes +LFLAGS = -L. + +########################################################################### + +OBJS = \ + example_varargs.o \ + +LIBS = \ + -lc + +########################################################################### + +all: $(NAME) + +$(NAME): $(OBJS) + @echo "Linking $@" + @$(CC) -o $@.debug $(CFLAGS) $(LFLAGS) $(OBJS) $(LIBS) + @m68k-amigaos-strip -R.comment -o $@ $@.debug + +########################################################################### + +example_varargs.o : example_varargs.c + +########################################################################### + +clean: + -rm *.o *.debug $(NAME) diff --git a/test/sdi/examples/varargs/makefile.os4 b/test/sdi/examples/varargs/makefile.os4 new file mode 100644 index 0000000000..200aa6ade0 --- /dev/null +++ b/test/sdi/examples/varargs/makefile.os4 @@ -0,0 +1,59 @@ +# +# $Id: makefile.os4,v 1.2 2005/06/08 06:54:25 damato Exp $ +# +# :ts=4 +# + +CC = ppc-amigaos-gcc + +.c.o: + @echo "Compiling $<" + @$(CC) -c $(CFLAGS) -o $*.o $< + +########################################################################### + +NAME = hello_varargs +VERSION = 51 + +########################################################################### + +WARNINGS = \ + -Wall -W -Wshadow -Wpointer-arith -Wsign-compare -Wmissing-prototypes \ + -Wundef -Wbad-function-cast -Wmissing-declarations + +CPU = -mcpu=604e -mmultiple +OPTIONS = -DNDEBUG -D__USE_INLINE__ +OPTIMIZE = -O3 -fomit-frame-pointer -fstrength-reduce -finline-functions +DEBUG = -g + +########################################################################### + +CFLAGS = $(WARNINGS) $(OPTIMIZE) $(DEBUG) $(CPU) $(OPTIONS) -I. \ + -I../../includes +LFLAGS = -L. + +########################################################################### + +OBJS = \ + example_varargs.o \ + +LIBS = \ + -lc -lm + +########################################################################### + +all: $(NAME) + +$(NAME): $(OBJS) + @echo "Linking $@" + @$(CC) -o $@.debug $(CFLAGS) $(LFLAGS) $(OBJS) $(LIBS) + @ppc-amigaos-strip -R.comment -o $@ $@.debug + +########################################################################### + +example_varargs.o : example_varargs.c + +########################################################################### + +clean: + -rm *.o *.debug $(NAME) -- 2.11.4.GIT