home *** CD-ROM | disk | FTP | other *** search
/ Aminet 18 / aminetcdnumber181997.iso / Aminet / misc / emu / AROSdev.lha / AROS / rom / utility / utility_init.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-02-03  |  5.7 KB  |  230 lines

  1. /*
  2.     Copyright (C) 1995-97 AROS - The Amiga Replacement OS
  3.     $Id: utility_init.c,v 1.9 1997/02/03 02:59:42 ldp Exp $
  4.  
  5.     Desc: Utility Resident and initialization.
  6.     Lang: english
  7. */
  8. #include <exec/types.h>
  9. #include <aros/system.h>
  10. #include <aros/libcall.h>
  11. #include <exec/alerts.h>
  12. #include <exec/libraries.h>
  13. #include <exec/resident.h>
  14. #include <exec/execbase.h>
  15. #include <dos/dos.h>
  16. #include <proto/exec.h>
  17. #include <proto/utility.h>
  18.  
  19. #include "utility_intern.h"
  20.  
  21. extern const UBYTE name[];
  22. extern const UBYTE version[];
  23. extern const APTR inittabl[4];
  24. extern void *const Utility_functable[];
  25. struct UtilityBase *AROS_SLIB_ENTRY(init,Utility)();
  26. extern const char Utility_end;
  27.  
  28. extern ULONG AROS_SLIB_ENTRY(SMult32_020,Utility)();
  29. extern ULONG AROS_SLIB_ENTRY(UMult32_020,Utility)();
  30. extern ULONG AROS_SLIB_ENTRY(SMult64_020,Utility)();
  31. extern ULONG AROS_SLIB_ENTRY(UMult64_020,Utility)();
  32. extern ULONG AROS_SLIB_ENTRY(SDivMod32_020,Utility)();
  33. extern ULONG AROS_SLIB_ENTRY(UDivMod32_020,Utility)();
  34.  
  35. int Utility_entry(void)
  36. {
  37.     /* If the library was executed by accident return error code. */
  38.     return -1;
  39. }
  40.  
  41. const struct Resident Utility_resident=
  42. {
  43.     RTC_MATCHWORD,
  44.     (struct Resident *)&Utility_resident,
  45.     (APTR)&Utility_end,
  46.     RTF_AUTOINIT|RTF_COLDSTART,
  47.     41,
  48.     NT_LIBRARY,
  49.     103,
  50.     (STRPTR)name,
  51.     (STRPTR)&version[6],
  52.     (ULONG *)inittabl
  53. };
  54.  
  55. const UBYTE name[]="utility.library";
  56.  
  57. const UBYTE version[]="$VER: AROS utility 41.9 (2.2.97)";
  58.  
  59. const APTR inittabl[4]=
  60. {
  61.     (APTR)sizeof(struct IntUtilityBase),
  62.     (APTR)Utility_functable,
  63.     NULL,
  64.     &AROS_SLIB_ENTRY(init,Utility)
  65. };
  66.  
  67. static struct TagItem nstags[] =
  68. {
  69.     { ANO_NameSpace, TRUE },
  70.     { ANO_Flags, NSF_NODUPS },
  71.     { TAG_DONE, 0 }
  72. };
  73.  
  74. #ifdef SysBase
  75. #undef SysBase
  76. #endif
  77.  
  78. /* iaint:
  79.     Sigh, I require this to compile this with DICE, I will
  80.     remove it at a later date...or at least change it :)
  81. */
  82.  
  83. #ifdef __GNUC__
  84. #define SysBase GetIntUtilityBase(UtilityBase)->ub_SysBase
  85. #else
  86. struct ExecBase *SysBase = 0L;
  87. #endif
  88.  
  89. #define SetFunc(a,b) SetFunction((struct Library *)UtilityBase, a * -LIB_VECTSIZE, AROS_SLIB_ENTRY(b,Utility))
  90.  
  91. AROS_LH2(struct UtilityBase *, init,
  92.     AROS_LHA(struct UtilityBase *, UtilityBase, D0),
  93.     AROS_LHA(BPTR,               segList,   A0),
  94.     struct ExecBase *, sysBase, 0, Utility)
  95. {
  96.     AROS_LIBFUNC_INIT
  97.  
  98.     /* Store arguments */
  99.     GetIntUtilityBase(UtilityBase)->ub_SysBase=sysBase;
  100.     GetIntUtilityBase(UtilityBase)->ub_SegList=segList;
  101. #ifdef _DCC
  102.     SysBase = sysBase;
  103. #endif
  104.  
  105.     /* Set up UtilityBase */
  106.     UtilityBase->ub_LibNode.lib_Node.ln_Pri = 0;
  107.     UtilityBase->ub_LibNode.lib_Node.ln_Type = NT_LIBRARY;
  108.     (const)UtilityBase->ub_LibNode.lib_Node.ln_Name = name;
  109.     UtilityBase->ub_LibNode.lib_Flags = LIBF_SUMUSED | LIBF_CHANGED;
  110.     UtilityBase->ub_LibNode.lib_Version = 41;
  111.     UtilityBase->ub_LibNode.lib_Revision = 8;
  112.     (const)UtilityBase->ub_LibNode.lib_IdString = &version[6];
  113.  
  114.     GetIntUtilityBase(UtilityBase)->ub_LastID = 0;
  115.  
  116.     GetIntUtilityBase(UtilityBase)->ub_GlobalNameSpace =
  117.         AllocNamedObjectA("utility global name space", nstags);
  118.  
  119.     if(GetIntUtilityBase(UtilityBase)->ub_GlobalNameSpace == NULL)
  120.     {
  121.         Alert(AG_NoMemory | AO_UtilityLib);
  122.     }
  123.  
  124. #if defined(__mc68000__)
  125.     /* Are we running on a m68020 or higher?
  126.        If so we should setfunction all the relevant functions to use
  127.        native code.
  128.     */
  129.     if(SysBase->AttnFlags & AFF_68020)
  130.     {
  131.         SetFunc(23, SMult32_020);
  132.         SetFunc(24, UMult32_020);
  133.         SetFunc(25, SDivMod32_020);
  134.         SetFunc(26, UDivMod32_020);
  135.  
  136. #if 0
  137.         /* The 060 doesn't have some of the instructions I use... */
  138.         if((SysBase->AttnFlags & AFF_68060) == 0)
  139.         {
  140.             SetFunc(33, SMult64_020);
  141.             SetFunc(34, UMult64_020);
  142.         }
  143. #endif
  144.     }
  145. #endif
  146.  
  147.     /* You would return NULL if the init failed */
  148.     return UtilityBase;
  149.     AROS_LIBFUNC_EXIT
  150. }
  151.  
  152. AROS_LH1(struct UtilityBase *, open,
  153.  AROS_LHA(ULONG, version, D0),
  154.            struct UtilityBase *, UtilityBase, 1, Utility)
  155. {
  156.     AROS_LIBFUNC_INIT
  157.  
  158.     /* Keep compiler happy */
  159.     version=0;
  160.  
  161.     /* I have one more opener. */
  162.     UtilityBase->ub_LibNode.lib_OpenCnt++;
  163.     UtilityBase->ub_LibNode.lib_Flags&=~LIBF_DELEXP;
  164.  
  165.     /* You would return NULL if the open failed. */
  166.     return UtilityBase;
  167.     AROS_LIBFUNC_EXIT
  168. }
  169.  
  170. AROS_LH0(BPTR, close,
  171.            struct UtilityBase *, UtilityBase, 2, Utility)
  172. {
  173.     AROS_LIBFUNC_INIT
  174.  
  175.     /* I have one fewer opener. */
  176.     if(!--UtilityBase->ub_LibNode.lib_OpenCnt)
  177.     {
  178. #ifdef DISK_BASED
  179.         /* Delayed expunge pending? */
  180.         if(UtilityBase->ub_LibNode.lib_Flags&LIBF_DELEXP)
  181.             /* Then expunge the library */
  182.             return expunge();
  183. #endif
  184.     }
  185.     return 0;
  186.     AROS_LIBFUNC_EXIT
  187. }
  188.  
  189. AROS_LH0(BPTR, expunge,
  190.            struct UtilityBase *, UtilityBase, 3, Utility)
  191. {
  192.     AROS_LIBFUNC_INIT
  193.  
  194.     BPTR ret;
  195.  
  196.     /* Test for openers. */
  197.     if(UtilityBase->ub_LibNode.lib_OpenCnt)
  198.     {
  199.         /* Set the delayed expunge flag and return. */
  200.         UtilityBase->ub_LibNode.lib_Flags|=LIBF_DELEXP;
  201.         return 0;
  202.     }
  203. #ifdef DISK_BASED
  204.     FreeNamedObject(GetIntUtilityBase(UtilityBase)->ub_GlobalNameSpace);
  205.  
  206.     /* Get rid of the library. Remove it from the list. */
  207.     Remove(&UtilityBase->ub_LibNode.lib_Node);
  208.  
  209.     /* Get returncode here - FreeMem() will destroy the field. */
  210.     ret=GetIntUtilityBase(UtilityBase)->ub_SegList;
  211.  
  212.     /* Free the memory. */
  213.     FreeMem((char *)UtilityBase-UtilityBase->ub_LibNode.lib_NegSize,
  214.             UtilityBase->ub_LibNode.lib_NegSize+UtilityBase->ub_LibNode.lib_PosSize);
  215. #else
  216.     ret = 0;
  217. #endif
  218.  
  219.     return ret;
  220.     AROS_LIBFUNC_EXIT
  221. }
  222.  
  223. AROS_LH0I(int, null,
  224.             struct UtilityBase *, UtilityBase, 4, Utility)
  225. {
  226.     AROS_LIBFUNC_INIT
  227.     return 0;
  228.     AROS_LIBFUNC_EXIT
  229. }
  230.