1 /** Test for "dead-loops" over bitfield or bit tests in a byte.
3 varType: 0, 1, 2, 3, 4, 5, 6
6 #pragma disable_warning 88
8 // Disable for ds390: bug #3211
9 // Absolute addressing has some issues for pdk. And if those are fixed, there might be alack of memory, still.
10 // mcs51 creates invalid assembler. Don't know if that is a bug or just a bad choice for ABS_ADDR1 and ABS_ADDR2 below.
11 #if defined(__SDCC_ds390) || defined(__SDCC_pdk14) || defined(__SDCC_pdk15) || defined(__SDCC_mcs51)
15 // These tests assume the bitfields are allocated in LSB to MSB order
16 // but some hosts allocate them in MSB to LSB order. Disable the
17 // tests on these hosts
18 #if defined(PORT_HOST) && (defined(__ppc__) || defined(__PPC__) || defined(__sparc) || defined(__sparc64__))
29 #define VAR_TYPE ({varType})
30 #define TYPE_IS_STRUCT ({struct})
35 unsigned int bit0
: 1;
36 unsigned int bit1
: 1;
37 unsigned int bit2
: 1;
38 unsigned int bit3
: 1;
39 unsigned int high
: 4;
43 #define TYPE struct_8bits
48 #if defined(__SDCC_pic16)
49 #define ABS_ADDR1 0x0200
50 #define ABS_ADDR2 0x0204
51 #elif defined(__SDCC_pic14)
52 #define ABS_ADDR1 0x0100
53 #define ABS_ADDR2 0x0104
54 #elif defined(__SDCC_stm8)
55 #define ABS_ADDR1 0x1000
56 #define ABS_ADDR2 0x1004
57 #elif defined(__SDCC_f8)
58 #define ABS_ADDR1 0x3000
59 #define ABS_ADDR2 0x3004
61 #if !defined(__SDCC_pdk14) && !defined(__SDCC_pdk15) // TODO: Make test suitable for pdk
62 #if !defined(PORT_HOST) // Never do absolute address test with host
63 #define ABS_ADDR1 0xCA00
64 #define ABS_ADDR2 0xCA04
70 volatile TYPE volatileBits
;
73 #define volatileBits (*(volatile TYPE*)ABS_ADDR1)
79 #define volatileBits (*(volatile TYPE*)ABS_ADDR2)
84 #define VOLATILE_BITS_DEF volatile TYPE volatileBits
86 #define VOLATILE_BITS_DEF static volatile TYPE volatileBits
89 #define VOLATILE_BITS_DEF static volatile TYPE __at(ABS_ADDR1) volatileBits
95 #define VOLATILE_BITS_DEF static volatile TYPE __at(ABS_ADDR2) volatileBits
96 #define USE_ONLY_1_BYTE
101 #error "Unknown VAR_TYPE case"
104 #ifndef VOLATILE_BITS_DEF
105 #define VOLATILE_BITS_DEF
112 #define AS_UINT8(x) (*(uint8_t *)&x)
118 AS_UINT8(volatileBits
) = 0x00;
119 while(AS_UINT8(volatileBits
) != 0x00);
120 while(volatileBits
.high
!= 0x00);
121 while(volatileBits
.bit0
);
122 while(volatileBits
.bit1
);
123 while(volatileBits
.bit2
);
124 while(volatileBits
.bit3
);
126 AS_UINT8(volatileBits
) = 0xFF;
127 while(AS_UINT8(volatileBits
) != 0xFF);
128 while(volatileBits
.high
!= 0x0F);
129 while(!volatileBits
.bit0
);
130 while(!volatileBits
.bit1
);
131 while(!volatileBits
.bit2
);
132 while(!volatileBits
.bit3
);
134 AS_UINT8(volatileBits
) = 0x01;
135 while(AS_UINT8(volatileBits
) != 0x01);
136 while(volatileBits
.high
!= 0x00);
137 while(!volatileBits
.bit0
);
138 while( volatileBits
.bit1
);
139 while( volatileBits
.bit2
);
140 while( volatileBits
.bit3
);
142 AS_UINT8(volatileBits
) = 0x02;
143 while(AS_UINT8(volatileBits
) != 0x02);
144 while(volatileBits
.high
!= 0x00);
145 while( volatileBits
.bit0
);
146 while(!volatileBits
.bit1
);
147 while( volatileBits
.bit2
);
148 while( volatileBits
.bit3
);
150 AS_UINT8(volatileBits
) = 0xF0;
151 while(AS_UINT8(volatileBits
) != 0xF0);
152 while(volatileBits
.high
!= 0x0F);
153 while(volatileBits
.bit0
);
154 while(volatileBits
.bit1
);
155 while(volatileBits
.bit2
);
156 while(volatileBits
.bit3
);
161 #define AS_UINT8(x) x
168 while(volatileBits
!= 0x00);
169 while((volatileBits
& 0xF0) != 0x00);
170 while((volatileBits
& 0x01) != 0x00);
171 while((volatileBits
& 0x02) != 0x00);
172 while((volatileBits
& 0x04) != 0x00);
173 while((volatileBits
& 0x08) != 0x00);
176 while(volatileBits
!= 0xFF);
177 while((uint8_t)(volatileBits
& 0xF0) != 0xF0);
178 while((uint8_t)(volatileBits
& 0x01) != 0x01);
179 while((uint8_t)(volatileBits
& 0x02) != 0x02);
180 while((uint8_t)(volatileBits
& 0x04) != 0x04);
181 while((uint8_t)(volatileBits
& 0x08) != 0x08);
184 while(volatileBits
!= 0x01);
185 while( (volatileBits
& 0xF0) != 0x00);
186 while((uint8_t)(volatileBits
& 0x01) != 0x01);
187 while( (volatileBits
& 0x02) != 0x00);
188 while( (volatileBits
& 0x04) != 0x00);
189 while( (volatileBits
& 0x08) != 0x00);
192 while(volatileBits
!= 0x02);
193 while( (volatileBits
& 0xF0) != 0x00);
194 while( (volatileBits
& 0x01) != 0x00);
195 while((uint8_t)(volatileBits
& 0x02) != 0x02);
196 while( (volatileBits
& 0x04) != 0x00);
197 while( (volatileBits
& 0x08) != 0x00);
200 while(volatileBits
!= 0xF0);
201 while((uint8_t)(volatileBits
& 0xF0) != 0xF0);
202 while( (volatileBits
& 0x01) != 0x00);
203 while( (volatileBits
& 0x02) != 0x00);
204 while( (volatileBits
& 0x04) != 0x00);
205 while( (volatileBits
& 0x08) != 0x00);
214 testBitfieldsDeadLoop(void)