home *** CD-ROM | disk | FTP | other *** search
/ MACD 4 / MACD4.iso / Emulatory / AROS / dos / dos_init.c < prev    next >
Encoding:
C/C++ Source or Header  |  1978-03-06  |  6.1 KB  |  238 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: dos_init.c,v 1.9 1996/10/24 15:50:26 aros Exp $
  4.     $Log: dos_init.c,v $
  5.     Revision 1.9  1996/10/24 15:50:26  aros
  6.     Use the official AROS macros over the __AROS versions.
  7.  
  8.     Revision 1.8  1996/10/23 14:23:06  aros
  9.     Use LIB_VECTSIZE over sizeof(struct JumpVec)
  10.  
  11.     Revision 1.7  1996/09/17 18:40:21  digulla
  12.     Only one global DOSBase to avoid multiple opens without close
  13.     InitSemaphore() needs SysBase
  14.  
  15.     Revision 1.6  1996/09/13 17:50:06  digulla
  16.     Use IPTR
  17.  
  18.     Revision 1.5  1996/09/12 14:52:03  digulla
  19.     Use correct way to access external names (was missing)
  20.  
  21.     Revision 1.4  1996/09/11 16:54:23  digulla
  22.     Always use AROS_SLIB_ENTRY() to access shared external symbols, because
  23.     some systems name an external symbol "x" as "_x" and others as "x".
  24.     (The problem arises with assembler symbols which might differ)
  25.  
  26.     Revision 1.3  1996/08/13 13:52:53  digulla
  27.     Replaced <dos/dosextens.h> by "dos_intern.h" or added "dos_intern.h"
  28.     Replaced AROS_LA by AROS_LHA
  29.  
  30.     Revision 1.2  1996/08/01 17:40:49  digulla
  31.     Added standard header for all files
  32.  
  33.     Desc:
  34.     Lang:
  35. */
  36. #include <exec/types.h>
  37. #include <exec/resident.h>
  38. #include <exec/execbase.h>
  39. #include <exec/libraries.h>
  40. #include <clib/exec_protos.h>
  41. #include <aros/libcall.h>
  42. #include <dos/dosextens.h>
  43. #include <dos/dostags.h>
  44. #include <clib/dos_protos.h>
  45. #include <utility/tagitem.h>
  46. #include "dos_intern.h"
  47.  
  48. static const char name[];
  49. static const char version[];
  50. static const APTR Dos_inittabl[4];
  51. static void *const Dos_functable[];
  52. struct DosLibrary *AROS_SLIB_ENTRY(init,Dos) ();
  53. extern const char Dos_end;
  54.  
  55. int Dos_entry(void)
  56. {
  57.     /* If the library was executed by accident return error code. */
  58.     return -1;
  59. }
  60.  
  61. const struct Resident Dos_resident=
  62. {
  63.     RTC_MATCHWORD,
  64.     (struct Resident *)&Dos_resident,
  65.     (APTR)&Dos_end,
  66.     RTF_AUTOINIT,
  67.     39,
  68.     NT_LIBRARY,
  69.     0,
  70.     (char *)name,
  71.     (char *)&version[6],
  72.     (ULONG *)Dos_inittabl
  73. };
  74.  
  75. static const char name[]="dos.library";
  76.  
  77. static const char version[]="$VER: dos 39.0 (28.3.96)\n\015";
  78.  
  79. static const APTR Dos_inittabl[4]=
  80. {
  81.     (APTR)sizeof(struct DosLibrary),
  82.     (APTR)Dos_functable,
  83.     NULL,
  84.     &AROS_SLIB_ENTRY(init,Dos)
  85. };
  86.  
  87. void LDDemon();
  88. void AROS_SLIB_ENTRY(OpenLibrary,Dos)();
  89. void AROS_SLIB_ENTRY(OpenDevice,Dos)();
  90. void AROS_SLIB_ENTRY(CloseLibrary,Dos)();
  91. void AROS_SLIB_ENTRY(CloseDevice,Dos)();
  92. void AROS_SLIB_ENTRY(RemLibrary,Dos)();
  93. void LDFlush();
  94.  
  95. #undef SysBase
  96.  
  97. AROS_LH2(struct DosLibrary *, init,
  98.  AROS_LHA(struct DosLibrary *, DOSBase, D0),
  99.  AROS_LHA(BPTR,               segList,   A0),
  100.        struct ExecBase *, SysBase, 0, Dos)
  101. {
  102.     AROS_LIBFUNC_INIT
  103.     /* This function is single-threaded by exec by calling Forbid. */
  104.  
  105.     /* Store arguments */
  106.     DOSBase->dl_SysBase=SysBase;
  107.     DOSBase->dl_SegList=segList;
  108.  
  109.     InitSemaphore(&DOSBase->dl_DosListLock);
  110.     InitSemaphore(&DOSBase->dl_LDSigSem);
  111.  
  112.     DOSBase->dl_UtilityBase=OpenLibrary("utility.library",39);
  113.     if(DOSBase->dl_UtilityBase!=NULL)
  114.     {
  115.     static const struct TagItem tags[]=
  116.     {
  117.         { NP_Entry, (IPTR)LDDemon },
  118.         { NP_Input, 0 },
  119.         { NP_Output, 0 },
  120.         { NP_Name, (IPTR)"lib & dev loader demon" },
  121.         { TAG_END, 0 }
  122.     };
  123.  
  124.     DOSBase->dl_LDDemon=CreateNewProc((struct TagItem *)tags);
  125.  
  126.     if(DOSBase->dl_LDDemon!=NULL)
  127.     {
  128.         (void)SetFunction(&SysBase->LibNode,-92*LIB_VECTSIZE,AROS_SLIB_ENTRY(OpenLibrary,Dos));
  129.         (void)SetFunction(&SysBase->LibNode,-74*LIB_VECTSIZE,AROS_SLIB_ENTRY(OpenDevice,Dos));
  130.         (void)SetFunction(&SysBase->LibNode,-69*LIB_VECTSIZE,AROS_SLIB_ENTRY(CloseLibrary,Dos));
  131.         (void)SetFunction(&SysBase->LibNode,-75*LIB_VECTSIZE,AROS_SLIB_ENTRY(CloseDevice,Dos));
  132.         (void)SetFunction(&SysBase->LibNode,-67*LIB_VECTSIZE,AROS_SLIB_ENTRY(RemLibrary,Dos));
  133.         (void)SetFunction(&SysBase->LibNode,-73*LIB_VECTSIZE,AROS_SLIB_ENTRY(RemLibrary,Dos));
  134.  
  135.         DOSBase->dl_LDHandler.is_Node.ln_Name="lib & dev loader demon";
  136.         DOSBase->dl_LDHandler.is_Node.ln_Pri=0;
  137.         DOSBase->dl_LDHandler.is_Code=LDFlush;
  138.  
  139.         AddMemHandler(&DOSBase->dl_LDHandler);
  140.  
  141.         return DOSBase;
  142.     }
  143.  
  144.     CloseLibrary(DOSBase->dl_UtilityBase);
  145.     }
  146.  
  147.     return NULL;
  148.     AROS_LIBFUNC_EXIT
  149. }
  150.  
  151. #define SysBase     (DOSBase->dl_SysBase)
  152.  
  153. AROS_LH1(struct DosLibrary *, open,
  154.  AROS_LHA(ULONG, version, D0),
  155.        struct DosLibrary *, DOSBase, 1, Dos)
  156. {
  157.     AROS_LIBFUNC_INIT
  158.     /*
  159.     This function is single-threaded by exec by calling Forbid.
  160.     If you break the Forbid() another task may enter this function
  161.     at the same time. Take care.
  162.     */
  163.  
  164.     /* Keep compiler happy */
  165.     version=0;
  166.  
  167.     /* I have one more opener. */
  168.     DOSBase->dl_lib.lib_OpenCnt++;
  169.     DOSBase->dl_lib.lib_Flags&=~LIBF_DELEXP;
  170.  
  171.     /* You would return NULL if the open failed. */
  172.     return DOSBase;
  173.     AROS_LIBFUNC_EXIT
  174. }
  175.  
  176. AROS_LH0(BPTR, close,
  177.        struct DosLibrary *, DOSBase, 2, Dos)
  178. {
  179.     AROS_LIBFUNC_INIT
  180.     /*
  181.     This function is single-threaded by exec by calling Forbid.
  182.     If you break the Forbid() another task may enter this function
  183.     at the same time. Take care.
  184.     */
  185.  
  186.     /* I have one fewer opener. */
  187.     if(!--DOSBase->dl_lib.lib_OpenCnt)
  188.     {
  189.     /* Delayed expunge pending? */
  190.     if(DOSBase->dl_lib.lib_Flags&LIBF_DELEXP)
  191.         /* Then expunge the library */
  192.         return expunge();
  193.     }
  194.     return 0;
  195.     AROS_LIBFUNC_EXIT
  196. }
  197.  
  198. AROS_LH0(BPTR, expunge,
  199.        struct DosLibrary *, DOSBase, 3, Dos)
  200. {
  201.     AROS_LIBFUNC_INIT
  202.  
  203.     BPTR ret;
  204.     /*
  205.     This function is single-threaded by exec by calling Forbid.
  206.     Never break the Forbid() or strange things might happen.
  207.     */
  208.  
  209.     /* Test for openers. */
  210.     if(DOSBase->dl_lib.lib_OpenCnt)
  211.     {
  212.     /* Set the delayed expunge flag and return. */
  213.     DOSBase->dl_lib.lib_Flags|=LIBF_DELEXP;
  214.     return 0;
  215.     }
  216.  
  217.     /* Get rid of the library. Remove it from the list. */
  218.     Remove(&DOSBase->dl_lib.lib_Node);
  219.  
  220.     /* Get returncode here - FreeMem() will destroy the field. */
  221.     ret=DOSBase->dl_SegList;
  222.  
  223.     /* Free the memory. */
  224.     FreeMem((char *)DOSBase-DOSBase->dl_lib.lib_NegSize,
  225.         DOSBase->dl_lib.lib_NegSize+DOSBase->dl_lib.lib_PosSize);
  226.  
  227.     return ret;
  228.     AROS_LIBFUNC_EXIT
  229. }
  230.  
  231. AROS_LH0I(int, null,
  232.         struct DosLibrary *, DOSBase, 4, Dos)
  233. {
  234.     AROS_LIBFUNC_INIT
  235.     return 0;
  236.     AROS_LIBFUNC_EXIT
  237. }
  238.