Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / obp / obp / pkg / confvar / interfaces / ui-cvars.fth
CommitLineData
920dae64
AT
1\ ========== Copyright Header Begin ==========================================
2\
3\ Hypervisor Software File: ui-cvars.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: @(#)ui-cvars.fth 1.9 07/02/07
43purpose:
44copyright: Copyright 2007 Sun Microsystems, Inc. All Rights Reserved
45copyright: Use is subject to license terms.
46
47unexported-words
48
49: $find-option ( adr len -- false | xt true )
50 ['] options search-wordlist
51;
52
53: find-option ( adr len -- false | xt true )
54 2dup $find-option if ( adr len xt )
55 nip nip true ( xt true )
56 else ( adr len )
57 ." Unknown option: " type cr ( )
58 false ( false )
59 then
60;
61
62exported-headers
63
64: getenv-default \ name ( -- )
65 parse-word dup if ( adr len )
66 find-option if ( acf )
67 do-get-default ( str,len )
68 then ( )
69 else ( adr len )
70 2drop ." Usage: get-default option-name" cr ( )
71 then ( )
72;
73
74: set-default \ name ( -- )
75 parse-word dup if ( adr len )
76 find-option if ( acf )
77 do-set-default ( -- )
78 then ( )
79 else ( adr len )
80 2drop ." Usage: set-default option-name" cr ( )
81 then ( )
82;
83
84: set-defaults ( -- )
85 ." Setting NVRAM parameters to default values." cr
86 (set-defaults)
87;
88
89unexported-words
90
91: to-column: \ name ( col# -- ) ( -- )
92 create c, does> c@ to-column
93;
94
95d# 24 to-column: value-column
96d# 55 to-column: default-column
97
98: (type-entry) ( adr,len -- )
99 2dup text? if
100 bounds ?do
101 i c@ dup newline = if
102 drop cr value-column exit? ?leave
103 else
104 emit
105 then
106 loop
107 else
108 chdump
109 then
110;
111: $type-entry ( adr len -- )
112 tuck 2dup text? if d# 24 else 8 then ( len adr len len' )
113 min rot over ( adr len' len len' )
114 > >r (type-entry) r> if ." ..." then ( )
115;
116: $type-entry-long ( adr len acf -- ) decode (type-entry) ;
117
118\ XXX should be done using "string-property" or "driver" or something
119\ create name " options" 1+ ", does> count ; \ Include null byte in count
120
121: show-config-entry ( acf -- )
122 >r
123 r@ .name
124 value-column r@ get r@ decode $type-entry
125 r> do-get-default default-column $type-entry
126 cr
127;
128
129: show-current-value ( acf -- )
130 dup .name ." = " value-column
131 >r r@ get r> ( adr len acf ) $type-entry-long cr
132;
133
134: printenv-all ( -- )
135 ." Variable Name" value-column ." Value"
136 default-column ." Default Value" cr cr
137
138 0 ['] options ( alf voc-acf )
139 begin
140 another-word? exit? if if 3drop then false then
141 while ( alf' voc-acf anf )
142 dup name>string " name" $= if ( alf' voc-acf anf )
143 \ Don't display the "name" property
144 drop ( alf' voc-acf )
145 else ( alf' voc-acf anf )
146 name> show-config-entry ( alf' voc-acf )
147 then ( alf' voc-acf )
148 repeat ( )
149 show-extra-env-vars ( )
150;
151
152: (printenv) ( adr len -- )
153 2dup $find-option if
154 nip nip show-current-value
155 else
156 show-extra-env-var
157 then
158;
159
160: usage ( -- ) ." Usage: setenv option-name value" cr ;
161
162
163: list ( addr count -- ) \ a version of "type" used for displaying nvramrc
164 bounds ?do
165 i c@ newline = if cr else i c@ emit then
166 loop
167;
168
169exported-headers
170
171: $set-default ( name$ -- )
172 $find-option if ( xt )
173 do-set-default
174 then
175;
176
177: $getenv ( name$ -- true | value$ false )
178 2dup $find-option if ( name$ xt )
179 nip nip ( xt )
180 >r r@ get r> decode false ( value$ false )
181 else ( value$ )
182 get-env-var
183 then
184;
185
186: printenv \ [ option-name ] ( -- )
187 parse-word dup if (printenv) else 2drop printenv-all then
188;
189
190: $setenv ( value$ name$ -- )
191 2dup $find-option if ( value$ name$ xt )
192 nip nip
193
194 >r r@ encode if
195 r> drop ." Invalid value; previous value retained." cr
196 exit
197 then ( value )
198
199 \ We've passed all the error checks, now set the option value.
200
201 r@ set r> show-current-value ( )
202 else
203 put-extra-env-var
204 then
205;
206
207\ Used to set nvram variables without the unabashed verbosity of $setenv
208\ For example, when loading and setting ldom-variables from the MD
209: $silent-setenv ( value$ name$ -- )
210 2dup $find-option if ( value$ name$ xt )
211 nip nip
212
213 >r r@ encode if
214 r> drop
215 exit
216 then ( value )
217
218 \ We've passed all the error checks, now set the option value.
219
220 r@ set r> drop
221 else
222 put-extra-env-var
223 then
224;
225
226: $silent-change-default ( value$ name$ -- )
227 $find-option if ( value$ xt )
228 >r r@ encode if ( ) ( R: xt )
229 r> drop ( ) ( R: )
230 exit ( ) ( R: )
231 then ( value ) ( R: xt )
232 \ We've passed all the error checks, now change the default value.
233 r> 7 perform-action ( ) ( R: )
234 else ( value$ ) ( R: )
235 2drop ( ) ( R: )
236 then
237;
238
239: setenv \ name value ( -- )
240 parse-word -1 parse strip-blanks ( name$ value$ )
241 ?dup 0= if 3drop usage exit then 2swap ( value$ name$ )
242 2 pick over or 0= if 2drop 2drop usage exit then ( value$ name$ )
243 $setenv
244;
245
246\ Note - the following code should really be in it's own file. Leaving it
247\ here temporarily to avoid depend.mk problems.
248
249\ Define handler to set keyboard layout for commodity keyboards
250
251\ NVRAM variable to hold layout string - defaults to empty string
2520 0 d# 32 config-string keyboard-layout
253
254\ Working buffers. Concatenated length of all layout names should be under 512
255h# 200 value keylayoutlen
256keylayoutlen buffer: keylayouts
257h# 10 value keyselectlen
258keyselectlen buffer: keyselect
259
260: callkbd stdin @ $call-method ; ( ??? -- ??? )
261
262\ Routine called from <F1> keypress to ask for keyboard layout.
263
264: (ask-layout) ( -- )
265
266 \ Select US keyboard to guarantee numbers are in known location
267 " US-English" " set-keyboard-layout" callkbd
268 ?dup if
269 dup 2 = \ Layout will fail with code 2 if keyboard
270 if \ is hardware identifiable
271 cr ." Keyboard has hardware country identification, "
272 ." cannot select layout." cr exit
273 then
274 cr ." Unable to set default layout for prompt. Internal failure" cr exit
275 then
276
277 \ Get list of all layout names, so we can print them and ask for a
278 \ selection by number (since alphabetic keys may be scrambled).
279
280 keylayouts keylayoutlen " get-layout-names" callkbd
281 dup 0 = if
282 ." No keyboard layout names returned. Internal failure." cr exit
283 then
284
285 base @ d# 10 base ! swap dup ( base len len )
286
287 \ Now that we have the list of layout names, parse them out of list
288 \ (they are separated by nulls) and print them out.
289 cr ." Please select a national keyboard layout:" cr ( base len len )
290 keylayouts swap ( base len buffer len )
291 0 -rot ( base len count buffer len )
292 begin ( base len count buffer len )
293 dup while ( base len count buffer len )
294 \ Print out names three to a line
295 rot dup 3 mod 0= if cr then ( base len buffer len count )
296 1+ dup 2 u.r space -rot ( base len count' buffer len )
297 0 left-parse-string ( base len count' buffer' len'
298 name namlen )
299 \ Maximum length name is under 32 bytes - line 'em up.
300 tuck type d# 20 swap - spaces ( base len count' buffer' len' )
301 repeat
302 cr 3drop ( base len )
303 swap base ! ( len )
304
305 \ Loop asking for keyboard number
306 begin true while
307 base @ d# 10 base ! over ( len base len)
308 cr ." Keyboard number: " ( len base len )
309 keyselect keyselectlen accept ( len base len input-len )
310 keyselect swap ( len base len keyselect input-len )
311 $number ( len base len [ true| n false ] )
312 if
313 ." Please type a number" cr 0
314 then ( len base len n )
315
316 rot base ! ( len len n )
317
318 \ User has typed a keyboard number. Walk keylayouts again to find it.
319
320 0 rot keylayouts swap ( len n count buffer len )
321 begin ( len n count buffer len )
322 dup while ( len n count buffer len )
323 0 left-parse-string ( len n count buffer len' name namlen )
324 2>r 2swap 1+ 2dup = 2r> rot if ( len buffer len n count name namelen )
325
326 \ We've reached the keyboard number requested. Set it.
327 2dup " set-keyboard-layout" callkbd
328 if
329 ." Failed to set keyboard layout to " type cr
330 else
331 " keyboard-layout" $setenv ( len buffer len' n count )
332 3drop 2drop ( )
333 exit ( )
334 then
335
336 else
337 2drop 2swap ( len n count buffer len' )
338 then
339 repeat
340 \ Ran out of buffer looking for that keyboard number.
341 3drop
342 ." Unrecognized keyboard number " .d cr
343 repeat
344;
345
346['] (ask-layout) is (ask-layout
347
348unexported-words
349