File:  [gforth] / gforth / Attic / hppa.h
Revision 1.3: download - view: text, annotated - select for diffs
Tue Oct 4 18:23:59 1994 UTC (29 years, 6 months ago) by pazsan
Branches: MAIN
CVS tags: HEAD
Added delay slot copying

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

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