Commit | Line | Data |
---|---|---|
86530b38 AT |
1 | // ========== Copyright Header Begin ========================================== |
2 | // | |
3 | // OpenSPARC T2 Processor File: pcg_data_gen.vr | |
4 | // Copyright (C) 1995-2007 Sun Microsystems, Inc. All Rights Reserved | |
5 | // 4150 Network Circle, Santa Clara, California 95054, U.S.A. | |
6 | // | |
7 | // * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
8 | // | |
9 | // This program is free software; you can redistribute it and/or modify | |
10 | // it under the terms of the GNU General Public License as published by | |
11 | // the Free Software Foundation; version 2 of the License. | |
12 | // | |
13 | // This program is distributed in the hope that it will be useful, | |
14 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | // GNU General Public License for more details. | |
17 | // | |
18 | // You should have received a copy of the GNU General Public License | |
19 | // along with this program; if not, write to the Free Software | |
20 | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
21 | // | |
22 | // For the avoidance of doubt, and except that if any non-GPL license | |
23 | // choice is available it will apply instead, Sun elects to use only | |
24 | // the General Public License version 2 (GPLv2) at this time for any | |
25 | // software where a choice of GPL license versions is made | |
26 | // available with the language indicating that GPLv2 or any later version | |
27 | // may be used, or where a choice of which version of the GPL is applied is | |
28 | // otherwise unspecified. | |
29 | // | |
30 | // Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, | |
31 | // CA 95054 USA or visit www.sun.com if you need additional information or | |
32 | // have any questions. | |
33 | // | |
34 | // ========== Copyright Header End ============================================ | |
35 | task data_gen(integer type, integer seed, integer len, byte_array buf, var integer offset, bit[63:0] options, | |
36 | pg my_root, integer tagged, integer ifedx) { | |
37 | integer min,max,n,o,b,l; | |
38 | bit [15:0] tmp16; | |
39 | bit [7:0] tmp8,s; | |
40 | integer exact_len; | |
41 | integer debug_dg = 1; | |
42 | ||
43 | if(debug_dg) printf("DEBUG: PG: data_gen: input: type: %0d (%h), len: %0d, offset: %0d, tagged: %0d, ifedx: %0d\n", | |
44 | type,type,len,offset,tagged,ifedx); | |
45 | ||
46 | ||
47 | exact_len = (type & DAT_LEN_EXACT) ? 1 : 0; | |
48 | exact_len = ptr_to_first_pg.check_option(type, DAT_LEN_EXACT); | |
49 | type = type & DAT_TYPE_MASK; | |
50 | ||
51 | if(len<0) exact_len = 1; | |
52 | ||
53 | case(len) { | |
54 | -1: len = 64; | |
55 | -2: len = 128; | |
56 | -3: len = 256; | |
57 | -4: len = 512; | |
58 | -5: len = 1024; | |
59 | -6: len = (tagged) ? 1522 : 1518; | |
60 | -7: { | |
61 | // len = random(seed); | |
62 | len = random(); | |
63 | min = 64; | |
64 | max = (tagged) ? 1522 : 1518; | |
65 | while(len<min | len>max) len = random(); | |
66 | } | |
67 | -8: len = 63-offset-4; | |
68 | -9: len = 65-offset-4; | |
69 | -10: len = (tagged) ? 1521 : 1517; | |
70 | -11: len = (tagged) ? 1523 : 1519; | |
71 | } | |
72 | ||
73 | if(exact_len) { | |
74 | len = len-offset-4; | |
75 | if(ifedx) len = len - 4; | |
76 | } else len = len - 2; // Compensate for token | |
77 | ||
78 | if(len<0) { | |
79 | len = 0; | |
80 | if(!quiet_on) printf("PG[%0d]: WARNING: Data length (payload) is zero.\n",my_port); | |
81 | } | |
82 | ||
83 | o=offset; // Safe offset | |
84 | b = seed; | |
85 | ||
86 | if( my_root != null & check_option(options, O_FRM_LEN_ERR2) ) | |
87 | len = cfg_reg[CFG_FRM_LEN] - offset -4; | |
88 | ||
89 | if(debug_dg) printf("DEBUG: PG: data_gen: offset: %0d, len: %0d type: %0d\n",o,len,type); | |
90 | ||
91 | l = 1; | |
92 | case(type) { | |
93 | DAT_RAND:{ | |
94 | // Do not Set Seed not required in Vera, creates problem | |
95 | // random(seed); | |
96 | random(); | |
97 | ||
98 | // Fill bufffer with random data | |
99 | for(n=0;n<len;n++) buf.val[offset++]=random(); | |
100 | } | |
101 | ||
102 | DAT_SEQ: // Fill bufffer with Sequential | |
103 | for(n=0;n<len;n++) { | |
104 | //printf("Payload[%0d]=%0d\n",n,seed); | |
105 | buf.val[offset++]=seed++; | |
106 | } | |
107 | ||
108 | DAT_W1: // Fill with walking ones | |
109 | for(n=0;n<len;n++) { | |
110 | tmp8 = 0; | |
111 | tmp16=n; | |
112 | if(l==1) { | |
113 | l=0; | |
114 | if(b<8) tmp8[7-b++] = 1; | |
115 | s = tmp8; | |
116 | } else { | |
117 | l=1; | |
118 | if( s==0 ) | |
119 | if(b>7) tmp8[15-b++] = 1; | |
120 | } | |
121 | if(b>15) b = 0; | |
122 | buf.val[offset++] = tmp8; | |
123 | } | |
124 | DAT_W0: // Fill with walking ones | |
125 | for(n=0;n<len;n++) { | |
126 | tmp8 = 8'hff; | |
127 | if(l==1) { | |
128 | l=0; | |
129 | if(b<8) tmp8[7-b++] = 0; | |
130 | s = tmp8; | |
131 | } else { | |
132 | l=1; | |
133 | if( s==8'hff ) | |
134 | if(b>7) tmp8[15-b++] = 0; | |
135 | } | |
136 | if(b>15) b = 0; | |
137 | buf.val[offset++] = tmp8; | |
138 | } | |
139 | DAT_FC_PAUSE: // Frame Control Pause Frame | |
140 | { | |
141 | len = 64-offset-4; | |
142 | o = offset; | |
143 | for(n=0;n<len;n++) buf.val[offset++] = 0; | |
144 | '{buf.val[o++], buf.val[o++]} = FC_PAUSE_OPCODE; | |
145 | '{buf.val[o++], buf.val[o++]} = seed; // Pause Time | |
146 | } | |
147 | DAT_FC_PAUSE_ERR: // Frame Control Pause Frame With opcode error | |
148 | { | |
149 | bit [15:0] tmp16 = cfg_reg[CFG_CRC_MASK]; | |
150 | len = 64-offset-4; | |
151 | o = offset; | |
152 | for(n=0;n<len;n++) buf.val[offset++] = 0; | |
153 | '{buf.val[o++], buf.val[o++]} = FC_PAUSE_OPCODE ^ tmp16; | |
154 | '{buf.val[o++], buf.val[o++]} = seed; // Pause Time | |
155 | } | |
156 | default: | |
157 | { | |
158 | print_err(); | |
159 | printf("PG: Data Gen: invalid type (%0d)\n",type); | |
160 | } | |
161 | } | |
162 | ||
163 | if(debug_dg & 0) | |
164 | for(n=0;n<len;n++) | |
165 | printf("PG: Data Gen: buf[%0d]: %h\n",o+n,buf.val[o+n]); | |
166 | } | |
167 | ||
168 | ||
169 | function bit [31:0] crc_gen(byte_array p, integer start, integer len) { | |
170 | bit [31:0] tmp0, poly; | |
171 | integer i; | |
172 | ||
173 | printf("CRC Function is called \n"); | |
174 | ||
175 | tmp0 = 32'hffff_ffff; | |
176 | ||
177 | for(i=start;i<len;i=i+1) begin // For each byte in buffer | |
178 | tmp0 = crc32_add( p.val[i], tmp0 ); | |
179 | end | |
180 | tmp0 = ~tmp0; | |
181 | ||
182 | // Reverse bit and byte order ... | |
183 | for(i=0;i<32;i=i+1) | |
184 | crc_gen[i] = tmp0[31-i]; | |
185 | ||
186 | tmp0 = crc_gen; | |
187 | crc_gen[31:24] = tmp0[07:00]; | |
188 | crc_gen[23:16] = tmp0[15:08]; | |
189 | crc_gen[15:08] = tmp0[23:16]; | |
190 | crc_gen[07:00] = tmp0[31:24]; | |
191 | ||
192 | } | |
193 | ||
194 | ||
195 | local function bit [31:0] crc32_add(bit [7:0] data, bit [31:0] crc) { | |
196 | bit feedback; | |
197 | integer i; | |
198 | ||
199 | for(i=0;i<8;i=i+1) begin | |
200 | // | |
201 | // CRC-32 | |
202 | // Polynominal = x32 + x26 + x23 +x22 + x16 + x12 + x11 + x10 | |
203 | // + x8 + x7 + x5 + x4 + x2 + x + 1 | |
204 | // | |
205 | feedback = crc[31] ^ data[i]; | |
206 | crc[31:27] = crc[30:26]; | |
207 | crc[26] = crc[25] ^ feedback; | |
208 | crc[25] = crc[24]; | |
209 | crc[24] = crc[23]; | |
210 | crc[23] = crc[22] ^ feedback; | |
211 | crc[22] = crc[21] ^ feedback; | |
212 | crc[21:17] = crc[20:16]; | |
213 | crc[16] = crc[15] ^ feedback; | |
214 | crc[15:13] = crc[14:12]; | |
215 | crc[12] = crc[11] ^ feedback; | |
216 | crc[11] = crc[10] ^ feedback; | |
217 | crc[10] = crc[9] ^ feedback; | |
218 | crc[9] = crc[8]; | |
219 | crc[8] = crc[7] ^ feedback; | |
220 | crc[7] = crc[6] ^ feedback; | |
221 | crc[6] = crc[5]; | |
222 | crc[5] = crc[4] ^ feedback; | |
223 | crc[4] = crc[3] ^ feedback; | |
224 | crc[3] = crc[2]; | |
225 | crc[2] = crc[1] ^ feedback; | |
226 | crc[1] = crc[0] ^ feedback; | |
227 | crc[0] = feedback; | |
228 | end | |
229 | ||
230 | crc32_add = crc; | |
231 | ||
232 | } | |
233 | ||
234 | function integer check_option(bit [63:0] option, bit [63:0] flag) { | |
235 | if((option[63:0] & flag[63:0]) > 64'h0) check_option = 1; | |
236 | else check_option = 0; | |
237 | } | |
238 | ||
239 | ||
240 | function bit [7:0] class_mask(integer funct, bit[7:0] a, bit[7:0] b) { | |
241 | case(funct) { | |
242 | CLF_SRC: class_mask = a; | |
243 | CLF_DST: class_mask = b; | |
244 | CLF_OR: class_mask = a && b; | |
245 | CLF_AND: class_mask = a || b; | |
246 | default: class_mask = 8'h00; | |
247 | } | |
248 | } | |
249 | ||
250 |