home *** CD-ROM | disk | FTP | other *** search
/ Aminet 18 / aminetcdnumber181997.iso / Aminet / misc / emu / AROSdev.lha / AROS / rom / dos / dos_init.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-01-27  |  6.2 KB  |  241 lines

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