Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / obp / obp / dev / sun4v-devices / legion-nvram / nvram.tok
CommitLineData
920dae64
AT
1\ ========== Copyright Header Begin ==========================================
2\
3\ Hypervisor Software File: nvram.tok
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: @(#)nvram.tok 1.2 07/06/22
43purpose:
44copyright: Copyright 2006 Sun Microsystems, Inc. All Rights Reserved
45copyright: Use is subject to license terms.
46
47Fcode-Version3
48
49" nvram" device-name
50" nvram" device-type
51
52my-space encode-int " reg" property
53
54headerless
55
560 constant nvraw-base
57h# 1fe0 constant /nvraw-region
58
590 constant nvfixed-base
60h# 40 constant /nvfixed-region
61
62nvfixed-base /nvfixed-region + constant nvhash-base
63h# 1ee0 constant /nvhash-region
64
65nvhash-base /nvhash-region + constant keystore-base
66h# 100 constant /keystore-region
67
68
690 instance value psize \ Partition size
700 instance value basepos \ Absolute offset of this partition
710 instance value filepos \ Current position in partition
72
73h# f2 constant nvram-read-fun
74h# f3 constant nvram-write-fun
75
76h# 80 constant fast-trap
77
78-1 h# 1fff - constant page#mask
79
80: >ra ( va -- ra )
81 dup >physical drop ( vaddr papage )
82 swap page#mask invert and or ( ra )
83;
84
85: hget ( offset buf,len fun# trap# -- len status )
86 >r >r swap >ra swap ( offset raddr len )
87 \ 3 args in, 2 out
88 3 2 r> r> htrap ( len status )( R: )
89;
90
91alias hput hget
92
93: nvram-read ( offset addr len -- #bytes errno )
94 nvram-read-fun fast-trap hget
95;
96
97: nvram-write ( offset addr len -- #bytes errno )
98 nvram-write-fun fast-trap hput
99;
100
101: $= ( adr,len adr2,len -- same? )
102 rot tuck <> if 3drop false exit then comp 0=
103;
104
105: clip-range ( len -- len' ) psize filepos - min ;
106: bump-pos ( n -- ) filepos + psize min to filepos ;
107
108external
109
110: open ( -- true )
111 nvhash-base /nvhash-region
112 my-args " fixed" $= if 2drop nvfixed-base /nvfixed-region then
113 my-args " keys" $= if 2drop keystore-base /keystore-region then
114 my-args " raw" $= if 2drop nvraw-base /nvraw-region then
115 to psize to basepos ( )
116 0 to filepos ( )
117 true ( true )
118;
119
120: close ( -- ) ;
121
122: sync ( -- ) ;
123
124: seek ( lo hi -- fail? )
125 drop dup 0< if psize + then ( offset )
126 dup 0 psize within if ( offset )
127 to filepos false ( false )
128 else ( offset )
129 drop true ( true )
130 then ( failed? )
131;
132
133: read ( adr len -- len' )
134 clip-range basepos filepos + -rot nvram-read if
135 drop 0
136 then
137 dup bump-pos
138;
139
140: write ( adr len -- len' )
141 clip-range basepos filepos + -rot nvram-write if
142 drop 0
143 then
144 dup bump-pos
145;
146
147\ return the number of bytes available..
148: size ( -- n ) psize filepos - ;
149
150end0