Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | /* |
2 | * ========== Copyright Header Begin ========================================== | |
3 | * | |
4 | * OpenSPARC T2 Processor File: BL_Hamming_32_7_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_32_7_Synd_h__ | |
37 | #define __BL_Hamming_32_7_Synd_h__ | |
38 | #include "BL_BaseSynd.h" | |
39 | #include "BL_HammingEcc.h" | |
40 | ||
41 | class BL_Hamming_32_7_Synd : public BL_BaseSynd | |
42 | { | |
43 | public: | |
44 | ||
45 | BL_Hamming_32_7_Synd(uint32_t syndrome) : BL_BaseSynd(syndrome) | |
46 | { | |
47 | if (syndrome > 0x7f) | |
48 | { | |
49 | fprintf(stderr,"ERROR: Bad Syndrome!"); | |
50 | exit(-1); | |
51 | } | |
52 | } | |
53 | ||
54 | BL_Hamming_32_7_Synd(uint32_t data, BL_EccBits ecc) : | |
55 | BL_BaseSynd(BL_HammingEcc:: | |
56 | get_hamming_32_7_synd(data,ecc.get()).getSyndrome()) | |
57 | {} | |
58 | ||
59 | ~BL_Hamming_32_7_Synd() {} | |
60 | ||
61 | bool isDoubleBitError() const { return (syndrome_ - 1) < 0x3f; } | |
62 | ||
63 | bool isSingleBitError() const { return (syndrome_ - 0x40) < 0x27; } | |
64 | ||
65 | // ((syndrome_ - 0x40) & syndrome_ - 0x41)) returns true if | |
66 | // "syndrome_ - 0x40" *NOT* a power of 2. See Table A-7 to see | |
67 | // that this is true for all data bits. | |
68 | bool isDataBitError() const | |
69 | { | |
70 | return (isSingleBitError() && ((syndrome_ - 0x40) & syndrome_ - 0x41)); | |
71 | } | |
72 | ||
73 | // This method works because the check bits are at powers of 2 | |
74 | // (after substracting 0x40) so the data bits break up into | |
75 | // large ranges. | |
76 | uint32_t getDataBit() const | |
77 | { | |
78 | if (!isDataBitError()) | |
79 | { | |
80 | fprintf(stderr,"ERROR: Not data bit error!"); | |
81 | exit(-1); | |
82 | } | |
83 | ||
84 | uint32_t bit = syndrome_ - 0x40; | |
85 | if (bit >= 0x10) | |
86 | return (bit >= 0x20) ? bit - 7 : bit - 6; | |
87 | else if (bit > 8) | |
88 | return bit - 5; | |
89 | else if (bit > 4) | |
90 | return bit - 4; | |
91 | else | |
92 | return bit - 3; | |
93 | } | |
94 | ||
95 | // !((syndrome_ - 0x40) & syndrome_ - 0x41)) returns true | |
96 | // "syndrome_ - 0x40" is a power of 2. See Table A-7 to see | |
97 | // that this is true for all check bits. | |
98 | bool isCheckBitError() const | |
99 | { | |
100 | return (isSingleBitError() && !((syndrome_ - 0x40) & syndrome_ - 0x41)); | |
101 | } | |
102 | ||
103 | // This method works because the check bits are at powers of 2 | |
104 | // (after substracting 0x40) so this divide and conquer search | |
105 | // is quite fast. | |
106 | uint32_t getCheckBit() const | |
107 | { | |
108 | if (!isCheckBitError()) | |
109 | { | |
110 | fprintf(stderr,"ERROR: Not check bit error!"); | |
111 | exit(-1); | |
112 | } | |
113 | ||
114 | uint32_t bit = syndrome_ - 0x40; | |
115 | if (bit >= 0x10) | |
116 | return (bit >= 0x20) ? 5 : 4; | |
117 | else if (bit == 8) | |
118 | return 3; | |
119 | else if (bit == 4) | |
120 | return 2; | |
121 | else | |
122 | return (bit == 0) ? 6 : bit - 1; | |
123 | } | |
124 | ||
125 | bool isMultipleBitError() const { return (syndrome_ - 0x67) < (0x19); } | |
126 | ||
127 | static BL_EccBits calc_check_bits(unsigned long long data) | |
128 | { | |
129 | return BL_HammingEcc::calc_check_bits(BL_HammingEcc::BL_Hamming_32_7, data); | |
130 | } | |
131 | ||
132 | #define BL_HAMMING_32_7_DIE(S) { \ | |
133 | fprintf(stderr, S " line: %d\n", __LINE__); \ | |
134 | exit(-1); \ | |
135 | } | |
136 | ||
137 | static void validate() | |
138 | { | |
139 | uint32_t data = 0x12345678; | |
140 | uint32_t ecc = BL_Hamming_32_7_Synd::calc_check_bits(data).get(); | |
141 | ||
142 | BL_Hamming_32_7_Synd syndrome = | |
143 | BL_HammingEcc::get_hamming_32_7_synd(data, ecc); | |
144 | ||
145 | if (!syndrome.noError()) | |
146 | BL_HAMMING_32_7_DIE("NoError fails"); | |
147 | ||
148 | int i; | |
149 | for (i = 0; i < 32; ++i) { | |
150 | syndrome = | |
151 | BL_HammingEcc::get_hamming_32_7_synd((1<<i)^data, ecc); | |
152 | ||
153 | if (syndrome.noError()) | |
154 | BL_HAMMING_32_7_DIE("NoError succeeds"); | |
155 | ||
156 | if (!syndrome.isSingleBitError()) | |
157 | BL_HAMMING_32_7_DIE("isSingleBit fails"); | |
158 | ||
159 | if (syndrome.isDoubleBitError()) | |
160 | BL_HAMMING_32_7_DIE("isDoubleBit succeeds"); | |
161 | ||
162 | if (syndrome.isMultipleBitError() || syndrome.isUncorrectableError()) | |
163 | BL_HAMMING_32_7_DIE("isMultipleBit/isUncorrectable succeeds"); | |
164 | ||
165 | if (syndrome.getDataBit() != i) | |
166 | BL_HAMMING_32_7_DIE("getDataBit mismatch"); | |
167 | } | |
168 | ||
169 | for (i = 0; i < 7; ++i) { | |
170 | syndrome = | |
171 | BL_HammingEcc::get_hamming_32_7_synd(data, (1<<i)^ecc); | |
172 | ||
173 | if (syndrome.noError()) | |
174 | BL_HAMMING_32_7_DIE("NoError succeeds"); | |
175 | ||
176 | if (!syndrome.isSingleBitError()) | |
177 | BL_HAMMING_32_7_DIE("isSingleBit fails"); | |
178 | ||
179 | if (syndrome.isDoubleBitError()) | |
180 | BL_HAMMING_32_7_DIE("isDoubleBit succeeds"); | |
181 | ||
182 | if (syndrome.isMultipleBitError() || syndrome.isUncorrectableError()) | |
183 | BL_HAMMING_32_7_DIE("isMultipleBit/isUncorrectable succeeds"); | |
184 | ||
185 | if (syndrome.getCheckBit() != i) | |
186 | BL_HAMMING_32_7_DIE("getCheckBit mismatch"); | |
187 | } | |
188 | ||
189 | for (i = 1; i < 32; ++i) { | |
190 | int j; | |
191 | for (j = 0; j < i; ++j) { | |
192 | syndrome = | |
193 | BL_HammingEcc::get_hamming_32_7_synd((1<<i)^(1<<j)^data, | |
194 | ecc); | |
195 | ||
196 | if (syndrome.noError()) | |
197 | BL_HAMMING_32_7_DIE("NoError succeeds"); | |
198 | ||
199 | if (syndrome.isSingleBitError()) | |
200 | BL_HAMMING_32_7_DIE("isSingleBit succeeds"); | |
201 | ||
202 | if (!syndrome.isDoubleBitError()) | |
203 | BL_HAMMING_32_7_DIE("isDoubleBit fails"); | |
204 | ||
205 | if (syndrome.isMultipleBitError()) | |
206 | BL_HAMMING_32_7_DIE("isMultipleBit succeeds"); | |
207 | ||
208 | if (!syndrome.isUncorrectableError()) | |
209 | BL_HAMMING_32_7_DIE("isUncorrectable fails"); | |
210 | } | |
211 | } | |
212 | ||
213 | for (i = 1; i < 7; ++i) { | |
214 | int j; | |
215 | for (j = 0; j < i; ++j) { | |
216 | ||
217 | syndrome = | |
218 | BL_HammingEcc::get_hamming_32_7_synd(data, | |
219 | (1<<i)^(1<<j)^ecc); | |
220 | ||
221 | if (syndrome.noError()) | |
222 | BL_HAMMING_32_7_DIE("NoError succeeds"); | |
223 | ||
224 | if (syndrome.isSingleBitError()) | |
225 | BL_HAMMING_32_7_DIE("isSingleBit succeeds"); | |
226 | ||
227 | if (!syndrome.isDoubleBitError()) | |
228 | BL_HAMMING_32_7_DIE("isDoubleBit fails"); | |
229 | ||
230 | if (syndrome.isMultipleBitError()) | |
231 | BL_HAMMING_32_7_DIE("isMultipleBit succeeds"); | |
232 | ||
233 | if (!syndrome.isUncorrectableError()) | |
234 | BL_HAMMING_32_7_DIE("isUncorrectable fails"); | |
235 | } | |
236 | } | |
237 | } | |
238 | ||
239 | #undef BL_HAMMING_32_7_DIE | |
240 | ||
241 | private: | |
242 | ||
243 | BL_Hamming_32_7_Synd(); | |
244 | }; | |
245 | ||
246 | #endif |