2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
5 Desc: Make a library ready for use.
8 #include <exec/execbase.h>
9 #include <exec/memory.h>
11 #include <aros/libcall.h>
12 #include <aros/asmcall.h>
13 #include <proto/exec.h>
15 /*****************************************************************************
19 AROS_LH5(struct Library
*, MakeLibrary
,
22 AROS_LHA(APTR
, funcInit
, A0
),
23 AROS_LHA(APTR
, structInit
, A1
),
24 AROS_LHA(ULONG_FUNC
, libInit
, A2
),
25 AROS_LHA(ULONG
, dataSize
, D0
),
26 AROS_LHA(BPTR
, segList
, D1
),
29 struct ExecBase
*, SysBase
, 14, Exec
)
32 Allocates memory for the library, builds it and calls the library's
33 init vector. Generally this function is for internal use and for
34 use by library programmers that don't want to use the automatic
35 initialization procedure.
38 funcInit - Either a pointer to an array of function offsets
39 (starts with -1, relative to funcInit) or to an array
40 of absolute function pointers.
41 structInit - Pointer to a InitStruct() data region or NULL.
42 libInit - The library's init vector or NULL.
43 The init vector is called with the library address (D0),
44 the segList (A0) and ExecBase (A6) as arguments.
45 If the init fails the init code has to free the base memory
46 and return NULL (the library address for success).
47 dataSize - Size of the library structure including system structures.
48 Must be at least sizeof(struct Library).
49 segList - BCPL pointer to the library segments. Used to free the
53 The library base address or NULL.
56 The library base is always aligned to the maximum of sizeof(LONG)
57 and double alignment restrictions.
64 AddLibrary(), RemLibrary(), MakeFunctions(), InitStruct(), SumLibrary()
68 ******************************************************************************/
72 struct Library
*library
;
75 /* Calculate the jumptable's size */
76 if(*(WORD
*)funcInit
==-1)
79 WORD
*fp
=(WORD
*)funcInit
+1;
81 negsize
+=LIB_VECTSIZE
;
85 /* Count function pointers */
86 void **fp
=(void **)funcInit
;
87 while(*fp
++!=(void *)-1)
88 negsize
+=LIB_VECTSIZE
;
91 /* Align library base */
92 negsize
=AROS_ALIGN(negsize
);
95 library
=(struct Library
*)AllocMem(dataSize
+negsize
,MEMF_PUBLIC
|MEMF_CLEAR
);
97 /* And initilize the library */
100 /* Get real library base */
101 library
=(struct Library
*)((char *)library
+negsize
);
103 /* Build jumptable */
104 if(*(WORD
*)funcInit
==-1)
106 MakeFunctions(library
,(WORD
*)funcInit
+1,(WORD
*)funcInit
);
108 /* function pointers */
109 MakeFunctions(library
,funcInit
,NULL
);
112 library
->lib_NegSize
=negsize
;
113 library
->lib_PosSize
=dataSize
;
115 /* Create structure */
117 InitStruct(structInit
,library
,0);
119 /* Call init vector */
121 library
=AROS_UFC3(struct Library
*, libInit
,
122 AROS_UFCA(struct Library
*, library
, D0
),
123 AROS_UFCA(BPTR
, segList
, A0
),
124 AROS_UFCA(struct ExecBase
*, SysBase
, A6
)