Commit | Line | Data |
---|---|---|
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 ============================================ | |
42 | id: @(#)register.fth 2.16 07/06/05 10:54:45 | |
43 | purpose: Register names for saved program state | |
44 | copyright: Copyright 2007 Sun Microsystems, Inc. All Rights Reserved | |
45 | copyright: 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 | ||
77 | needs action: objects.fth | |
78 | ||
79 | decimal | |
80 | ||
81 | only forth hidden also forth also definitions | |
82 | ||
83 | 3 actions | |
84 | action: @ >state @ ; | |
85 | action: @ >state ! ; ( is ) | |
86 | action: @ >state ; ( addr ) | |
87 | transient | |
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 | |
104 | resident | |
105 | ||
106 | headerless | |
107 | variable view-window | |
108 | variable previous-outs | |
109 | : >outreg ( reg# -- ) previous-outs @ + ; | |
110 | : >window ( reg# -- ) view-window @ + ; | |
111 | headers | |
112 | ||
113 | 3 actions | |
114 | action: @ >window @ ; | |
115 | action: @ >window ! ; ( is ) | |
116 | action: @ >window ; ( addr ) | |
117 | transient | |
118 | : local-regs \ name name ... ( reg# #regs -- ) | |
119 | bounds ?do create i /n* , use-actions loop | |
120 | ; | |
121 | resident | |
122 | ||
123 | 3 actions | |
124 | action: @ >outreg @ ; | |
125 | action: @ >outreg ! ; ( is ) | |
126 | action: @ >outreg ; ( addr ) | |
127 | ||
128 | transient | |
129 | : out-regs \ name name ... ( #regs -- ) | |
130 | ( #regs ) 0 do create i /n* , use-actions loop | |
131 | ; | |
132 | resident | |
133 | ||
134 | 4 global-regs %pc %npc %y %psr | |
135 | ||
136 | [ifdef] firmware | |
137 | 2 global-regs %wim %tbr | |
138 | [then] | |
139 | ||
140 | 8 global-regs %g0 %g1 %g2 %g3 %g4 %g5 %g6 %g7 | |
141 | ||
142 | 2 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 | |
149 | 3 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 | ||
160 | 8 out-regs %o0 %o1 %o2 %o3 %o4 %o5 %o6 %o7 | |
161 | ||
162 | 0 8 local-regs %l0 %l1 %l2 %l3 %l4 %l5 %l6 %l7 | |
163 | 8 8 local-regs %i0 %i1 %i2 %i3 %i4 %i5 %i6 %i7 | |
164 | ||
165 | alias %base %g2 | |
166 | alias %up %g3 | |
167 | alias %tos %g4 | |
168 | alias %ip %i3 | |
169 | alias %rp %i4 | |
170 | alias %sp %i5 | |
171 | ||
172 | ||
173 | false value standalone? \ Can be used to turn off stuff in stand.exe | |
174 | headerless | |
175 | ||
176 | 0 value window# | |
177 | ||
178 | : aligned? ( adr -- flag ) 3 and 0= ; | |
179 | defer 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 | ||
188 | headers | |
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. | |
197 | defer 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 | ||
220 | headerless | |
221 | defer .other-regs ' noop is .other-regs | |
222 | headers | |
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" | |
236 | cr | |
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 | ||
246 | only forth also definitions |