Annotation of gforth/386.h, revision 1.13

1.1       anton       1: /*
1.11      anton       2:   This is the machine-specific part for Intel 386 compatible processors
                      3: 
                      4:   Copyright (C) 1995 Free Software Foundation, Inc.
                      5: 
                      6:   This file is part of Gforth.
1.1       anton       7: 
1.11      anton       8:   Gforth is free software; you can redistribute it and/or
                      9:   modify it under the terms of the GNU General Public License
                     10:   as published by the Free Software Foundation; either version 2
                     11:   of the License, or (at your option) any later version.
                     12: 
                     13:   This program is distributed in the hope that it will be useful,
                     14:   but WITHOUT ANY WARRANTY; without even the implied warranty of
                     15:   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     16:   GNU General Public License for more details.
                     17: 
                     18:   You should have received a copy of the GNU General Public License
                     19:   along with this program; if not, write to the Free Software
                     20:   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
1.1       anton      21: */
                     22: 
1.7       anton      23: #include "32bit.h"
1.1       anton      24: 
1.7       anton      25: /* indirect threading is faster on the 486, on the 386 direct
                     26:    threading is probably faster. Therefore we leave defining
                     27:    DIRECT_THREADED to configure */
1.1       anton      28: 
1.3       anton      29: /* define this if the processor cannot exploit instruction-level
1.4       anton      30:    parallelism (no pipelining or too few registers) */
1.3       anton      31: #define CISC_NEXT
                     32: 
1.9       anton      33: /* 386 and below have no cache, 486 has a shared cache, and the
                     34:    Pentium probably employs hardware cache consistency, so
                     35:    flush-icache is a noop */
1.10      pazsan     36: #define FLUSH_ICACHE(addr,size)
1.9       anton      37: 
1.1       anton      38: #ifdef DIRECT_THREADED
1.10      pazsan     39: 
                     40: #define CALL 0xe8 /* call */
                     41: #define JMP  0xe9 /* jmp  */
                     42: #define GETCFA(reg)  ({ asm("popl %0" : "=r" (reg)); (int)reg -= 5;});
                     43: 
1.1       anton      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 */
1.2       pazsan     49: #define CODE_ADDRESS(cfa) \
1.5       anton      50:     ({long _cfa = (long)(cfa); (Label)(_cfa+*((long *)(_cfa+1))+5);})
1.1       anton      51: /* MAKE_CF creates an appropriate code field at the cfa; ca is the code address */
1.2       pazsan     52: #define MAKE_CF(cfa,ca)        ({long _cfa = (long)(cfa); \
                     53:                           long _ca  = (long)(ca); \
1.10      pazsan     54:                          *(char *)_cfa = CALL; \
1.2       pazsan     55:                          *(long *)(_cfa+1) = _ca-(_cfa+5);})
1.1       anton      56: 
                     57: /* this is the point where the does code starts if label points to the
                     58:  * jump dodoes */
1.2       pazsan     59: #define DOES_HANDLER_SIZE       8
1.12      pazsan     60: #define DOES_CODE(xt) \
1.13    ! anton      61: ({ long _xt = (long)(xt); \
        !            62:    long _ca = (long)(CODE_ADDRESS(_xt)); \
        !            63:    (((*(unsigned char *)_xt) == CALL) && \
        !            64:     ((*(unsigned char *)_ca) == JMP) && \
        !            65:     ((long)(CODE_ADDRESS(_ca)) == (long)symbols[DODOES])) ? \
        !            66:       _ca+DOES_HANDLER_SIZE : 0L; })
1.1       anton      67: 
                     68: /* this is a special version of DOES_CODE for use in dodoes */
1.12      pazsan     69: #define DOES_CODE1(label)      (CODE_ADDRESS(label)+DOES_HANDLER_SIZE)
1.1       anton      70: 
                     71: /* this stores a jump dodoes at addr */
1.10      pazsan     72: #define MAKE_DOES_CF(addr,doesp)       ({long _addr = (long)(addr); \
                     73:                           long _doesp  = (long)(doesp)-8; \
                     74:                          *(char *)_addr = CALL; \
                     75:                          *(long *)(_addr+1) = _doesp-(_addr+5);})
                     76: 
                     77: #define MAKE_DOES_HANDLER(addr)        ({long _addr = (long)(addr); \
                     78:                           long _dodo  = (long)symbols[DODOES]; \
                     79:                          *(char *)_addr = JMP; \
                     80:                          *(long *)(_addr+1) = _dodo-(_addr+5);})
1.1       anton      81: #endif
1.4       anton      82: 
                     83: #ifdef FORCE_REG
1.8       anton      84: #if (__GNUC__==2 && defined(__GNUC_MINOR__) && __GNUC_MINOR__==5)
                     85: /* i.e. gcc-2.5.x */
                     86: /* this works with 2.5.7; nothing works with 2.5.8 */
1.4       anton      87: #define IPREG asm("%esi")
                     88: #define SPREG asm("%edi")
                     89: #ifdef USE_TOS
                     90: #define CFAREG asm("%ecx")
                     91: #else
                     92: #define CFAREG asm("%edx")
                     93: #endif
1.8       anton      94: #else /* gcc-version */
                     95: /* this works with 2.6.3 (and quite well, too) */
                     96: /* since this is not very demanding, it's the default for other gcc versions */
1.10      pazsan     97: #if defined(USE_TOS) && !defined(CFA_NEXT)
                     98: #define IPREG asm("%ebx")
                     99: #else
1.8       anton     100: #define SPREG asm("%ebx")
1.10      pazsan    101: #endif /* USE_TOS && !CFA_NEXT */
1.8       anton     102: #endif /* gcc-version */
1.4       anton     103: #endif /* FORCE_REG */

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