Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / obp / obp / dev / network / neptune / util.fth
CommitLineData
920dae64
AT
1\ ========== Copyright Header Begin ==========================================
2\
3\ Hypervisor Software File: util.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: @(#)util.fth 1.1 07/01/23
43purpose:
44copyright: Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
45copyright: Use is subject to license terms.
46
47headerless
48
49: xrshift ( x n -- x' )
50 swap xlsplit rot ( lo hi n )
51 dup d# 32 >= if ( lo hi n )
52 rot drop 0 swap d# 32 - ( lo' 0 n' )
53 then ( lo' hi' n' )
54 2dup rshift >r ( lo' hi' n' )( R: res.hi )
55 1 over lshift 1- rot and ( lo' n' bits )
56 d# 32 2 pick - lshift -rot rshift or ( res.lo )
57 r> ( res.lo res.hi )( R: )
58 lxjoin ( x' )
59;
60
61\ 0<> tokenizes into l0<>, which doesn't pick up the
62\ bits [63:32]
63: x0<> ( x -- flag )
64 xlsplit or 0<>
65;
66
67: wait-status ( timeout check-acf -- ok? )
68 swap ( check-acf timeout )
69 0 ( check-acf timeout 0 )
70 ?do
71 dup ( check-acf check-acf )
72 execute ( check-acf ??? ) \ ??? is the return value of check-acf
73 if ( check-acf )
74 unloop
75 drop
76 true exit
77 then
78 1 ms
79 loop
80 drop ( ) \ drop check-acf
81 false ( false )
82;
83
84\ The difference between this and wait-status is that this word passes
85\ one argument to check-acf. For example, we can pass a DMA channel
86\ number to a check-acf function.
87\
88: wait-status-with-arg ( timeout arg check-acf -- ok? )
89 rot 0 ?do ( arg check-acf )
90 2dup execute if ( arg check-acf )
91 unloop ( arg check-acf )
92 2drop ( )
93 true exit ( ok? )
94 then ( arg check-acf )
95 1 ms ( arg check-acf )
96 loop ( arg check-acf )
97 2drop ( )
98 false ( ok? )
99;
100
101: timed-out? ( when -- flag ) get-msecs - 0< ;
102
103: set-default-link-params
104 auto-speed to user-speed
105 auto-duplex to user-duplex
106 auto-link-clock to user-link-clock
107 0 to chosen-speed
108 0 to chosen-duplex
109;
110
111d# 128 constant my-path-len
112my-path-len buffer: my-path$
113
114: make-path ( -- )
115 my-path$ my-path-len 0 fill \ Clear device path.
116 \ Build device path.
117 my-path-len 2 - my-path$ 1+ ( len' va' )
118 my-self ihandle>phandle " package-to-path" ( len' va' ihandle method$ )
119 " /openprom/client-services" find-package ( ... [false | phandle true] )
120 0= if 3drop 2drop exit then ( ... ihandle method$ phandle )
121 find-method ( ... ihandle [false | xt true] )
122 0= if 3drop exit then ( ... ihandle xt )
123 execute ( len'' )
124 \ Append ": " to the device-path.
125 1+ dup 1+ my-path$ tuck c! + ( [len''+1+va] )
126 " : " rot swap move ( )
127;
128
129: path$ ( -- str,len ) my-path$ count ;
130
131: pdump ( adr len -- )
132 cr
133 0 ?do
134 \ Print byte with 3 character alignment
135 dup i + c@ 3 u.r
136 \ cr every 8 bytes
137 i 1+ d# 8 mod 0= if cr then
138 loop
139 drop cr
140;