check_short.c
2.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/* The purpose of this program is to detect short circuit between bits. This */
/* test guarantees that any two bits can have different values. */
#include <ultra64.h>
#include <assert.h>
#include "main.h"
extern errorReport1(u32, u32, u32);
extern errorReport2(u32, u32, u32, u32, u32);
u32 checkShort(u32 *begadr, u32 *endadr)
{
u32 mask;
u32 *ptr;
u8 loop_cnt, i;
u32 error_cnt=0;
u32 value, xor;
u32 pattern1=0x0;
u32 pattern2=~(pattern1);
u32 bitpattern[5]=
{
0xaaaaaaaa, /* 10101010_10101010_10101010_10101010 */
0xcccccccc, /* 11001100_11001100_11001100_11001100 */
0xf0f0f0f0, /* 11110000_11110000_11110000_11110000 */
0xff00ff00, /* 11111111_00000000_11111111_00000000 */
0xffff0000 /* 11111111_11111111_00000000_00000000 */
};
u32 reverse=0x0;
/* First, we must know how long do we have to do the test in order not to do */
/* unnecessary tests.*/
mask=0x80000000;
xor=(u32)begadr ^ ((u32)endadr - 1);
for (loop_cnt=32; loop_cnt>0; loop_cnt--)
{
if (xor & mask)
break;
mask >>= 1;
}
#ifdef DEBUG
SOAKPRINTF("loop_cnt = %d\n", loop_cnt);
#endif
do
{
for (i=0; i<5; i++) /* 32bit(1 word) = 2 ^ 5 */
{
#ifdef DEBUG
SOAKPRINTF("mask = 2 ^ %d\n", i);
#endif
for (ptr=begadr; ptr<endadr; ptr++)
*ptr = bitpattern[i] ^ reverse;
for (ptr=begadr; ptr<endadr; ptr++)
if (*ptr != (bitpattern[i] ^ reverse))
{
error_cnt++;
#ifdef DEBUG
errorReport1((u32)ptr, bitpattern[i] ^ reverse, *ptr);
#endif
}
}
mask=0x4;
for (i=2; i<loop_cnt; i++) /* Since i=0 (and 1) in this part is exactly the same */
/* as i=3 (resp. 4) in the previous part, we start */
/* with i=2.*/
{
#ifdef DEBUG
SOAKPRINTF("mask = %x\n", mask);
#endif
for (ptr=begadr; ptr<endadr; ptr++)
*ptr = ((u32)ptr & mask)? pattern2^reverse : pattern1^reverse;
for (ptr=begadr; ptr<endadr; ptr++)
{
value = ((u32)ptr & mask)? pattern2^reverse : pattern1^reverse;
if (*ptr != value)
{
error_cnt++;
#ifdef DEBUG
errorReport1((u32)ptr, value, *ptr);
#endif
}
}
mask <<= 1;
}
reverse = ~reverse;
} while (reverse);
return error_cnt;
}