2 Copyright © 1995-2011, The AROS Development Team. All rights reserved.
5 Desc: Make a library ready for use.
9 #include <exec/execbase.h>
10 #include <exec/memory.h>
12 #include <aros/libcall.h>
13 #include <aros/asmcall.h>
14 #include <proto/exec.h>
16 #include "exec_debug.h"
18 /*****************************************************************************
22 AROS_LH5(struct Library
*, MakeLibrary
,
25 AROS_LHA(CONST_APTR
, funcInit
, A0
),
26 AROS_LHA(CONST_APTR
, structInit
, A1
),
27 AROS_LHA(ULONG_FUNC
, libInit
, A2
),
28 AROS_LHA(ULONG
, dataSize
, D0
),
29 AROS_LHA(BPTR
, segList
, D1
),
32 struct ExecBase
*, SysBase
, 14, Exec
)
35 Allocates memory for the library, builds it and calls the library's
36 init vector. Generally this function is for internal use and for
37 use by library programmers that don't want to use the automatic
38 initialization procedure.
41 funcInit - Either a pointer to an array of function offsets
42 (starts with -1, relative to funcInit) or to an array
43 of absolute function pointers.
44 structInit - Pointer to a InitStruct() data region or NULL.
45 libInit - The library's init vector or NULL.
46 The init vector is called with the library address (D0),
47 the segList (A0) and ExecBase (A6) as arguments.
48 If the init fails the init code has to free the base memory
49 and return NULL (the library address for success).
50 dataSize - Size of the library structure including system structures.
51 Must be at least sizeof(struct Library).
52 segList - BCPL pointer to the library segments. Used to free the
56 The library base address or NULL.
59 The library base is always aligned to the maximum of sizeof(LONG)
60 and double alignment restrictions.
67 AddLibrary(), RemLibrary(), MakeFunctions(), InitStruct(), SumLibrary()
71 ******************************************************************************/
75 struct Library
*library
;
79 DCREATELIBRARY("MakeLibrary: functions table at 0x%p, data size is %lu", funcInit
, dataSize
);
81 /* Can't do the following check on machines like x86, because 0x????ffff is
82 a valid address for code there! */
84 #if defined(__mc68000) || defined(__ppc__) || defined(__powerpc__)
85 /* Calculate the jumptable's size */
86 if (*(WORD
*)funcInit
==-1)
89 WORD
*fp
=(WORD
*)funcInit
+1;
93 DCREATELIBRARY("Table contains %lu relative offsets", count
);
98 /* Count function pointers */
99 void **fp
=(void **)funcInit
;
101 while(*fp
++!=(void *)-1)
104 DCREATELIBRARY("Table contains %lu absolute pointers", count
);
107 /* Align library base */
108 negsize
=AROS_ALIGN(count
* LIB_VECTSIZE
);
110 /* Allocate memory */
111 library
=(struct Library
*)AllocMem(dataSize
+negsize
,MEMF_PUBLIC
|MEMF_CLEAR
);
112 DCREATELIBRARY("Allocated vector table at 0x%p, size is %lu", library
, negsize
);
114 /* And initilize the library */
117 /* Get real library base */
118 library
=(struct Library
*)((char *)library
+negsize
);
120 /* Build jumptable */
121 #if defined(__mc68000) || defined(__ppc__) || defined(__powerpc__)
122 if(*(WORD
*)funcInit
==-1)
124 MakeFunctions(library
,(WORD
*)funcInit
+1,(WORD
*)funcInit
);
127 /* function pointers */
128 MakeFunctions(library
,funcInit
,NULL
);
131 library
->lib_NegSize
=negsize
;
132 library
->lib_PosSize
=dataSize
;
134 /* Create structure, do not clear struct Library */
136 InitStruct(structInit
,library
,0);
138 /* Call init vector */
141 DCREATELIBRARY("Calling init function 0x%p", libInit
);
143 library
=AROS_UFC3(struct Library
*, libInit
,
144 AROS_UFCA(struct Library
*, library
, D0
),
145 AROS_UFCA(BPTR
, segList
, A0
),
146 AROS_UFCA(struct ExecBase
*, SysBase
, A6
)
152 DCREATELIBRARY("Created library 0x%p", library
);