revert between 56095 -> 55830 in arch
[AROS.git] / rom / exec / initresident.c
blobaedc530efcc5dce118b571edfc2db8c8753ad828
1 /*
2 Copyright © 1995-2014, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Build a library or device from a resident structure.
6 Lang: english
7 */
9 #include <aros/debug.h>
10 #include <dos/dos.h>
11 #include <aros/asmcall.h>
12 #include <exec/devices.h>
14 #include "exec_debug.h"
15 #include "exec_intern.h"
17 /*****************************************************************************
19 NAME */
20 #include <exec/resident.h>
21 #include <dos/bptr.h>
22 #include <proto/exec.h>
24 AROS_LH2(APTR, InitResident,
26 /* SYNOPSIS */
27 AROS_LHA(struct Resident *, resident, A1),
28 AROS_LHA(BPTR, segList, D1),
30 /* LOCATION */
31 struct ExecBase *, SysBase, 17, Exec)
33 /* FUNCTION
34 Test the resident structure and build the library or device
35 with the information given therein. The Init() vector is
36 called and the base address returned.
38 The Init() vector is called with the following registers:
39 D0 = 0
40 A0 = segList
41 A6 = ExecBase
43 INPUTS
44 resident - Pointer to resident structure.
45 segList - Pointer to loaded module, 0 for resident modules.
47 RESULT
48 A pointer returned from the Init() vector. Usually this is the
49 base of the library/device/resource. NULL for failure.
51 NOTES
52 AUTOINIT modules are automatically added to the correct exec list.
53 Non AUTOINIT modules have to do all the work themselves.
55 EXAMPLE
57 BUGS
59 SEE ALSO
61 INTERNALS
63 ******************************************************************************/
65 AROS_LIBFUNC_INIT
67 struct Library *library = NULL;
69 DINITRESIDENT("InitResident begin 0x%p (\"%s\")", resident, resident->rt_Name);
71 /* Check for validity */
72 if(resident->rt_MatchWord != RTC_MATCHWORD ||
73 resident->rt_MatchTag != resident)
74 return NULL;
76 /* Depending on the autoinit flag... */
77 if(resident->rt_Flags & RTF_AUTOINIT)
79 /* ...initialize automatically... */
80 struct init
82 ULONG dSize;
83 APTR vectors;
84 APTR structure;
85 ULONG_FUNC init;
87 struct init *init = (struct init *)resident->rt_Init;
89 DINITRESIDENT("InitResident RTF_AUTOINIT");
92 Make the library. Don't call the Init routine yet, but delay
93 that until we can copy stuff from the tag to the libbase.
95 library = MakeLibrary(init->vectors, init->structure,
96 NULL, init->dSize, segList);
98 if(library != NULL)
101 Copy over the interesting stuff from the ROMtag, and set the
102 library state to indicate that this lib has changed and
103 should be checksummed at the next opportunity.
105 Don't copy the priority, because a tag's priority doesn't
106 mean the same as a lib's priority.
108 library->lib_Node.ln_Type = resident->rt_Type;
109 library->lib_Node.ln_Name = (char *)resident->rt_Name;
110 /* Even if this is a resource, it was created using MakeLibrary(), this assumes
111 that it has struct Library in the beginning - sonic
112 if (resident->rt_Type != NT_RESOURCE)
114 library->lib_Version = resident->rt_Version;
115 library->lib_IdString = (char *)resident->rt_IdString;
116 library->lib_Flags = LIBF_SUMUSED|LIBF_CHANGED;
118 if (resident->rt_Flags & RTF_EXTENDED)
120 library->lib_Revision = resident->rt_Revision;
122 /* }*/
125 Call the library init vector, if set.
127 if(init->init)
129 library = AROS_UFC3(struct Library *, init->init,
130 AROS_UFCA(struct Library *, library, D0),
131 AROS_UFCA(BPTR, segList, A0),
132 AROS_UFCA(struct ExecBase *, SysBase, A6)
137 Test the library base, in case the init routine failed in
138 some way.
140 if(library != NULL)
143 Add the initialized module to the system.
145 switch(resident->rt_Type)
147 case NT_DEVICE:
148 AddDevice((struct Device *)library);
149 break;
150 case NT_LIBRARY:
151 case NT_HIDD: /* XXX Remove when new Hidd system ok. */
152 AddLibrary(library);
153 break;
154 case NT_RESOURCE:
155 AddResource(library);
156 break;
161 else
163 DINITRESIDENT("InitResident !RTF_AUTOINIT");
165 /* ...or let the library do it. */
166 if (resident->rt_Init) {
167 #if !defined(__mc68000__)
168 library = AROS_UFC3(struct Library *, resident->rt_Init,
169 AROS_UFCA(struct Library *, 0L, D0),
170 AROS_UFCA(BPTR, segList, A0),
171 AROS_UFCA(struct ExecBase *, SysBase, A6)
173 #else
174 library = AROS_UFC4(struct Library *, resident->rt_Init,
175 AROS_UFCA(struct Library *, 0L, D0),
176 AROS_UFCA(BPTR, segList, A0),
177 // Dummy variable. Bad programs may not preserve A4.
178 AROS_UFCA(ULONG, 0L, A4),
179 AROS_UFCA(struct ExecBase *, SysBase, A6)
181 #endif
185 DINITRESIDENT("InitResident end 0x%p (\"%s\"), result 0x%p", resident, resident->rt_Name, library);
187 return library;
189 AROS_LIBFUNC_EXIT
190 } /* InitResident */