File:  [gforth] / gforth / Attic / hppa.h
Revision 1.5: download - view: text, annotated - select for diffs
Mon Dec 12 17:10:39 1994 UTC (26 years, 9 months ago) by anton
Branches: MAIN
CVS tags: HEAD
Reorganized configuration: configure is now created by autoconf from
configure.in; I still left it in the CVS repository because not
everyone has autoconf. decstation.h renamed to mips.h and apollo68k to
m68k. Added general 32bit.h description, which the other machine
descriptions use. Created/copied replacement files install-sh memcmp.c
memmove.c select.c (carved out from ecvt.c) strtol.c
strtoul.c. Bytesex is now handled by configure.

Deciding the threading method is now done in machine.h, this should
also be done for USE_TOS and USE_FTOS.

    1: /*
    2:   $Id: hppa.h,v 1.5 1994/12/12 17:10:39 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: #ifndef INDIRECT_THREADED
    9: #ifndef DIRECT_THREADED
   10: #define DIRECT_THREADED
   11: #endif
   12: #endif
   13: 
   14: /* 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: #else
   25: #  define CACHE_FLUSH(addr,size) \
   26: 		({ (void)cacheflush((void *)(addr), (int)(size), 32); })
   27: #  endif
   28: #endif
   29: 
   30: #include "32bit.h"
   31: 
   32: #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: #	define PFA1(cfa)       PFA(cfa)
   38: 	/* 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: 
   42: 	/* 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: 
   46: #ifdef DIRECT_THREADED
   47: 
   48: #  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: 
   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: 		int _ca      = (int)(ca)+4; \
   95: 		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: 				_cfa[1] = ((long *)(_ca))[-1]; /* or %r0,%r0,%r0 */; \
  105: 			} \
  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: 				_cfa[1] = ((long *)(_ca))[-1]; /* 0x08000240 or %r0,%r0,%r0 */; \
  114: 			} \
  115: 		else \
  116: 			{ \
  117: 				_ca -= 4; \
  118: 				_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: 	/* 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: #	define DOES_CODE(cfa)	((Xt *)(((long *)(cfa))[1]))
  139: 
  140: 	/* this is a special version of DOES_CODE for use in dodoes */
  141: #	define DOES_CODE1(cfa)  DOES_CODE(cfa) \
  142: /*	({register Xt * _ret asm("%r31"); _ret;}) */
  143: 
  144: 	/* HPPA uses register 2 for branch and link */
  145: 
  146: #	define DOES_HANDLER_SIZE 8
  147: #	define MAKE_DOES_HANDLER(cfa)  ({ *(long *)(cfa)=DODOES; })
  148: #ifdef undefined
  149: #	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: #endif
  192: 
  193: #	define MAKE_DOES_CF(cfa,ca) \
  194: 	({ \
  195: 		long *_cfa   = (long *)(cfa); \
  196: 		int _ca      = (int)symbols[DODOES]; \
  197: 		int _dp      = _ca-(int)(_cfa+2); \
  198: 		\
  199: 		if(_ca < 0x40000) /* Branch absolute */ \
  200: 			{ \
  201: 				_cfa[0] =((0x38 << 26) | /* major opcode */ \
  202: 				          (   0 << 21) | /* register */ \
  203: 				          (   0 << 13) | /* space register */ \
  204: 				          (   1 <<  1))| /* if 1, don't execute delay slot */ \
  205: 				          ASS17(_ca); \
  206: 				_cfa[1] = (long)(ca); \
  207: 			} \
  208: 		else if(_dp < 0x40000 || _dp >= -0x40000) \
  209: 			{ \
  210: 				_cfa[0] =((0x3A << 26) | /* major opcode */ \
  211: 				          (   0 << 21) | /* register */ \
  212: 				          (   0 << 13) | /* space register */ \
  213: 				          (   1 <<  1))| /* if 1, don't execute delay slot */ \
  214: 				          ASS17(_dp); \
  215: 				_cfa[1] = (long)(ca); \
  216: 			} \
  217: 		else \
  218: 			{ \
  219: 				fprintf(stderr,"DOESCFA assignment failed, use ITC instead of DTC\n"); exit(1); \
  220: 			} \
  221: 			DOUT("%08x: %08x,%08x\n",(int)_cfa,_cfa[0],_cfa[1]); \
  222: 	})
  223: 	/* this stores a call dodoes at addr */
  224: #endif
  225: 

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