2 Copyright © 1995-2014, The AROS Development Team. All rights reserved.
5 Desc: Build a library or device from a resident structure.
9 #include <aros/debug.h>
11 #include <aros/asmcall.h>
12 #include <exec/devices.h>
14 #include "exec_debug.h"
15 #include "exec_intern.h"
17 /*****************************************************************************
20 #include <exec/resident.h>
22 #include <proto/exec.h>
24 AROS_LH2(APTR
, InitResident
,
27 AROS_LHA(struct Resident
*, resident
, A1
),
28 AROS_LHA(BPTR
, segList
, D1
),
31 struct ExecBase
*, SysBase
, 17, Exec
)
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:
44 resident - Pointer to resident structure.
45 segList - Pointer to loaded module, 0 for resident modules.
48 A pointer returned from the Init() vector. Usually this is the
49 base of the library/device/resource. NULL for failure.
52 AUTOINIT modules are automatically added to the correct exec list.
53 Non AUTOINIT modules have to do all the work themselves.
63 ******************************************************************************/
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
)
76 /* Depending on the autoinit flag... */
77 if(resident
->rt_Flags
& RTF_AUTOINIT
)
79 /* ...initialize automatically... */
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
);
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
;
125 Call the library init vector, if set.
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
143 Add the initialized module to the system.
145 switch(resident
->rt_Type
)
148 AddDevice((struct Device
*)library
);
151 case NT_HIDD
: /* XXX Remove when new Hidd system ok. */
155 AddResource(library
);
163 DINITRESIDENT("InitResident !RTF_AUTOINIT");
165 /* ...or let the library do it. */
166 if (resident
->rt_Init
) {
167 library
= AROS_UFC3(struct Library
*, resident
->rt_Init
,
168 AROS_UFCA(struct Library
*, 0L, D0
),
169 AROS_UFCA(BPTR
, segList
, A0
),
170 AROS_UFCA(struct ExecBase
*, SysBase
, A6
)
175 DINITRESIDENT("InitResident end 0x%p (\"%s\"), result 0x%p", resident
, resident
->rt_Name
, library
);