Annotation of gforth/mips.h, revision 1.6

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

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