home *** CD-ROM | disk | FTP | other *** search
/ Aminet 18 / aminetcdnumber181997.iso / Aminet / misc / emu / AROSdev.lha / AROS / rom / exec / initresident.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-01-10  |  3.1 KB  |  138 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: initresident.c,v 1.9 1997/01/10 12:44:37 digulla Exp $
  4.  
  5.     Desc:
  6.     Lang:
  7. */
  8. #include <dos/dos.h>
  9. #include <aros/asmcall.h>
  10. #include "exec_intern.h"
  11. #include <exec/resident.h>
  12. #include <exec/devices.h>
  13. #include <proto/exec.h>
  14.  
  15. /*****************************************************************************
  16.  
  17.     NAME */
  18.  
  19.     AROS_LH2(APTR, InitResident,
  20.  
  21. /*  SYNOPSIS */
  22.     AROS_LHA(struct Resident *, resident, A1),
  23.     AROS_LHA(BPTR,              segList,  D1),
  24.  
  25. /*  LOCATION */
  26.     struct ExecBase *, SysBase, 17, Exec)
  27.  
  28. /*  FUNCTION
  29.     Test the resident structure and build the library or device
  30.     with the information given therein. The Init() vector is
  31.     called and the base address returned.
  32.  
  33.     INPUTS
  34.     resident - Pointer to resident structure.
  35.     segList  - Pointer to loaded module, 0 for resident modules.
  36.  
  37.     RESULT
  38.     A pointer to the library or device ready to add to the exec lists.
  39.  
  40.     NOTES
  41.  
  42.     EXAMPLE
  43.  
  44.     BUGS
  45.  
  46.     SEE ALSO
  47.  
  48.     INTERNALS
  49.  
  50.     HISTORY
  51.  
  52. ******************************************************************************/
  53. {
  54.     AROS_LIBFUNC_INIT
  55.  
  56.     /* Check for validity */
  57.     if(resident->rt_MatchWord != RTC_MATCHWORD ||
  58.        resident->rt_MatchTag != resident)
  59.     return NULL;
  60.  
  61.     /* Depending on the autoinit flag... */
  62.     if(resident->rt_Flags & RTF_AUTOINIT)
  63.     {
  64.     /* ...initialize automatically... */
  65.     struct init
  66.     {
  67.         ULONG dSize;
  68.         APTR vectors;
  69.         APTR structure;
  70.         ULONG_FUNC init;
  71.     };
  72.     struct init *init = (struct init *)resident->rt_Init;
  73.     struct Library *library;
  74.     library = MakeLibrary(init->vectors, init->structure,
  75.                   NULL, init->dSize, segList);
  76.  
  77.     if(library != NULL)
  78.     {
  79.         /*
  80.         Copy over the interesting stuff from the ROMtag, and set the
  81.         library state to indicate that this lib has changed and
  82.         should be checksummed at the next opportunity.
  83.         */
  84.         library->lib_Node.ln_Type = resident->rt_Type;
  85.         library->lib_Node.ln_Name = resident->rt_Name;
  86.         library->lib_Version      = resident->rt_Version;
  87.         library->lib_IdString     = resident->rt_IdString;
  88.         library->lib_Flags          = LIBF_SUMUSED|LIBF_CHANGED;
  89.  
  90.         /*
  91.         Call the library init vector, if set.
  92.         */
  93.         if(init->init)
  94.         {
  95.         library = AROS_UFC3(struct Library *, init->init,
  96.             AROS_UFCA(struct Library *,  library, D0),
  97.             AROS_UFCA(BPTR,              segList, A0),
  98.             AROS_UFCA(struct ExecBase *, SysBase, A6)
  99.         );
  100.         }
  101.  
  102.         /*
  103.         Test the library base, in case the init routine failed in
  104.         some way.
  105.         */
  106.         if(library != NULL)
  107.         {
  108.         /*
  109.             Add the initialized module to the system.
  110.         */
  111.         switch(resident->rt_Type)
  112.         {
  113.             case NT_DEVICE:
  114.             AddDevice((struct Device *)library);
  115.             break;
  116.             case NT_LIBRARY:
  117.             AddLibrary(library);
  118.             break;
  119.             case NT_RESOURCE:
  120.             AddResource(library);
  121.             break;
  122.         }
  123.         }
  124.     }
  125.  
  126.     return library;
  127.     }
  128.     else
  129.     /* ...or let the library do it. */
  130.     return AROS_UFC3(struct Library *, resident->rt_Init,
  131.         AROS_UFCA(ULONG,             0L,      D0),
  132.         AROS_UFCA(BPTR,              segList, A0),
  133.         AROS_UFCA(struct ExecBase *, SysBase, A6)
  134.     );
  135.  
  136.     AROS_LIBFUNC_EXIT
  137. } /* InitResident */
  138.