Annotation of gforth/arch/mips/machine.h, revision 1.8
1.1 anton 1: /* This is the machine-specific part for MIPS R[2346810]000 processors
2:
1.5 anton 3: Copyright (C) 1995,1996,1997,1998 Free Software Foundation, Inc.
1.1 anton 4:
5: This file is part of Gforth.
6:
7: Gforth is free software; you can redistribute it and/or
8: modify it under the terms of the GNU General Public License
9: as published by the Free Software Foundation; either version 2
10: of the License, or (at your option) any later version.
11:
12: This program is distributed in the hope that it will be useful,
13: but WITHOUT ANY WARRANTY; without even the implied warranty of
14: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15: GNU General Public License for more details.
16:
17: You should have received a copy of the GNU General Public License
18: along with this program; if not, write to the Free Software
19: Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20: */
21:
1.7 anton 22: #ifndef THREADING_SCHEME
23: #define THREADING_SCHEME 5
24: #endif
25:
1.1 anton 26: #if !defined(USE_TOS) && !defined(USE_NO_TOS)
27: /* on the mips this is a mixed blessing, since defining this spills
28: the rp with some gcc versions. This machine has 31 regs, yet that's
29: not enough for gcc-2.4.5 :-( */
30: #define USE_TOS
31: #endif
32:
33: /* cache flush stuff */
34:
35: #ifndef INDIRECT_THREADED
36: #ifndef DIRECT_THREADED
37: #define DIRECT_THREADED
38: /* direct threading saves 2 cycles per primitive on an R3000, 4 on an R4000 */
39: #endif
40: #endif
41:
1.6 anton 42: #if defined(INDIRECT_THREADED)
43: #undef DIRECT_THREADED
44: /* configure may define both on the MIPS */
45: #endif
46:
1.1 anton 47: #ifdef ultrix
48: #include <mips/cachectl.h>
49: #else
50: /* works on Irix */
51: #include <sys/cachectl.h>
52: #endif
53:
54: #define FLUSH_ICACHE(addr,size) \
55: cacheflush((char *)(addr), (int)(size), BCACHE)
56:
1.4 anton 57: #include "../generic/machine.h"
1.1 anton 58:
59: #ifdef DIRECT_THREADED
60: /* some definitions for composing opcodes */
61: #define JUMP_MASK 0x03ffffff
62: #define J_PATTERN 0x08000000
63: #define JAL_PATTERN 0x0c000000
64: /* this provides the first 4 bits of a jump address, i.e. it must be <16 */
65: #define SEGMENT_NUM 1
66:
1.8 ! anton 67: #define JUMP(addr) (J_PATTERN|((((unsigned)(addr))>>2)&JUMP_MASK))
! 68: #define CALL(addr) (JAL_PATTERN|((((unsigned)(addr))>>2)&JUMP_MASK))
1.1 anton 69:
70: /* PFA gives the parameter field address corresponding to a cfa */
71: # define PFA(cfa) (((Cell *)cfa)+2)
72: /* PFA1 is a special version for use just after a NEXT1 */
73: # define PFA1(cfa) PFA(cfa)
1.8 ! anton 74:
! 75: /* the address of the code, if we know the code field contains a jump */
! 76: #define CODE_ADDRESS1(cfa) ((Label)(((*(unsigned *)(cfa))^J_PATTERN^(SEGMENT_NUM<<26))<<2))
! 77: /* CODE_ADDRESS is the address of the code jumped to through the code field */
! 78: #define CODE_ADDRESS(cfa) ({ \
! 79: int *__cfa=((int *)(cfa)); \
! 80: unsigned _code=*__cfa; \
! 81: (((_code>>26)==(J_PATTERN>>26)) ? \
! 82: CODE_ADDRESS1(__cfa) : \
! 83: ((Label)__cfa)); \
! 84: })
! 85:
1.1 anton 86: /* MAKE_CF creates an appropriate code field at the cfa; ca is the code address */
87: # define MAKE_CF(cfa,ca) ({long * _cfa = (long *)(cfa); \
88: _cfa[0] = JUMP(ca); \
89: _cfa[1] = 0; /* nop */})
90: # ifdef undefined
91: /* the following version uses JAL to make PFA1 faster */
92: # define PFA1(label) ({register Cell *pfa asm("$31"); \
93: pfa; })
94: /* CODE_ADDRESS is the address of the code jumped to through the code field */
95: # define CODE_ADDRESS(cfa) ((Label)(((*(unsigned *)(cfa))^JAL_PATTERN^(SEGMENT_NUM<<26))<<2))
96: # define MAKE_CF(cfa,ca) ({long *_cfa = (long *)(cfa); \
97: long _ca = (long)(ca); \
98: _cfa[0] = CALL(_ca); \
99: _cfa[1] = 0; /* *(long *)_ca; delay slot */})
100: # endif /* undefined */
101:
102: /* this is the point where the does code starts if cfa points to a
103: code field of a does>-defined word */
104: #define DOES_CODE(cfa) \
105: ({ Xt _cfa=(Xt)(cfa); \
106: Label _ca=CODE_ADDRESS(_cfa); \
1.8 ! anton 107: ((*(unsigned *)_ca) == JUMP(symbols[DODOES])) ? _ca+DOES_HANDLER_SIZE : 0; })
1.1 anton 108:
109:
110: /* this is a special version of DOES_CODE for use in dodoes */
1.8 ! anton 111: #define DOES_CODE1(cfa) ((Xt *)(((char *)CODE_ADDRESS1(cfa))+DOES_HANDLER_SIZE))
1.1 anton 112:
113:
114: # define MAKE_DOES_CF(cfa,does_code) \
115: ({long does_handlerp=((long)(does_code))-DOES_HANDLER_SIZE; \
116: long *_cfa = (long*)(cfa); \
117: _cfa[0] = JUMP(does_handlerp); \
118: _cfa[1] = 0; /* nop */})
119: /*
120: # define MAKE_DOES_CF(cfa, does_code) ({char *does_handlerp=((char *)does_code)-DOES_HANDLER_SIZE; \
121: MAKE_CF(cfa,does_handlerp); \
122: MAKE_DOES_HANDLER(does_handlerp) ;})
123: */
124: /* this stores a jump dodoes at addr */
125: # define MAKE_DOES_HANDLER(addr) MAKE_CF(addr,symbols[DODOES])
126:
127: #endif
128: #ifdef undefined
129: /* and here are some more efficient versions that can be tried later */
130:
131: /* the first version saves one cycle by doing something useful in the
132: delay slot. !! check that the instruction in the delay slot is legal
133: */
134:
135: #define MAKE_DOESJUMP(addr) ({long * _addr = (long *)addr; \
136: _addr[0] = JUMP(((unsigned)symbols[DODOES])+4); \
137: _addr[1] = *(long *)symbols[DODOES]; /* delay */})
138:
139: /* the following version uses JAL to make DOES_CODE1 faster */
140: /* !! does the declaration clear the register ? */
141: /* it's ok to use the same reg as in PFA1:
142: dodoes is the only potential problem and I have taken care of it */
143:
144: #define DOES_CODE1(cfa) ({register Code *_does_code asm("$31"); \
145: _does_code; })
146: #define MAKE_DOESJUMP(addr) ({long * _addr = (long *)addr; \
147: _addr[0] = CALL(((long)symbols[DODOES])+4);
148: _addr[1] = *(long *)symbols[DODOES]; /* delay */})
149:
150: #endif
151:
152: #ifdef FORCE_REG
153: #define IPREG asm("$16")
154: #define SPREG asm("$17")
155: #define RPREG asm("$18")
156: #define LPREG asm("$19")
157: #define CFAREG asm("$20")
158: #define TOSREG asm("$21")
159: #endif /* FORCE_REG */
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>