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