home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 20 / AACD20.BIN / AACD / Programming / AmIDE / developer / example / StartUp.c < prev   
Encoding:
C/C++ Source or Header  |  2001-03-04  |  9.9 KB  |  304 lines

  1. /*
  2. **      $VER: StartUp.c 37.31 (18.3.98)
  3. **
  4. **      Library startup-code and function table definition
  5. **
  6. **      (C) Copyright 1996-98 Andreas R. Kleinert
  7. **      All Rights Reserved.
  8. **
  9. **      Modifications for the AmIDE_API v1.0
  10. **      (C) Copyright 2001 Jens Langner
  11. **      All Rights Reserved.
  12. **
  13. */
  14.  
  15. #define __USE_SYSBASE        // perhaps only recognized by SAS/C
  16.  
  17. #include <exec/types.h>
  18. #include <exec/memory.h>
  19. #include <exec/libraries.h>
  20. #include <exec/execbase.h>
  21. #include <exec/resident.h>
  22. #include <exec/initializers.h>
  23.  
  24.  
  25. #ifdef __MAXON__
  26. #include <pragma/exec_lib.h>
  27. #include <linkerfunc.h>
  28. #else
  29. #include <proto/exec.h>    // all other compilers
  30. #endif
  31. #include "compiler.h"
  32. #include "sasc.module.h"
  33.  
  34. #include <amide/amide_api_base.h>
  35.  
  36. extern ULONG __saveds __stdargs L_OpenLibs(struct AmIDE_API_Base *API_Base);
  37. extern void  __saveds __stdargs L_CloseLibs(void);
  38.  
  39. struct AmIDE_API_Base * __saveds ASM InitLib( register __a6 struct ExecBase    *sysbase GNUCREG(a6),
  40.                                               register __a0 SEGLISTPTR          seglist GNUCREG(a0),
  41.                                               register __d0 struct AmIDE_API_Base *exb     GNUCREG(d0));
  42. struct AmIDE_API_Base * __saveds ASM OpenLib( register __a6 struct AmIDE_API_Base *API_Base GNUCREG(a6));
  43. SEGLISTPTR __saveds ASM CloseLib( register __a6 struct AmIDE_API_Base *API_Base GNUCREG(a6));
  44. SEGLISTPTR __saveds ASM ExpungeLib( register __a6 struct AmIDE_API_Base *exb GNUCREG(a6));
  45. ULONG ASM ExtFuncLib(void);
  46.  
  47.  
  48. /* ----------------------------------------------------------------------------------------
  49.    ! LibStart:
  50.    !
  51.    ! If someone tries to start a library as an executable, it must return (LONG) -1
  52.    ! as result. That's what we are doing here.
  53.    ---------------------------------------------------------------------------------------- */
  54.  
  55. LONG ASM LibStart(void)
  56. {
  57.  return(-1);
  58. }
  59.  
  60.  
  61. /* ----------------------------------------------------------------------------------------
  62.    ! Function and Data Tables:
  63.    !
  64.    ! The function and data tables have been placed here for traditional reasons.
  65.    ! Placing the RomTag structure before (-> LibInit.c) would also be a good idea,
  66.    ! but it depends on whether you would like to keep the "version" stuff separately.
  67.    ---------------------------------------------------------------------------------------- */
  68.  
  69. extern APTR FuncTab [];
  70. /*  extern struct MyDataInit DataTab;  */
  71. extern DataTab; /* DICE fix */
  72.                                   /* Instead you may place ROMTag + Datatab directly, here */
  73.                                   /* (see LibInit.c). This may fix "Installer" version     */
  74.                                   /* checking problems, too - try it.                      */
  75.  
  76. struct InitTable                       /* do not change */
  77. {
  78.  ULONG              LibBaseSize;
  79.  APTR              *FunctionTable;
  80.  struct MyDataInit *DataTable;
  81.  APTR               InitLibTable;
  82. } InitTab =
  83. {
  84.  (ULONG)               sizeof(struct AmIDE_API_Base),
  85.  (APTR              *) &FuncTab[0],
  86.  (struct MyDataInit *) &DataTab,
  87.  (APTR)                InitLib
  88. };
  89.  
  90. APTR FuncTab [] =
  91. {
  92.  OpenLib,
  93.  CloseLib,
  94.  ExpungeLib,
  95.  ExtFuncLib,
  96.  
  97.  AmIDE_API_GetClass,  /* add your own functions here */
  98.  
  99.  (APTR) ((LONG)-1)
  100. };
  101.  
  102.  
  103. extern struct AmIDE_API_Base *API_Base;
  104.  
  105. /* ----------------------------------------------------------------------------------------
  106.    ! InitLib:
  107.    !
  108.    ! This one is single-threaded by the Ramlib process. Theoretically you can do, what
  109.    ! you like here, since you have full exclusive control over all the library code and data.
  110.    ! But due to some bugs in Ramlib V37-40, you can easily cause a deadlock when opening
  111.    ! certain libraries here (which open other libraries, that open other libraries, that...)
  112.    !
  113.    ---------------------------------------------------------------------------------------- */
  114.  
  115. struct AmIDE_API_Base * __saveds ASM InitLib( register __a6 struct ExecBase      *sysbase GNUCREG(a6),
  116.                                            register __a0 SEGLISTPTR            seglist GNUCREG(a0),
  117.                                            register __d0 struct AmIDE_API_Base   *exb     GNUCREG(d0))
  118. {
  119.  API_Base = exb;
  120.  
  121.  API_Base->exb_SysBase = sysbase;
  122.  API_Base->exb_SegList = seglist;
  123.  
  124.  if(L_OpenLibs(API_Base)) return(API_Base);
  125.  
  126.  L_CloseLibs();
  127.  
  128.   {
  129.    ULONG negsize, possize, fullsize;
  130.    UBYTE *negptr = (UBYTE *) API_Base;
  131.  
  132.    negsize  = API_Base->exb_LibNode.lib_NegSize;
  133.    possize  = API_Base->exb_LibNode.lib_PosSize;
  134.    fullsize = negsize + possize;
  135.    negptr  -= negsize;
  136.  
  137.    FreeMem(negptr, fullsize);
  138.  
  139.    #ifdef __MAXON__
  140.    CleanupModules();
  141.    #endif
  142.   }
  143.  
  144.  return(NULL);
  145. }
  146.  
  147. /* ----------------------------------------------------------------------------------------
  148.    ! OpenLib:
  149.    !
  150.    ! This one is enclosed within a Forbid/Permit pair by Exec V37-40. Since a Wait() call
  151.    ! would break this Forbid/Permit(), you are not allowed to start any operations that
  152.    ! may cause a Wait() during their processing. It's possible, that future OS versions
  153.    ! won't turn the multi-tasking off, but instead use semaphore protection for this
  154.    ! function.
  155.    !
  156.    ! Currently you only can bypass this restriction by supplying your own semaphore
  157.    ! mechanism.
  158.    ---------------------------------------------------------------------------------------- */
  159.  
  160. struct AmIDE_API_Base * __saveds ASM OpenLib( register __a6 struct AmIDE_API_Base *API_Base GNUCREG(a6))
  161. {
  162.  #ifdef __MAXON__
  163.  GetBaseReg();
  164.  InitModules();
  165.  #endif
  166.  
  167.  API_Base->exb_LibNode.lib_OpenCnt++;
  168.  
  169.  API_Base->exb_LibNode.lib_Flags &= ~LIBF_DELEXP;
  170.  
  171.  return(API_Base);
  172. }
  173.  
  174. /* ----------------------------------------------------------------------------------------
  175.    ! CloseLib:
  176.    !
  177.    ! This one is enclosed within a Forbid/Permit pair by Exec V37-40. Since a Wait() call
  178.    ! would break this Forbid/Permit(), you are not allowed to start any operations that
  179.    ! may cause a Wait() during their processing. It's possible, that future OS versions
  180.    ! won't turn the multi-tasking off, but instead use semaphore protection for this
  181.    ! function.
  182.    !
  183.    ! Currently you only can bypass this restriction by supplying your own semaphore
  184.    ! mechanism.
  185.    ---------------------------------------------------------------------------------------- */
  186.  
  187. SEGLISTPTR __saveds ASM CloseLib( register __a6 struct AmIDE_API_Base *API_Base GNUCREG(a6))
  188. {
  189.  API_Base->exb_LibNode.lib_OpenCnt--;
  190.  
  191.  if(!API_Base->exb_LibNode.lib_OpenCnt)
  192.   {
  193.    if(API_Base->exb_LibNode.lib_Flags & LIBF_DELEXP)
  194.     {
  195.      return( ExpungeLib(API_Base) );
  196.     }
  197.   }
  198.  
  199.  return(NULL);
  200. }
  201.  
  202. /* ----------------------------------------------------------------------------------------
  203.    ! ExpungeLib:
  204.    !
  205.    ! This one is enclosed within a Forbid/Permit pair by Exec V37-40. Since a Wait() call
  206.    ! would break this Forbid/Permit(), you are not allowed to start any operations that
  207.    ! may cause a Wait() during their processing. It's possible, that future OS versions
  208.    ! won't turn the multi-tasking off, but instead use semaphore protection for this
  209.    ! function.
  210.    !
  211.    ! Currently you only could bypass this restriction by supplying your own semaphore
  212.    ! mechanism - but since expunging can't be done twice, one should avoid it here.
  213.    ---------------------------------------------------------------------------------------- */
  214.  
  215. SEGLISTPTR __saveds ASM ExpungeLib( register __a6 struct AmIDE_API_Base *exb GNUCREG(a6))
  216. {
  217.  struct AmIDE_API_Base *API_Base = exb;
  218.  SEGLISTPTR seglist;
  219.  
  220.  if(!API_Base->exb_LibNode.lib_OpenCnt)
  221.   {
  222.    ULONG negsize, possize, fullsize;
  223.    UBYTE *negptr = (UBYTE *) API_Base;
  224.  
  225.    seglist = API_Base->exb_SegList;
  226.  
  227.    Remove((struct Node *)API_Base);
  228.  
  229.    L_CloseLibs();
  230.  
  231.    negsize  = API_Base->exb_LibNode.lib_NegSize;
  232.    possize  = API_Base->exb_LibNode.lib_PosSize;
  233.    fullsize = negsize + possize;
  234.    negptr  -= negsize;
  235.  
  236.    FreeMem(negptr, fullsize);
  237.  
  238.    #ifdef __MAXON__
  239.    CleanupModules();
  240.    #endif
  241.  
  242.    return(seglist);
  243.   }
  244.  
  245.  API_Base->exb_LibNode.lib_Flags |= LIBF_DELEXP;
  246.  
  247.  return(NULL);
  248. }
  249.  
  250. /* ----------------------------------------------------------------------------------------
  251.    ! ExtFunct:
  252.    !
  253.    ! This one is enclosed within a Forbid/Permit pair by Exec V37-40. Since a Wait() call
  254.    ! would break this Forbid/Permit(), you are not allowed to start any operations that
  255.    ! may cause a Wait() during their processing. It's possible, that future OS versions
  256.    ! won't turn the multi-tasking off, but instead use semaphore protection for this
  257.    ! function.
  258.    !
  259.    ! Currently you only can bypass this restriction by supplying your own semaphore
  260.    ! mechanism - but since this function currently is unused, you should not touch
  261.    ! it, either.
  262.    ---------------------------------------------------------------------------------------- */
  263.  
  264. ULONG ASM ExtFuncLib(void)
  265. {
  266.  return(NULL);
  267. }
  268.  
  269. struct AmIDE_API_Base *API_Base = NULL;
  270.  
  271.  
  272. /* ----------------------------------------------------------------------------------------
  273.    ! __SASC stuff:
  274.    !
  275.    ! This is only for SAS/C - its intention is to turn off internal CTRL-C handling
  276.    ! for standard C functions and to avoid calls to exit() et al.
  277.    ---------------------------------------------------------------------------------------- */
  278.  
  279. #ifdef __SASC
  280.  
  281. #ifdef ARK_OLD_STDIO_FIX
  282.  
  283. ULONG XCEXIT       = NULL; /* These symbols may be referenced by    */
  284. ULONG _XCEXIT      = NULL; /* some functions of sc.lib, but should  */
  285. ULONG ONBREAK      = NULL; /* never be used inside a shared library */
  286. ULONG _ONBREAK     = NULL;
  287. ULONG base         = NULL; /* Note, that XCEXIT/ONBREAK actually    */
  288. ULONG _base        = NULL; /* should have been defined as functions */
  289. ULONG ProgramName  = NULL; /* and not as ULONGs...                  */
  290. ULONG _ProgramName = NULL;
  291. ULONG StackPtr     = NULL;
  292. ULONG _StackPtr    = NULL;
  293. ULONG oserr        = NULL;
  294. ULONG _oserr       = NULL;
  295. ULONG OSERR        = NULL;
  296. ULONG _OSERR       = NULL;
  297.  
  298. #endif /* ARK_OLD_STDIO_FIX */
  299.  
  300. void __regargs __chkabort(void) { }  /* a shared library cannot be    */
  301. void __regargs _CXBRK(void)     { }  /* CTRL-C aborted when doing I/O */
  302.  
  303. #endif /* __SASC */
  304.