OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [insight/] [gdb/] [testsuite/] [gdb.base/] [bitfields.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 578 markom
/* Test program to test bit field operations */
2
 
3
/* For non-ANSI compilers, use plain ints for the signed bit fields.  However,
4
   whether they actually end up signed or not is implementation defined, so
5
   this may cause some tests to fail.  But at least we can still compile
6
   the test program and run the tests... */
7
 
8
#if !defined(__STDC__) && !defined(__cplusplus)
9
#define signed  /**/
10
#endif
11
 
12
struct fields
13
{
14
  unsigned char uc    ;
15
  signed int    s1 : 1;
16
  unsigned int  u1 : 1;
17
  signed int    s2 : 2;
18
  unsigned int  u2 : 2;
19
  signed int    s3 : 3;
20
  unsigned int  u3 : 3;
21
  signed int    s9 : 9;
22
  unsigned int  u9 : 9;
23
  signed char   sc    ;
24
} flags;
25
 
26
void break1 ()
27
{
28
}
29
 
30
void break2 ()
31
{
32
}
33
 
34
void break3 ()
35
{
36
}
37
 
38
void break4 ()
39
{
40
}
41
 
42
void break5 ()
43
{
44
}
45
 
46
void break6 ()
47
{
48
}
49
 
50
void break7 ()
51
{
52
}
53
 
54
void break8 ()
55
{
56
}
57
 
58
void break9 ()
59
{
60
}
61
 
62
void break10 ()
63
{
64
}
65
 
66
/* This is used by bitfields.exp to determine if the target understands
67
   signed bitfields.  */
68
int i;
69
 
70
int main ()
71
{
72
  /* For each member, set that member to 1, allow gdb to verify that the
73
     member (and only that member) is 1, and then reset it back to 0. */
74
 
75
#ifdef usestubs
76
  set_debug_traps();
77
  breakpoint();
78
#endif
79
  flags.uc = 1;
80
  break1 ();
81
  flags.uc = 0;
82
 
83
  flags.s1 = 1;
84
  break1 ();
85
  flags.s1 = 0;
86
 
87
  flags.u1 = 1;
88
  break1 ();
89
  flags.u1 = 0;
90
 
91
  flags.s2  = 1;
92
  break1 ();
93
  flags.s2 = 0;
94
 
95
  flags.u2 = 1;
96
  break1 ();
97
  flags.u2 = 0;
98
 
99
  flags.s3  = 1;
100
  break1 ();
101
  flags.s3 = 0;
102
 
103
  flags.u3 = 1;
104
  break1 ();
105
  flags.u3 = 0;
106
 
107
  flags.s9 = 1;
108
  break1 ();
109
  flags.s9 = 0;
110
 
111
  flags.u9 = 1;
112
  break1 ();
113
  flags.u9 = 0;
114
 
115
  flags.sc = 1;
116
  break1 ();
117
  flags.sc = 0;
118
 
119
  /* Fill alternating fields with all 1's and verify that none of the bits
120
     "bleed over" to the other fields. */
121
 
122
  flags.uc = 0xFF;
123
  flags.u1 = 0x1;
124
  flags.u2 = 0x3;
125
  flags.u3 = 0x7;
126
  flags.u9 = 0x1FF;
127
  break2 ();
128
  flags.uc = 0;
129
  flags.u1 = 0;
130
  flags.u2 = 0;
131
  flags.u3 = 0;
132
  flags.u9 = 0;
133
 
134
  flags.s1 = 0x1;
135
  flags.s2 = 0x3;
136
  flags.s3 = 0x7;
137
  flags.s9 = 0x1FF;
138
  flags.sc = 0xFF;
139
  break2 ();
140
  flags.s1 = 0;
141
  flags.s2 = 0;
142
  flags.s3 = 0;
143
  flags.s9 = 0;
144
  flags.sc = 0;
145
 
146
  /* Fill the unsigned fields with the maximum positive value and verify
147
     that the values are printed correctly. */
148
 
149
  /* Maximum positive values */
150
  flags.u1 = 0x1;
151
  flags.u2 = 0x3;
152
  flags.u3 = 0x7;
153
  flags.u9 = 0x1FF;
154
  break3 ();
155
  flags.u1 = 0;
156
  flags.u2 = 0;
157
  flags.u3 = 0;
158
  flags.u9 = 0;
159
 
160
  /* Fill the signed fields with the maximum positive value, then the maximally
161
     negative value, then -1, and verify in each case that the values are
162
     printed correctly. */
163
 
164
  /* Maximum positive values */
165
  flags.s1 = 0x0;
166
  flags.s2 = 0x1;
167
  flags.s3 = 0x3;
168
  flags.s9 = 0xFF;
169
  break4 ();
170
 
171
  /* Maximally negative values */
172
  flags.s1 = 0x1;
173
  flags.s2 = 0x2;
174
  flags.s3 = 0x4;
175
  flags.s9 = 0x100;
176
  /* Extract bitfield value so that bitfield.exp can check if the target
177
     understands signed bitfields.  */
178
  i = flags.s9;
179
  break4 ();
180
 
181
  /* -1 */
182
  flags.s1 = 0x1;
183
  flags.s2 = 0x3;
184
  flags.s3 = 0x7;
185
  flags.s9 = 0x1FF;
186
  break4 ();
187
 
188
  flags.s1 = 0;
189
  flags.s2 = 0;
190
  flags.s3 = 0;
191
  flags.s9 = 0;
192
 
193
  return 0;
194
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.