File:  [gforth] / gforth / Attic / mips.h
Revision 1.2: download - view: text, annotated - select for diffs
Wed Dec 14 16:15:29 1994 UTC (24 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:   Copyright 1992 by the ANSI figForth Development Group
    3: 
    4:   This is the machine-specific part for MIPS R[2346810]000 processors
    5: */
    6: 
    7: #if !defined(USE_TOS) && !defined(USE_NO_TOS)
    8: /* on the mips this is a mixed blessing, since defining this spills
    9:    the rp with some gcc versions. This machine has 31 regs, yet that's
   10:    not enough for gcc-2.4.5 :-( */
   11: #define USE_TOS
   12: #endif
   13: 
   14: /* cache flush stuff */
   15: 
   16: #ifndef INDIRECT_THREADED
   17: #ifndef DIRECT_THREADED
   18: #define DIRECT_THREADED
   19: /* direct threading saves 2 cycles per primitive on an R3000, 4 on an R4000 */
   20: #endif
   21: #endif
   22: 
   23: #ifdef DIRECT_THREADED
   24: 
   25: /* this works on Ultrix. Let's hope it works on others, too */
   26: #include <mips/cachectl.h>
   27: 
   28: #define CACHE_FLUSH(addr,size) \
   29: 			cacheflush((char *)(addr), (int)(size), BCACHE)
   30: 
   31: #endif
   32: 
   33: #include "32bit.h"
   34: 
   35: #ifdef DIRECT_THREADED
   36: /* some definitions for composing opcodes */
   37: #define JUMP_MASK	0x03ffffff
   38: #define J_PATTERN	0x08000000
   39: #define JAL_PATTERN	0x0c000000
   40: /* this provides the first 4 bits of a jump address, i.e. it must be <16 */
   41: #define SEGMENT_NUM	1
   42: 
   43: 
   44: 	/* PFA gives the parameter field address corresponding to a cfa */
   45: #	define PFA(cfa)	(((Cell *)cfa)+2)
   46: 	/* PFA1 is a special version for use just after a NEXT1 */
   47: #	define PFA1(cfa)	PFA(cfa)
   48: 	/* CODE_ADDRESS is the address of the code jumped to through the code field */
   49: #	define CODE_ADDRESS(cfa)	((Label)(((*(unsigned *)(cfa))^J_PATTERN^(SEGMENT_NUM<<26))<<2))
   50: 	/* MAKE_CF creates an appropriate code field at the cfa; ca is the code address */
   51: #	define MAKE_CF(cfa,ca)	({long * _cfa = (long *)(cfa); \
   52: 					  _cfa[0] = J_PATTERN|((((long)(ca))&JUMP_MASK)>>2); /* J ca */ \
   53: 					  _cfa[1] = 0; /* nop */})
   54: #	ifdef undefined
   55: 		/* the following version uses JAL to make PFA1 faster */
   56: #		define PFA1(label)	({register Cell *pfa asm("$31"); \
   57: 						pfa; })
   58: 		/* CODE_ADDRESS is the address of the code jumped to through the code field */
   59: #		define CODE_ADDRESS(cfa)	((Label)(((*(unsigned *)(cfa))^JAL_PATTERN^(SEGMENT_NUM<<26))<<2))
   60: #		define MAKE_CF(cfa,ca)	({long *_cfa = (long *)(cfa); \
   61: 					  long _ca = (long)(ca); \
   62: 						  _cfa[0] = JAL_PATTERN|(((((long)_ca)>>2))&JUMP_MASK); /* JAL ca+4 */ \
   63: 						  _cfa[1] = 0; /* *(long *)_ca; delay slot */})
   64: #	endif /* undefined */
   65: 
   66: 	/* this is the point where the does code starts if label points to the
   67: 	 * jump dodoes */
   68: #	define DOES_CODE(cfa)	((Xt *)(((char *)CODE_ADDRESS(cfa))+8))
   69: 
   70: 	/* this is a special version of DOES_CODE for use in dodoes */
   71: #	define DOES_CODE1(cfa)	DOES_CODE(cfa)
   72: 
   73: #	define DOES_HANDLER_SIZE	8
   74: #	define MAKE_DOES_CF(cfa,does_code) \
   75: 			({long does_handlerp=((long)(does_code))-DOES_HANDLER_SIZE; \
   76: 			  long *_cfa = (long*)(cfa); \
   77: 			  _cfa[0] = J_PATTERN|((does_handlerp&JUMP_MASK)>>2); /* J ca */ \
   78: 			  _cfa[1] = 0; /* nop */})
   79: /*
   80: #	define MAKE_DOES_CF(cfa, does_code)	({char *does_handlerp=((char *)does_code)-DOES_HANDLER_SIZE;	\
   81: 						  MAKE_CF(cfa,does_handlerp);	\
   82: 						  MAKE_DOES_HANDLER(does_handlerp) ;})
   83: */
   84: 	/* this stores a jump dodoes at addr */
   85: #	define MAKE_DOES_HANDLER(addr)	MAKE_CF(addr,symbols[DODOES])
   86: 
   87: #endif
   88: #ifdef undefined
   89: /* and here are some more efficient versions that can be tried later */
   90: 
   91: /* the first version saves one cycle by doing something useful in the
   92:    delay slot. !! check that the instruction in the delay slot is legal
   93: */
   94: 
   95: #define MAKE_DOESJUMP(addr)	({long * _addr = (long *)addr; \
   96: 				  _addr[0] = J_PATTERN|(((((long)symbols[DODOES])>>2)+4)&JUMP_MASK), /* J dodoes+4 */ \
   97: 				  _addr[1] = *(long *)symbols[DODOES]; /* delay */})
   98: 
   99: /* the following version uses JAL to make DOES_CODE1 faster */
  100: /* !! does the declaration clear the register ? */
  101: /* it's ok to use the same reg as in PFA1:
  102:    dodoes is the only potential problem and I have taken care of it */
  103: 
  104: #define DOES_CODE1(cfa)	({register Code *_does_code asm("$31"); \
  105: 				    _does_code; })
  106: #define MAKE_DOESJUMP(addr)	({long * _addr = (long *)addr; \
  107: 				  _addr[0] = JAL_PATTERN|(((((long)symbols[DODOES])>>2)+4)&JUMP_MASK), /* JAL dodoes+4 */ \
  108: 				  _addr[1] = *(long *)symbols[DODOES]; /* delay */})
  109: 
  110: #endif
  111: 
  112: #ifdef FORCE_REG
  113: #define IPREG asm("$16")
  114: #define SPREG asm("$17")
  115: #define RPREG asm("$18")
  116: #define LPREG asm("$19")
  117: #define CFAREG asm("$20")
  118: #define TOSREG asm("$21")
  119: #endif /* FORCE_REG */

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