Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / obp / obp / dev / network / bge / bge-test.fth
CommitLineData
920dae64
AT
1\ ========== Copyright Header Begin ==========================================
2\
3\ Hypervisor Software File: bge-test.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: @(#)bge-test.fth 1.1 02/09/06
43purpose: Test Routines
44copyright: Copyright 2002 Sun Microsystems, Inc. All Rights Reserved
45copyright: Use is subject to license terms.
46
47hex
48
49headers
50
51create loopback-data
52 ff c, 00 c, \ Ones and zeroes
53 01 c, 02 c,
54 04 c, 08 c,
55 10 c, 20 c,
56 40 c, 80 c, \ Walking ones
57 fe c, fd c,
58 fb c, f7 c,
59 ef c, 0df c,
60
61 0bf c, 7f c, \ Walking zeroes
62 55 c, aa c,
63 ff c, 00 c, \ Ones and zeroes
64 01 c, 02 c,
65 04 c, 08 c,
66 10 c, 20 c,
67 40 c, 80 c, \ Walking ones
68 fe c, fd c,
69
70 fb c, f7 c,
71 ef c, 0df c,
72 bf c, 7f c, \ Walking zeroes
73 55 c, aa c,
74 01 c, 02 c,
75 04 c, 08 c,
76 10 c, 20 c,
77 40 c, 80 c, \ Walking ones
78 da c, da c,
79 da c, da c,
80
81d# 52 constant /loopback-data
82d# 64 constant /loopback-pkt
83
84: loopback-buffer ( -- adr len )
85 get-tx-buffer
86 mac-address drop over 6 cmove \ Set dest address
87 mac-address drop over 6 + 6 cmove \ Set source address
88 loopback-data over d# 12 + /loopback-data cmove \ Set buffer contents
89 /loopback-pkt
90;
91
92: pdump ( adr -- )
93 base @ >r hex
94 dup d# 10 bounds do i c@ 3 u.r loop cr
95 d# 10 + dup d# 10 bounds do i c@ 3 u.r loop cr
96 d# 10 + dup d# 10 bounds do i c@ 3 u.r loop cr
97 d# 10 + dup d# 10 bounds do i c@ 3 u.r loop cr
98 d# 10 + dup d# 10 bounds do i c@ 3 u.r loop cr
99 d# 10 + d# 2 bounds do i c@ 3 u.r loop cr
100 r> base !
101;
102
103: .loopback ( -- )
104 mac-mode int-loopback = if
105 ." Internal Loopback test -- "
106 else
107 ." Unknown mode"
108 then
109;
110
111: check-len&data ( pkt len -- ok? )
112
113 dup /loopback-pkt <> if ( pkt len )
114 .loopback ." Wrong packet length. Expected" ( pkt len )
115 /loopback-pkt .d ( pkt len )
116 ." Received" .d ( pkt )
117 drop false exit ( false )
118 then
119
120 swap dup d# 12 + loopback-data /loopback-data comp 0<> if
121 .loopback
122 ." Received packet contained incorrect data. Expected: " cr
123 loopback-data /loopback-data pdump
124 ." Observed" d# 12 + swap pdump
125 false exit
126 then 2drop
127
128 true
129;
130
131: timed-receive ( timeout-ms -- [ buf-handle pkt len ] err? )
132 0 ?do
133 receive-ready? if
134 receive dup if
135 unloop 4 - \ last 4 bytes = checksum
136 false exit
137 then
138 2drop return-buffer
139 then
140 1 ms
141 loop true
142;
143
144\ headers
145
146: (loopback-test) ( -- success? )
147 loopback-buffer transmit 0= if
148 .loopback ." Cannot send loopback packet" cr
149 false
150 else
151 d# 2000 timed-receive if ( handle pkt len )
152 .loopback ." Did not receive expected loopback packet" cr
153 false
154 else ( handle pkt len )
155 check-len&data ( handle flag )
156 swap return-buffer ( flag )
157 then
158 then
159;
160
161: loopback-test ( loopback-mode -- pass? )
162 mac-mode >r
163 to mac-mode
164 net-on if
165 configure-mac
166 (loopback-test)
167 else
168 false
169 then
170 net-off
171 r> to mac-mode
172;
173
174: watch-test ( -- )
175 ." Looking for Ethernet Packets." cr
176 ." '.' is a Good Packet. 'X' is a Bad Packet." cr
177 ." Type any key to stop." cr
178 begin
179 key? 0=
180 while
181 receive-ready? if
182 receive if ." ." else ." X" then
183 drop return-buffer
184 then
185 repeat
186 key drop
187;