File:  [gforth] / gforth / Attic / hppa.h
Revision 1.6: download - view: text, annotated - select for diffs
Wed Dec 14 16:15:28 1994 UTC (26 years, 9 months ago) by anton
Branches: MAIN
CVS tags: HEAD
Fixed a few bugs in config.in
added USE_TOS and USE_FTOS to the machine.h files as appropriate

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

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