Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / obp / obp / pkg / confvar / interfaces / nvramrc.fth
CommitLineData
920dae64
AT
1\ ========== Copyright Header Begin ==========================================
2\
3\ Hypervisor Software File: nvramrc.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: @(#)nvramrc.fth 1.13 06/10/11
43purpose: Implements NVRAMRC and its editor
44copyright: Copyright 2006 Sun Microsystems, Inc. All Rights Reserved
45copyright: Use is subject to license terms.
46
47\ The default size of the nvramrc file is zero. set-defaults will
48\ establish this size, but nvrecover may be used to recover the
49\ previous contents of the nvramrc file if there were any.
50
51headerless
52
530 value nvramrc-buffer \ Buffer for editing nvramrc
540 value nvramrc-size \ Current size of file being edited in memory
550 value nvramrc-allocd \ Current alloced size.
56
57[ifdef] SUN4V
58\ ### keep the 'old' nvramrc definition around on sun4v platforms a little
59\ ### longer,but use a set size of 1024 bytes for ldom-variable backed nvramrc
60
61: /max-nvramrc ( -- n )
62 nvram-package if
63 nvoption-size d# 12 - nvramrc nip max
64 else
65 d# 1024
66 then
67;
68[else]
69: /max-nvramrc ( -- n ) nvoption-size d# 12 - nvramrc nip max ;
70[then]
71
72: deallocate-buffer ( -- )
73 nvramrc-buffer if
74\nvdebug ." deallocate-buffer: " nvramrc-buffer .x nvramrc-allocd .x cr
75 nvramrc-buffer nvramrc-allocd free-mem
76 then
77 0 is nvramrc-buffer
78 0 is nvramrc-size
79;
80
81: allocate-buffer ( -- )
82 /max-nvramrc 0< abort" No space left for NVRAMRC"
83 nvramrc-buffer 0= if
84 ['] nvramrc get ( adr,len )
85 dup to nvramrc-size ( adr,len )
86 /max-nvramrc dup to nvramrc-allocd ( adr,len max-len )
87 alloc-mem dup is nvramrc-buffer ( adr,len dest )
88 dup nvramrc-allocd erase ( adr,len dest )
89 swap move ( -- )
90\nvdebug ." allocate-buffer: " nvramrc-buffer .x
91\nvdebug nvramrc-allocd .x nvramrc-size .x cr
92 then
93;
94
95exported-headers
96
97\ Returns address and length of edit buffer
98: nvbuf ( -- adr len ) nvramrc-buffer nvramrc-size ;
99
100\ Begin or continue editing nvramrc
101: nvedit ( -- )
102 allocate-buffer
103 [ also hidden ]
104 nvbuf nvramrc-allocd edit-file is nvramrc-size
105 [ previous ]
106;
107
108\ Allows you to recover the contents of the nvramrc file if its size
109\ has been set to 0 by set-defaults.
110: nvrecover ( -- )
111 ['] nvramrc >body 1 ta+ token@ get ( adr,len )
112 strdup ( old$,len )
113 2dup to nvramrc ( old$,len )
114 free-mem ( -- )
115 nvedit ( -- )
116;
117
118\ Stop editing nvramrc, discarding the changes
119: nvquit ( -- )
120 " Discard edits" confirmed? if deallocate-buffer then
121;
122
123exported-headerless
124
125\ Execute the contents of the stack buffer
126: (nvrun) ( str,len -- )
127 use-nvramrc? >r r@ if 0 to use-nvramrc? then
128 ['] interpret-string catch if 2drop then
129 r> if true to use-nvramrc? then
130;
131
132exported-headers
133
134: nvrun ( -- ) nvbuf (nvrun) ;
135
136\ Copy the contents of the nvramrce edit buffer back into the NVRAM,
137\ and deallocate the edit buffer.
138: nvstore ( -- )
139 nvramrc-buffer if
140 nvbuf to nvramrc
141 deallocate-buffer
142 then
143;
144
145exported-headerless
146
147: execute-nvramrc ( -- )
148 " nvramrc-" do-drop-in ( )
149 use-nvramrc? if nvramrc (nvrun) then ( )
150 " nvramrc+" do-drop-in ( )
151;
152
153unexported-words