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