Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / obp / obp / arch / sun4v / mdlib.fth
CommitLineData
920dae64
AT
1\ ========== Copyright Header Begin ==========================================
2\
3\ Hypervisor Software File: mdlib.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: @(#)mdlib.fth 1.3 07/02/12
43purpose:
44copyright: Copyright 2007 Sun Microsystems, Inc. All Rights Reserved
45copyright: Use is subject to license terms.
46
47fload ${BP}/arch/sun4v/mdnode.fth
48
49headerless
50
51: md-prop-match? ( prop name$ type -- match? )
52 -rot 2swap ( name$ prop type )
53 over mde-type over = swap -1 = or if ( name$ prop )
54 mde-name $= ( match? )
55 else ( name$ prop )
56 3drop false ( false )
57 then ( match? )
58;
59
60headers
61
62: md-node-name ( entry -- $name ) mde-name ;
63: md-prop-name ( entry -- $name ) mde-name ;
64
65: md-prop-type ( entry -- type ) mde-type ;
66
67: md-next-node ( node -- nextnode | 0 )
68 ?dup 0= if ( )
69 md-nodeblk ( nodeblk )
70 else ( node )
71 >mde-next unaligned-x@ mde-index>adr ( node' )
72 then ( node' )
73 md-noops-skip ( nextnode )
74 dup mde-type MD_LIST_END = if
75 drop 0
76 then ( nextnode | 0 )
77;
78
79: md-next-prop ( node prev -- nextprop | 0 )
80 ?dup if nip then /md-entry + ( mdentry )
81 md-noops-skip ( nextprop )
82 dup mde-type MD_NODE_END = if
83 drop 0
84 then ( nextprop | 0 )
85;
86
87: md-find-prop ( node name$ type -- prop | 0 )
88 >r rot r> swap ( name$ type node )
89 dup 0 md-next-prop ( name$ type node prop )
90 begin dup while ( name$ type node prop )
91 tuck 2>r ( name$ type prop ) ( r: node prop )
92 2over 3 pick md-prop-match? if ( name$ type )
93 3drop 2r> nip exit ( prop )
94 then ( name$ type )
95 2r> over swap md-next-prop ( name$ type prop nextprop ) ( r: )
96 repeat 2drop 3drop 0 ( 0 )
97;
98
99: md-decode-prop ( prop -- $data,type | val,type | 0 )
100 dup mde-type ( prop type )
101 dup case ( prop type type )
102 MD_PROP_VAL of swap mde-value swap endof ( val type )
103 MD_PROP_STR of swap mde-data 1- rot endof ( buf,len type )
104 MD_PROP_DATA of swap mde-data rot endof ( buf,len type )
105 MD_PROP_ARC of swap mde-value
106 mde-index>adr swap endof ( node type)
107 ( prop type type ) nip nip 0 swap ( 0 type )
108 endcase
109;
110
111headerless
112
113: md-nametag ( mdetype index len -- nametag )
114 rot d# 56 << swap d# 48 << or or
115;
116
117: md-find-name ( name$ -- index true | false )
118 md-nameblk ( name$ nameblk )
119 md-nameblksz 0 ?do ( name$ nameblk )
120 3dup i + dup cstrlen dup 1+ >r $= if ( name$ nameblk ) ( r: incr )
121 r> 2drop 2drop i true unloop exit ( index true )
122 then r> ( name$ nameblk incr ) ( r: )
123 +loop 3drop false ( false )
124;
125
126headers
127
128: md-find-node ( node|0 $name -- node|0 )
129 tuck ( node len $name )
130 md-find-name 0= if
131 2drop 0 exit ( 0 )
132 then ( node len index )
133 swap MD_NODE -rot ( node type index len )
134 md-nametag swap ( nametag node )
135 begin ( nametag node )
136 md-next-node dup ( nametag next next )
137 while ( nametag next )
138 2dup mde-nametag@ = ( nametag next match? )
139 if nip exit then ( next )
140 repeat
141 nip ( 0 )
142;
143
144
145headerless
146
147: md-next-fwd ( node fwd|0 -- entry|0 )
148 begin
149 over swap md-next-prop dup ( node next )
150 while
151 dup mde-type MD_PROP_ARC = if ( node next )
152 dup mde-name " fwd" $= if ( node next )
153 nip exit ( entry )
154 then ( node next )
155 then ( node next )
156 repeat
157 nip ( 0 )
158;
159
160headers
161
162: md-applyto-fwds ( ??? acf node -- ??? )
163 0 ( ?? acf node 0 )
164 begin
165 2dup md-next-fwd nip dup ( ?? acf node next-fwd|0 next-fwd|0 )
166 while
167 dup mde-value mde-index>adr ( ?? acf node next-fwd fwd-node )
168 -rot 2>r swap >r r@ ( ?? fwd-node acf )
169 catch ?dup if
170 r> 2r> 3drop throw
171 then
172 r> 2r> ( acf node next-fwd )
173 repeat
174 3drop ( )
175;
176
177: md-root-node ( -- node ) 0 " root" md-find-node ;
178
179: md-get-required-prop ( node $name -- [val type] | [buf len type] )
180 3dup -1 md-find-prop ?dup if
181 nip nip nip md-decode-prop ( [val type] | [buf len type] )
182 else
183 rot md-node-name 2swap ( $name $prop )
184 cmn-fatal[ " Missing required property: %s " cmn-append
185 " in node %s" ]cmn-end
186 then
187;
188
189\ This function temporarily sets md-data to some other MD stored in memory
190\ an md-pointer value of 0 means use the guest-md
191\ !IMPORTANT! - When using this function, ALWAYS reset the md-data pointer back
192\ to the guest-md using the command '0 md-set-working-md' when finished
193: md-set-working-md ( md-pointer -- )
194 ?dup if
195 to md-data
196 else
197 guest-md to md-data
198 then
199;
200
201headerless