Initial commit of OpenSPARC T2 design and verification files.
[OpenSPARC-T2-DV] / verif / model / pcie / dll / calculate_lcrc.cpp
CommitLineData
86530b38
AT
1// ========== Copyright Header Begin ==========================================
2//
3// OpenSPARC T2 Processor File: calculate_lcrc.cpp
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#include "dll_top.hpp"
36
37namespace pcie {
38
39 /**
40 This function calculates the LCRC value
41 **/
42 sc_uint<32> dll_top::calculate_lcrc(RefPciePacket received_packet,int pkt_begin,int pkt_end)
43 {
44 int index,byte_index;;
45 sc_uint<32> tmp_lcrc;
46 sc_uint<8> byte;
47 sc_uint<32> lcrc_mapped;
48
49 /// Resetting the initial lcrc value
50 lcrc = 0xffffffff;
51
52 for(byte_index=pkt_begin; byte_index < pkt_end; byte_index++)
53 {
54 byte = received_packet->get_byte(byte_index);
55 for (index=0; index < 8; index++)
56 {
57 tmp_lcrc = lcrc;
58 lcrc[0] = byte[index] ^ tmp_lcrc[31];
59 lcrc[1] = byte[index] ^ tmp_lcrc[0] ^ tmp_lcrc[31];
60 lcrc[2] = byte[index] ^ tmp_lcrc[1] ^ tmp_lcrc[31];
61 lcrc[3] = tmp_lcrc[2];
62 lcrc[4] = byte[index] ^ tmp_lcrc[3] ^ tmp_lcrc[31];
63 lcrc[5] = byte[index] ^ tmp_lcrc[4] ^ tmp_lcrc[31];
64 lcrc[6] = tmp_lcrc[5];
65 lcrc[7] = byte[index] ^ tmp_lcrc[6] ^ tmp_lcrc[31];
66 lcrc[8] = byte[index] ^ tmp_lcrc[7] ^ tmp_lcrc[31];
67 lcrc[9] = tmp_lcrc[8];
68 lcrc[10] = byte[index] ^ tmp_lcrc[9] ^ tmp_lcrc[31];
69 lcrc[11] = byte[index] ^ tmp_lcrc[10] ^ tmp_lcrc[31];
70 lcrc[12] = byte[index] ^ tmp_lcrc[11] ^ tmp_lcrc[31];
71 lcrc[13] = tmp_lcrc[12];
72 lcrc[14] = tmp_lcrc[13];
73 lcrc[15] = tmp_lcrc[14];
74 lcrc[16] = byte[index] ^ tmp_lcrc[15] ^ tmp_lcrc[31];
75 lcrc[17] = tmp_lcrc[16];
76 lcrc[18] = tmp_lcrc[17];
77 lcrc[19] = tmp_lcrc[18];
78 lcrc[20] = tmp_lcrc[19];
79 lcrc[21] = tmp_lcrc[20];
80 lcrc[22] = byte[index] ^ tmp_lcrc[21] ^ tmp_lcrc[31];
81 lcrc[23] = byte[index] ^ tmp_lcrc[22] ^ tmp_lcrc[31];
82 lcrc[24] = tmp_lcrc[23];
83 lcrc[25] = tmp_lcrc[24];
84 lcrc[26] = byte[index] ^ tmp_lcrc[25] ^ tmp_lcrc[31];
85 lcrc[27] = tmp_lcrc[26];
86 lcrc[28] = tmp_lcrc[27];
87 lcrc[29] = tmp_lcrc[28];
88 lcrc[30] = tmp_lcrc[29];
89 lcrc[31] = tmp_lcrc[30];
90
91 lcrc_mapped[0] = ~lcrc[7];
92 lcrc_mapped[1] = ~lcrc[6];
93 lcrc_mapped[2] = ~lcrc[5];
94 lcrc_mapped[3] = ~lcrc[4];
95 lcrc_mapped[4] = ~lcrc[3];
96 lcrc_mapped[5] = ~lcrc[2];
97 lcrc_mapped[6] = ~lcrc[1];
98 lcrc_mapped[7] = ~lcrc[0];
99
100 lcrc_mapped[8] = ~lcrc[15];
101 lcrc_mapped[9] = ~lcrc[14];
102 lcrc_mapped[10] = ~lcrc[13];
103 lcrc_mapped[11] = ~lcrc[12];
104 lcrc_mapped[12] = ~lcrc[11];
105 lcrc_mapped[13] = ~lcrc[10];
106 lcrc_mapped[14] = ~lcrc[9];
107 lcrc_mapped[15] = ~lcrc[8];
108
109 lcrc_mapped[16] = ~lcrc[23];
110 lcrc_mapped[17] = ~lcrc[22];
111 lcrc_mapped[18] = ~lcrc[21];
112 lcrc_mapped[19] = ~lcrc[20];
113 lcrc_mapped[20] = ~lcrc[19];
114 lcrc_mapped[21] = ~lcrc[18];
115 lcrc_mapped[22] = ~lcrc[17];
116 lcrc_mapped[23] = ~lcrc[16];
117
118 lcrc_mapped[24] = ~lcrc[31];
119 lcrc_mapped[25] = ~lcrc[30];
120 lcrc_mapped[26] = ~lcrc[29];
121 lcrc_mapped[27] = ~lcrc[28];
122 lcrc_mapped[28] = ~lcrc[27];
123 lcrc_mapped[29] = ~lcrc[26];
124 lcrc_mapped[30] = ~lcrc[25];
125 lcrc_mapped[31] = ~lcrc[24];
126 }// for
127 } // for
128 return lcrc_mapped;
129 }// void calculate_lcrc
130}
131