2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
5 Desc: Build a library or device from a resident structure.
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
18 #if DEBUG_InitResident
21 #include <aros/debug.h>
24 /*****************************************************************************
27 #include <exec/resident.h>
29 #include <proto/exec.h>
31 AROS_LH2(APTR
, InitResident
,
34 AROS_LHA(struct Resident
*, resident
, A1
),
35 AROS_LHA(BPTR
, segList
, D1
),
38 struct ExecBase
*, SysBase
, 17, Exec
)
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:
51 resident - Pointer to resident structure.
52 segList - Pointer to loaded module, 0 for resident modules.
55 A pointer returned from the Init() vector. Usually this is the
56 base of the library/device/resource. NULL for failure.
59 AUTOINIT modules are automatically added to the correct exec list.
60 Non AUTOINIT modules have to do all the work themselves.
70 ******************************************************************************/
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
)
83 /* Depending on the autoinit flag... */
84 if(resident
->rt_Flags
& RTF_AUTOINIT
)
86 /* ...initialize automatically... */
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
);
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
;
132 Call the library init vector, if set.
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
151 Add the initialized module to the system.
153 switch(resident
->rt_Type
)
156 AddDevice((struct Device
*)library
);
159 case NT_HIDD
: /* XXX Remove when new Hidd system ok. */
163 AddResource(library
);
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
));