Fix consistency of use of AROS calling macro's:
[AROS.git] / rom / exec / initresident.c
bloba575c121553dde51a3ec0d389df02400973865be
1 /*
2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Build a library or device from a resident structure.
6 Lang: english
7 */
8 #include <dos/dos.h>
9 #include <aros/asmcall.h>
10 #include "exec_intern.h"
11 #include <exec/devices.h>
13 #include "exec_debug.h"
14 #ifndef DEBUG_InitResident
15 # define DEBUG_InitResident 0
16 #endif
17 #undef DEBUG
18 #if DEBUG_InitResident
19 # define DEBUG 1
20 #endif
21 #include <aros/debug.h>
22 #undef kprintf
24 /*****************************************************************************
26 NAME */
27 #include <exec/resident.h>
28 #include <dos/bptr.h>
29 #include <proto/exec.h>
31 AROS_LH2(APTR, InitResident,
33 /* SYNOPSIS */
34 AROS_LHA(struct Resident *, resident, A1),
35 AROS_LHA(BPTR, segList, D1),
37 /* LOCATION */
38 struct ExecBase *, SysBase, 17, Exec)
40 /* FUNCTION
41 Test the resident structure and build the library or device
42 with the information given therein. The Init() vector is
43 called and the base address returned.
45 The Init() vector is called with the following registers:
46 D0 = 0
47 A0 = segList
48 A6 = ExecBase
50 INPUTS
51 resident - Pointer to resident structure.
52 segList - Pointer to loaded module, 0 for resident modules.
54 RESULT
55 A pointer returned from the Init() vector. Usually this is the
56 base of the library/device/resource. NULL for failure.
58 NOTES
59 AUTOINIT modules are automatically added to the correct exec list.
60 Non AUTOINIT modules have to do all the work themselves.
62 EXAMPLE
64 BUGS
66 SEE ALSO
68 INTERNALS
70 ******************************************************************************/
72 AROS_LIBFUNC_INIT
74 struct Library *library = NULL;
76 D(bug("InitResident begin $%lx (\"%s\")\n", resident, resident->rt_Name));
78 /* Check for validity */
79 if(resident->rt_MatchWord != RTC_MATCHWORD ||
80 resident->rt_MatchTag != resident)
81 return NULL;
83 /* Depending on the autoinit flag... */
84 if(resident->rt_Flags & RTF_AUTOINIT)
86 /* ...initialize automatically... */
87 struct init
89 ULONG dSize;
90 APTR vectors;
91 APTR structure;
92 ULONG_FUNC init;
94 struct init *init = (struct init *)resident->rt_Init;
96 D(bug("Initresident RTF_AUTOINIT\n"));
99 Make the library. Don't call the Init routine yet, but delay
100 that until we can copy stuff from the tag to the libbase.
102 library = MakeLibrary(init->vectors, init->structure,
103 NULL, init->dSize, segList);
105 if(library != NULL)
108 Copy over the interesting stuff from the ROMtag, and set the
109 library state to indicate that this lib has changed and
110 should be checksummed at the next opportunity.
112 Don't copy the priority, because a tag's priority doesn't
113 mean the same as a lib's priority.
115 library->lib_Node.ln_Type = resident->rt_Type;
116 library->lib_Node.ln_Name = (char *)resident->rt_Name;
117 /* Even if this is a resource, it was created using MakeLibrary(), this assumes
118 that it has struct Library in the beginning - sonic
119 if (resident->rt_Type != NT_RESOURCE)
121 library->lib_Version = resident->rt_Version;
122 library->lib_IdString = (char *)resident->rt_IdString;
123 library->lib_Flags = LIBF_SUMUSED|LIBF_CHANGED;
125 if (resident->rt_Flags & RTF_EXTENDED)
127 library->lib_Revision = resident->rt_Revision;
129 /* }*/
132 Call the library init vector, if set.
134 if(init->init)
136 D(bug("Initresident call init @%p\n", init->init));
137 library = AROS_UFC3(struct Library *, init->init,
138 AROS_UFCA(struct Library *, library, D0),
139 AROS_UFCA(BPTR, segList, A0),
140 AROS_UFCA(struct ExecBase *, SysBase, A6)
145 Test the library base, in case the init routine failed in
146 some way.
148 if(library != NULL)
151 Add the initialized module to the system.
153 switch(resident->rt_Type)
155 case NT_DEVICE:
156 AddDevice((struct Device *)library);
157 break;
158 case NT_LIBRARY:
159 case NT_HIDD: /* XXX Remove when new Hidd system ok. */
160 AddLibrary(library);
161 break;
162 case NT_RESOURCE:
163 AddResource(library);
164 break;
169 else
171 D(bug("Initresident !RTF_AUTOINIT\n"));
173 /* ...or let the library do it. */
174 library = AROS_UFC3(struct Library *, resident->rt_Init,
175 AROS_UFCA(struct Library *, 0L, D0),
176 AROS_UFCA(BPTR, segList, A0),
177 AROS_UFCA(struct ExecBase *, SysBase, A6)
181 D(bug("InitResident end $%lx (\"%s\")\n", resident, resident->rt_Name));
183 return library;
185 AROS_LIBFUNC_EXIT
186 } /* InitResident */