File:  [gforth] / gforth / Attic / hppa.h
Revision 1.11: download - view: text, annotated - select for diffs
Thu Oct 26 22:48:40 1995 UTC (25 years, 9 months ago) by pazsan
Branches: MAIN
CVS tags: HEAD
Changed threading ifdefs.
Requires debugging !!!!!!
Perhaps change concepts with LONG_LATENCY
on RISCs.
Added sokoban.fs as a nice little game.

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

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