tools/adflib: build only host variant which is used by Sam440 target
[AROS.git] / rom / exec / makefunctions.c
blob952e08e7348e634107e264fbebfe372d11bb020d
1 /*
2 Copyright © 1995-2011, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Create the jumptable for a shared library or a device.
6 Lang: english
7 */
9 #include <exec/execbase.h>
10 #include <aros/asmcall.h>
11 #include <aros/libcall.h>
12 #include <proto/exec.h>
14 #include "exec_debug.h"
16 AROS_LD3(void, CacheClearE,
17 AROS_LHA(APTR, address, A0),
18 AROS_LHA(ULONG, length, D0),
19 AROS_LHA(ULONG, caches, D1),
20 struct ExecBase *, SysBase, 107, Exec);
22 /*****************************************************************************
24 NAME */
26 AROS_LH3(ULONG, MakeFunctions,
28 /* SYNOPSIS */
29 AROS_LHA(APTR, target, A0),
30 AROS_LHA(CONST_APTR, functionArray, A1),
31 AROS_LHA(CONST_APTR, funcDispBase, A2),
33 /* LOCATION */
34 struct ExecBase *, SysBase, 15, Exec)
36 /* FUNCTION
37 Creates the jumptable for a shared library and flushes the processor's
38 instruction cache. Does not checksum the library.
40 INPUTS
41 target - The highest byte +1 of the jumptable. Typically
42 this is the library's base address.
43 functionArray - Pointer to either an array of function pointers or
44 an array of WORD displacements to a given location
45 in memory. A value of -1 terminates the array in both
46 cases.
47 funcDispBase - The base location for WORD displacements or NULL
48 for function pointers.
50 RESULT
51 Size of the jumptable.
53 NOTES
55 EXAMPLE
57 BUGS
59 SEE ALSO
61 INTERNALS
63 ******************************************************************************/
65 AROS_LIBFUNC_INIT
66 long n;
67 APTR lastvec;
69 DCREATELIBRARY("MakeFunctions(0x%p, 0x%p, 0x%p)", target, functionArray, funcDispBase);
71 n = 1;
73 if (funcDispBase!=NULL)
75 /* If FuncDispBase is non-NULL it's an array of relative offsets */
76 WORD *fp=(WORD *)functionArray;
78 /* -1 terminates the array */
79 while(*fp!=-1)
81 /* Decrement vector pointer by one and install vector */
82 __AROS_INITVEC(target,n);
83 if (*fp)
84 __AROS_SETVECADDR(target,n,(void *)funcDispBase+*fp);
86 /* Use next array entry */
87 fp++;
88 n++;
91 else
93 /* If FuncDispBase is NULL it's an array of function pointers */
94 void **fp=(void **)functionArray;
96 /* -1 terminates the array */
97 while(*fp!=(void *)-1)
99 /* Decrement vector pointer by one and install vector */
100 __AROS_INITVEC(target,n);
101 if (*fp)
102 __AROS_SETVECADDR(target,n,*fp);
104 /* Use next array entry */
105 fp++;
106 n++;
110 lastvec = __AROS_GETJUMPVEC(target,n);
111 n = (IPTR)target-(IPTR)lastvec;
113 #ifdef __AROS_USE_FULLJMP
114 /* Clear instruction cache for the whole jumptable. We need to do it only if
115 the jumptable actually contains executable code. __AROS_USE_FULLJMP must
116 be defined in cpu.h in this case.
118 Note that we call this function directly because MakeFunctions() is also
119 used for building ExecBase itself. */
120 if (SysBase->LibNode.lib_Node.ln_Type != NT_LIBRARY) {
121 AROS_CALL3NR(void, AROS_SLIB_ENTRY(CacheClearE, Exec, 107),
122 AROS_UFCA(APTR, lastvec, A0),
123 AROS_UFCA(ULONG, n, D0),
124 AROS_UFCA(ULONG, CACRF_ClearI|CACRF_ClearD, D1),
125 struct ExecBase *, SysBase);
126 } else {
127 /* call CacheClearE() indirectly if SysBase is already valid.
128 * CacheClearE may have been SetFunction()'d for specific CPU type.
130 CacheClearE(lastvec, n, CACRF_ClearI|CACRF_ClearD);
132 #endif
134 /* Return size of jumptable */
135 DCREATELIBRARY("Created %lu vectors", n);
136 return n;
138 AROS_LIBFUNC_EXIT
139 } /* MakeFunctions */