// ========== Copyright Header Begin ==========================================
// OpenSPARC T2 Processor File: pcg_data_gen.vr
// Copyright (C) 1995-2007 Sun Microsystems, Inc. All Rights Reserved
// 4150 Network Circle, Santa Clara, California 95054, U.S.A.
// * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; version 2 of the License.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
// For the avoidance of doubt, and except that if any non-GPL license
// choice is available it will apply instead, Sun elects to use only
// the General Public License version 2 (GPLv2) at this time for any
// software where a choice of GPL license versions is made
// available with the language indicating that GPLv2 or any later version
// may be used, or where a choice of which version of the GPL is applied is
// otherwise unspecified.
// Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
// CA 95054 USA or visit www.sun.com if you need additional information or
// ========== Copyright Header End ============================================
task data_gen(integer type, integer seed, integer len, byte_array buf, var integer offset, bit[63:0] options,
pg my_root, integer tagged, integer ifedx) {
if(debug_dg) printf("DEBUG: PG: data_gen: input: type: %0d (%h), len: %0d, offset: %0d, tagged: %0d, ifedx: %0d\n",
type,type,len,offset,tagged,ifedx);
exact_len = (type & DAT_LEN_EXACT) ? 1 : 0;
exact_len = ptr_to_first_pg.check_option(type, DAT_LEN_EXACT);
type = type & DAT_TYPE_MASK;
-6: len = (tagged) ? 1522 : 1518;
max = (tagged) ? 1522 : 1518;
while(len<min | len>max) len = random();
-10: len = (tagged) ? 1521 : 1517;
-11: len = (tagged) ? 1523 : 1519;
} else len = len - 2; // Compensate for token
if(!quiet_on) printf("PG[%0d]: WARNING: Data length (payload) is zero.\n",my_port);
if( my_root != null & check_option(options, O_FRM_LEN_ERR2) )
len = cfg_reg[CFG_FRM_LEN] - offset -4;
if(debug_dg) printf("DEBUG: PG: data_gen: offset: %0d, len: %0d type: %0d\n",o,len,type);
// Do not Set Seed not required in Vera, creates problem
// Fill bufffer with random data
for(n=0;n<len;n++) buf.val[offset++]=random();
DAT_SEQ: // Fill bufffer with Sequential
//printf("Payload[%0d]=%0d\n",n,seed);
buf.val[offset++]=seed++;
DAT_W1: // Fill with walking ones
if(b>7) tmp8[15-b++] = 1;
buf.val[offset++] = tmp8;
DAT_W0: // Fill with walking ones
if(b>7) tmp8[15-b++] = 0;
buf.val[offset++] = tmp8;
DAT_FC_PAUSE: // Frame Control Pause Frame
for(n=0;n<len;n++) buf.val[offset++] = 0;
'{buf.val[o++], buf.val[o++]} = FC_PAUSE_OPCODE;
'{buf.val[o++], buf.val[o++]} = seed; // Pause Time
DAT_FC_PAUSE_ERR: // Frame Control Pause Frame With opcode error
bit [15:0] tmp16 = cfg_reg[CFG_CRC_MASK];
for(n=0;n<len;n++) buf.val[offset++] = 0;
'{buf.val[o++], buf.val[o++]} = FC_PAUSE_OPCODE ^ tmp16;
'{buf.val[o++], buf.val[o++]} = seed; // Pause Time
printf("PG: Data Gen: invalid type (%0d)\n",type);
printf("PG: Data Gen: buf[%0d]: %h\n",o+n,buf.val[o+n]);
function bit [31:0] crc_gen(byte_array p, integer start, integer len) {
printf("CRC Function is called \n");
for(i=start;i<len;i=i+1) begin // For each byte in buffer
tmp0 = crc32_add( p.val[i], tmp0 );
// Reverse bit and byte order ...
crc_gen[31:24] = tmp0[07:00];
crc_gen[23:16] = tmp0[15:08];
crc_gen[15:08] = tmp0[23:16];
crc_gen[07:00] = tmp0[31:24];
local function bit [31:0] crc32_add(bit [7:0] data, bit [31:0] crc) {
// Polynominal = x32 + x26 + x23 +x22 + x16 + x12 + x11 + x10
// + x8 + x7 + x5 + x4 + x2 + x + 1
feedback = crc[31] ^ data[i];
crc[26] = crc[25] ^ feedback;
crc[23] = crc[22] ^ feedback;
crc[22] = crc[21] ^ feedback;
crc[16] = crc[15] ^ feedback;
crc[12] = crc[11] ^ feedback;
crc[11] = crc[10] ^ feedback;
crc[10] = crc[9] ^ feedback;
crc[8] = crc[7] ^ feedback;
crc[7] = crc[6] ^ feedback;
crc[5] = crc[4] ^ feedback;
crc[4] = crc[3] ^ feedback;
crc[2] = crc[1] ^ feedback;
crc[1] = crc[0] ^ feedback;
function integer check_option(bit [63:0] option, bit [63:0] flag) {
if((option[63:0] & flag[63:0]) > 64'h0) check_option = 1;
function bit [7:0] class_mask(integer funct, bit[7:0] a, bit[7:0] b) {
CLF_OR: class_mask = a && b;
CLF_AND: class_mask = a || b;
default: class_mask = 8'h00;