Annotation of gforth/hppa.h, revision 1.14

1.14    ! anton       1: /* This is the machine-specific part for a HPPA running HP-UX
1.1       anton       2: 
1.14    ! anton       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.
1.1       anton      20: */
1.6       anton      21: 
                     22: #if !defined(USE_TOS) && !defined(USE_NO_TOS)
                     23: #define USE_TOS
                     24: #endif
1.5       anton      25: 
                     26: #ifndef INDIRECT_THREADED
                     27: #ifndef DIRECT_THREADED
                     28: #define DIRECT_THREADED
                     29: #endif
                     30: #endif
                     31: 
1.13      pazsan     32: #define LONG_LATENCY
                     33: 
1.2       pazsan     34: /* cache flush stuff */
1.10      pazsan     35: extern void cacheflush(void *, int, int);
1.2       pazsan     36: #ifdef DEBUG
1.9       anton      37: #  define FLUSH_ICACHE(addr,size) \
1.10      pazsan     38: ({ \
                     39:    fprintf(stderr,"Flushing Cache at %08x:%08x\n",(int) addr, size); \
                     40:    fflush(stderr); \
1.11      pazsan     41:    cacheflush((void *)(addr), (int)(size), 32); \
                     42:    fprintf(stderr,"Cache flushed\n");  })
1.3       pazsan     43: #else
1.9       anton      44: #  define FLUSH_ICACHE(addr,size) \
1.10      pazsan     45:      cacheflush((void *)(addr), (int)(size), 32)
1.2       pazsan     46: #endif
1.1       anton      47: 
1.5       anton      48: #include "32bit.h"
1.2       pazsan     49: 
1.1       anton      50: #ifdef DIRECT_THREADED
1.10      pazsan     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 */
1.1       anton      57: 
1.10      pazsan     58:    /* CODE_ADDRESS is the address of the code jumped to through the code field */
1.2       pazsan     59: 
1.10      pazsan     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 */
1.1       anton      62: #endif
1.2       pazsan     63: 
1.1       anton      64: #ifdef DIRECT_THREADED
1.2       pazsan     65: 
1.3       pazsan     66: #  ifdef DEBUG
                     67: #        define DOUT(a,b,c,d)  fprintf(stderr,a,b,c,d)
                     68: #  else
1.10      pazsan     69: #    define DOUT(a,b,c,d)
1.3       pazsan     70: #  endif
1.2       pazsan     71: 
                     72: #  define ASS17(n)(((((n) >> 13) & 0x1F) << 16)| /* first 5 bits */ \
1.10      pazsan     73:                   ((((n) >>  2) & 0x3FF) << 3)| /* second 11 bits */ \
1.12      pazsan     74:                   ((((n) >> 12) & 0x1) << 2)  | /* lo sign (aaarg!) */ \
1.10      pazsan     75:                   (((n) < 0) << 0)) /* sign bit */
1.2       pazsan     76: 
                     77: #  define DIS17(n)(((((n) >> 16) & 0x1F) << 13)| /* first 5 bits */ \
1.10      pazsan     78:                   ((((n) >>  3) & 0x3FF) << 2)| /* second 11 bits */ \
1.12      pazsan     79:                   ((((n) >>  2) & 0x1) << 12) | /* lo sign (aaarg!) */ \
1.10      pazsan     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 */ \
1.12      pazsan    121:                   (   0 <<  1) | /* if 1, don't execute delay slot */ \
                    122:                   ASS17(_ca)); \
1.10      pazsan    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 */ \
1.12      pazsan    130:                   (   0 <<  1) | /* if 1, don't execute delay slot */ \
                    131:                   ASS17(_dp)); \
1.10      pazsan    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 */ \
1.12      pazsan    147:                   (   1 <<  1) | /* if 1, don't execute delay slot */ \
                    148:                   ASS17(_ca)); \
1.10      pazsan    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 */
1.1       anton     153: 
1.10      pazsan    154: /* this is the point where the does code starts if label points to the
                    155:  * jump dodoes */
1.1       anton     156: 
1.10      pazsan    157: #  define DOES_CODE(cfa)       ((Xt *)(((long *)(cfa))[1]))
1.1       anton     158: 
1.10      pazsan    159: /* this is a special version of DOES_CODE for use in dodoes */
                    160: #  define DOES_CODE1(cfa)  DOES_CODE(cfa) \
1.2       pazsan    161: /*     ({register Xt * _ret asm("%r31"); _ret;}) */
                    162: 
1.10      pazsan    163: /* HPPA uses register 2 for branch and link */
1.1       anton     164: 
1.10      pazsan    165: #  define DOES_HANDLER_SIZE 8
                    166: #  define MAKE_DOES_HANDLER(cfa)  ({ *(long *)(cfa)=DODOES; })
1.3       pazsan    167: #ifdef undefined
1.10      pazsan    168: #  define MAKE_DOES_HANDLER(cfa) \
                    169: ({ \
                    170:      long *_cfa   = (long *)(cfa); \
                    171:      int _ca      = (int)symbols[DODOES]; \
                    172:      int _dp      = _ca-(int)(_cfa+2); \
                    173:      \
                    174:      if(_ca < 0x40000) /* Branch absolute */ \
                    175:      { \
                    176:         _cfa[0] =((0x38 << 26) | /* major opcode */ \
                    177:                   (   0 << 21) | /* register */ \
                    178:                   (   0 << 13) | /* space register */ \
1.12      pazsan    179:                   (   0 <<  1) | /* if 1, don't execute delay slot */ \
                    180:                   ASS17(_ca)); \
1.10      pazsan    181:         _cfa[1] = 0x08000240 /* or %r0,%r0,%r0 */; \
                    182:      } \
                    183:      else if(_dp < 0x40000 || _dp >= -0x40000) \
                    184:      { \
                    185:         _cfa[0] =((0x3A << 26) | /* major opcode */ \
                    186:                   (   0 << 21) | /* register */ \
                    187:                   (   0 << 13) | /* space register */ \
1.12      pazsan    188:                   (   0 <<  1) | /* if 1, don't execute delay slot */ \
                    189:                   ASS17(_dp)); \
1.10      pazsan    190:         _cfa[1] = 0x08000240 /* or %r0,%r0,%r0 */; \
                    191:      } \
                    192:      else \
                    193:      { \
                    194:         fprintf(stderr,"DOESHANDLER assignment failed, use ITC instead of DTC\n"); exit(1); \
                    195:         _cfa[0] = ((0x08 << 26) | \
                    196:                    ((int)_ca<0) | \
                    197:                    (_ca & 0x00001800)<<1 | \
                    198:                    (_ca & 0x0003E000)<<3 | \
                    199:                    (_ca & 0x000C0000)>>4 | \
                    200:                    (_ca & 0x7FF00000)>>19); \
                    201:         _ca &= 0x3FF; \
                    202:         _cfa[1] =((0x38 << 26) | /* major opcode */ \
                    203:                   (   1 << 21) | /* register */ \
                    204:                   (   0 << 13) | /* space register */ \
1.12      pazsan    205:                   (   1 <<  1) | /* if 1, don't execute delay slot */ \
                    206:                   ASS17(_ca)); \
1.10      pazsan    207:      } \
                    208:      DOUT("%08x: %08x,%08x\n",(int)_cfa,_cfa[0],_cfa[1]); \
                    209:  })
                    210: #endif
                    211: 
                    212: #  define MAKE_DOES_CF(cfa,ca) \
                    213: ({ \
                    214:      long *_cfa   = (long *)(cfa); \
                    215:      int _ca      = (int)symbols[DODOES]; \
                    216:      int _dp      = _ca-(int)(_cfa+2); \
                    217:      \
                    218:      if(_ca < 0x40000) /* Branch absolute */ \
                    219:      { \
                    220:         _cfa[0] =((0x38 << 26) | /* major opcode */ \
                    221:                   (   0 << 21) | /* register */ \
                    222:                   (   0 << 13) | /* space register */ \
1.12      pazsan    223:                   (   1 <<  1) | /* if 1, don't execute delay slot */ \
                    224:                   ASS17(_ca)); \
1.10      pazsan    225:         _cfa[1] = (long)(ca); \
                    226:      } \
                    227:      else if(_dp < 0x40000 || _dp >= -0x40000) \
                    228:      { \
                    229:         _cfa[0] =((0x3A << 26) | /* major opcode */ \
                    230:                   (   0 << 21) | /* register */ \
                    231:                   (   0 << 13) | /* space register */ \
1.12      pazsan    232:                   (   1 <<  1) | /* if 1, don't execute delay slot */ \
                    233:                   ASS17(_dp)); \
1.10      pazsan    234:         _cfa[1] = (long)(ca); \
                    235:      } \
                    236:      else \
                    237:      { \
                    238:         fprintf(stderr,"DOESCFA assignment failed, use ITC instead of DTC\n"); exit(1); \
                    239:      } \
                    240:      DOUT("%08x: %08x,%08x\n",(int)_cfa,_cfa[0],_cfa[1]); \
                    241:  })
                    242: /* this stores a call dodoes at addr */
1.1       anton     243: #endif
1.2       pazsan    244: 
1.7       pazsan    245: #undef HAVE_LOG1P
                    246: #undef HAVE_RINT
                    247: 
                    248: #ifdef FORCE_REG
                    249: #define IPREG asm("%r10")
                    250: #define SPREG asm("%r9")
                    251: #define RPREG asm("%r8")
                    252: #define LPREG asm("%r7")
                    253: #define CFAREG asm("%r6")
                    254: #define TOSREG asm("%r11")
                    255: #endif /* FORCE_REG */

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