Support rastport clipping rectangle for layerless rastports
[tangerine.git] / rom / exec / initresident.c
blob0b052806914fc7f4f561bf1832008197b418a462
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 D(bug("InitResident $%lx (\"%s\")\n", resident, resident->rt_Name));
76 /* Check for validity */
77 if(resident->rt_MatchWord != RTC_MATCHWORD ||
78 resident->rt_MatchTag != resident)
79 return NULL;
81 /* Depending on the autoinit flag... */
82 if(resident->rt_Flags & RTF_AUTOINIT)
84 /* ...initialize automatically... */
85 struct init
87 ULONG dSize;
88 APTR vectors;
89 APTR structure;
90 ULONG_FUNC init;
92 struct init *init = (struct init *)resident->rt_Init;
93 struct Library *library;
96 Make the library. Don't call the Init routine yet, but delay
97 that until we can copy stuff from the tag to the libbase.
99 library = MakeLibrary(init->vectors, init->structure,
100 NULL, init->dSize, segList);
102 if(library != NULL)
105 Copy over the interesting stuff from the ROMtag, and set the
106 library state to indicate that this lib has changed and
107 should be checksummed at the next opportunity.
109 Don't copy the priority, because a tag's priority doesn't
110 mean the same as a lib's priority.
112 library->lib_Node.ln_Type = resident->rt_Type;
113 library->lib_Node.ln_Name = resident->rt_Name;
114 if (resident->rt_Type != NT_RESOURCE)
116 library->lib_Version = resident->rt_Version;
117 library->lib_IdString = resident->rt_IdString;
118 library->lib_Flags = LIBF_SUMUSED|LIBF_CHANGED;
120 if (resident->rt_Flags & RTF_EXTENDED)
122 library->lib_Revision = resident->rt_Revision;
127 Call the library init vector, if set.
129 if(init->init)
131 library = AROS_UFC3(struct Library *, init->init,
132 AROS_UFCA(struct Library *, library, D0),
133 AROS_UFCA(BPTR, segList, A0),
134 AROS_UFCA(struct ExecBase *, SysBase, A6)
139 Test the library base, in case the init routine failed in
140 some way.
142 if(library != NULL)
145 Add the initialized module to the system.
147 switch(resident->rt_Type)
149 case NT_DEVICE:
150 AddDevice((struct Device *)library);
151 break;
152 case NT_LIBRARY:
153 case NT_HIDD: /* XXX Remove when new Hidd system ok. */
154 AddLibrary(library);
155 break;
156 case NT_RESOURCE:
157 AddResource(library);
158 break;
163 return library;
165 else
167 /* ...or let the library do it. */
168 return AROS_UFC3(struct Library *, resident->rt_Init,
169 AROS_UFCA(ULONG, 0L, D0),
170 AROS_UFCA(BPTR, segList, A0),
171 AROS_UFCA(struct ExecBase *, SysBase, A6)
175 AROS_LIBFUNC_EXIT
176 } /* InitResident */