home *** CD-ROM | disk | FTP | other *** search
/ Aminet 18 / aminetcdnumber181997.iso / Aminet / misc / emu / AROSdev.lha / AROS / rom / exec / makefunctions.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-01-09  |  3.2 KB  |  138 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: makefunctions.c,v 1.10 1997/01/01 03:46:11 ldp Exp $
  4.     $Log: makefunctions.c,v $
  5.     Revision 1.10  1997/01/01 03:46:11  ldp
  6.     Committed Amiga native (support) code
  7.  
  8.     Changed clib to proto
  9.  
  10.     Revision 1.9  1996/12/10 13:51:48  aros
  11.     Moved all #include's in the first column so makedepend can see it.
  12.  
  13.     Revision 1.8  1996/12/03 08:43:12  aros
  14.     Ooops :-) Wrong address
  15.  
  16.     Revision 1.7  1996/10/24 15:50:51  aros
  17.     Use the official AROS macros over the __AROS versions.
  18.  
  19.     Revision 1.6  1996/10/23 14:28:53  aros
  20.     Use the respective macros to access and manipulate a libraries' jumptable
  21.  
  22.     Revision 1.5  1996/10/19 17:07:26  aros
  23.     Include <aros/machine.h> instead of machine.h
  24.  
  25.     Revision 1.4  1996/08/13 13:56:03  digulla
  26.     Replaced AROS_LA by AROS_LHA
  27.     Replaced some AROS_LH*I by AROS_LH*
  28.     Sorted and added includes
  29.  
  30.     Revision 1.3  1996/08/01 17:41:13  digulla
  31.     Added standard header for all files
  32.  
  33.     Desc:
  34.     Lang: english
  35. */
  36. #include <exec/execbase.h>
  37. #include <aros/libcall.h>
  38. #include <aros/machine.h>
  39. #include <proto/exec.h>
  40.  
  41. /*****************************************************************************
  42.  
  43.     NAME */
  44.  
  45.     AROS_LH3(ULONG, MakeFunctions,
  46.  
  47. /*  SYNOPSIS */
  48.     AROS_LHA(APTR, target,        A0),
  49.     AROS_LHA(APTR, functionArray, A1),
  50.     AROS_LHA(APTR, funcDispBase,  A2),
  51.  
  52. /*  LOCATION */
  53.     struct ExecBase *, SysBase, 15, Exec)
  54.  
  55. /*  FUNCTION
  56.     Creates the jumptable for a shared library and flushes the processor's
  57.     instruction cache. Does not checksum the library.
  58.  
  59.     INPUTS
  60.     target          - The highest byte +1 of the jumptable. Typically
  61.             this is the library's base address.
  62.     functionArray - Pointer to either an array of function pointers or
  63.             an array of WORD displacements to a given location
  64.             in memory. A value of -1 terminates the array in both
  65.             cases.
  66.     funcDispBase  - The base location for WORD displacements or NULL
  67.             for function pointers.
  68.  
  69.     RESULT
  70.     Size of the jumptable.
  71.  
  72.     NOTES
  73.  
  74.     EXAMPLE
  75.  
  76.     BUGS
  77.  
  78.     SEE ALSO
  79.  
  80.     INTERNALS
  81.  
  82.     HISTORY
  83.  
  84. ******************************************************************************/
  85. {
  86.     AROS_LIBFUNC_INIT
  87.     long n;
  88.     APTR lastvec;
  89.  
  90.     n = 1;
  91.  
  92.     if (funcDispBase!=NULL)
  93.     {
  94.     /* If FuncDispBase is non-NULL it's an array of relative offsets */
  95.     WORD *fp=(WORD *)functionArray;
  96.  
  97.     /* -1 terminates the array */
  98.     while(*fp!=-1)
  99.     {
  100.         /* Decrement vector pointer by one and install vector */
  101.         __AROS_INITVEC(target,n);
  102.         __AROS_SETVECADDR(target,n,funcDispBase+*fp);
  103.  
  104.         /* Use next array entry */
  105.         fp++;
  106.         n++;
  107.     }
  108.     }
  109.     else
  110.     {
  111.     /* If FuncDispBase is NULL it's an array of function pointers */
  112.     void **fp=(void **)functionArray;
  113.  
  114.     /* -1 terminates the array */
  115.     while(*fp!=(void *)-1)
  116.     {
  117.         /* Decrement vector pointer by one and install vector */
  118.         __AROS_INITVEC(target,n);
  119.         __AROS_SETVECADDR(target,n,*fp);
  120.  
  121.         /* Use next array entry */
  122.         fp++;
  123.         n++;
  124.     }
  125.     }
  126.  
  127.     lastvec = __AROS_GETJUMPVEC(target,n);
  128.     n = (IPTR)target-(IPTR)lastvec;
  129.  
  130.     /* Clear instruction cache for the whole jumptable */
  131.     CacheClearE(lastvec, n, CACRF_ClearI);
  132.  
  133.     /* Return size of jumptable */
  134.     return n;
  135.     AROS_LIBFUNC_EXIT
  136. } /* MakeFunctions */
  137.  
  138.