Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / obp / obp / cpu / sparc / asmmacro.fth
CommitLineData
920dae64
AT
1\ ========== Copyright Header Begin ==========================================
2\
3\ Hypervisor Software File: asmmacro.fth
4\
5\ Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
6\
7\ - Do no alter or remove copyright notices
8\
9\ - Redistribution and use of this software in source and binary forms, with
10\ or without modification, are permitted provided that the following
11\ conditions are met:
12\
13\ - Redistribution of source code must retain the above copyright notice,
14\ this list of conditions and the following disclaimer.
15\
16\ - Redistribution in binary form must reproduce the above copyright notice,
17\ this list of conditions and the following disclaimer in the
18\ documentation and/or other materials provided with the distribution.
19\
20\ Neither the name of Sun Microsystems, Inc. or the names of contributors
21\ may be used to endorse or promote products derived from this software
22\ without specific prior written permission.
23\
24\ This software is provided "AS IS," without a warranty of any kind.
25\ ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
26\ INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
27\ PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
28\ MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
29\ ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
30\ DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN
31\ OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR
32\ FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
33\ DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
34\ ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
35\ SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
36\
37\ You acknowledge that this software is not designed, licensed or
38\ intended for use in the design, construction, operation or maintenance of
39\ any nuclear facility.
40\
41\ ========== Copyright Header End ============================================
42id: @(#)asmmacro.fth 2.13 07/06/05 10:54:41
43purpose: Assembly language macros related to the Forth implementation
44copyright: Copyright 2007 Sun Microsystems, Inc. All Rights Reserved
45copyright: Use is subject to license terms.
46\ Copyright 1985-1990 Bradley Forthware
47
48\ These words are specific to the virtual machine implementation
49: assembler ( -- ) srassembler ;
50
51only forth also assembler also definitions
52
53\ Forth Virtual Machine registers
54
55\ Note that the Forth Stack Pointer (r1) is NOT the same register that
56\ C uses for the stack pointer (r14). The hardware does all sorts of
57\ funny things with the C stack pointer when you do save and restore
58\ instructions, and when the register windows overflow.
59
60: base %g2 ; : up %g3 ; : tos %g4 ;
61: ip %i3 ; : rp %i4 ; : sp %i5 ;
62
63: scr %l0 ; : sc1 %l1 ; : sc2 %l2 ; : sc3 %l3 ;
64: sc4 %l4 ; : sc5 %l5 ; : sc6 %l6 ; : sc7 %l7 ;
65
66\ C stack pointer is %o6
67: spc %o7 ; \ Saved Program Counter - set by the CALL instruction
68
69\ Macros:
70
7132\ : slln ( rs1 rs2 rd -- ) sll ;
7232\ : srln ( rs1 rs2 rd -- ) srl ;
7332\ : sran ( rs1 rs2 rd -- ) sra ;
7432\ : nget ( ptr off dst -- ) ld ;
7532\ : nput ( src off ptr -- ) st ;
76
7764\ : slln ( rs1 rs2 rd -- ) sllx ;
7864\ : srln ( rs1 rs2 rd -- ) srlx ;
7964\ : sran ( rs1 rs2 rd -- ) srax ;
8064\ : nput ( src off ptr -- ) stx ;
8164\ : nget ( ptr off dst -- ) ldx ;
82
83: put ( src ptr -- ) 0 swap nput ;
84: get ( ptr dst -- ) 0 swap nget ;
85
86: lget ( ptr dst -- ) 0 swap ld ;
87: lput ( src ptr -- ) 0 swap st ;
88
89: move ( src dst -- ) %g0 -rot add ;
90: ainc ( ptr -- ) dup /n swap add ;
91: adec ( ptr -- ) dup /n swap sub ;
92: push ( src ptr -- ) dup adec put ;
93: pop ( ptr dst -- ) over -rot get ainc ;
94: test ( src -- ) %g0 %g0 addcc ;
95: cmp ( s1 s2 -- ) %g0 subcc ;
96: %hi ( n -- n.hi ) h# 03ff invert land ;
97: %lo ( n -- n.lo ) h# 03ff land ;
98: rtget ( srca srcb dst -- )
99\t16 dup >r lduh r> ( dst ) tshift over sll
100\t32 ld
101;
102
103\ Put a bubble in the pipeline to patch the load interlock bug
104: bubble ( nop ) ;
105
106\ The next few words are already in the forth vocabulary;
107\ we want them in the assembler vocabulary too
108alias next next
109: exitcode ( -- )
110 previous
111;
112' exitcode is do-exitcode
113
114alias end-code end-code
115alias c; c;
116
117: 'user \ name ( -- user-addressing-mode )
118 up ( reg# )
119 ' ( acf-of-user-variable )
120 >user# ( reg# offset )
121 dup h# 1000 [ also forth ] >= [ previous ] abort" user number too big"
122;
123: 'body \ name ( -- variable-apf-offset )
124 ' ( acf-of-user-variable ) >body origin-
125;
126: 'acf \ name ( -- variable-acf-offset )
127 ' ( acf-of-user-variable ) origin-
128;
129
130\ If 'user kicks you out -- or if you think it might -- use this:
131\ It uses a temp-register to allow for a large user-offset.
132\ If the user-offset is small enough, it acts like 'user
133\
134\ Oh! And another nice thing about this: If this is going to be part
135\ of a "load" instruction (e.g., LD , LDX, NGET, etc.), the destination
136\ register of that instruction can be used as the temp-register ...
137\
138: 'userx ( temp-reg -- user-addressing-mode ) \ <Name>
139 dup up ' >user# ( temp-reg temp-reg user-reg# offset )
140 dup h# 1000 [ also forth ] < if
141 2swap 2drop exit ( user-reg# offset )
142 then [ previous ] ( temp-reg temp-reg user-reg# offset )
143 \ Generate instruction(s) to load
144 \ the offset into temp-register .
145 rot ( temp-reg user-reg# offset temp-reg )
146 set ( temp-reg user-reg# )
147;
148
149: apf ( -- reg offset )
150\t16 sc1 2 \ code field is a 16-bit token
151\t32 spc 8 \ code field is 2 instructions
152;
153
154: nops ( n -- ) 0 ?do nop loop ;
155: .align ( n -- ) here swap round-up here - 2 rshift nops ;
156
157: entercode ( -- ) !csp align also assembler ;
158' entercode is do-entercode
159
160only forth also definitions