Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / obp / obp / pkg / confvar / fixed-access.fth
CommitLineData
920dae64
AT
1\ ========== Copyright Header Begin ==========================================
2\
3\ Hypervisor Software File: fixed-access.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: @(#)fixed-access.fth 1.9 03/10/28
43purpose:
44copyright: Copyright 1998-2003 Sun Microsystems, Inc. All Rights Reserved
45copyright: Use is subject to license terms.
46
47\
48\ Fixed variables don't have matching hash codes. they are based upon
49\ fixed addresses within the device.
50\
51\ Fixed config variables may not be created at runtime, so all the
52\ construction routines are transient.
53\
54\ Format of a fixed definition:
55\ seek-pos /l with bit 31 set to indicate no default
56\ len 1 data length
57\
58\ For the fixed data we do write through, with the data being cached.
59\ We cache all the 'fixed' bytes, but only checksum from 0x20 to the end.
60\
61\
62
63unexported-words
64
650 value fixed-buffer \ Cached data
660 value fixed-xfer-buffer \ Transfer buffer
67false value fixed-store-disabled? \ Disable device updates
68d# 256 constant /max-dev-path \ Max len nvram device path with args
69
70exported-headerless
71
72false value fixed-options-open?
73
74: open-nvfixed-region ( nvdevice$ -- ok? )
75 \ Concatenate device path and argument strings into allocated memory
76 /max-dev-path dup alloc-mem tuck 0 2swap 2>r $add ( dev$ ) ( r: buf,len )
77 " :fixed" 2swap $add nvfixed-open if ( )
78 nvfixed-size dup la1+ alloc-mem is fixed-buffer ( n )
79 alloc-mem is fixed-xfer-buffer ( )
80 true dup to fixed-options-open? ( true )
81 else ( )
82 false ( false )
83 then ( ok? )
84 2r> free-mem ( ok? )
85;
86
87: init-nvfixed-region ( -- )
88 fixed-options-open? if ( )
89 0 nvfixed-seek ( )
90 fixed-buffer nvfixed-size 2dup la1+ erase ( adr,len )
91 nvfixed-write ( )
92 0 nvfixed-seek ( )
93 then ( )
94;
95
96: load-nvfixed-data ( -- )
97 fixed-options-open? if ( )
98 0 nvfixed-seek ( )
99 fixed-buffer la1+ nvfixed-size nvfixed-read ( )
100 nvmagic# fixed-buffer l! ( )
101 0 nvfixed-seek ( )
102 then ( )
103;
104
105: nvfixed-region-ok? ( -- ) true ;
106
107exported-headers
108transient
109
110variable fixed-ptr
111
112: fixed-alloc ( n -- ptr )
113 fixed-ptr dup @ >r +! r>
114;
115
116: fixed-create \ name ( ptr -- )
117 ['] $header behavior >r ( ptr )
118 ['] ($header) to $header ( ptr )
119 parse-word ( ptr adr,len )
120 also options definitions ( ptr adr,len )
121 $create ( ptr )
122 r> to $header ( ptr )
123 previous definitions ( ptr )
124 l, ( -- )
125;
126
127: fixed-config \ name ( len -- )
128 fixed-alloc fixed-create ( -- )
129;
130
131: nodefault-fixed-config \ name ( len -- )
132 fixed-alloc h# 8000.0000 or fixed-create ( -- )
133;
134
135headerless resident
136
137unexported-words
138
139: fixed-len@ ( apf -- len ) la1+ c@ ;
140: fixed-pos@ ( apf -- pos ) unaligned-l@ h# 8000.0000 invert and ;
141
142: >fixed-default ( apf -- adr ) la1+ 1+ ;
143: fixed-nodefault? ( apf -- flag ) unaligned-l@ h# 8000.0000 and ;
144
145: >fixed-buffer ( pos -- adr ) fixed-buffer la1+ + ;
146
147: fixed-adr ( apf -- adr )
148 fixed-options-open? if
149 fixed-pos@ >fixed-buffer
150 else
151 dup fixed-nodefault? if drop <no-default> else >fixed-default then
152 then
153;
154
155: (fixed-write) ( adr len pos -- )
156 fixed-store-disabled? 0= if ( adr len pos )
157 nvfixed-ftell >r ( adr len pos ) ( r: curpos )
158 nvfixed-seek nvfixed-write ( )
159 r> nvfixed-seek ( ) ( r: )
160 nvfixed-sync ( )
161 else ( adr len pos )
162 3drop ( )
163 then ( )
164;
165
166: fixed-write ( adr len apf -- )
167\nvdebug ." setting fixed data "
168 fixed-options-open? if ( adr len apf )
169 fixed-pos@ dup >r ( adr len pos ) ( r: pos )
170 >fixed-buffer swap 2dup 2>r move 2r> ( bufadr len )
171 r> (fixed-write) ( ) ( r: )
172 else ( adr len apf )
173 3drop ( )
174 then ( )
175;
176
177: fixed-byte! ( byte apf -- )
178 >r fixed-xfer-buffer tuck c! ( adr )
179 /c r> fixed-write ( )
180;
181
182: fixed-int! ( int apf -- )
183 >r fixed-xfer-buffer tuck l! ( adr )
184 /l r> fixed-write ( )
185;
186
187: fixed-xint! ( int apf -- )
188 >r fixed-xfer-buffer tuck x! ( adr )
189 /x r> fixed-write ( )
190;
191
192: fixed-string@ ( apf -- adr len )
193 >r r@ fixed-adr ( adr )
194 count ( adr' len )
195 r> fixed-len@ 2- min ( adr' len' )
196;
197
198: fixed-string! ( adr len apf -- )
199 >r r@ fixed-len@ 2- min tuck ( len' adr len' )
200 fixed-xfer-buffer pack swap 2+ r> ( adr len' apf )
201 fixed-write ( )
202;
203
204unexported-words