File:  [gforth] / gforth / Attic / hppa.h
Revision 1.9: download - view: text, annotated - select for diffs
Sat Oct 7 17:38:16 1995 UTC (25 years, 9 months ago) by anton
Branches: MAIN
CVS tags: HEAD
added code.fs (code, ;code, end-code, assembler)
renamed dostruc to dofield
made index and doc-entries nicer
Only words containing 'e' or 'E' are converted to FP numbers.
added many wordset comments
added flush-icache primitive and FLUSH_ICACHE macro
added +DO, U+DO, -DO, U-DO and -LOOP
added code address labels (`docol:' etc.)
fixed sparc cache_flush

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

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