[gforth] / gforth / Attic / power.h  

gforth: gforth/Attic/power.h


1 : anton 1.3 /* This is the machine-specific part for the Power (incl. PPC) architecture
2 : anton 1.1
3 : anton 1.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.
20 : anton 1.1 */
21 :    
22 :     #if !defined(USE_TOS) && !defined(USE_NO_TOS)
23 :     #define USE_TOS
24 :     #endif
25 :    
26 :     #ifndef INDIRECT_THREADED
27 :     #ifndef DIRECT_THREADED
28 :     /* #define DIRECT_THREADED */
29 :     #endif
30 :     #endif
31 :    
32 :     #include "32bit.h"
33 :    
34 :     /* cache flush stuff */
35 :     #warning If you get assembly errors, here is the reason why
36 : anton 1.2 #define FLUSH_ICACHE(addr,size) asm("icbi (%0); isync"::"b"(addr))
37 : anton 1.1 /* this assumes size=4 */
38 :     /* the mnemonics are for the PPC and the syntax is a wild guess; for
39 :     Power the mnemonic for the isync instruction is "ics" and I have
40 :     not found an equivalent for the icbi instruction in my reference.
41 :     */
42 : anton 1.2
43 :     #ifdef DIRECT_THREADED
44 :     #warning Direct threading for Power has not been tested
45 : anton 1.1
46 :     /* PFA gives the parameter field address corresponding to a cfa */
47 :     #define PFA(cfa) (((Cell *)cfa)+2)
48 :     /* PFA1 is a special version for use just after a NEXT1 */
49 :     /* the improvement here is that we may destroy cfa before using PFA1 */
50 :     #define PFA1(cfa) PFA(cfa)
51 :    
52 :     /* I'll assume the code resides in the lower (or upper) 32M of the
53 :     address space and use absolute addressing in the jumps to the
54 :     handlers. This makes it possible to use the full address space for
55 :     direct threaded Forth (even on 64-bit PowerPCs). However, the
56 :     linker has to ensure that this really happens */
57 :    
58 :     #define JUMP_TARGET_BITS 0
59 :     /* assuming the code is in the lower 32M; if it is in the upper 32M,
60 :     define JUMP_TARGET_BITS as ~0x3ffffff */
61 :     #define JUMP_MASK 0x3fffffc
62 :    
63 :     /* CODE_ADDRESS is the address of the code jumped to through the code field */
64 :     #define CODE_ADDRESS(cfa) ((Label)(((*(unsigned *)(cfa))&JUMP_MASK)|JUMP_TARGET_BITS))
65 :    
66 :     /* MAKE_CF creates an appropriate code field at the cfa; ca is the
67 :     code address. For those familiar with assembly, this is a `ba'
68 :     instruction in both Power and PowerPC assembly languages */
69 :     #define MAKE_CF(cfa,ca) (*(long *)(cfa) = 0x48000002|(ca))
70 :    
71 :     /* this is the point where the does code for the word with the xt cfa
72 :     starts. Since a branch is only a cell on Power, we can use the
73 :     second cell of the cfa for storing the does address */
74 : anton 1.4 #define DOES_CODE(cfa) \
75 : anton 1.5 ({ unsigned *_cfa=(unsigned *)(cfa); \
76 : anton 1.4 _cfa[0]==(0x48000002|&&docol) ? DOES_CODE1(_cfa) : 0; })
77 :    
78 :    
79 :     DOES_CODE(label)
80 : anton 1.1 /* this is a special version of DOES_CODE for use in dodoes */
81 : anton 1.4 #define DOES_CODE1(cfa) ((Xt *)(((long *)(cfa))[1]))
82 : anton 1.1
83 :     /* the does handler resides between DOES> and the following Forth
84 :     code. Since the code-field jumps directly to dodoes, the
85 :     does-handler is not needed for the Power architecture */
86 :     #define DOES_HANDLER_SIZE 8
87 :     #define MAKE_DOES_HANDLER(addr) 0
88 :    
89 :     /* This makes a code field for a does-defined word. doesp is the
90 :     address of the does-code. On the PPC, the code field consists of a
91 :     jump to dodoes and the address of the does code */
92 :     #define MAKE_DOES_CF(cfa,doesp) ({Xt *_cfa = (Xt *)(cfa); \
93 :     MAKE_CF(_cfa, symbols[DODOES]); \
94 :     _cfa[1] = (doesp); })
95 :     #endif

CVS Admin

Powered by ViewCVS 1.0-dev
(Powered by ViewCVS)

ViewCVS and CVS Help