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

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: setfunction.c,v 1.9 1997/01/01 03:46:16 ldp Exp $
  4.     $Log: setfunction.c,v $
  5.     Revision 1.9  1997/01/01 03:46:16  ldp
  6.     Committed Amiga native (support) code
  7.  
  8.     Changed clib to proto
  9.  
  10.     Revision 1.8  1996/12/10 13:51:54  aros
  11.     Moved all #include's in the first column so makedepend can see it.
  12.  
  13.     Revision 1.7  1996/10/24 15:36:47  aros
  14.     Named all macros which the user/developer can use as "AROS".
  15.  
  16.     For some strange reason, GCC produces incorrect code for "x /= -5;". "x = (-x)
  17.     / 5" works...
  18.  
  19.     Revision 1.6  1996/10/23 14:28:54  aros
  20.     Use the respective macros to access and manipulate a libraries' jumptable
  21.  
  22.     Revision 1.5  1996/10/19 17:07:27  aros
  23.     Include <aros/machine.h> instead of machine.h
  24.  
  25.     Revision 1.4  1996/08/13 13:56:08  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:19  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(APTR, SetFunction,
  46.  
  47. /*  SYNOPSIS */
  48.     AROS_LHA(struct Library *, library,     A1),
  49.     AROS_LHA(LONG,             funcOffset,  A0),
  50.     AROS_LHA(APTR,             newFunction, D0),
  51.  
  52. /*  LOCATION */
  53.     struct ExecBase *, SysBase, 70, Exec)
  54.  
  55. /*  FUNCTION
  56.     Replaces a certain jumptable entry with another one. This function only
  57.     Forbid()s taskswitching but doesn't Disable() interrupts. You have
  58.     to do your own arbitration for functions which are callable from
  59.     interrupts.
  60.  
  61.     INPUTS
  62.     library     - Pointer to library structure.
  63.     funcOffset  - Offset of the jumpvector from the library base address in
  64.               bytes.
  65.     newFunction - New jumptable entry (pointer to the new function).
  66.  
  67.     RESULT
  68.     Old jumptable entry (pointer to the old function).
  69.  
  70.     NOTES
  71.     While it's more or less safe to patch a library vector with
  72.     SetFunction() it's not possible to safely remove the patch later.
  73.     So don't use this function if it can be avoided.
  74.  
  75.     EXAMPLE
  76.  
  77.     BUGS
  78.  
  79.     SEE ALSO
  80.     MakeLibrary(), MakeFunctions(), SumLibrary().
  81.  
  82.     INTERNALS
  83.  
  84.     HISTORY
  85.  
  86. ******************************************************************************/
  87. {
  88.     AROS_LIBFUNC_INIT
  89.     APTR ret;
  90.  
  91.     funcOffset = (-funcOffset) / LIB_VECTSIZE;
  92.  
  93.     /*
  94.     Arbitrate for the jumptable. This isn't enough for interrupt callable
  95.     functions - but it need not be.
  96.     */
  97.     Forbid();
  98.  
  99.     /* Mark the library as changed. */
  100.     library->lib_Flags|=LIBF_CHANGED;
  101.  
  102.     /* Get old vector. */
  103.     ret = __AROS_GETVECADDR (library, funcOffset);
  104.  
  105.     /* Write new one. */
  106.     __AROS_SETVECADDR (library, funcOffset, newFunction);
  107.  
  108.     /* And clear the instruction cache. */
  109.     /*
  110.        Fixed to also flush data cache (very important for CopyBack style
  111.        caches) [ldp]
  112.     */
  113.     CacheClearE (__AROS_GETJUMPVEC(library,funcOffset),LIB_VECTSIZE,CACRF_ClearI|CACRF_ClearD);
  114.  
  115.     /* Arbitration is no longer needed */
  116.     Permit();
  117.  
  118.     /* Sum the library up again */
  119.     SumLibrary(library);
  120.  
  121.     /* All done. */
  122.     return ret;
  123.     AROS_LIBFUNC_EXIT
  124. } /* SetFunction */
  125.  
  126.