File:  [gforth] / gforth / Attic / hppa.h
Revision 1.16: download - view: text, annotated - select for diffs
Fri Jul 19 20:45:01 1996 UTC (27 years, 9 months ago) by pazsan
Branches: MAIN
CVS tags: v0-3-0, v0-2-1, v0-2-0, HEAD
Fixed DOES_CODE for hppa

    1: /* This is the machine-specific part for a HPPA running HP-UX
    2: 
    3:   Copyright (C) 1995 Free Software Foundation, Inc.
    4: 
    5:   This file is part of Gforth.
    6: 
    7:   Gforth is free software; you can redistribute it and/or
    8:   modify it under the terms of the GNU General Public License
    9:   as published by the Free Software Foundation; either version 2
   10:   of the License, or (at your option) any later version.
   11: 
   12:   This program is distributed in the hope that it will be useful,
   13:   but WITHOUT ANY WARRANTY; without even the implied warranty of
   14:   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   15:   GNU General Public License for more details.
   16: 
   17:   You should have received a copy of the GNU General Public License
   18:   along with this program; if not, write to the Free Software
   19:   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
   20: */
   21: 
   22: #if !defined(USE_TOS) && !defined(USE_NO_TOS)
   23: #define USE_TOS
   24: #endif
   25: 
   26: #ifndef INDIRECT_THREADED
   27: #ifndef DIRECT_THREADED
   28: #define DIRECT_THREADED
   29: #endif
   30: #endif
   31: 
   32: #define LONG_LATENCY
   33: 
   34: /* cache flush stuff */
   35: extern void cacheflush(void *, int, int);
   36: #ifdef DEBUG
   37: #  define FLUSH_ICACHE(addr,size) \
   38: ({ \
   39:    fprintf(stderr,"Flushing Cache at %08x:%08x\n",(int) addr, size); \
   40:    fflush(stderr); \
   41:    cacheflush((void *)(addr), (int)(size), 32); \
   42:    fprintf(stderr,"Cache flushed\n");  })
   43: #else
   44: #  define FLUSH_ICACHE(addr,size) \
   45:      cacheflush((void *)(addr), (int)(size), 32)
   46: #endif
   47: 
   48: #include "32bit.h"
   49: 
   50: #ifdef DIRECT_THREADED
   51:    /* PFA gives the parameter field address corresponding to a cfa */
   52: #  define PFA(cfa)	(((Cell *)cfa)+2)
   53:    /* PFA1 is a special version for use just after a NEXT1 */
   54:    /* the improvement here is that we may destroy cfa before using PFA1 */
   55: #  define PFA1(cfa)       PFA(cfa)
   56:    /* HPPA uses register 2 for branch and link */
   57: 
   58:    /* CODE_ADDRESS is the address of the code jumped to through the code field */
   59: 
   60:    /* MAKE_CF creates an appropriate code field at the cfa; ca is the code address */
   61:    /* we use ble and a register, since 'bl' only has 21 bits displacement */
   62: #endif
   63: 
   64: #ifdef DIRECT_THREADED
   65: 
   66: #  ifdef DEBUG
   67: #	  define DOUT(a,b,c,d)  fprintf(stderr,a,b,c,d)
   68: #  else
   69: #    define DOUT(a,b,c,d)
   70: #  endif
   71: 
   72: #  define ASS17(n)(((((n) >> 13) & 0x1F) << 16)| /* first 5 bits */ \
   73: 		   ((((n) >>  2) & 0x3FF) << 3)| /* second 11 bits */ \
   74: 		   ((((n) >> 12) & 0x1) << 2)  | /* intermediate bit */ \
   75: 		   (((n) < 0) << 0)) /* low sign bit (aaarg!) */
   76: 
   77: #  define DIS17(n)(((((n) >> 16) & 0x1F) << 13)| /* first 5 bits */ \
   78: 		   ((((n) >>  3) & 0x3FF) << 2)| /* second 11 bits */ \
   79: 		   ((((n) >>  2) & 0x1) << 12) | /* intermediate bit */ \
   80: 		   (-((n) & 1) << 18)) /* low sign bit (aaarg!) */
   81: 
   82: #  define CODE_ADDRESS(cfa)\
   83: ((Label)({ \
   84: 	     unsigned int *_cfa=(unsigned int *)(cfa); \
   85: 	     unsigned int _ca = DIS17(_cfa[0]); \
   86: 	     if((_cfa[0] & 0xFFE0E000) == 0xE8000000) /* relative branch */ \
   87: 	     { \
   88: 		 _ca += (int) (_cfa + 1); \
   89: 	     } \
   90: 	     else if((_cfa[0] & 0xFFE0E000) == 0xE0000000) /* absolute branch */ \
   91: 	     { \
   92: 		 _ca = _ca-4; \
   93: 	     } \
   94: 	     else \
   95: 	     { \
   96: 		 _ca = (int)_cfa; \
   97: 	     } \
   98: 	     /* printf("code-address at %08x: %08x\n",_ca,_cfa); */ \
   99: 	     _ca + ((_cfa[0] & 2) << 1); \
  100: 	 }))
  101: 
  102: #  define MAKE_CF(cfa,ca) \
  103: ({ \
  104:      long *_cfa   = (long *)(cfa); \
  105:      int _ca      = (int)(ca)+4; \
  106:      int _dp      = _ca-(int)(_cfa+2); \
  107:      \
  108:      if(_ca < 0x40000) /* Branch absolute */ \
  109:      { \
  110: 	 _cfa[0] =((0x38 << 26) | /* major opcode */ \
  111: 		   (   0 << 21) | /* register */ \
  112: 		   (   0 << 13) | /* space register */ \
  113: 		   (   0 <<  1) | /* if 1, don't execute delay slot */ \
  114: 		   ASS17(_ca)); \
  115: 	 _cfa[1] = ((long *)(_ca))[-1]; /* fill delay slot with first inst */ \
  116:      } \
  117:      else if(_dp < 0x40000 || _dp >= -0x40000) \
  118:      { \
  119: 	 _cfa[0] =((0x3A << 26) | /* major opcode */ \
  120: 		   (   0 << 21) | /* register */ \
  121: 		   (   0 << 13) | /* space register */ \
  122: 		   (   0 <<  1) | /* if 1, don't execute delay slot */ \
  123: 		   ASS17(_dp)); \
  124: 	 _cfa[1] = ((long *)(_ca))[-1]; /* fill delay slot with first inst */ \
  125:      } \
  126:      else \
  127:      { \
  128: 	 fprintf(stderr,"CODE FIELD assignment failed, use ITC instead of DTC\n"); exit(1); \
  129:      } \
  130:      DOUT("%08x: %08x,%08x\n",(int)_cfa,_cfa[0],_cfa[1]); \
  131:  })
  132: /* HP wins the price for the most obfuscated binary opcode */
  133: 
  134: /* this is the point where the does code starts if label points to the
  135:  * jump dodoes */
  136: 
  137: /* this is a special version of DOES_CODE for use in dodoes */
  138: #  define DOES_CODE1(cfa)	((Xt *)(((long *)(cfa))[1]))
  139: 
  140: #  define DOES_CODE(cfa) \
  141:    (((((*(long *)(cfa)) & 0xF7E0E002) == 0xE0000002) && \
  142:      ((long)(CODE_ADDRESS(cfa)) == (long)symbols[DODOES])) ? \
  143:     DOES_CODE1(cfa) : 0L)
  144: 
  145: /*	({register Xt * _ret asm("%r31"); _ret;}) */
  146: 
  147: /* HPPA uses register 2 for branch and link */
  148: 
  149: #  define DOES_HANDLER_SIZE 8
  150: #  define MAKE_DOES_HANDLER(cfa)
  151: 
  152: #  define MAKE_DOES_CF(cfa,ca) \
  153: ({ \
  154:      long *_cfa   = (long *)(cfa); \
  155:      int _ca      = (int)symbols[DODOES]; \
  156:      int _dp      = _ca-(int)(_cfa+2); \
  157:      \
  158:      if(_ca < 0x40000) /* Branch absolute */ \
  159:      { \
  160: 	 _cfa[0] =((0x38 << 26) | /* major opcode */ \
  161: 		   (   0 << 21) | /* register */ \
  162: 		   (   0 << 13) | /* space register */ \
  163: 		   (   1 <<  1) | /* if 1, don't execute delay slot */ \
  164: 		   ASS17(_ca)); \
  165: 	 _cfa[1] = (long)(ca); \
  166:      } \
  167:      else if(_dp < 0x40000 || _dp >= -0x40000) \
  168:      { \
  169: 	 _cfa[0] =((0x3A << 26) | /* major opcode */ \
  170: 		   (   0 << 21) | /* register */ \
  171: 		   (   0 << 13) | /* space register */ \
  172: 		   (   1 <<  1) | /* if 1, don't execute delay slot */ \
  173: 		   ASS17(_dp)); \
  174: 	 _cfa[1] = (long)(ca); \
  175:      } \
  176:      else \
  177:      { \
  178: 	 fprintf(stderr,"DOESCFA assignment failed, use ITC instead of DTC\n"); exit(1); \
  179:      } \
  180:      DOUT("%08x: %08x,%08x\n",(int)_cfa,_cfa[0],_cfa[1]); \
  181:  })
  182: /* this stores a call dodoes at addr */
  183: #endif
  184: 
  185: #undef HAVE_LOG1P
  186: #undef HAVE_RINT
  187: 
  188: #ifdef FORCE_REG
  189: #define IPREG asm("%r10")
  190: #define SPREG asm("%r9")
  191: #define RPREG asm("%r8")
  192: #define LPREG asm("%r7")
  193: #define CFAREG asm("%r6")
  194: #define TOSREG asm("%r11")
  195: #endif /* FORCE_REG */

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>