Annotation of gforth/hppa.h, revision 1.2
1.1 anton 1: /*
1.2 ! pazsan 2: $Id: hppa.h,v 1.1 1993/04/08 15:31:36 pazsan Exp pazsan $
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.2 ! pazsan 7: /* cache flush stuff */
1.1 anton 8:
1.2 ! pazsan 9: #ifdef DIRECT_THREADED
! 10:
! 11: extern void * cacheflush(void *, int, int);
! 12: #ifdef DEBUG
! 13: # define CACHE_FLUSH(addr,size) \
! 14: ({ fprintf(stderr,"Flushing Cache at %08x:%08x\n",(int) addr, size); \
! 15: fflush(stderr); \
! 16: fprintf(stderr,"Cache flushed, final address: %08x\n", \
! 17: (int)cacheflush((void *)(addr), (int)(size), 32)); })
! 18: # else
! 19: /*
! 20: # define CACHE_FLUSH(addr,size) \
! 21: ({ fprintf(stderr,"Flushing Cache at %08x:%08x\n",(int) addr, size); \
! 22: fflush(stderr); \
! 23: fprintf(stderr,"Cache flushed, final address: %08x\n", \
! 24: (int)cacheflush((void *)(addr), (int)(size), 32)); })
! 25: */
! 26: # define CACHE_FLUSH(addr,size) \
! 27: ({ (void)cacheflush((void *)(addr), (int)(size), 32); })
! 28:
! 29: # endif
! 30: #endif
1.1 anton 31:
1.2 ! pazsan 32:
1.1 anton 33: /* Cell and UCell must be the same size as a pointer */
34: typedef long Cell;
35: typedef unsigned long UCell;
36:
37: /* DCell and UDCell must be twice as large as Cell */
38: typedef long long DCell;
39: typedef unsigned long long UDCell;
40:
41: /* define this if IEEE singles and doubles are available as C data types */
42: #define IEEE_FP
43:
44: /* the IEEE types are used only for loading and storing */
45: /* the IEEE double precision type */
46: typedef double DFloat;
47: /* the IEEE single precision type */
48: typedef float SFloat;
49:
50: /* define this if the least-significant byte is at the largets address */
51: #define BIG_ENDIAN
52:
53: #ifdef DIRECT_THREADED
54: /* PFA gives the parameter field address corresponding to a cfa */
55: # define PFA(cfa) (((Cell *)cfa)+2)
56: /* PFA1 is a special version for use just after a NEXT1 */
57: /* the improvement here is that we may destroy cfa before using PFA1 */
1.2 ! pazsan 58: # define PFA1(cfa) PFA(cfa)
1.1 anton 59: /* HPPA uses register 2 for branch and link */
60:
61: /* CODE_ADDRESS is the address of the code jumped to through the code field */
1.2 ! pazsan 62:
1.1 anton 63: /* MAKE_CF creates an appropriate code field at the cfa; ca is the code address */
64: /* we use ble and a register, since 'bl' only has 21 bits displacement */
65: #endif
1.2 ! pazsan 66:
! 67: #ifdef undefined
1.1 anton 68: #define MAKE_CFA(cfa,ca) ({long *_cfa = (long *)(cfa); \
69: unsigned _ca = (unsigned)(ca); \
1.2 ! pazsan 70: _cfa[0] = 0xE4A02000 | (((int)_ca+4-(int)symbols[0]) & 0x7FC)<<1 ; \
1.1 anton 71: _cfa[1] = *(long *)(_ca); \
72: /* printf("%08x:%08x,%08x\n",_cfa,_cfa[0],_cfa[1]); */ \
73: })
1.2 ! pazsan 74: #endif
1.1 anton 75:
76: #ifdef DIRECT_THREADED
1.2 ! pazsan 77:
! 78: #ifdef DEBUG
! 79: # define DOUT(a,b,c,d) fprintf(stderr,a,b,c,d)
! 80: #else
! 81: # define DOUT(a,b,c,d)
! 82: #endif
! 83:
! 84: # define ASS17(n)(((((n) >> 13) & 0x1F) << 16)| /* first 5 bits */ \
! 85: ((((n) >> 2) & 0x3FF) << 3)| /* second 11 bits */ \
! 86: ((((n) >> 12) & 0x1) << 2) | /* lo sign (arg!) */ \
! 87: (((n) < 0) << 0)) /* sign bit */
! 88:
! 89: # define DIS17(n)(((((n) >> 16) & 0x1F) << 13)| /* first 5 bits */ \
! 90: ((((n) >> 3) & 0x3FF) << 2)| /* second 11 bits */ \
! 91: ((((n) >> 2) & 0x1) << 12) | /* lo sign (arg!) */ \
! 92: (-((n) & 1) << 18)) /* sign bit */
! 93:
! 94: # define CODE_ADDRESS(cfa) ((Label)({ \
! 95: unsigned int *_cfa=(unsigned int *)(cfa); unsigned _ca; \
! 96: if((_cfa[0] & 0xFFE0E002) == 0xE8000000) /* relative branch */ \
! 97: { \
! 98: _ca = _cfa[0]; \
! 99: _ca = DIS17(_ca); \
! 100: _ca += (int) (_cfa + 2); \
! 101: } \
! 102: else if((_cfa[0] & 0xFFE0E002) == 0xE0000000) /* absolute branch */ \
! 103: { \
! 104: _ca = _cfa[0]; \
! 105: _ca = DIS17(_ca); \
! 106: } \
! 107: else \
! 108: { \
! 109: _ca = _cfa[0]; \
! 110: _ca = (_ca<<31) | \
! 111: ((_ca>>1 ) & 0x00001800) | \
! 112: ((_ca>>3 ) & 0x0003E000) | \
! 113: ((_ca<<4 ) & 0x000C0000) | \
! 114: ((_ca<<19) & 0x7FF00000) | \
! 115: ((_cfa[1]>>1) & 0xFFC); \
! 116: } \
! 117: /* printf("code-address at %08x: %08x\n",_ca,_cfa); */ \
! 118: _ca; \
! 119: }))
! 120:
! 121: # define MAKE_CF(cfa,ca) \
! 122: ({ \
! 123: long *_cfa = (long *)(cfa); \
! 124: int _ca = (int)(ca); \
! 125: int _dp = _ca-(int)(_cfa+2); \
! 126: \
! 127: if(_ca < 0x40000) /* Branch absolute */ \
! 128: { \
! 129: _cfa[0] =((0x38 << 26) | /* major opcode */ \
! 130: ( 0 << 21) | /* register */ \
! 131: ( 0 << 13) | /* space register */ \
! 132: ( 0 << 1))| /* if 1, don't execute delay slot */ \
! 133: ASS17(_ca); \
! 134: _cfa[1] = 0x08000240 /* or %r0,%r0,%r0 */; \
! 135: } \
! 136: else if(_dp < 0x40000 || _dp >= -0x40000) \
! 137: { \
! 138: _cfa[0] =((0x3A << 26) | /* major opcode */ \
! 139: ( 0 << 21) | /* register */ \
! 140: ( 0 << 13) | /* space register */ \
! 141: ( 0 << 1))| /* if 1, don't execute delay slot */ \
! 142: ASS17(_dp); \
! 143: _cfa[1] = 0x08000240 /* or %r0,%r0,%r0 */; \
! 144: } \
! 145: else \
! 146: { \
! 147: _cfa[0] = (0x08 << 26) | \
! 148: ((int)_ca<0) | \
! 149: (_ca & 0x00001800)<<1 | \
! 150: (_ca & 0x0003E000)<<3 | \
! 151: (_ca & 0x000C0000)>>4 | \
! 152: (_ca & 0x7FF00000)>>19; \
! 153: _ca &= 0x3FF; \
! 154: _cfa[1] =((0x38 << 26) | /* major opcode */ \
! 155: ( 1 << 21) | /* register */ \
! 156: ( 0 << 13) | /* space register */ \
! 157: ( 1 << 1))| /* if 1, don't execute delay slot */ \
! 158: ASS17(_ca); \
! 159: } \
! 160: DOUT("%08x: %08x,%08x\n",(int)_cfa,_cfa[0],_cfa[1]); \
! 161: })
1.1 anton 162: /* HP wins the price for the most obfuscated binary opcode */
163:
164: /* this is the point where the does code starts if label points to the
165: * jump dodoes */
166:
1.2 ! pazsan 167: # define DOES_CODE(cfa) ((Xt *)(((char *)CODE_ADDRESS(cfa))+8))
1.1 anton 168:
169: /* this is a special version of DOES_CODE for use in dodoes */
1.2 ! pazsan 170: # define DOES_CODE1(cfa) DOES_CODE(cfa) \
! 171: /* ({register Xt * _ret asm("%r31"); _ret;}) */
! 172:
1.1 anton 173: /* HPPA uses register 2 for branch and link */
174:
1.2 ! pazsan 175: # define DOES_HANDLER_SIZE 8
! 176: # define MAKE_DOES_HANDLER(cfa) \
! 177: ({ \
! 178: long *_cfa = (long *)(cfa); \
! 179: int _ca = (int)symbols[DODOES]; \
! 180: int _dp = _ca-(int)(_cfa+2); \
! 181: \
! 182: if(_ca < 0x40000) /* Branch absolute */ \
! 183: { \
! 184: _cfa[0] =((0x38 << 26) | /* major opcode */ \
! 185: ( 0 << 21) | /* register */ \
! 186: ( 0 << 13) | /* space register */ \
! 187: ( 0 << 1))| /* if 1, don't execute delay slot */ \
! 188: ASS17(_ca); \
! 189: _cfa[1] = 0x08000240 /* or %r0,%r0,%r0 */; \
! 190: } \
! 191: else if(_dp < 0x40000 || _dp >= -0x40000) \
! 192: { \
! 193: _cfa[0] =((0x3A << 26) | /* major opcode */ \
! 194: ( 0 << 21) | /* register */ \
! 195: ( 0 << 13) | /* space register */ \
! 196: ( 0 << 1))| /* if 1, don't execute delay slot */ \
! 197: ASS17(_dp); \
! 198: _cfa[1] = 0x08000240 /* or %r0,%r0,%r0 */; \
! 199: } \
! 200: else \
! 201: { \
! 202: fprintf(stderr,"DOESHANDLER assignment failed, use ITC instead of DTC\n"); exit(1); \
! 203: _cfa[0] = (0x08 << 26) | \
! 204: ((int)_ca<0) | \
! 205: (_ca & 0x00001800)<<1 | \
! 206: (_ca & 0x0003E000)<<3 | \
! 207: (_ca & 0x000C0000)>>4 | \
! 208: (_ca & 0x7FF00000)>>19; \
! 209: _ca &= 0x3FF; \
! 210: _cfa[1] =((0x38 << 26) | /* major opcode */ \
! 211: ( 1 << 21) | /* register */ \
! 212: ( 0 << 13) | /* space register */ \
! 213: ( 1 << 1))| /* if 1, don't execute delay slot */ \
! 214: ASS17(_ca); \
! 215: } \
! 216: DOUT("%08x: %08x,%08x\n",(int)_cfa,_cfa[0],_cfa[1]); \
! 217: })
! 218:
! 219: # define MAKE_DOES_CF(cfa,ca) \
! 220: ({ \
! 221: long *_cfa = (long *)(cfa); \
! 222: int _ca = (int)(ca)-DOES_HANDLER_SIZE; \
! 223: int _dp = _ca-(int)(_cfa+2); \
! 224: \
! 225: if(_dp < 0x40000 || _dp >= -0x40000) \
! 226: { \
! 227: _cfa[0] = (0x3A << 26) | /* major opcode */ \
! 228: ( 0 << 21) | /* register */ \
! 229: ( 0 << 13) | /* space register */ \
! 230: ( 0 << 1) | /* if 1, don't execute delay slot */ \
! 231: ASS17(_dp); \
! 232: _cfa[1] = 0x08000240 /* or %r0,%r0,%r0 */; \
! 233: } \
! 234: else if(_ca < 0x40000) /* Branch absolute */ \
! 235: { \
! 236: _cfa[0] = (0x38 << 26) | /* major opcode */ \
! 237: ( 0 << 21) | /* register */ \
! 238: ( 0 << 13) | /* space register */ \
! 239: ( 0 << 1) | /* if 1, don't execute delay slot */ \
! 240: ASS17(_ca); \
! 241: _cfa[1] = 0x08000240 /* or %r0,%r0,%r0 */; \
! 242: } \
! 243: else \
! 244: { \
! 245: _cfa[0] = (0x08 << 26) | \
! 246: ((int)_ca<0) | \
! 247: (_ca & 0x00001800)<<1 | \
! 248: (_ca & 0x0003E000)<<3 | \
! 249: (_ca & 0x000C0000)>>4 | \
! 250: (_ca & 0x7FF00000)>>19; \
! 251: _ca &= 0x3FF; \
! 252: _cfa[1] = (0x38 << 26) | /* major opcode */ \
! 253: ( 1 << 21) | /* register */ \
! 254: ( 0 << 13) | /* space register */ \
! 255: ( 1 << 1) | /* if 1, don't execute delay slot */ \
! 256: ASS17(_ca); \
! 257: } \
! 258: DOUT("%08x: %08x,%08x\n",(int)_cfa,_cfa[0],_cfa[1]); \
! 259: })
1.1 anton 260: /* this stores a call dodoes at addr */
261: #endif
262:
263: /* OS dependences */
264:
265: #define SEEK_SET 0
266: #define rint(x) floor((x)+0.5)
267:
1.2 ! pazsan 268:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>