Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / obp / obp / cpu / sparc / register.fth
CommitLineData
920dae64
AT
1\ ========== Copyright Header Begin ==========================================
2\
3\ Hypervisor Software File: register.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: @(#)register.fth 2.16 07/06/05 10:54:45
43purpose: Register names for saved program state
44copyright: Copyright 2007 Sun Microsystems, Inc. All Rights Reserved
45copyright: Use is subject to license terms.
46\ Copyright 1985-1990 Bradley Forthware
47
48\ This version uses multiple-code-field defining words for the self-fetching
49\ register names.
50
51\ Display and modify the saved state of the machine.
52\
53\ This code is highly machine-dependent.
54\
55\ Version for the SPARC processor
56\
57\ Requires:
58\
59\ >state ( offset -- addr )
60\ Returns an address within the processor state array given the
61\ offset into that array
62\ #windows ( -- n )
63\ The number of implemented register windows
64\ window-registers ( -- offset )
65\ The offset from CPU-STATE to the start of the area where the
66\ window registers are stored
67\
68\ Defines:
69\
70\ %g0 .. %g7 %o0 .. %o7 %l0 .. %l7 %i0 .. %i7
71\ %pc %npc %y %psr
72\ V8, Priviliged: %wim %tbr
73\ Priviliged: cwp
74\ w
75\ .registers .locals
76
77needs action: objects.fth
78
79decimal
80
81only forth hidden also forth also definitions
82
833 actions
84action: @ >state @ ;
85action: @ >state ! ; ( is )
86action: @ >state ; ( addr )
87transient
88: global-reg \ name ( offset -- offset+/n )
89 create allocate-reg ,
90 use-actions
91;
92: global-regs \ name name ... ( offset #regs -- offset' )
93 ( offset #regs ) 0 ?do global-reg loop ( offset' )
94;
95: offset-of \ name ( -- offset )
96 parse-word ['] forth $vfind if
97 >body @ 1
98 else
99 ." offset-of can't find " type cr
100 where
101 then
102 do-literal
103; immediate
104resident
105
106headerless
107variable view-window
108variable previous-outs
109: >outreg ( reg# -- ) previous-outs @ + ;
110: >window ( reg# -- ) view-window @ + ;
111headers
112
1133 actions
114action: @ >window @ ;
115action: @ >window ! ; ( is )
116action: @ >window ; ( addr )
117transient
118: local-regs \ name name ... ( reg# #regs -- )
119 bounds ?do create i /n* , use-actions loop
120;
121resident
122
1233 actions
124action: @ >outreg @ ;
125action: @ >outreg ! ; ( is )
126action: @ >outreg ; ( addr )
127
128transient
129: out-regs \ name name ... ( #regs -- )
130 ( #regs ) 0 do create i /n* , use-actions loop
131;
132resident
133
1344 global-regs %pc %npc %y %psr
135
136[ifdef] firmware
1372 global-regs %wim %tbr
138[then]
139
1408 global-regs %g0 %g1 %g2 %g3 %g4 %g5 %g6 %g7
141
1422 global-regs %state-valid %restartable?
143\ Following words defined here to satisfy the
144\ references to these "variables" anywhere else
145: state-valid ( -- addr ) addr %state-valid ;
146: restartable? ( -- addr ) addr %restartable? ;
147
148[ifdef] firmware
1493 global-regs %saved-my-self last-trap# error-reset-trap
150
151\ Following words defined here to satisfy the
152\ references to these "variables" anywhere else
153: saved-my-self ( -- addr ) addr %saved-my-self ;
154[then]
155
156\ The set of out registers has to be defined as a single batch.
157\ They can't be defined piecemeal like global registers.
158\ The set of local registers must be "batched" too.
159
1608 out-regs %o0 %o1 %o2 %o3 %o4 %o5 %o6 %o7
161
1620 8 local-regs %l0 %l1 %l2 %l3 %l4 %l5 %l6 %l7
1638 8 local-regs %i0 %i1 %i2 %i3 %i4 %i5 %i6 %i7
164
165alias %base %g2
166alias %up %g3
167alias %tos %g4
168alias %ip %i3
169alias %rp %i4
170alias %sp %i5
171
172
173false value standalone? \ Can be used to turn off stuff in stand.exe
174headerless
175
1760 value window#
177
178: aligned? ( adr -- flag ) 3 and 0= ;
179defer accessible? ( adr -- flag )
180: yes-accessible ( adr -- true ) drop true ;
181' yes-accessible is accessible?
182
183\ Invalid, unaligned, or inaccessible call point
184: pointer-bad? ( adr -- flag ) \ True if the address is not a good pointer
185 dup 0<> over aligned? and swap accessible? and 0=
186;
187
188headers
189
190: 0w ( -- )
191 window-registers >state dup previous-outs ! 8 na+ view-window !
192 0 is window#
193;
194
195\ cached-window? can be used in cases where the hardware register windows
196\ are saved in a place other than on the stack.
197defer cached-window? ( -- [ last? ] handled? ) ' false is cached-window?
198
199: (+w) ( -- last? )
200 cached-window? if exit then
201
202 %i6 pointer-bad? %i6 0= or if
203 true exit
204 else
205 addr %i0 previous-outs !
206 %i6 view-window !
207 then
208 window# 1+ is window#
209 false
210;
211: +w ( -- ) (+w) abort" No more valid windows" ;
212
213: set-window ( n -- ) 0w ( n ) 0 ?do (+w) ?leave loop ;
214: w ( n -- )
215 dup set-window window# <> if
216 ." Window number too large. The maximum number is " window# . cr
217 then
218;
219
220headerless
221defer .other-regs ' noop is .other-regs
222headers
223: .registers ( -- )
224 ??cr
225." "
226." %g0 %g1 %g2 %g3 %g4 %g5 %g6 %g7" cr
227." " addr %g0 8 .ndump cr
228." "
229." PC nPC Y" cr
230." " %pc .nx %npc .nx %y .nx cr
231.other-regs
232;
233: .locals
234." "
235." 0 1 2 3 4 5 6 7"
236cr
237." IN: " addr %i0 8 .ndump cr
238." LOC:" addr %l0 8 .ndump cr
239." OUT:" addr %o0 8 .ndump cr
240;
241
242: init-window ( -- ) 0w ;
243
244: .window ( window# -- ) w .locals ;
245
246only forth also definitions