Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / obp / obp / pkg / confvar / definitions / 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.3 06/11/22
43purpose: Implements NVRAMRC
44copyright: Copyright 2006 Sun Microsystems, Inc. All Rights Reserved
45copyright: Use is subject to license terms.
46
47\ Architecture document notes:
48\ * It may not be reasonable to test the contents of nvramrc without
49\ rebooting, because of temporal issues about probing (for instance,
50\ the probing may have already taken place).
51
52\ Some magic happens here..
53\ The format of this option is different to the others.
54\ /token acf of normal hash storage
55\ /token acf of fallback storage
56\ /w default length = 0
57\ /w default data = 0
58\
59\ This format prevents using some of the other options common code
60\ because the fields are in different positions. Be careful. This option
61\ is also different because a set-default doesn't just free the storage
62\ resource.
63\ The 'old' storage will persist until garbage collection happens.
64\ after that event nvrecover will do nothing.
65\
66
67" oldnvramrc" create-nvhash constant nvrecover#
68
690 2 ta+ /w + constant nvdata-offset
70
71: getnvram-default ( apf -- ) nvdata-offset + 0 ;
72
73: get-nvramrc ( apf -- )
74 options-open? if ( apf )
75 token@ execute exit ( adr,len )
76 then ( apf )
77 getnvram-default ( adr,len )
78;
79
80\
81\ Most of the time we Joe.User to know about write failures to the device
82\ However, for the nvramrc it is acceptable to lose the ability to
83\ nvrecover if space in the device is low, unfortunately the data->file
84\ tracking is handled entirely by the hash objects and by default they
85\ complain when write fail. So we have a silent flag.
86\
87: strset ( adr len acf error? -- )
88 write-errors? @ >r write-errors? !
89 over if set else 3 perform-action 2drop then
90 r> write-errors? !
91;
92
93\ like the 'C' library counterpart.
94: strdup ( adr len -- adr' len' )
95 tuck dup alloc-mem tuck >r ( len adr mem len )
96 move r> swap ( adr len )
97;
98
99\ Watch Out with this code.
100\ The trick here is to release as much resource as possible
101\ before starting to write anything. We release the various buffers
102\ first because a triggered garbage collection will not write any hash
103\ keys that have no data.
104\
105
106: set-nvramrc ( new$,len apf -- )
107 dup /token + token@ dup >r ( new$,len apf h2-acf )
108 4 perform-action ( new$,len apf )
109 token@ >r r@ get strdup ( new$,len old$,len )
110 r@ 4 perform-action ( new$,len old$,len )
111 2swap r> true strset ( old$,len )
112 2dup r> false strset ( old$,len )
113 free-mem ( -- )
114;
115
1167 actions
117action: get-nvramrc ; ( apf -- adr len )
118action: set-nvramrc ; ( adr len apf -- )
119action: config-adr ; ( apf -- adr )
120action: drop ; ( adr len acf -- adr len )
121action: drop ; ( adr len acf -- adr len )
122action: drop false ;
123action: getnvram-default ; ( apf -- adr,len )
124
125exported-headers transient
126
1270 value nvramrc-created?
128
129: nvramrc-bytes \ name ( -- )
130[ifdef] SUN4V
131 \ 1024 bytes is the maximum size of an LDOM variable.. (FWARC 2006/055)
132 0 0 d# 1024 config-long-string exit
133[then]
134 nvramrc-created? abort" Only One NVRAMRC file is permitted"
135 ['] $header behavior >r ( -- )
136 ['] ($header) to $header ( -- )
137 parse-word ( adr,len )
138 nvrecover# create-config-hash -rot ( h2-acf adr,len )
139 2dup create-nvhash ( h2-acf adr,len hash )
140 create-config-hash -rot ( h2-acf h1-acf adr,len )
141 also options definitions ( h2-acf h1-acf adr,len )
142 $create ( h2-acf h1-acf )
143 r> to $header ( h2-acf h1-acf )
144 previous definitions ( h2-acf h1-acf )
145 lastacf >r ( h2-acf h1-acf )
146 dup token, ( h2-acf h1-acf )
147 >body r> swap token! ( h2-acf )
148 token, ( -- )
149\ the next three lines are useful for debugging..
150\ as the keep the association between oldnvramrc and nvramrc
151\ >body r@ swap token! ( h2-acf )
152\ dup token, ( h2-acf )
153\ >body r> swap token! ( -- )
154 0 l, ( -- )
155 use-actions
156 true to nvramrc-created?
157;
158
159unexported-words resident