Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / obp / obp / cpu / sparc / register9.fth
CommitLineData
920dae64
AT
1\ ========== Copyright Header Begin ==========================================
2\
3\ Hypervisor Software File: register9.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: @(#)register9.fth 1.14 07/06/05 10:54:46
43purpose:
44copyright: Copyright 2007 Sun Microsystems, Inc. All Rights Reserved
45copyright: Use is subject to license terms.
46
47\ This version uses multiple-code-field defining words for the self-fetching
48\ register names.
49
50\ Display and modify the saved state of the machine.
51\
52\ This code is highly machine-dependent.
53\
54\ Version for the Spitfire processor
55\
56\ Requires:
57\
58\ >state ( offset -- addr )
59\ Returns an address within the processor state array given the
60\ offset into that array
61\ #windows ( -- n )
62\ The number of implemented register windows
63\ window-registers ( -- offset )
64\ The offset from CPU-STATE to the start of the area where the
65\ window registers are stored
66\
67\ Defines:
68\
69\ %g0 .. %g7 %o0 .. %o7 %l0 .. %l7 %i0 .. %i7
70\ %pc %npc %y %psr %wim %tbr
71\ cwp
72\ w
73\ .registers .locals
74
75needs action: objects.fth
76
77decimal
78
79only forth hidden also forth also definitions
80
81\ This is used to examine state inside the cpu struct.
82headerless
830 value cpu-reg-offset
844 actions
85action: w@ >state cpu-reg-offset + @ ;
86action: w@ >state cpu-reg-offset + ! ; \ to
87action: w@ >state cpu-reg-offset + ; \ addr
88action: drop /n ; \ size-of
89transient
90: global-reg \ name ( offset -- offset+/l )
91 create allocate-reg w,
92 use-actions
93;
94: global-regs \ name name ... ( offset #regs -- offset' )
95 ( offset #regs ) 0 ?do global-reg loop ( offset' )
96;
97: offset-of \ name ( -- offset )
98 parse-word ['] forth $vfind if
99 >body w@ 1
100 else
101 ." offset-of can't find " type cr
102 where
103 then
104 do-literal
105; immediate
106resident
107
108headerless
109d# 2047 constant V9_SP_BIAS
110variable view-window
111variable previous-outs
112: >outreg ( reg# -- adr flag )
113 previous-outs @ dup 1 and if
114 \ 64-bit stack frame
115 V9_SP_BIAS + swap na+ cpu-reg-offset + true
116 else
117 \ 32-bit stack frame
118 swap la+ cpu-reg-offset + false
119 then
120;
121: >window ( reg# -- adr flag )
122 view-window @ dup 1 and if
123 \ 64-bit stack frame
124 V9_SP_BIAS + swap na+ cpu-reg-offset + true
125 else
126 \ 32-bit stack frame
127 swap la+ cpu-reg-offset + false
128 then
129;
130headers
131
1324 actions
133action: w@ >window if x@ else l@ then ;
134action: w@ >window if x! else l! then ; \ to
135action: w@ \ addr
136 view-window @ dup 1 and if
137 \ 64-bit stack frame
138 swap na+
139 else
140 \ 32-bit stack frame
141 swap la+
142 then cpu-reg-offset +
143;
144action: drop view-window @ 1 and if /n else /l then ; \ size-of
145transient
146: local-regs \ name name ... ( reg# #regs -- )
147 bounds ?do create i w, use-actions loop
148;
149resident
150
1514 actions
152action: w@ >outreg if x@ else l@ then ;
153action: w@ >outreg if x! else x@ then ; \ to
154action: w@ \ addr
155 view-window @ dup 1 and if
156 \ 64-bit stack frame
157 swap na+
158 else
159 \ 32-bit stack frame
160 swap la+
161 then cpu-reg-offset +
162;
163action: drop view-window @ 1 and if /n else /l then ; \ size-of
164transient
165: out-regs \ name name ... ( #regs -- )
166 ( #regs ) 0 do create i w, use-actions loop
167;
168resident
1693 action-name size-of
170action-compiler: size-of
171
172[ifdef] SUN4V
1732 global-regs %tpc-1 %tpc-2
1742 global-regs %tnpc-1 %tnpc-2
1752 global-regs %tt-1 %tt-2
1762 global-regs %tstate-1 %tstate-2
1772 global-regs %gl %mmu-info-ptr
1782 constant #maxtl
179[else]
1805 global-regs %tpc-1 %tpc-2 %tpc-3 %tpc-4 %tpc-5
1815 global-regs %tnpc-1 %tnpc-2 %tnpc-3 %tnpc-4 %tnpc-5
1825 global-regs %tt-1 %tt-2 %tt-3 %tt-4 %tt-5
1835 global-regs %tstate-1 %tstate-2 %tstate-3 %tstate-4 %tstate-5
184
1858 global-regs %v0 %v1 %v2 %v3 %v4 %v5 %v6 %v7
1868 global-regs %m0 %m1 %m2 %m3 %m4 %m5 %m6 %m7
187
1881 global-regs %lsucr
1895 constant #maxtl
190[then]
191
1925 global-regs %tpc-c %tnpc-c %tt-c %tl-c %tstate-c
193
1941 global-regs %pc
1955 global-regs %npc %cwp %pil %cansave %otherwin
1965 global-regs %ccr %y %fprs %pstate %wstate
1974 global-regs %cleanwin %tba %asi %canrestore
198
1998 global-regs %g0 %g1 %g2 %g3 %g4 %g5 %g6 %g7
2008 global-regs %a0 %a1 %a2 %a3 %a4 %a5 %a6 %a7
201
2022 global-regs %pcontext %scontext
2034 global-regs %state-valid %restartable? %saved-my-self last-trap#
2043 global-regs error-reset-trap full-save? %nwins
205
206\ Following words defined here to satisfy the
207\ references to these "variables" anywhere else
208: saved-my-self ( -- addr ) addr %saved-my-self ;
209: state-valid ( -- addr ) addr %state-valid ;
210: restartable? ( -- addr ) addr %restartable? ;
211
212\ The set of out registers has to be defined as a single batch.
213\ They can't be defined piecemeal like global registers.
214\ The set of local registers must be "batched" too.
215
2168 out-regs %o0 %o1 %o2 %o3 %o4 %o5 %o6 %o7
217
2180 8 local-regs %l0 %l1 %l2 %l3 %l4 %l5 %l6 %l7
2198 8 local-regs %i0 %i1 %i2 %i3 %i4 %i5 %i6 %i7
220
221
222alias %base %g2
223alias %up %g3
224alias %tos %g4
225alias %ip %i3
226alias %rp %i4
227
228false value standalone? \ Can be used to turn off stuff in stand.exe
229headerless
230
2310 value window#
232
233: aligned? ( adr -- flag ) 3 and 0= ;
234defer accessible? ( adr -- flag )
235: yes-accessible ( adr -- true ) drop true ;
236' yes-accessible is accessible?
237
238\ Invalid, unaligned, or inaccessible call point
239headers
240: pointer-bad? ( adr -- flag ) \ True if the address is not a good pointer
241 dup 1 and if ( adr )
242 \ 64-bit stack frame
243 V9_SP_BIAS +
244 else ( adr )
245 \ 32-bit stack frame
246 n->l ( adr )
247 then ( adr )
248 dup aligned? ( adr flag )
249 swap accessible? ( flag flag )
250 and 0=
251;
252
253[ifnexist] log2 \ Might be defined in code
254headerless
255: log2 ( n -- log2-of-n )
256 -1 swap begin ( initl-log n )
257 ?dup while
258 swap 1+ swap
259 u2/
260 repeat
261;
262headers
263[then]
264
265\ : %cwp ( -- psr.cwp ) %psr h# 1f and ;
266
267: 0w ( -- )
268 0 is window#
269 window-registers >state
270 V9_SP_BIAS - dup previous-outs !
271 8 na+ view-window !
272;
273: (+w) ( -- last? )
274 standalone? if
275 #windows 1 - %cansave - ( #valid-windows )
276 window# 1+ > if
277 addr %i0 dup previous-outs ! 8 na+ view-window !
278 window# 1+ is window#
279 false exit
280 then
281 then
282
283 %i6 pointer-bad? %i6 0= or if
284 true exit
285 else
286 addr %i0 previous-outs !
287 %i6 view-window !
288 then
289 window# 1+ is window#
290 false
291;
292: +w ( -- ) (+w) abort" No more valid windows" ;
293
294: set-window ( n -- ) 0w ( n ) 0 ?do (+w) ?leave loop ;
295: w ( n -- )
296 dup set-window window# <> if
297 ." Window number too large. The maximum number is " window# . cr
298 then
299;
300
301headerless
302: .reg# ( n -- ) <# ascii : hold u#s u#> type space ;
303
304: .glob-regs ( adr0 -- )
305 8 0 do i .reg# dup i xa+ x@ .nx cr loop drop
306;
307
308: (.cc) ( cc -- )
309 dup 8 and if ." N" else ." n" then
310 dup 4 and if ." Z" else ." z" then
311 dup 2 and if ." V" else ." v" then
312 1 and if ." C" else ." c" then
313;
314: (.icc) ( ccr -- ) ." ICC:" (.cc) ;
315: (.xcc) ( ccr -- ) ." XCC:" 4 rshift (.cc) ;
316: (.ccr) ( ccr -- ) dup (.xcc) 3 spaces (.icc) ;
317headers
318: .icc ( -- ) %ccr (.icc) ;
319: .xcc ( -- ) %ccr (.xcc) ;
320: .ccr ( -- ) %ccr (.ccr) ;
321
322: .registers ( -- )
323 ??cr
324 d# 8 to-column ." Normal"
325[ifndef] SUN4V
326 d# 24 to-column ." Alternate"
327 d# 40 to-column ." MMU"
328 d# 58 to-column ." Vector" cr
329
330 0 .reg# %g0 .nx %a0 .nx %m0 .nx %v0 .nx cr
331 1 .reg# %g1 .nx %a1 .nx %m1 .nx %v1 .nx cr
332 2 .reg# %g2 .nx %a2 .nx %m2 .nx %v2 .nx cr
333 3 .reg# %g3 .nx %a3 .nx %m3 .nx %v3 .nx cr
334 4 .reg# %g4 .nx %a4 .nx %m4 .nx %v4 .nx cr
335 5 .reg# %g5 .nx %a5 .nx %m5 .nx %v5 .nx cr
336 6 .reg# %g6 .nx %a6 .nx %m6 .nx %v6 .nx cr
337 7 .reg# %g7 .nx %a7 .nx %m7 .nx %v7 .nx cr
338[else]
339 d# 24 to-column ." GL=1" cr
340 0 .reg# %g0 .nx %a0 .nx cr
341 1 .reg# %g1 .nx %a1 .nx cr
342 2 .reg# %g2 .nx %a2 .nx cr
343 3 .reg# %g3 .nx %a3 .nx cr
344 4 .reg# %g4 .nx %a4 .nx cr
345 5 .reg# %g5 .nx %a5 .nx cr
346 6 .reg# %g6 .nx %a6 .nx cr
347 7 .reg# %g7 .nx %a7 .nx cr
348[then]
349 ." %PC " %pc .x ." %nPC " %npc .x cr
350 ." %TBA " %tba .x ." %CCR " %ccr .x .ccr cr
351;
352
353: .globals ( -- ) addr %g0 .glob-regs ;
354: .alternate-globals ( -- ) addr %a0 .glob-regs ;
355[ifndef] SUN4V
356: .mmu-globals ( -- ) addr %m0 .glob-regs ;
357: .vector-globals ( -- ) addr %v0 .glob-regs ;
358[then]
359
360: .locals ( -- )
361 d# 8 to-column ." INs"
362 d# 24 to-column ." LOCALs"
363 d# 40 to-column ." OUTs" cr
364
365 0 .reg# %i0 .nx %l0 .nx %o0 .nx cr
366 1 .reg# %i1 .nx %l1 .nx %o1 .nx cr
367 2 .reg# %i2 .nx %l2 .nx %o2 .nx cr
368 3 .reg# %i3 .nx %l3 .nx %o3 .nx cr
369 4 .reg# %i4 .nx %l4 .nx %o4 .nx cr
370 5 .reg# %i5 .nx %l5 .nx %o5 .nx cr
371 6 .reg# %i6 .nx %l6 .nx %o6 .nx cr
372 7 .reg# %i7 .nx %l7 .nx %o7 .nx cr
373;
374
375: (.pstate) ( pstate -- )
376 ." AG:" 1 bits . \ 0
377 ." IE:" 1 bits . \ 1
378 ." PRIV:" 1 bits . \ 2
379 ." AM:" 1 bits . \ 3
380 ." PEF:" 1 bits . \ 4
381 ." RED:" 1 bits . \ 5
382 ." MM:" 2 bits . \ 7:6
383 ." TLE:" 1 bits . \ 8
384 ." CLE:" 1 bits . \ 9
385 ." MG:" 1 bits . \ 10
386 ." IG:" 1 bits . \ 11
387 drop
388;
389
390: (.tstate) ( tstate -- )
391 ." %TSTATE:" dup .x
392 ." %CWP:" 8 bits .x cr
393 ." %PSTATE:" d# 16 bits dup .x (.pstate) cr
394 ." %ASI:" 8 bits .x
395 ." %CCR:" 8 bits dup .x ." " (.ccr)
396 drop
397;
398
399headers
400: .pstate ( -- ) pstate@ (.pstate) ;
401
402: .tstate ( level -- )
403 1- addr %tstate-1 swap xa+ x@ (.tstate)
404;
405: %tstate ( level -- n ) 1- addr %tstate-1 swap xa+ x@ ;
406: %tpc ( level -- n ) 1- addr %tpc-1 swap xa+ x@ ;
407: %tnpc ( level -- n ) 1- addr %tnpc-1 swap xa+ x@ ;
408: %tt ( level -- n ) 1- addr %tt-1 swap xa+ x@ ;
409
410: .trap-registers ( -- )
411 ." TL: " %tl-c .x cr cr
412 #maxtl 1+ 1 do
413 ." %TL:" i .x
414 ." %TT:" i %tt .x
415 ." %TPC:" i %tpc .x
416 ." %TnPC:" i %tnpc .x cr
417 i %tstate (.tstate)
418 cr cr
419 loop
420;
421
422[ifndef] SUN4V
423: .ver ( -- )
424 ver@
425 ." MAXWIN:" 5 bits .x
426 ( reserved ) 3 bits drop
427 ." MAXTL:" 8 bits .x
428 ( reserved ) 8 bits drop
429 ." MASK:" 8 bits .x
430 ." IMPL:" d# 16 bits .x
431 ." MANUF:" d# 16 bits .x
432 drop
433;
434[then]
435
436: init-window ( -- ) 0w ;
437
438: .window ( window# -- ) w .locals ;
439
440: wr ( n -- )
441 init-window
442 #windows %cwp - + #windows mod 0 ?do
443 addr %i0 dup previous-outs !
444 8 na+ view-window !
445 loop
446;
447
448only forth also definitions