Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / obp / obp / dev / sun4v-devices / nvram / methods.fth
CommitLineData
920dae64
AT
1\ ========== Copyright Header Begin ==========================================
2\
3\ Hypervisor Software File: methods.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: @(#)methods.fth 1.1 06/02/16
43purpose:
44copyright: Copyright 2006 Sun Microsystems, Inc. All Rights Reserved
45copyright: Use is subject to license terms.
46
47headerless
48
49h# 0 constant fixbase
50h# 40 constant fixsize
51fixbase fixsize + constant nvbase
52h# 16c0 constant nvsize
53
54nvbase nvsize + constant keystore-base
55h# 100 constant keystore-size
56
57h# 0 constant rawbase
58h# 2000 constant rawsize
59
600 instance value basepos \ Absolute offset of this partition
610 instance value filepos \ Current position in partition
620 instance value psize \ Partition size
63
64: clip-range ( len -- len' ) psize filepos - min ;
65: bump-pos ( n -- ) filepos + psize min to filepos ;
66: range-bad? ( offset -- offset flag ) dup 0 psize within invert ;
67
68struct
69 /w field >offset
70 /c field >command
71 /c field >send-size
72constant /send-hdr
73
74struct
75 /c field >status
76 /c field >reply-size
77constant /reply-hdr
78
79d# 32 constant blocksize
80
81: setup-pkt ( len cmd -- tx-bytes )
82 dup >r outbuf >command c! ( len )
83 basepos filepos + outbuf >offset w! ( )
84 blocksize min dup outbuf >send-size c! ( len' )
85 r> 0= if drop 0 then /send-hdr + ( tx-bytes )
86;
87
88: recv ( -- len )
89 recv if
90 inbuf >status c@ if
91 0
92 else
93 inbuf >reply-size c@ dup filepos + is filepos
94 then
95 else
96 0
97 then
98;
99
100: poll ( acf -- )
101 >r d# 100 begin r@ execute 0= over 0<> and while 1 - 10 ms repeat
102 r> drop 0= if
103 cmn-error[ " NVRAM transfer timed out." ]cmn-end -1 throw
104 then
105;
106
107: (read) ( adr len -- actual-len )
108 0 setup-pkt ( adr bytes )
109 ['] send? poll send ( adr )
110 ['] recv? poll recv ?dup if ( adr len )
111 tuck inbuf /reply-hdr + -rot move ( len true )
112 else ( adr )
113 drop 0 ( 0 )
114 then
115;
116
117: (write) ( adr len -- actual-len )
118 1 setup-pkt ( adr bytes )
119 swap outbuf /send-hdr + outbuf >send-size c@ move ( bytes )
120 ['] send? poll send ( )
121 ['] recv? poll recv ( len )
122;
123
1240 instance value action
125
126: xfer ( buf len acf -- len )
127 is action
128 clip-range
129 0 -rot begin ( bytes buf len )
130 ?dup while ( bytes buf len )
131 2dup blocksize min ( bytes buf len buf n )
132 action catch if ( bytes buf len buf n )
133 3drop 0 ( bytes buf 0 )
134 else ( bytes buf len n )
135 tuck - >r ( bytes buf n )
136 tuck + >r ( bytes n )
137 + r> r> ( bytes buf' len' )
138 then ( bytes buf' len' )
139 repeat drop ( bytes )
140;
141
142: $= ( adr,len adr2,len -- same? )
143 rot tuck <> if 3drop false exit then comp 0=
144;
145
146external
147
148: read ( buf len -- len' ) ['] (read) xfer ;
149
150: write ( buf len -- len' ) ['] (write) xfer ;
151
152: open ( -- true )
153 nvbase nvsize
154 my-args " keys" $= if 2drop keystore-base keystore-size then
155 my-args " fixed" $= if 2drop fixbase fixsize then
156 my-args " raw" $= if 2drop rawbase rawsize then
157 to psize to basepos ( )
158 0 to filepos ( )
159 1 /send-hdr blocksize + init-svc
160 true
161;
162
163: close ( -- ) finish-svc ;
164
165: seek ( lo hi -- error )
166 drop dup 0< if psize + then
167 range-bad? tuck if drop else to filepos then ( fail? )
168;
169
170: size ( -- n ) psize filepos - ;
171
172: sync ( -- ) ;
173
174headers