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 /* Calculate the jumptable's size */
82 if (*(WORD
*)funcInit
==-1)
85 WORD
*fp
=(WORD
*)funcInit
+1;
89 DCREATELIBRARY("Table contains %lu relative offsets", count
);
93 /* Count function pointers */
94 void **fp
=(void **)funcInit
;
96 while(*fp
++!=(void *)-1)
99 DCREATELIBRARY("Table contains %lu absolute pointers", count
);
102 /* Align library base */
103 negsize
=AROS_ALIGN(count
* LIB_VECTSIZE
);
105 /* Allocate memory */
106 library
=(struct Library
*)AllocMem(dataSize
+negsize
,MEMF_PUBLIC
|MEMF_CLEAR
);
107 DCREATELIBRARY("Allocated vector table at 0x%p, size is %lu", library
, negsize
);
109 /* And initilize the library */
112 /* Get real library base */
113 library
=(struct Library
*)((char *)library
+negsize
);
115 /* Build jumptable */
116 if(*(WORD
*)funcInit
==-1)
118 MakeFunctions(library
,(WORD
*)funcInit
+1,(WORD
*)funcInit
);
120 /* function pointers */
121 MakeFunctions(library
,funcInit
,NULL
);
124 library
->lib_NegSize
=negsize
;
125 library
->lib_PosSize
=dataSize
;
127 /* Create structure, do not clear struct Library */
129 InitStruct(structInit
,library
,0);
131 /* Call init vector */
134 DCREATELIBRARY("Calling init function 0x%p", libInit
);
136 library
=AROS_UFC3(struct Library
*, libInit
,
137 AROS_UFCA(struct Library
*, library
, D0
),
138 AROS_UFCA(BPTR
, segList
, A0
),
139 AROS_UFCA(struct ExecBase
*, SysBase
, A6
)
145 DCREATELIBRARY("Created library 0x%p", library
);