Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / sam / cpus / vonk / bl / lib / ecc / src / BL_Hamming_22_6_Synd.h
CommitLineData
920dae64
AT
1/*
2* ========== Copyright Header Begin ==========================================
3*
4* OpenSPARC T2 Processor File: BL_Hamming_22_6_Synd.h
5* Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
6* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES.
7*
8* The above named program is free software; you can redistribute it and/or
9* modify it under the terms of the GNU General Public
10* License version 2 as published by the Free Software Foundation.
11*
12* The above named program is distributed in the hope that it will be
13* useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15* General Public License for more details.
16*
17* You should have received a copy of the GNU General Public
18* License along with this work; if not, write to the Free Software
19* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
20*
21* ========== Copyright Header End ============================================
22*/
23/************************************************************************
24**
25** Copyright (C) 2006, Sun Microsystems, Inc.
26**
27** Sun considers its source code as an unpublished, proprietary
28** trade secret and it is available only under strict license provisions.
29** This copyright notice is placed here only to protect Sun in the event
30** the source is deemed a published work. Disassembly, decompilation,
31** or other means of reducing the object code to human readable form
32** is prohibited by the license agreement under which this code is
33** provided to the user or company in possession of this copy.
34**
35*************************************************************************/
36#ifndef __BL_Hamming_22_6_Synd_h__
37#define __BL_Hamming_22_6_Synd_h__
38#include "BL_BaseSynd.h"
39#include "BL_HammingEcc.h"
40
41class BL_Hamming_22_6_Synd : public BL_BaseSynd
42{
43 public:
44
45 BL_Hamming_22_6_Synd(uint32_t syndrome) : BL_BaseSynd(syndrome)
46 {
47 if (syndrome > 0x3f)
48 {
49 fprintf(stderr,"ERROR: Bad Syndrome!");
50 exit(-1);
51 }
52 }
53
54 BL_Hamming_22_6_Synd(uint32_t data, BL_EccBits ecc) :
55 BL_BaseSynd(BL_HammingEcc::
56 get_hamming_22_6_synd(data,ecc.get()).getSyndrome())
57 {}
58
59 ~BL_Hamming_22_6_Synd() {}
60
61 bool isDoubleBitError() const { return (syndrome_ - 1) < 0x1f; }
62
63 bool isSingleBitError() const { return (syndrome_ - 0x20) < 0x1e; }
64
65 bool isDataBitError() const
66 {
67 return (isSingleBitError() && ((syndrome_ - 0x20) & syndrome_ - 0x21));
68 }
69
70 uint32_t getDataBit() const
71 {
72 if (!isDataBitError())
73 {
74 fprintf(stderr,"ERROR: Not data bit error!");
75 exit(-1);
76 }
77
78 uint32_t bit = syndrome_ - 0x20;
79 if (bit >= 0x10)
80 return bit - 6;
81 else if (bit > 8)
82 return bit - 5;
83 else if (bit > 4)
84 return bit - 4;
85 else
86 return bit - 3;
87 }
88
89 bool isCheckBitError() const
90 {
91 return (isSingleBitError() && !((syndrome_ - 0x20) & syndrome_ - 0x21));
92 }
93
94 uint32_t getCheckBit() const
95 {
96 if (!isCheckBitError())
97 {
98 fprintf(stderr,"ERROR: Not check bit error!");
99 exit(-1);
100 }
101
102 uint32_t bit = syndrome_ - 0x20;
103 if (bit >= 0x10)
104 return 4;
105 else if (bit == 8)
106 return 3;
107 else if (bit == 4)
108 return 2;
109 else
110 return (bit == 0) ? 5 : bit - 1;
111 return 0;
112 }
113
114 bool isMultipleBitError() const
115 {
116 return false;
117 }
118
119 static BL_EccBits calc_check_bits(unsigned long long data)
120 {
121 return BL_HammingEcc::calc_check_bits(BL_HammingEcc::BL_Hamming_22_6, data);
122 }
123
124 private:
125
126 BL_Hamming_22_6_Synd();
127};
128
129#endif