home *** CD-ROM | disk | FTP | other *** search
/ The CDPD Public Domain Collection for CDTV 3 / CDPDIII.bin / pd / programming / gnuc / library / rcs / ix_patch_functions.c,v < prev    next >
Encoding:
Text File  |  1992-08-09  |  8.1 KB  |  279 lines

  1. head    1.2;
  2. access;
  3. symbols
  4.     version39-41:1.1;
  5. locks;
  6. comment    @ *  @;
  7.  
  8.  
  9. 1.2
  10. date    92.08.09.20.54.44;    author amiga;    state Exp;
  11. branches;
  12. next    1.1;
  13.  
  14. 1.1
  15. date    92.05.14.19.55.40;    author mwild;    state Exp;
  16. branches;
  17. next    ;
  18.  
  19.  
  20. desc
  21. @patch certain functions of ixemul.library to make use of for example
  22. a faster cpu.
  23. @
  24.  
  25.  
  26. 1.2
  27. log
  28. @add panic functions for systems not having some math librar{ies,y}
  29. @
  30. text
  31. @/*
  32.  *  This file is part of ixemul.library for the Amiga.
  33.  *  Copyright (C) 1991, 1992  Markus M. Wild
  34.  *
  35.  *  This library is free software; you can redistribute it and/or
  36.  *  modify it under the terms of the GNU Library General Public
  37.  *  License as published by the Free Software Foundation; either
  38.  *  version 2 of the License, or (at your option) any later version.
  39.  *
  40.  *  This library is distributed in the hope that it will be useful,
  41.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  42.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  43.  *  Library General Public License for more details.
  44.  *
  45.  *  You should have received a copy of the GNU Library General Public
  46.  *  License along with this library; if not, write to the Free
  47.  *  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  48.  *
  49.  *  $Id: ix_patch_functions.c,v 1.1 1992/05/14 19:55:40 mwild Exp $
  50.  *
  51.  *  $Log: ix_patch_functions.c,v $
  52.  *  Revision 1.1  1992/05/14  19:55:40  mwild
  53.  *  Initial revision
  54.  *
  55.  */
  56.  
  57. #define KERNEL
  58. #include "ixemul.h"
  59.  
  60. #undef DEBUG 
  61.  
  62. #ifdef DEBUG
  63. #define DP(a) kprintf a
  64. #else
  65. #define DP(a)
  66. #endif
  67.  
  68. #ifndef AFF_68030
  69. #define AFF_68030    (1L<<2)
  70. #define AFF_68040    (1L<<3)
  71. #endif
  72.  
  73. extern struct ExecBase *SysBase;
  74.  
  75.  
  76. /*
  77.  * Note: these functions don't really return void, this is just to
  78.  *       declare them as functions, so that the table below is generated
  79.  *       right.
  80.  */
  81.  
  82. extern void __adddf3_20(), __addsf3_20(), __cmpdf2_20(), __cmpsf2_20(),
  83.             __divdf3_20(), __divsf3_20(), __divsi3_20(), __extendsfdf2_20(), 
  84.             __fabs_20(), __fixdfsi_20(), __fixunsdfsi_20(), __floatsidf_20(), 
  85.             frexp_20(), ldexp_20(), modf_20(), __modsi3_20(), __muldf3_20(),
  86.             __mulsf3_20(), __mulsi3_20(), __negdf2_20(), __negsf2_20(), 
  87.             __subdf3_20(), __subsf3_20(), __truncdfsf2_20(), __udivsi3_20(), 
  88.             __umodsi3_20(), __umulsi3_20();
  89.  
  90. /*
  91.  * Property flags. These characterize the used machine, and enable alternate
  92.  * functions specified in the following table.
  93.  * The MMU properties are for the later implementation of virtual memory ;-))
  94.  */
  95.  
  96. /* requires a 68030 MMU (this works for the 68851 as well, no TT regs are used */
  97. #define PF_FULL_MMU    (1<<0)
  98. /* this works with a 68040 MMU.
  99.  * NOTE: a 68030 can use this function as well, but a 68040 can't use PF_FULL_MMU
  100.  */
  101. #define PF_REDU_MMU    (1<<1)
  102.  
  103. /* a 68020 or higher required */
  104. #define PF_32BITCPU    (1<<5)
  105. /* an fpu required. */
  106. #define PF_FPU        (1<<6)
  107.  
  108. /* these are `negative' property flags, they indicate that an optional library
  109.    is missing. */
  110.  
  111. /* no mathieeedoubtrans.library */
  112. #define PF_NODT        (1<<29)
  113. /* no mathieeedoubbas.library */
  114. #define PF_NODB        (1<<30)
  115. /* no mathieeesingbas.library */
  116. #define PF_NOSB        (1<<31)
  117.  
  118. /* panic functions if a function requiring a not available library is invoked */
  119. static void panic_nodt () { ix_panic ("mathieeedoubtrans.library required!"); _exit (1); }
  120. static void panic_nodb () { ix_panic ("mathieeedoubbas.library required!"); _exit (1); }
  121. static void panic_nosb () { ix_panic ("mathieeesingbas.library required!"); _exit (1); }
  122.  
  123.  
  124. /*
  125.  * This table defines, which library functions should be replaced by an alternate
  126.  * function, this replacement should happen, if one of the specified flags is
  127.  * true for the current system configuration
  128.  *
  129.  * Place panic stubs for not available libraries before cpu replacements, that
  130.  * way you can get away without mathieeesingbas.library if you have an fpu, for
  131.  * example.
  132.  */
  133.  
  134. struct patch_table {
  135.   enum _syscall_ pt_entry;    /* the slot to replace */
  136.   void         (*pt_func)();    /* some `prototype', no void result required */
  137.   u_int         pt_flags;    /* all needed properties */
  138. } ix_patch_table[] = {
  139.   /* basic math support requiring mathieee{sing,doub}bas.library */
  140.   SYS___adddf3,        panic_nodb,        PF_NODB,
  141.   SYS___addsf3,        panic_nosb,        PF_NOSB,
  142.   SYS___cmpdf2,        panic_nodb,        PF_NODB,
  143.   SYS___cmpsf2,        panic_nosb,        PF_NOSB,
  144.   SYS___divdf3,        panic_nodb,        PF_NODB,
  145.   SYS___divsf3,        panic_nosb,        PF_NOSB,
  146.   SYS___extendsfdf2,    panic_nodb,        PF_NODB,
  147.   SYS___fixdfsi,    panic_nodb,        PF_NODB,
  148.   SYS___fixunsdfsi,    panic_nodb,        PF_NODB,
  149.   SYS___floatsidf,    panic_nodb,        PF_NODB,
  150.   SYS_frexp,        panic_nodb,        PF_NODB,
  151.   SYS_ldexp,        panic_nodb,        PF_NODB,
  152.   SYS_modf,        panic_nodb,        PF_NODB,
  153.   SYS___muldf3,        panic_nodb,        PF_NODB,
  154.   SYS___mulsf3,        panic_nosb,        PF_NOSB,
  155.   SYS___negdf2,        panic_nodb,        PF_NODB,
  156.   SYS___negsf2,        panic_nosb,        PF_NOSB,
  157.   SYS___subdf3,        panic_nodb,        PF_NODB,
  158.   SYS___subsf3,        panic_nosb,        PF_NOSB,
  159.   SYS___truncdfsf2,    panic_nodb,        PF_NODB,
  160.  
  161.   /* transcendental functions, mathieeedoubtrans.library */
  162.   SYS_atan,        panic_nodt,        PF_NODT,
  163.   SYS_sin,        panic_nodt,        PF_NODT,
  164.   SYS_cos,        panic_nodt,        PF_NODT,
  165.   SYS_tan,        panic_nodt,        PF_NODT,
  166.   SYS_sincos,        panic_nodt,        PF_NODT,
  167.   SYS_sinh,        panic_nodt,        PF_NODT,
  168.   SYS_cosh,        panic_nodt,        PF_NODT,
  169.   SYS_tanh,        panic_nodt,        PF_NODT,
  170.   SYS_exp,        panic_nodt,        PF_NODT,
  171.   SYS_log,        panic_nodt,        PF_NODT,
  172.   SYS_pow,        panic_nodt,        PF_NODT,
  173.   SYS_sqrt,        panic_nodt,        PF_NODT,
  174.   SYS_asin,        panic_nodt,        PF_NODT,
  175.   SYS_acos,        panic_nodt,        PF_NODT,
  176.   SYS_log10,        panic_nodt,        PF_NODT,
  177.   SYS_floor,        panic_nodb,        PF_NODB,
  178.   SYS_ceil,        panic_nodb,        PF_NODB,
  179.  
  180.   /* fpu/mmu support */
  181.   SYS___adddf3,        __adddf3_20,        PF_FPU,
  182.   SYS___addsf3,        __addsf3_20,        PF_FPU,
  183.   SYS___cmpdf2,        __cmpdf2_20,        PF_FPU,
  184.   SYS___cmpsf2,        __cmpsf2_20,        PF_FPU,
  185.   SYS___divdf3,        __divdf3_20,        PF_FPU,
  186.   SYS___divsf3,        __divsf3_20,        PF_FPU,
  187.   SYS___divsi3,        __divsi3_20,        PF_32BITCPU,
  188.   SYS___extendsfdf2,    __extendsfdf2_20,    PF_FPU,
  189.   SYS___fixdfsi,    __fixdfsi_20,        PF_FPU,
  190.   SYS___fixunsdfsi,    __fixunsdfsi_20,    PF_FPU,
  191.   SYS___floatsidf,    __floatsidf_20,        PF_FPU,
  192.   SYS_frexp,        frexp_20,        PF_FPU,
  193.   SYS_ldexp,        ldexp_20,        PF_FPU,
  194.   SYS_modf,        modf_20,        PF_FPU,
  195.   SYS___modsi3,        __modsi3_20,        PF_32BITCPU,
  196.   SYS___muldf3,        __muldf3_20,        PF_FPU,
  197.   SYS___mulsf3,        __mulsf3_20,        PF_FPU,
  198.   SYS___mulsi3,        __mulsi3_20,        PF_32BITCPU,
  199.   SYS___negdf2,        __negdf2_20,        PF_FPU,
  200.   SYS___negsf2,        __negsf2_20,        PF_FPU,
  201.   SYS___subdf3,        __subdf3_20,        PF_FPU,
  202.   SYS___subsf3,        __subsf3_20,        PF_FPU,
  203.   SYS___truncdfsf2,    __truncdfsf2_20,    PF_FPU,
  204.   SYS___udivsi3,    __udivsi3_20,        PF_32BITCPU,
  205.   SYS___umodsi3,    __umodsi3_20,        PF_32BITCPU,
  206. };
  207.  
  208. void
  209. ix_patch_functions (struct ixemul_base *ixbase)
  210. {
  211.   u_int pflags;
  212.   struct patch_table *pt;
  213.  
  214.   pflags = 0;
  215.  
  216.   /* try to figure out properties from the AttnFlags in ExecBase. Later on
  217.    * we'll have to decide as well on some user-specified flags (for example
  218.    * whether virtual memory should be enabled, and probably others as well ;-))
  219.    */
  220.  
  221.   /* AFF_68020 is set for any 68020, 68030, 68040... */
  222.   if (SysBase->AttnFlags & AFF_68020)
  223.     pflags |= PF_32BITCPU;
  224.     
  225.   if (SysBase->AttnFlags & AFF_68040)
  226.     pflags |= PF_REDU_MMU | PF_FPU;
  227.   else 
  228.     {
  229.       /* currently the 68851 is not supported, I'm too lazy to find out
  230.        * whether there's a 68851 or not... */
  231.       if (SysBase->AttnFlags & AFF_68030)
  232.     pflags |= PF_FULL_MMU;
  233.  
  234.       /* set for either 68881 or 68882 */
  235.       if (SysBase->AttnFlags & AFF_68881)
  236.         pflags |= PF_FPU;
  237.     }
  238.  
  239.   /*
  240.    * if the machine hasn't any special properties, just return
  241.    */
  242.   if (! pflags) return;
  243.  
  244.   for (pt = ix_patch_table; 
  245.        pt < &ix_patch_table[sizeof (ix_patch_table)/sizeof (struct patch_table)];
  246.        pt++)
  247.     if (pt->pt_flags & pflags)
  248.       {
  249.         /* -6*(s + 4) converts syscall# into _LVO */
  250.         SetFunction ((struct Library *)ixbase, -6*(pt->pt_entry + 4), pt->pt_func);
  251.         DP(("Patching vector %ld.\n", pt->pt_entry));
  252.       }
  253. }
  254. @
  255.  
  256.  
  257. 1.1
  258. log
  259. @Initial revision
  260. @
  261. text
  262. @d19 1
  263. a19 1
  264.  *  $Id$
  265. d21 4
  266. a24 1
  267.  *  $Log$
  268. d43 3
  269. d69 1
  270. a69 1
  271.  * NOTE: a 68030 can use this function as well, but a 68040 can't use PF_MMU_30
  272. d78 14
  273. d93 1
  274. d98 4
  275. d109 42
  276. a180 1
  277.   struct ExecBase *SysBase = *(struct ExecBase **)4;
  278. @
  279.