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