Annotation of gforth/hppa.h, revision 1.13

1.1       anton       1: /*
1.10      pazsan      2:   $Id: hppa.h,v 1.9 1995/10/07 17:38:16 anton Exp $
1.1       anton       3:   Copyright 1992 by the ANSI figForth Development Group
                      4: 
                      5:   This is the machine-specific part for a HPPA running HP-UX
                      6: */
1.6       anton       7: 
                      8: #if !defined(USE_TOS) && !defined(USE_NO_TOS)
                      9: #define USE_TOS
                     10: #endif
1.5       anton      11: 
                     12: #ifndef INDIRECT_THREADED
                     13: #ifndef DIRECT_THREADED
                     14: #define DIRECT_THREADED
                     15: #endif
                     16: #endif
                     17: 
1.13    ! pazsan     18: #define LONG_LATENCY
        !            19: 
1.2       pazsan     20: /* cache flush stuff */
1.10      pazsan     21: extern void cacheflush(void *, int, int);
1.2       pazsan     22: #ifdef DEBUG
1.9       anton      23: #  define FLUSH_ICACHE(addr,size) \
1.10      pazsan     24: ({ \
                     25:    fprintf(stderr,"Flushing Cache at %08x:%08x\n",(int) addr, size); \
                     26:    fflush(stderr); \
1.11      pazsan     27:    cacheflush((void *)(addr), (int)(size), 32); \
                     28:    fprintf(stderr,"Cache flushed\n");  })
1.3       pazsan     29: #else
1.9       anton      30: #  define FLUSH_ICACHE(addr,size) \
1.10      pazsan     31:      cacheflush((void *)(addr), (int)(size), 32)
1.2       pazsan     32: #endif
1.1       anton      33: 
1.5       anton      34: #include "32bit.h"
1.2       pazsan     35: 
1.1       anton      36: #ifdef DIRECT_THREADED
1.10      pazsan     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 */
1.1       anton      43: 
1.10      pazsan     44:    /* CODE_ADDRESS is the address of the code jumped to through the code field */
1.2       pazsan     45: 
1.10      pazsan     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 */
1.1       anton      48: #endif
1.2       pazsan     49: 
1.1       anton      50: #ifdef DIRECT_THREADED
1.2       pazsan     51: 
1.3       pazsan     52: #  ifdef DEBUG
                     53: #        define DOUT(a,b,c,d)  fprintf(stderr,a,b,c,d)
                     54: #  else
1.10      pazsan     55: #    define DOUT(a,b,c,d)
1.3       pazsan     56: #  endif
1.2       pazsan     57: 
                     58: #  define ASS17(n)(((((n) >> 13) & 0x1F) << 16)| /* first 5 bits */ \
1.10      pazsan     59:                   ((((n) >>  2) & 0x3FF) << 3)| /* second 11 bits */ \
1.12      pazsan     60:                   ((((n) >> 12) & 0x1) << 2)  | /* lo sign (aaarg!) */ \
1.10      pazsan     61:                   (((n) < 0) << 0)) /* sign bit */
1.2       pazsan     62: 
                     63: #  define DIS17(n)(((((n) >> 16) & 0x1F) << 13)| /* first 5 bits */ \
1.10      pazsan     64:                   ((((n) >>  3) & 0x3FF) << 2)| /* second 11 bits */ \
1.12      pazsan     65:                   ((((n) >>  2) & 0x1) << 12) | /* lo sign (aaarg!) */ \
1.10      pazsan     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 */ \
1.12      pazsan    107:                   (   0 <<  1) | /* if 1, don't execute delay slot */ \
                    108:                   ASS17(_ca)); \
1.10      pazsan    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 */ \
1.12      pazsan    116:                   (   0 <<  1) | /* if 1, don't execute delay slot */ \
                    117:                   ASS17(_dp)); \
1.10      pazsan    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 */ \
1.12      pazsan    133:                   (   1 <<  1) | /* if 1, don't execute delay slot */ \
                    134:                   ASS17(_ca)); \
1.10      pazsan    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 */
1.1       anton     139: 
1.10      pazsan    140: /* this is the point where the does code starts if label points to the
                    141:  * jump dodoes */
1.1       anton     142: 
1.10      pazsan    143: #  define DOES_CODE(cfa)       ((Xt *)(((long *)(cfa))[1]))
1.1       anton     144: 
1.10      pazsan    145: /* this is a special version of DOES_CODE for use in dodoes */
                    146: #  define DOES_CODE1(cfa)  DOES_CODE(cfa) \
1.2       pazsan    147: /*     ({register Xt * _ret asm("%r31"); _ret;}) */
                    148: 
1.10      pazsan    149: /* HPPA uses register 2 for branch and link */
1.1       anton     150: 
1.10      pazsan    151: #  define DOES_HANDLER_SIZE 8
                    152: #  define MAKE_DOES_HANDLER(cfa)  ({ *(long *)(cfa)=DODOES; })
1.3       pazsan    153: #ifdef undefined
1.10      pazsan    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 */ \
1.12      pazsan    165:                   (   0 <<  1) | /* if 1, don't execute delay slot */ \
                    166:                   ASS17(_ca)); \
1.10      pazsan    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 */ \
1.12      pazsan    174:                   (   0 <<  1) | /* if 1, don't execute delay slot */ \
                    175:                   ASS17(_dp)); \
1.10      pazsan    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 */ \
1.12      pazsan    191:                   (   1 <<  1) | /* if 1, don't execute delay slot */ \
                    192:                   ASS17(_ca)); \
1.10      pazsan    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 */ \
1.12      pazsan    209:                   (   1 <<  1) | /* if 1, don't execute delay slot */ \
                    210:                   ASS17(_ca)); \
1.10      pazsan    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 */ \
1.12      pazsan    218:                   (   1 <<  1) | /* if 1, don't execute delay slot */ \
                    219:                   ASS17(_dp)); \
1.10      pazsan    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 */
1.1       anton     229: #endif
1.2       pazsan    230: 
1.7       pazsan    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>