File:  [gforth] / gforth / Attic / hppa.h
Revision 1.15: download - view: text, annotated - select for diffs
Tue Jul 16 20:57:11 1996 UTC (25 years ago) by pazsan
Branches: MAIN
CVS tags: HEAD
SPECIAL: to create special "state-smart" words

    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)  | /* lo sign (aaarg!) */ \
   75: 		   (((n) < 0) << 0)) /* sign bit */
   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) | /* lo sign (aaarg!) */ \
   80: 		   (-((n) & 1) << 18)) /* sign bit */
   81: 
   82: #  define CODE_ADDRESS(cfa)\
   83: ((Label)({ \
   84: 	     unsigned int *_cfa=(unsigned int *)(cfa); unsigned _ca; \
   85: 	     if((_cfa[0] & 0xFFE0E002) == 0xE8000000) /* relative branch */ \
   86: 	     { \
   87: 		 _ca = _cfa[0]; \
   88: 		 _ca = DIS17(_ca); \
   89: 		 _ca += (int) (_cfa + 1); \
   90: 	     } \
   91: 	     else if((_cfa[0] & 0xFFE0E002) == 0xE0000000) /* absolute branch */ \
   92: 	     { \
   93: 		 _ca = _cfa[0]; \
   94: 		 _ca = DIS17(_ca)-4; \
   95: 	     } \
   96: 	     else \
   97: 	     { \
   98: 		 _ca = _cfa[0]; \
   99: 		 _ca = (_ca<<31) | \
  100: 		 ((_ca>>1 ) & 0x00001800) | \
  101: 		 ((_ca>>3 ) & 0x0003E000) | \
  102: 		 ((_ca<<4 ) & 0x000C0000) | \
  103: 		 ((_ca<<19) & 0x7FF00000) |  \
  104: 		 ((_cfa[1]>>1) & 0xFFC); \
  105: 	     } \
  106: 	     /* printf("code-address at %08x: %08x\n",_ca,_cfa); */ \
  107: 	     _ca; \
  108: 	 }))
  109: 
  110: #  define MAKE_CF(cfa,ca) \
  111: ({ \
  112:      long *_cfa   = (long *)(cfa); \
  113:      int _ca      = (int)(ca)+4; \
  114:      int _dp      = _ca-(int)(_cfa+2); \
  115:      \
  116:      if(_ca < 0x40000) /* Branch absolute */ \
  117:      { \
  118: 	 _cfa[0] =((0x38 << 26) | /* major opcode */ \
  119: 		   (   0 << 21) | /* register */ \
  120: 		   (   0 << 13) | /* space register */ \
  121: 		   (   0 <<  1) | /* if 1, don't execute delay slot */ \
  122: 		   ASS17(_ca)); \
  123: 	 _cfa[1] = ((long *)(_ca))[-1]; /* or %r0,%r0,%r0 */; \
  124:      } \
  125:      else if(_dp < 0x40000 || _dp >= -0x40000) \
  126:      { \
  127: 	 _cfa[0] =((0x3A << 26) | /* major opcode */ \
  128: 		   (   0 << 21) | /* register */ \
  129: 		   (   0 << 13) | /* space register */ \
  130: 		   (   0 <<  1) | /* if 1, don't execute delay slot */ \
  131: 		   ASS17(_dp)); \
  132: 	 _cfa[1] = ((long *)(_ca))[-1]; /* 0x08000240 or %r0,%r0,%r0 */; \
  133:      } \
  134:      else \
  135:      { \
  136: 	 _ca -= 4; \
  137: 	 _cfa[0] = (0x08 << 26) | \
  138: 	 ((int)_ca<0) | \
  139: 	 (_ca & 0x00001800)<<1 | \
  140: 	 (_ca & 0x0003E000)<<3 | \
  141: 	 (_ca & 0x000C0000)>>4 | \
  142: 	 (_ca & 0x7FF00000)>>19; \
  143: 	 _ca &= 0x3FF; \
  144: 	 _cfa[1] =((0x38 << 26) | /* major opcode */ \
  145: 		   (   1 << 21) | /* register */ \
  146: 		   (   0 << 13) | /* space register */ \
  147: 		   (   1 <<  1) | /* if 1, don't execute delay slot */ \
  148: 		   ASS17(_ca)); \
  149:      } \
  150:      DOUT("%08x: %08x,%08x\n",(int)_cfa,_cfa[0],_cfa[1]); \
  151:  })
  152: /* HP wins the price for the most obfuscated binary opcode */
  153: 
  154: /* this is the point where the does code starts if label points to the
  155:  * jump dodoes */
  156: 
  157: /* this is a special version of DOES_CODE for use in dodoes */
  158: #  define DOES_CODE1(cfa)	((Xt *)(((long *)(cfa))[1]))
  159: 
  160: #  define DOES_CODE(cfa) \
  161:    (((((*(long *)(cfa)) & 0xF7E0E002) == 0xE0000000) && \
  162:      ((long)(CODE_ADDRESS(CODE_ADDRESS(cfa))) == (long)symbols[DODOES])) ? \
  163:     DOES_CODE1(cfa) : 0L)
  164: 
  165: /*	({register Xt * _ret asm("%r31"); _ret;}) */
  166: 
  167: /* HPPA uses register 2 for branch and link */
  168: 
  169: #  define DOES_HANDLER_SIZE 8
  170: #  define MAKE_DOES_HANDLER(cfa)  ({ *(long *)(cfa)=DODOES; })
  171: #ifdef undefined
  172: #  define MAKE_DOES_HANDLER(cfa) \
  173: ({ \
  174:      long *_cfa   = (long *)(cfa); \
  175:      int _ca      = (int)symbols[DODOES]; \
  176:      int _dp      = _ca-(int)(_cfa+2); \
  177:      \
  178:      if(_ca < 0x40000) /* Branch absolute */ \
  179:      { \
  180: 	 _cfa[0] =((0x38 << 26) | /* major opcode */ \
  181: 		   (   0 << 21) | /* register */ \
  182: 		   (   0 << 13) | /* space register */ \
  183: 		   (   0 <<  1) | /* if 1, don't execute delay slot */ \
  184: 		   ASS17(_ca)); \
  185: 	 _cfa[1] = 0x08000240 /* or %r0,%r0,%r0 */; \
  186:      } \
  187:      else if(_dp < 0x40000 || _dp >= -0x40000) \
  188:      { \
  189: 	 _cfa[0] =((0x3A << 26) | /* major opcode */ \
  190: 		   (   0 << 21) | /* register */ \
  191: 		   (   0 << 13) | /* space register */ \
  192: 		   (   0 <<  1) | /* if 1, don't execute delay slot */ \
  193: 		   ASS17(_dp)); \
  194: 	 _cfa[1] = 0x08000240 /* or %r0,%r0,%r0 */; \
  195:      } \
  196:      else \
  197:      { \
  198: 	 _ca -= 4; \
  199: 	 _cfa[0] = ((0x08 << 26) | \
  200: 		    ((int)_ca<0) | \
  201: 		    (_ca & 0x00001800)<<1 | \
  202: 		    (_ca & 0x0003E000)<<3 | \
  203: 		    (_ca & 0x000C0000)>>4 | \
  204: 		    (_ca & 0x7FF00000)>>19); \
  205: 	 _ca &= 0x3FF; \
  206: 	 _cfa[1] =((0x38 << 26) | /* major opcode */ \
  207: 		   (   1 << 21) | /* register */ \
  208: 		   (   0 << 13) | /* space register */ \
  209: 		   (   1 <<  1) | /* if 1, don't execute delay slot */ \
  210: 		   ASS17(_ca)); \
  211:      } \
  212:      DOUT("%08x: %08x,%08x\n",(int)_cfa,_cfa[0],_cfa[1]); \
  213:  })
  214: #endif
  215: 
  216: #  define MAKE_DOES_CF(cfa,ca) \
  217: ({ \
  218:      long *_cfa   = (long *)(cfa); \
  219:      int _ca      = (int)symbols[DODOES]; \
  220:      int _dp      = _ca-(int)(_cfa+2); \
  221:      \
  222:      if(_ca < 0x40000) /* Branch absolute */ \
  223:      { \
  224: 	 _cfa[0] =((0x38 << 26) | /* major opcode */ \
  225: 		   (   0 << 21) | /* register */ \
  226: 		   (   0 << 13) | /* space register */ \
  227: 		   (   1 <<  1) | /* if 1, don't execute delay slot */ \
  228: 		   ASS17(_ca)); \
  229: 	 _cfa[1] = (long)(ca); \
  230:      } \
  231:      else if(_dp < 0x40000 || _dp >= -0x40000) \
  232:      { \
  233: 	 _cfa[0] =((0x3A << 26) | /* major opcode */ \
  234: 		   (   0 << 21) | /* register */ \
  235: 		   (   0 << 13) | /* space register */ \
  236: 		   (   1 <<  1) | /* if 1, don't execute delay slot */ \
  237: 		   ASS17(_dp)); \
  238: 	 _cfa[1] = (long)(ca); \
  239:      } \
  240:      else \
  241:      { \
  242: 	 fprintf(stderr,"DOESCFA assignment failed, use ITC instead of DTC\n"); exit(1); \
  243:      } \
  244:      DOUT("%08x: %08x,%08x\n",(int)_cfa,_cfa[0],_cfa[1]); \
  245:  })
  246: /* this stores a call dodoes at addr */
  247: #endif
  248: 
  249: #undef HAVE_LOG1P
  250: #undef HAVE_RINT
  251: 
  252: #ifdef FORCE_REG
  253: #define IPREG asm("%r10")
  254: #define SPREG asm("%r9")
  255: #define RPREG asm("%r8")
  256: #define LPREG asm("%r7")
  257: #define CFAREG asm("%r6")
  258: #define TOSREG asm("%r11")
  259: #endif /* FORCE_REG */

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