File:  [gforth] / gforth / Attic / hppa.h
Revision 1.13: download - view: text, annotated - select for diffs
Thu Nov 2 14:20:53 1995 UTC (25 years, 9 months ago) by pazsan
Branches: MAIN
CVS tags: HEAD
Some bugfixes and added features (like -loop) in see.fs and debug.fs
Defined LONG_LATENCY in hppa.h (gives more than 10% speed boost)

    1: /*
    2:   $Id: hppa.h,v 1.13 1995/11/02 14:20:53 pazsan Exp $
    3:   Copyright 1992 by the ANSI figForth Development Group
    4: 
    5:   This is the machine-specific part for a HPPA running HP-UX
    6: */
    7: 
    8: #if !defined(USE_TOS) && !defined(USE_NO_TOS)
    9: #define USE_TOS
   10: #endif
   11: 
   12: #ifndef INDIRECT_THREADED
   13: #ifndef DIRECT_THREADED
   14: #define DIRECT_THREADED
   15: #endif
   16: #endif
   17: 
   18: #define LONG_LATENCY
   19: 
   20: /* cache flush stuff */
   21: extern void cacheflush(void *, int, int);
   22: #ifdef DEBUG
   23: #  define FLUSH_ICACHE(addr,size) \
   24: ({ \
   25:    fprintf(stderr,"Flushing Cache at %08x:%08x\n",(int) addr, size); \
   26:    fflush(stderr); \
   27:    cacheflush((void *)(addr), (int)(size), 32); \
   28:    fprintf(stderr,"Cache flushed\n");  })
   29: #else
   30: #  define FLUSH_ICACHE(addr,size) \
   31:      cacheflush((void *)(addr), (int)(size), 32)
   32: #endif
   33: 
   34: #include "32bit.h"
   35: 
   36: #ifdef DIRECT_THREADED
   37:    /* PFA gives the parameter field address corresponding to a cfa */
   38: #  define PFA(cfa)	(((Cell *)cfa)+2)
   39:    /* PFA1 is a special version for use just after a NEXT1 */
   40:    /* the improvement here is that we may destroy cfa before using PFA1 */
   41: #  define PFA1(cfa)       PFA(cfa)
   42:    /* HPPA uses register 2 for branch and link */
   43: 
   44:    /* CODE_ADDRESS is the address of the code jumped to through the code field */
   45: 
   46:    /* MAKE_CF creates an appropriate code field at the cfa; ca is the code address */
   47:    /* we use ble and a register, since 'bl' only has 21 bits displacement */
   48: #endif
   49: 
   50: #ifdef DIRECT_THREADED
   51: 
   52: #  ifdef DEBUG
   53: #	  define DOUT(a,b,c,d)  fprintf(stderr,a,b,c,d)
   54: #  else
   55: #    define DOUT(a,b,c,d)
   56: #  endif
   57: 
   58: #  define ASS17(n)(((((n) >> 13) & 0x1F) << 16)| /* first 5 bits */ \
   59: 		   ((((n) >>  2) & 0x3FF) << 3)| /* second 11 bits */ \
   60: 		   ((((n) >> 12) & 0x1) << 2)  | /* lo sign (aaarg!) */ \
   61: 		   (((n) < 0) << 0)) /* sign bit */
   62: 
   63: #  define DIS17(n)(((((n) >> 16) & 0x1F) << 13)| /* first 5 bits */ \
   64: 		   ((((n) >>  3) & 0x3FF) << 2)| /* second 11 bits */ \
   65: 		   ((((n) >>  2) & 0x1) << 12) | /* lo sign (aaarg!) */ \
   66: 		   (-((n) & 1) << 18)) /* sign bit */
   67: 
   68: #  define CODE_ADDRESS(cfa)\
   69: ((Label)({ \
   70: 	     unsigned int *_cfa=(unsigned int *)(cfa); unsigned _ca; \
   71: 	     if((_cfa[0] & 0xFFE0E002) == 0xE8000000) /* relative branch */ \
   72: 	     { \
   73: 		 _ca = _cfa[0]; \
   74: 		 _ca = DIS17(_ca); \
   75: 		 _ca += (int) (_cfa + 1); \
   76: 	     } \
   77: 	     else if((_cfa[0] & 0xFFE0E002) == 0xE0000000) /* absolute branch */ \
   78: 	     { \
   79: 		 _ca = _cfa[0]; \
   80: 		 _ca = DIS17(_ca)-4; \
   81: 	     } \
   82: 	     else \
   83: 	     { \
   84: 		 _ca = _cfa[0]; \
   85: 		 _ca = (_ca<<31) | \
   86: 		 ((_ca>>1 ) & 0x00001800) | \
   87: 		 ((_ca>>3 ) & 0x0003E000) | \
   88: 		 ((_ca<<4 ) & 0x000C0000) | \
   89: 		 ((_ca<<19) & 0x7FF00000) |  \
   90: 		 ((_cfa[1]>>1) & 0xFFC); \
   91: 	     } \
   92: 	     /* printf("code-address at %08x: %08x\n",_ca,_cfa); */ \
   93: 	     _ca; \
   94: 	 }))
   95: 
   96: #  define MAKE_CF(cfa,ca) \
   97: ({ \
   98:      long *_cfa   = (long *)(cfa); \
   99:      int _ca      = (int)(ca)+4; \
  100:      int _dp      = _ca-(int)(_cfa+2); \
  101:      \
  102:      if(_ca < 0x40000) /* Branch absolute */ \
  103:      { \
  104: 	 _cfa[0] =((0x38 << 26) | /* major opcode */ \
  105: 		   (   0 << 21) | /* register */ \
  106: 		   (   0 << 13) | /* space register */ \
  107: 		   (   0 <<  1) | /* if 1, don't execute delay slot */ \
  108: 		   ASS17(_ca)); \
  109: 	 _cfa[1] = ((long *)(_ca))[-1]; /* or %r0,%r0,%r0 */; \
  110:      } \
  111:      else if(_dp < 0x40000 || _dp >= -0x40000) \
  112:      { \
  113: 	 _cfa[0] =((0x3A << 26) | /* major opcode */ \
  114: 		   (   0 << 21) | /* register */ \
  115: 		   (   0 << 13) | /* space register */ \
  116: 		   (   0 <<  1) | /* if 1, don't execute delay slot */ \
  117: 		   ASS17(_dp)); \
  118: 	 _cfa[1] = ((long *)(_ca))[-1]; /* 0x08000240 or %r0,%r0,%r0 */; \
  119:      } \
  120:      else \
  121:      { \
  122: 	 _ca -= 4; \
  123: 	 _cfa[0] = (0x08 << 26) | \
  124: 	 ((int)_ca<0) | \
  125: 	 (_ca & 0x00001800)<<1 | \
  126: 	 (_ca & 0x0003E000)<<3 | \
  127: 	 (_ca & 0x000C0000)>>4 | \
  128: 	 (_ca & 0x7FF00000)>>19; \
  129: 	 _ca &= 0x3FF; \
  130: 	 _cfa[1] =((0x38 << 26) | /* major opcode */ \
  131: 		   (   1 << 21) | /* register */ \
  132: 		   (   0 << 13) | /* space register */ \
  133: 		   (   1 <<  1) | /* if 1, don't execute delay slot */ \
  134: 		   ASS17(_ca)); \
  135:      } \
  136:      DOUT("%08x: %08x,%08x\n",(int)_cfa,_cfa[0],_cfa[1]); \
  137:  })
  138: /* HP wins the price for the most obfuscated binary opcode */
  139: 
  140: /* this is the point where the does code starts if label points to the
  141:  * jump dodoes */
  142: 
  143: #  define DOES_CODE(cfa)	((Xt *)(((long *)(cfa))[1]))
  144: 
  145: /* this is a special version of DOES_CODE for use in dodoes */
  146: #  define DOES_CODE1(cfa)  DOES_CODE(cfa) \
  147: /*	({register Xt * _ret asm("%r31"); _ret;}) */
  148: 
  149: /* HPPA uses register 2 for branch and link */
  150: 
  151: #  define DOES_HANDLER_SIZE 8
  152: #  define MAKE_DOES_HANDLER(cfa)  ({ *(long *)(cfa)=DODOES; })
  153: #ifdef undefined
  154: #  define MAKE_DOES_HANDLER(cfa) \
  155: ({ \
  156:      long *_cfa   = (long *)(cfa); \
  157:      int _ca      = (int)symbols[DODOES]; \
  158:      int _dp      = _ca-(int)(_cfa+2); \
  159:      \
  160:      if(_ca < 0x40000) /* Branch absolute */ \
  161:      { \
  162: 	 _cfa[0] =((0x38 << 26) | /* major opcode */ \
  163: 		   (   0 << 21) | /* register */ \
  164: 		   (   0 << 13) | /* space register */ \
  165: 		   (   0 <<  1) | /* if 1, don't execute delay slot */ \
  166: 		   ASS17(_ca)); \
  167: 	 _cfa[1] = 0x08000240 /* or %r0,%r0,%r0 */; \
  168:      } \
  169:      else if(_dp < 0x40000 || _dp >= -0x40000) \
  170:      { \
  171: 	 _cfa[0] =((0x3A << 26) | /* major opcode */ \
  172: 		   (   0 << 21) | /* register */ \
  173: 		   (   0 << 13) | /* space register */ \
  174: 		   (   0 <<  1) | /* if 1, don't execute delay slot */ \
  175: 		   ASS17(_dp)); \
  176: 	 _cfa[1] = 0x08000240 /* or %r0,%r0,%r0 */; \
  177:      } \
  178:      else \
  179:      { \
  180: 	 fprintf(stderr,"DOESHANDLER assignment failed, use ITC instead of DTC\n"); exit(1); \
  181: 	 _cfa[0] = ((0x08 << 26) | \
  182: 		    ((int)_ca<0) | \
  183: 		    (_ca & 0x00001800)<<1 | \
  184: 		    (_ca & 0x0003E000)<<3 | \
  185: 		    (_ca & 0x000C0000)>>4 | \
  186: 		    (_ca & 0x7FF00000)>>19); \
  187: 	 _ca &= 0x3FF; \
  188: 	 _cfa[1] =((0x38 << 26) | /* major opcode */ \
  189: 		   (   1 << 21) | /* register */ \
  190: 		   (   0 << 13) | /* space register */ \
  191: 		   (   1 <<  1) | /* if 1, don't execute delay slot */ \
  192: 		   ASS17(_ca)); \
  193:      } \
  194:      DOUT("%08x: %08x,%08x\n",(int)_cfa,_cfa[0],_cfa[1]); \
  195:  })
  196: #endif
  197: 
  198: #  define MAKE_DOES_CF(cfa,ca) \
  199: ({ \
  200:      long *_cfa   = (long *)(cfa); \
  201:      int _ca      = (int)symbols[DODOES]; \
  202:      int _dp      = _ca-(int)(_cfa+2); \
  203:      \
  204:      if(_ca < 0x40000) /* Branch absolute */ \
  205:      { \
  206: 	 _cfa[0] =((0x38 << 26) | /* major opcode */ \
  207: 		   (   0 << 21) | /* register */ \
  208: 		   (   0 << 13) | /* space register */ \
  209: 		   (   1 <<  1) | /* if 1, don't execute delay slot */ \
  210: 		   ASS17(_ca)); \
  211: 	 _cfa[1] = (long)(ca); \
  212:      } \
  213:      else if(_dp < 0x40000 || _dp >= -0x40000) \
  214:      { \
  215: 	 _cfa[0] =((0x3A << 26) | /* major opcode */ \
  216: 		   (   0 << 21) | /* register */ \
  217: 		   (   0 << 13) | /* space register */ \
  218: 		   (   1 <<  1) | /* if 1, don't execute delay slot */ \
  219: 		   ASS17(_dp)); \
  220: 	 _cfa[1] = (long)(ca); \
  221:      } \
  222:      else \
  223:      { \
  224: 	 fprintf(stderr,"DOESCFA assignment failed, use ITC instead of DTC\n"); exit(1); \
  225:      } \
  226:      DOUT("%08x: %08x,%08x\n",(int)_cfa,_cfa[0],_cfa[1]); \
  227:  })
  228: /* this stores a call dodoes at addr */
  229: #endif
  230: 
  231: #undef HAVE_LOG1P
  232: #undef HAVE_RINT
  233: 
  234: #ifdef FORCE_REG
  235: #define IPREG asm("%r10")
  236: #define SPREG asm("%r9")
  237: #define RPREG asm("%r8")
  238: #define LPREG asm("%r7")
  239: #define CFAREG asm("%r6")
  240: #define TOSREG asm("%r11")
  241: #endif /* FORCE_REG */

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