home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / a2ixlibrary-1.0-bin.lha / share / a2ixlibrary / auto_init.c < prev    next >
C/C++ Source or Header  |  1996-10-12  |  2KB  |  90 lines

  1.  
  2. #include <exec/types.h>
  3. #include <proto/exec.h>
  4. #include <exec/execbase.h>
  5.  
  6. #include <unistd.h>
  7. #include <stdlib.h>
  8. #include <string.h>
  9.  
  10. #include "a2ixlibrary.h"
  11.  
  12. asm(".text
  13. _" xstr(CLOSEINST) ":     movel    _" SNAME "Base,a0
  14.             jmp    a0@(-30:w)
  15.  
  16. _" xstr(SETVARSINST) ":    movel    _" SNAME "Base,a0
  17.             jmp    a0@(-36:w)
  18. ");
  19.  
  20. struct Library * BASE = 0;
  21.  
  22. /* externs from crt0.c */
  23. extern void *ixemulbase;
  24. extern int errno;
  25. extern char *_ctype_;
  26. extern void *__sF;
  27.  
  28. void CLOSEINST(void);
  29. int  SETVARSINST();
  30.  
  31. #define STRING(a) a, sizeof (a) - 1
  32.  
  33. void TFSTART();
  34. void TDSTART();
  35. void DFSTART();
  36. void DDSTART();
  37. void _stext();
  38. void _sdata();
  39. void _etext();
  40. void _bss_start();
  41. void __text_size();
  42.  
  43. static void
  44. constructor ()
  45. {
  46.   if (!(BASE = OpenLibrary ("lib" SNAME ".ixlibrary", VERSION)))
  47.     {
  48.       write (2, STRING("Can't open lib" SNAME ".ixlibrary!\n"));
  49.       abort ();
  50.     }
  51.  
  52.   if (!(SETVARSINST(_stext, TFSTART - _bss_start + _etext,
  53.                     TDSTART - _bss_start + _etext,
  54.             _sdata, DFSTART - _bss_start + _etext,
  55.                 DDSTART - _bss_start + _etext,
  56.             NULL, 4, ixemulbase, &errno, _ctype_, __sF)))
  57.     {
  58.       CLOSEINST();
  59.       CloseLibrary(BASE);
  60.       BASE = 0;
  61.       write (2, STRING("Some externals are missing in lib" SNAME ".ixlibrary!\n"));
  62.       abort ();
  63.     }
  64.   CacheClearE(_stext, (long)__text_size, CACRF_ClearI|CACRF_ClearD);
  65. #ifdef CONSTRUCTOR
  66.   {
  67.     CONSTRUCTOR;
  68.   }
  69. #endif
  70. }
  71.  
  72. static void
  73. destructor ()
  74. {
  75.   if (BASE)
  76.     {
  77. #ifdef DESTRUCTOR
  78.       {
  79.         DESTRUCTOR;
  80.       }
  81. #endif
  82.       CLOSEINST();
  83.       CloseLibrary (BASE);
  84.       BASE = 0;
  85.     }
  86. }
  87.  
  88. asm ("    .text;     .stabs \"___CTOR_LIST__\",22,0,0,_constructor");
  89. asm ("    .text;     .stabs \"___DTOR_LIST__\",22,0,0,_destructor");
  90.