Unification of "SEE ALSO" for exec.library
[cake.git] / rom / exec / makelibrary.c
blob6825d3b0875ad2352d81a6fb1aa197348754b24b
1 /*
2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Make a library ready for use.
6 Lang: english
7 */
8 #include <exec/execbase.h>
9 #include <exec/memory.h>
10 #include <dos/dos.h>
11 #include <aros/libcall.h>
12 #include <aros/asmcall.h>
13 #include <proto/exec.h>
15 /*****************************************************************************
17 NAME */
19 AROS_LH5(struct Library *, MakeLibrary,
21 /* SYNOPSIS */
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),
28 /* LOCATION */
29 struct ExecBase *, SysBase, 14, Exec)
31 /* FUNCTION
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.
37 INPUTS
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
50 library later.
52 RESULT
53 The library base address or NULL.
55 NOTES
56 The library base is always aligned to the maximum of sizeof(LONG)
57 and double alignment restrictions.
59 EXAMPLE
61 BUGS
63 SEE ALSO
64 AddLibrary(), RemLibrary(), MakeFunctions(), InitStruct(), SumLibrary()
66 INTERNALS
68 ******************************************************************************/
70 AROS_LIBFUNC_INIT
72 struct Library *library;
73 ULONG negsize=0;
75 /* Calculate the jumptable's size */
76 if(*(WORD *)funcInit==-1)
78 /* Count offsets */
79 WORD *fp=(WORD *)funcInit+1;
80 while(*fp++!=-1)
81 negsize+=LIB_VECTSIZE;
83 else
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);
94 /* Allocate memory */
95 library=(struct Library *)AllocMem(dataSize+negsize,MEMF_PUBLIC|MEMF_CLEAR);
97 /* And initilize the library */
98 if(library!=NULL)
100 /* Get real library base */
101 library=(struct Library *)((char *)library+negsize);
103 /* Build jumptable */
104 if(*(WORD *)funcInit==-1)
105 /* offsets */
106 MakeFunctions(library,(WORD *)funcInit+1,(WORD *)funcInit);
107 else
108 /* function pointers */
109 MakeFunctions(library,funcInit,NULL);
111 /* Write sizes */
112 library->lib_NegSize=negsize;
113 library->lib_PosSize=dataSize;
115 /* Create structure */
116 if(structInit!=NULL)
117 InitStruct(structInit,library,0);
119 /* Call init vector */
120 if(libInit!=NULL)
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)
127 /* All done */
128 return library;
130 AROS_LIBFUNC_EXIT
131 } /* MakeLibrary */