xref: /aosp_15_r20/external/elfutils/tests/read_unaligned.c (revision 7304104da70ce23c86437a01be71edd1a2d7f37e)
1*7304104dSAndroid Build Coastguard Worker /* Test program for read_[type]_unaligned.
2*7304104dSAndroid Build Coastguard Worker    Copyright (C) 2020, Red Hat Inc.
3*7304104dSAndroid Build Coastguard Worker    This file is part of elfutils.
4*7304104dSAndroid Build Coastguard Worker 
5*7304104dSAndroid Build Coastguard Worker    This file is free software; you can redistribute it and/or modify
6*7304104dSAndroid Build Coastguard Worker    it under the terms of the GNU General Public License as published by
7*7304104dSAndroid Build Coastguard Worker    the Free Software Foundation; either version 3 of the License, or
8*7304104dSAndroid Build Coastguard Worker    (at your option) any later version.
9*7304104dSAndroid Build Coastguard Worker 
10*7304104dSAndroid Build Coastguard Worker    elfutils is distributed in the hope that it will be useful, but
11*7304104dSAndroid Build Coastguard Worker    WITHOUT ANY WARRANTY; without even the implied warranty of
12*7304104dSAndroid Build Coastguard Worker    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13*7304104dSAndroid Build Coastguard Worker    GNU General Public License for more details.
14*7304104dSAndroid Build Coastguard Worker 
15*7304104dSAndroid Build Coastguard Worker    You should have received a copy of the GNU General Public License
16*7304104dSAndroid Build Coastguard Worker    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
17*7304104dSAndroid Build Coastguard Worker 
18*7304104dSAndroid Build Coastguard Worker #include <assert.h>
19*7304104dSAndroid Build Coastguard Worker #include <endian.h>
20*7304104dSAndroid Build Coastguard Worker #include <inttypes.h>
21*7304104dSAndroid Build Coastguard Worker #include <stdbool.h>
22*7304104dSAndroid Build Coastguard Worker #include <stdint.h>
23*7304104dSAndroid Build Coastguard Worker #include <stdio.h>
24*7304104dSAndroid Build Coastguard Worker 
25*7304104dSAndroid Build Coastguard Worker #include "../libdw/libdwP.h"
26*7304104dSAndroid Build Coastguard Worker #include "../libdw/memory-access.h"
27*7304104dSAndroid Build Coastguard Worker 
28*7304104dSAndroid Build Coastguard Worker union u8
29*7304104dSAndroid Build Coastguard Worker {
30*7304104dSAndroid Build Coastguard Worker   uint8_t v;
31*7304104dSAndroid Build Coastguard Worker   unsigned char c[1];
32*7304104dSAndroid Build Coastguard Worker };
33*7304104dSAndroid Build Coastguard Worker 
34*7304104dSAndroid Build Coastguard Worker union s8
35*7304104dSAndroid Build Coastguard Worker {
36*7304104dSAndroid Build Coastguard Worker   int8_t v;
37*7304104dSAndroid Build Coastguard Worker   unsigned char c[1];
38*7304104dSAndroid Build Coastguard Worker };
39*7304104dSAndroid Build Coastguard Worker 
40*7304104dSAndroid Build Coastguard Worker union u16
41*7304104dSAndroid Build Coastguard Worker {
42*7304104dSAndroid Build Coastguard Worker   uint16_t v;
43*7304104dSAndroid Build Coastguard Worker   unsigned char c[2];
44*7304104dSAndroid Build Coastguard Worker };
45*7304104dSAndroid Build Coastguard Worker 
46*7304104dSAndroid Build Coastguard Worker union s16
47*7304104dSAndroid Build Coastguard Worker {
48*7304104dSAndroid Build Coastguard Worker   int16_t v;
49*7304104dSAndroid Build Coastguard Worker   unsigned char c[2];
50*7304104dSAndroid Build Coastguard Worker };
51*7304104dSAndroid Build Coastguard Worker 
52*7304104dSAndroid Build Coastguard Worker union u24
53*7304104dSAndroid Build Coastguard Worker {
54*7304104dSAndroid Build Coastguard Worker   uint32_t v:24;
55*7304104dSAndroid Build Coastguard Worker   unsigned char c[3];
56*7304104dSAndroid Build Coastguard Worker } __attribute__((packed));
57*7304104dSAndroid Build Coastguard Worker 
58*7304104dSAndroid Build Coastguard Worker union u32
59*7304104dSAndroid Build Coastguard Worker {
60*7304104dSAndroid Build Coastguard Worker   uint32_t v;
61*7304104dSAndroid Build Coastguard Worker   unsigned char c[4];
62*7304104dSAndroid Build Coastguard Worker };
63*7304104dSAndroid Build Coastguard Worker 
64*7304104dSAndroid Build Coastguard Worker union s32
65*7304104dSAndroid Build Coastguard Worker {
66*7304104dSAndroid Build Coastguard Worker   int32_t v;
67*7304104dSAndroid Build Coastguard Worker   unsigned char c[4];
68*7304104dSAndroid Build Coastguard Worker };
69*7304104dSAndroid Build Coastguard Worker 
70*7304104dSAndroid Build Coastguard Worker union u64
71*7304104dSAndroid Build Coastguard Worker {
72*7304104dSAndroid Build Coastguard Worker   uint64_t v;
73*7304104dSAndroid Build Coastguard Worker   unsigned char c[8];
74*7304104dSAndroid Build Coastguard Worker };
75*7304104dSAndroid Build Coastguard Worker 
76*7304104dSAndroid Build Coastguard Worker union s64
77*7304104dSAndroid Build Coastguard Worker {
78*7304104dSAndroid Build Coastguard Worker   uint64_t v;
79*7304104dSAndroid Build Coastguard Worker   unsigned char c[8];
80*7304104dSAndroid Build Coastguard Worker };
81*7304104dSAndroid Build Coastguard Worker 
82*7304104dSAndroid Build Coastguard Worker uint8_t u8_nums[] =
83*7304104dSAndroid Build Coastguard Worker   {
84*7304104dSAndroid Build Coastguard Worker    0,
85*7304104dSAndroid Build Coastguard Worker    1,
86*7304104dSAndroid Build Coastguard Worker    UINT8_MAX / 2 - 1,
87*7304104dSAndroid Build Coastguard Worker    UINT8_MAX / 2,
88*7304104dSAndroid Build Coastguard Worker    UINT8_MAX / 2 + 1,
89*7304104dSAndroid Build Coastguard Worker    UINT8_MAX,
90*7304104dSAndroid Build Coastguard Worker    UINT8_MAX -1
91*7304104dSAndroid Build Coastguard Worker   };
92*7304104dSAndroid Build Coastguard Worker 
93*7304104dSAndroid Build Coastguard Worker int8_t s8_nums[] =
94*7304104dSAndroid Build Coastguard Worker   {
95*7304104dSAndroid Build Coastguard Worker    INT8_MIN,
96*7304104dSAndroid Build Coastguard Worker    INT8_MIN + 1,
97*7304104dSAndroid Build Coastguard Worker    -1,
98*7304104dSAndroid Build Coastguard Worker    0,
99*7304104dSAndroid Build Coastguard Worker    1,
100*7304104dSAndroid Build Coastguard Worker    INT8_MAX,
101*7304104dSAndroid Build Coastguard Worker    INT8_MAX - 1
102*7304104dSAndroid Build Coastguard Worker   };
103*7304104dSAndroid Build Coastguard Worker 
104*7304104dSAndroid Build Coastguard Worker uint16_t u16_nums[] =
105*7304104dSAndroid Build Coastguard Worker   {
106*7304104dSAndroid Build Coastguard Worker    0,
107*7304104dSAndroid Build Coastguard Worker    1,
108*7304104dSAndroid Build Coastguard Worker    UINT16_MAX / 2 - 1,
109*7304104dSAndroid Build Coastguard Worker    UINT16_MAX / 2,
110*7304104dSAndroid Build Coastguard Worker    UINT16_MAX / 2 + 1,
111*7304104dSAndroid Build Coastguard Worker    UINT16_MAX,
112*7304104dSAndroid Build Coastguard Worker    UINT16_MAX -1
113*7304104dSAndroid Build Coastguard Worker   };
114*7304104dSAndroid Build Coastguard Worker 
115*7304104dSAndroid Build Coastguard Worker int16_t s16_nums[] =
116*7304104dSAndroid Build Coastguard Worker   {
117*7304104dSAndroid Build Coastguard Worker    INT16_MIN,
118*7304104dSAndroid Build Coastguard Worker    INT16_MIN + 1,
119*7304104dSAndroid Build Coastguard Worker    -1,
120*7304104dSAndroid Build Coastguard Worker    0,
121*7304104dSAndroid Build Coastguard Worker    1,
122*7304104dSAndroid Build Coastguard Worker    INT16_MAX,
123*7304104dSAndroid Build Coastguard Worker    INT16_MAX - 1
124*7304104dSAndroid Build Coastguard Worker   };
125*7304104dSAndroid Build Coastguard Worker 
126*7304104dSAndroid Build Coastguard Worker #define UINT24_MAX 0xffffff
127*7304104dSAndroid Build Coastguard Worker 
128*7304104dSAndroid Build Coastguard Worker uint32_t u24_nums[] =
129*7304104dSAndroid Build Coastguard Worker   {
130*7304104dSAndroid Build Coastguard Worker    0,
131*7304104dSAndroid Build Coastguard Worker    1,
132*7304104dSAndroid Build Coastguard Worker    UINT24_MAX / 2 - 1,
133*7304104dSAndroid Build Coastguard Worker    UINT24_MAX / 2,
134*7304104dSAndroid Build Coastguard Worker    UINT24_MAX / 2 + 1,
135*7304104dSAndroid Build Coastguard Worker    UINT24_MAX,
136*7304104dSAndroid Build Coastguard Worker    UINT24_MAX -1
137*7304104dSAndroid Build Coastguard Worker   };
138*7304104dSAndroid Build Coastguard Worker 
139*7304104dSAndroid Build Coastguard Worker uint32_t u32_nums[] =
140*7304104dSAndroid Build Coastguard Worker   {
141*7304104dSAndroid Build Coastguard Worker    0,
142*7304104dSAndroid Build Coastguard Worker    1,
143*7304104dSAndroid Build Coastguard Worker    UINT32_MAX / 2 - 1,
144*7304104dSAndroid Build Coastguard Worker    UINT32_MAX / 2,
145*7304104dSAndroid Build Coastguard Worker    UINT32_MAX / 2 + 1,
146*7304104dSAndroid Build Coastguard Worker    UINT32_MAX,
147*7304104dSAndroid Build Coastguard Worker    UINT32_MAX -1
148*7304104dSAndroid Build Coastguard Worker   };
149*7304104dSAndroid Build Coastguard Worker 
150*7304104dSAndroid Build Coastguard Worker int32_t s32_nums[] =
151*7304104dSAndroid Build Coastguard Worker   {
152*7304104dSAndroid Build Coastguard Worker    INT32_MIN,
153*7304104dSAndroid Build Coastguard Worker    INT32_MIN + 1,
154*7304104dSAndroid Build Coastguard Worker    -1,
155*7304104dSAndroid Build Coastguard Worker    0,
156*7304104dSAndroid Build Coastguard Worker    1,
157*7304104dSAndroid Build Coastguard Worker    INT32_MAX,
158*7304104dSAndroid Build Coastguard Worker    INT32_MAX - 1
159*7304104dSAndroid Build Coastguard Worker   };
160*7304104dSAndroid Build Coastguard Worker 
161*7304104dSAndroid Build Coastguard Worker uint64_t u64_nums[] =
162*7304104dSAndroid Build Coastguard Worker   {
163*7304104dSAndroid Build Coastguard Worker    0,
164*7304104dSAndroid Build Coastguard Worker    1,
165*7304104dSAndroid Build Coastguard Worker    UINT64_MAX / 2 - 1,
166*7304104dSAndroid Build Coastguard Worker    UINT64_MAX / 2,
167*7304104dSAndroid Build Coastguard Worker    UINT64_MAX / 2 + 1,
168*7304104dSAndroid Build Coastguard Worker    UINT64_MAX,
169*7304104dSAndroid Build Coastguard Worker    UINT64_MAX -1
170*7304104dSAndroid Build Coastguard Worker   };
171*7304104dSAndroid Build Coastguard Worker 
172*7304104dSAndroid Build Coastguard Worker int64_t s64_nums[] =
173*7304104dSAndroid Build Coastguard Worker   {
174*7304104dSAndroid Build Coastguard Worker    INT64_MIN,
175*7304104dSAndroid Build Coastguard Worker    INT64_MIN + 1,
176*7304104dSAndroid Build Coastguard Worker    -1,
177*7304104dSAndroid Build Coastguard Worker    0,
178*7304104dSAndroid Build Coastguard Worker    1,
179*7304104dSAndroid Build Coastguard Worker    INT64_MAX,
180*7304104dSAndroid Build Coastguard Worker    INT64_MAX - 1
181*7304104dSAndroid Build Coastguard Worker   };
182*7304104dSAndroid Build Coastguard Worker 
183*7304104dSAndroid Build Coastguard Worker static unsigned char le_mem[] =
184*7304104dSAndroid Build Coastguard Worker   {
185*7304104dSAndroid Build Coastguard Worker     /* u8 */
186*7304104dSAndroid Build Coastguard Worker     0x00,
187*7304104dSAndroid Build Coastguard Worker     0x01,
188*7304104dSAndroid Build Coastguard Worker     0x7e,
189*7304104dSAndroid Build Coastguard Worker     0x7f,
190*7304104dSAndroid Build Coastguard Worker     0x80,
191*7304104dSAndroid Build Coastguard Worker     0xff,
192*7304104dSAndroid Build Coastguard Worker     0xfe,
193*7304104dSAndroid Build Coastguard Worker     /* s8 */
194*7304104dSAndroid Build Coastguard Worker     0x80,
195*7304104dSAndroid Build Coastguard Worker     0x81,
196*7304104dSAndroid Build Coastguard Worker     0xff,
197*7304104dSAndroid Build Coastguard Worker     0x00,
198*7304104dSAndroid Build Coastguard Worker     0x01,
199*7304104dSAndroid Build Coastguard Worker     0x7f,
200*7304104dSAndroid Build Coastguard Worker     0x7e,
201*7304104dSAndroid Build Coastguard Worker     /* u16 */
202*7304104dSAndroid Build Coastguard Worker     0x00, 0x00,
203*7304104dSAndroid Build Coastguard Worker     0x01, 0x00,
204*7304104dSAndroid Build Coastguard Worker     0xfe, 0x7f,
205*7304104dSAndroid Build Coastguard Worker     0xff, 0x7f,
206*7304104dSAndroid Build Coastguard Worker     0x00, 0x80,
207*7304104dSAndroid Build Coastguard Worker     0xff, 0xff,
208*7304104dSAndroid Build Coastguard Worker     0xfe, 0xff,
209*7304104dSAndroid Build Coastguard Worker     /* s16 */
210*7304104dSAndroid Build Coastguard Worker     0x00, 0x80,
211*7304104dSAndroid Build Coastguard Worker     0x01, 0x80,
212*7304104dSAndroid Build Coastguard Worker     0xff, 0xff,
213*7304104dSAndroid Build Coastguard Worker     0x00, 0x00,
214*7304104dSAndroid Build Coastguard Worker     0x01, 0x00,
215*7304104dSAndroid Build Coastguard Worker     0xff, 0x7f,
216*7304104dSAndroid Build Coastguard Worker     0xfe, 0x7f,
217*7304104dSAndroid Build Coastguard Worker     /* u24 */
218*7304104dSAndroid Build Coastguard Worker     0x00, 0x00, 0x00,
219*7304104dSAndroid Build Coastguard Worker     0x01, 0x00, 0x00,
220*7304104dSAndroid Build Coastguard Worker     0xfe, 0xff, 0x7f,
221*7304104dSAndroid Build Coastguard Worker     0xff, 0xff, 0x7f,
222*7304104dSAndroid Build Coastguard Worker     0x00, 0x00, 0x80,
223*7304104dSAndroid Build Coastguard Worker     0xff, 0xff, 0xff,
224*7304104dSAndroid Build Coastguard Worker     0xfe, 0xff, 0xff,
225*7304104dSAndroid Build Coastguard Worker     /* u32 */
226*7304104dSAndroid Build Coastguard Worker     0x00, 0x00, 0x00, 0x00,
227*7304104dSAndroid Build Coastguard Worker     0x01, 0x00, 0x00, 0x00,
228*7304104dSAndroid Build Coastguard Worker     0xfe, 0xff, 0xff, 0x7f,
229*7304104dSAndroid Build Coastguard Worker     0xff, 0xff, 0xff, 0x7f,
230*7304104dSAndroid Build Coastguard Worker     0x00, 0x00, 0x00, 0x80,
231*7304104dSAndroid Build Coastguard Worker     0xff, 0xff, 0xff, 0xff,
232*7304104dSAndroid Build Coastguard Worker     0xfe, 0xff, 0xff, 0xff,
233*7304104dSAndroid Build Coastguard Worker     /* s32 */
234*7304104dSAndroid Build Coastguard Worker     0x00, 0x00, 0x00, 0x80,
235*7304104dSAndroid Build Coastguard Worker     0x01, 0x00, 0x00, 0x80,
236*7304104dSAndroid Build Coastguard Worker     0xff, 0xff, 0xff, 0xff,
237*7304104dSAndroid Build Coastguard Worker     0x00, 0x00, 0x00, 0x00,
238*7304104dSAndroid Build Coastguard Worker     0x01, 0x00, 0x00, 0x00,
239*7304104dSAndroid Build Coastguard Worker     0xff, 0xff, 0xff, 0x7f,
240*7304104dSAndroid Build Coastguard Worker     0xfe, 0xff, 0xff, 0x7f,
241*7304104dSAndroid Build Coastguard Worker     /* u64 */
242*7304104dSAndroid Build Coastguard Worker     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
243*7304104dSAndroid Build Coastguard Worker     0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
244*7304104dSAndroid Build Coastguard Worker     0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f,
245*7304104dSAndroid Build Coastguard Worker     0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f,
246*7304104dSAndroid Build Coastguard Worker     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80,
247*7304104dSAndroid Build Coastguard Worker     0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
248*7304104dSAndroid Build Coastguard Worker     0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
249*7304104dSAndroid Build Coastguard Worker     /* s64 */
250*7304104dSAndroid Build Coastguard Worker     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80,
251*7304104dSAndroid Build Coastguard Worker     0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80,
252*7304104dSAndroid Build Coastguard Worker     0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
253*7304104dSAndroid Build Coastguard Worker     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
254*7304104dSAndroid Build Coastguard Worker     0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
255*7304104dSAndroid Build Coastguard Worker     0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f,
256*7304104dSAndroid Build Coastguard Worker     0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f,
257*7304104dSAndroid Build Coastguard Worker   };
258*7304104dSAndroid Build Coastguard Worker 
259*7304104dSAndroid Build Coastguard Worker static unsigned char be_mem[] =
260*7304104dSAndroid Build Coastguard Worker   {
261*7304104dSAndroid Build Coastguard Worker     /* u8 */
262*7304104dSAndroid Build Coastguard Worker     0x00,
263*7304104dSAndroid Build Coastguard Worker     0x01,
264*7304104dSAndroid Build Coastguard Worker     0x7e,
265*7304104dSAndroid Build Coastguard Worker     0x7f,
266*7304104dSAndroid Build Coastguard Worker     0x80,
267*7304104dSAndroid Build Coastguard Worker     0xff,
268*7304104dSAndroid Build Coastguard Worker     0xfe,
269*7304104dSAndroid Build Coastguard Worker     /* s8 */
270*7304104dSAndroid Build Coastguard Worker     0x80,
271*7304104dSAndroid Build Coastguard Worker     0x81,
272*7304104dSAndroid Build Coastguard Worker     0xff,
273*7304104dSAndroid Build Coastguard Worker     0x00,
274*7304104dSAndroid Build Coastguard Worker     0x01,
275*7304104dSAndroid Build Coastguard Worker     0x7f,
276*7304104dSAndroid Build Coastguard Worker     0x7e,
277*7304104dSAndroid Build Coastguard Worker     /* u16 */
278*7304104dSAndroid Build Coastguard Worker     0x00, 0x00,
279*7304104dSAndroid Build Coastguard Worker     0x00, 0x01,
280*7304104dSAndroid Build Coastguard Worker     0x7f, 0xfe,
281*7304104dSAndroid Build Coastguard Worker     0x7f, 0xff,
282*7304104dSAndroid Build Coastguard Worker     0x80, 0x00,
283*7304104dSAndroid Build Coastguard Worker     0xff, 0xff,
284*7304104dSAndroid Build Coastguard Worker     0xff, 0xfe,
285*7304104dSAndroid Build Coastguard Worker     /* s16 */
286*7304104dSAndroid Build Coastguard Worker     0x80, 0x00,
287*7304104dSAndroid Build Coastguard Worker     0x80, 0x01,
288*7304104dSAndroid Build Coastguard Worker     0xff, 0xff,
289*7304104dSAndroid Build Coastguard Worker     0x00, 0x00,
290*7304104dSAndroid Build Coastguard Worker     0x00, 0x01,
291*7304104dSAndroid Build Coastguard Worker     0x7f, 0xff,
292*7304104dSAndroid Build Coastguard Worker     0x7f, 0xfe,
293*7304104dSAndroid Build Coastguard Worker     /* u24 */
294*7304104dSAndroid Build Coastguard Worker     0x00, 0x00, 0x00,
295*7304104dSAndroid Build Coastguard Worker     0x00, 0x00, 0x01,
296*7304104dSAndroid Build Coastguard Worker     0x7f, 0xff, 0xfe,
297*7304104dSAndroid Build Coastguard Worker     0x7f, 0xff, 0xff,
298*7304104dSAndroid Build Coastguard Worker     0x80, 0x00, 0x00,
299*7304104dSAndroid Build Coastguard Worker     0xff, 0xff, 0xff,
300*7304104dSAndroid Build Coastguard Worker     0xff, 0xff, 0xfe,
301*7304104dSAndroid Build Coastguard Worker     /* u32 */
302*7304104dSAndroid Build Coastguard Worker     0x00, 0x00, 0x00, 0x00,
303*7304104dSAndroid Build Coastguard Worker     0x00, 0x00, 0x00, 0x01,
304*7304104dSAndroid Build Coastguard Worker     0x7f, 0xff, 0xff, 0xfe,
305*7304104dSAndroid Build Coastguard Worker     0x7f, 0xff, 0xff, 0xff,
306*7304104dSAndroid Build Coastguard Worker     0x80, 0x00, 0x00, 0x00,
307*7304104dSAndroid Build Coastguard Worker     0xff, 0xff, 0xff, 0xff,
308*7304104dSAndroid Build Coastguard Worker     0xff, 0xff, 0xff, 0xfe,
309*7304104dSAndroid Build Coastguard Worker     /* s32 */
310*7304104dSAndroid Build Coastguard Worker     0x80, 0x00, 0x00, 0x00,
311*7304104dSAndroid Build Coastguard Worker     0x80, 0x00, 0x00, 0x01,
312*7304104dSAndroid Build Coastguard Worker     0xff, 0xff, 0xff, 0xff,
313*7304104dSAndroid Build Coastguard Worker     0x00, 0x00, 0x00, 0x00,
314*7304104dSAndroid Build Coastguard Worker     0x00, 0x00, 0x00, 0x01,
315*7304104dSAndroid Build Coastguard Worker     0x7f, 0xff, 0xff, 0xff,
316*7304104dSAndroid Build Coastguard Worker     0x7f, 0xff, 0xff, 0xfe,
317*7304104dSAndroid Build Coastguard Worker     /* u64 */
318*7304104dSAndroid Build Coastguard Worker     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
319*7304104dSAndroid Build Coastguard Worker     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
320*7304104dSAndroid Build Coastguard Worker     0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe,
321*7304104dSAndroid Build Coastguard Worker     0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
322*7304104dSAndroid Build Coastguard Worker     0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
323*7304104dSAndroid Build Coastguard Worker     0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
324*7304104dSAndroid Build Coastguard Worker     0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe,
325*7304104dSAndroid Build Coastguard Worker     /* s64 */
326*7304104dSAndroid Build Coastguard Worker     0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
327*7304104dSAndroid Build Coastguard Worker     0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
328*7304104dSAndroid Build Coastguard Worker     0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
329*7304104dSAndroid Build Coastguard Worker     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
330*7304104dSAndroid Build Coastguard Worker     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
331*7304104dSAndroid Build Coastguard Worker     0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
332*7304104dSAndroid Build Coastguard Worker     0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe,
333*7304104dSAndroid Build Coastguard Worker   };
334*7304104dSAndroid Build Coastguard Worker 
335*7304104dSAndroid Build Coastguard Worker int
main(int argc,char ** argv)336*7304104dSAndroid Build Coastguard Worker main (int argc, char **argv __attribute__((unused)))
337*7304104dSAndroid Build Coastguard Worker {
338*7304104dSAndroid Build Coastguard Worker   /* No arguments means check, otherwise Write out the memory array.  */
339*7304104dSAndroid Build Coastguard Worker   bool write = false;
340*7304104dSAndroid Build Coastguard Worker   if (argc > 1)
341*7304104dSAndroid Build Coastguard Worker     write = true;
342*7304104dSAndroid Build Coastguard Worker 
343*7304104dSAndroid Build Coastguard Worker   bool is_le = (BYTE_ORDER == LITTLE_ENDIAN);
344*7304104dSAndroid Build Coastguard Worker 
345*7304104dSAndroid Build Coastguard Worker   if (write)
346*7304104dSAndroid Build Coastguard Worker     {
347*7304104dSAndroid Build Coastguard Worker       if (is_le)
348*7304104dSAndroid Build Coastguard Worker 	printf ("static unsigned char le_mem[] =\n");
349*7304104dSAndroid Build Coastguard Worker       else
350*7304104dSAndroid Build Coastguard Worker 	printf ("static unsigned char be_mem[] =\n");
351*7304104dSAndroid Build Coastguard Worker       printf ("  {\n");
352*7304104dSAndroid Build Coastguard Worker     }
353*7304104dSAndroid Build Coastguard Worker 
354*7304104dSAndroid Build Coastguard Worker   Dwarf dbg_le = { .other_byte_order = !is_le };
355*7304104dSAndroid Build Coastguard Worker   Dwarf dbg_be = { .other_byte_order = is_le };
356*7304104dSAndroid Build Coastguard Worker 
357*7304104dSAndroid Build Coastguard Worker   unsigned char *p_le = le_mem;
358*7304104dSAndroid Build Coastguard Worker   unsigned char *p_be = be_mem;
359*7304104dSAndroid Build Coastguard Worker 
360*7304104dSAndroid Build Coastguard Worker   union u8 u8;
361*7304104dSAndroid Build Coastguard Worker   if (write)
362*7304104dSAndroid Build Coastguard Worker     printf ("    /* u8 */\n");
363*7304104dSAndroid Build Coastguard Worker   for (size_t i = 0; i < sizeof (u8_nums) / sizeof (u8); i++)
364*7304104dSAndroid Build Coastguard Worker     {
365*7304104dSAndroid Build Coastguard Worker       if (write)
366*7304104dSAndroid Build Coastguard Worker 	{
367*7304104dSAndroid Build Coastguard Worker 	  u8.v = u8_nums[i];
368*7304104dSAndroid Build Coastguard Worker 	  printf ("    0x%02" PRIx8 ",\n", u8.c[0]);
369*7304104dSAndroid Build Coastguard Worker 	}
370*7304104dSAndroid Build Coastguard Worker       else
371*7304104dSAndroid Build Coastguard Worker 	{
372*7304104dSAndroid Build Coastguard Worker 	  uint8_t v = *p_le++;
373*7304104dSAndroid Build Coastguard Worker 	  assert (v == u8_nums[i]);
374*7304104dSAndroid Build Coastguard Worker 	  v = *p_be++;
375*7304104dSAndroid Build Coastguard Worker 	  assert (v == u8_nums[i]);
376*7304104dSAndroid Build Coastguard Worker 	}
377*7304104dSAndroid Build Coastguard Worker     }
378*7304104dSAndroid Build Coastguard Worker 
379*7304104dSAndroid Build Coastguard Worker   union s8 s8;
380*7304104dSAndroid Build Coastguard Worker   if (write)
381*7304104dSAndroid Build Coastguard Worker     printf ("    /* s8 */\n");
382*7304104dSAndroid Build Coastguard Worker   for (size_t i = 0; i < sizeof (s8_nums) / sizeof (s8); i++)
383*7304104dSAndroid Build Coastguard Worker     {
384*7304104dSAndroid Build Coastguard Worker       if (write)
385*7304104dSAndroid Build Coastguard Worker 	{
386*7304104dSAndroid Build Coastguard Worker 	  s8.v = s8_nums[i];
387*7304104dSAndroid Build Coastguard Worker 	  printf ("    0x%02" PRIx8 ",\n", s8.c[0]);
388*7304104dSAndroid Build Coastguard Worker 	}
389*7304104dSAndroid Build Coastguard Worker       else
390*7304104dSAndroid Build Coastguard Worker 	{
391*7304104dSAndroid Build Coastguard Worker 	  int8_t v = *p_le++;
392*7304104dSAndroid Build Coastguard Worker 	  assert (v == s8_nums[i]);
393*7304104dSAndroid Build Coastguard Worker 	  v = *p_be++;
394*7304104dSAndroid Build Coastguard Worker 	  assert (v == s8_nums[i]);
395*7304104dSAndroid Build Coastguard Worker 	}
396*7304104dSAndroid Build Coastguard Worker     }
397*7304104dSAndroid Build Coastguard Worker 
398*7304104dSAndroid Build Coastguard Worker   union u16 u16;
399*7304104dSAndroid Build Coastguard Worker   if (write)
400*7304104dSAndroid Build Coastguard Worker     printf ("    /* u16 */\n");
401*7304104dSAndroid Build Coastguard Worker   for (size_t i = 0; i < sizeof (u16_nums) / sizeof (u16); i++)
402*7304104dSAndroid Build Coastguard Worker     {
403*7304104dSAndroid Build Coastguard Worker       if (write)
404*7304104dSAndroid Build Coastguard Worker 	{
405*7304104dSAndroid Build Coastguard Worker 	  u16.v = u16_nums[i];
406*7304104dSAndroid Build Coastguard Worker 	  printf ("    0x%02" PRIx8 ", ", u16.c[0]);
407*7304104dSAndroid Build Coastguard Worker 	  printf ("0x%02" PRIx8 ",\n", u16.c[1]);
408*7304104dSAndroid Build Coastguard Worker 	}
409*7304104dSAndroid Build Coastguard Worker       else
410*7304104dSAndroid Build Coastguard Worker 	{
411*7304104dSAndroid Build Coastguard Worker 	  uint16_t v = read_2ubyte_unaligned_inc (&dbg_le, p_le);
412*7304104dSAndroid Build Coastguard Worker 	  assert (v == u16_nums[i]);
413*7304104dSAndroid Build Coastguard Worker 	  v = read_2ubyte_unaligned_inc (&dbg_be, p_be);
414*7304104dSAndroid Build Coastguard Worker 	  assert (v == u16_nums[i]);
415*7304104dSAndroid Build Coastguard Worker 	}
416*7304104dSAndroid Build Coastguard Worker     }
417*7304104dSAndroid Build Coastguard Worker 
418*7304104dSAndroid Build Coastguard Worker   union s16 s16;
419*7304104dSAndroid Build Coastguard Worker   if (write)
420*7304104dSAndroid Build Coastguard Worker     printf ("    /* s16 */\n");
421*7304104dSAndroid Build Coastguard Worker   for (size_t i = 0; i < sizeof (s16_nums) / sizeof (s16); i++)
422*7304104dSAndroid Build Coastguard Worker     {
423*7304104dSAndroid Build Coastguard Worker       if (write)
424*7304104dSAndroid Build Coastguard Worker 	{
425*7304104dSAndroid Build Coastguard Worker 	  s16.v = s16_nums[i];
426*7304104dSAndroid Build Coastguard Worker 	  printf ("    0x%02" PRIx8 ", ", s16.c[0]);
427*7304104dSAndroid Build Coastguard Worker 	  printf ("0x%02" PRIx8 ",\n", s16.c[1]);
428*7304104dSAndroid Build Coastguard Worker 	}
429*7304104dSAndroid Build Coastguard Worker       else
430*7304104dSAndroid Build Coastguard Worker 	{
431*7304104dSAndroid Build Coastguard Worker 	  int16_t v = read_2sbyte_unaligned_inc (&dbg_le, p_le);
432*7304104dSAndroid Build Coastguard Worker 	  assert (v == s16_nums[i]);
433*7304104dSAndroid Build Coastguard Worker 	  v = read_2sbyte_unaligned_inc (&dbg_be, p_be);
434*7304104dSAndroid Build Coastguard Worker 	  assert (v == s16_nums[i]);
435*7304104dSAndroid Build Coastguard Worker 	}
436*7304104dSAndroid Build Coastguard Worker     }
437*7304104dSAndroid Build Coastguard Worker 
438*7304104dSAndroid Build Coastguard Worker   union u24 u24;
439*7304104dSAndroid Build Coastguard Worker   if (write)
440*7304104dSAndroid Build Coastguard Worker     printf ("    /* u24 */\n");
441*7304104dSAndroid Build Coastguard Worker   for (size_t i = 0; i < sizeof (u24_nums) / sizeof (uint32_t); i++)
442*7304104dSAndroid Build Coastguard Worker     {
443*7304104dSAndroid Build Coastguard Worker       if (write)
444*7304104dSAndroid Build Coastguard Worker 	{
445*7304104dSAndroid Build Coastguard Worker 	  u24.v = u24_nums[i];
446*7304104dSAndroid Build Coastguard Worker 	  printf ("    0x%02" PRIx8 ", ", u24.c[0]);
447*7304104dSAndroid Build Coastguard Worker 	  printf ("0x%02" PRIx8 ", ", u24.c[1]);
448*7304104dSAndroid Build Coastguard Worker 	  printf ("0x%02" PRIx8 ",\n", u24.c[2]);
449*7304104dSAndroid Build Coastguard Worker 	}
450*7304104dSAndroid Build Coastguard Worker       else
451*7304104dSAndroid Build Coastguard Worker 	{
452*7304104dSAndroid Build Coastguard Worker 	  uint32_t v = read_3ubyte_unaligned_inc (&dbg_le, p_le);
453*7304104dSAndroid Build Coastguard Worker 	  assert (v == u24_nums[i]);
454*7304104dSAndroid Build Coastguard Worker 	  v = read_3ubyte_unaligned_inc (&dbg_be, p_be);
455*7304104dSAndroid Build Coastguard Worker 	  assert (v == u24_nums[i]);
456*7304104dSAndroid Build Coastguard Worker 	}
457*7304104dSAndroid Build Coastguard Worker     }
458*7304104dSAndroid Build Coastguard Worker 
459*7304104dSAndroid Build Coastguard Worker   union u32 u32;
460*7304104dSAndroid Build Coastguard Worker   if (write)
461*7304104dSAndroid Build Coastguard Worker     printf ("    /* u32 */\n");
462*7304104dSAndroid Build Coastguard Worker   for (size_t i = 0; i < sizeof (u32_nums) / sizeof (u32); i++)
463*7304104dSAndroid Build Coastguard Worker     {
464*7304104dSAndroid Build Coastguard Worker       if (write)
465*7304104dSAndroid Build Coastguard Worker 	{
466*7304104dSAndroid Build Coastguard Worker 	  u32.v = u32_nums[i];
467*7304104dSAndroid Build Coastguard Worker 	  printf ("    0x%02" PRIx8 ", ", u32.c[0]);
468*7304104dSAndroid Build Coastguard Worker 	  printf ("0x%02" PRIx8 ", ", u32.c[1]);
469*7304104dSAndroid Build Coastguard Worker 	  printf ("0x%02" PRIx8 ", ", u32.c[2]);
470*7304104dSAndroid Build Coastguard Worker 	  printf ("0x%02" PRIx8 ",\n", u32.c[3]);
471*7304104dSAndroid Build Coastguard Worker 	}
472*7304104dSAndroid Build Coastguard Worker       else
473*7304104dSAndroid Build Coastguard Worker 	{
474*7304104dSAndroid Build Coastguard Worker 	  uint32_t v = read_4ubyte_unaligned_inc (&dbg_le, p_le);
475*7304104dSAndroid Build Coastguard Worker 	  assert (v == u32_nums[i]);
476*7304104dSAndroid Build Coastguard Worker 	  v = read_4ubyte_unaligned_inc (&dbg_be, p_be);
477*7304104dSAndroid Build Coastguard Worker 	  assert (v == u32_nums[i]);
478*7304104dSAndroid Build Coastguard Worker 	}
479*7304104dSAndroid Build Coastguard Worker     }
480*7304104dSAndroid Build Coastguard Worker 
481*7304104dSAndroid Build Coastguard Worker   union s32 s32;
482*7304104dSAndroid Build Coastguard Worker   if (write)
483*7304104dSAndroid Build Coastguard Worker     printf ("    /* s32 */\n");
484*7304104dSAndroid Build Coastguard Worker   for (size_t i = 0; i < sizeof (s32_nums) / sizeof (s32); i++)
485*7304104dSAndroid Build Coastguard Worker     {
486*7304104dSAndroid Build Coastguard Worker       if (write)
487*7304104dSAndroid Build Coastguard Worker 	{
488*7304104dSAndroid Build Coastguard Worker 	  s32.v = s32_nums[i];
489*7304104dSAndroid Build Coastguard Worker 	  printf ("    0x%02" PRIx8 ", ", s32.c[0]);
490*7304104dSAndroid Build Coastguard Worker 	  printf ("0x%02" PRIx8 ", ", s32.c[1]);
491*7304104dSAndroid Build Coastguard Worker 	  printf ("0x%02" PRIx8 ", ", s32.c[2]);
492*7304104dSAndroid Build Coastguard Worker 	  printf ("0x%02" PRIx8 ",\n", s32.c[3]);
493*7304104dSAndroid Build Coastguard Worker 	}
494*7304104dSAndroid Build Coastguard Worker       else
495*7304104dSAndroid Build Coastguard Worker 	{
496*7304104dSAndroid Build Coastguard Worker 	  int32_t v = read_4sbyte_unaligned_inc (&dbg_le, p_le);
497*7304104dSAndroid Build Coastguard Worker 	  assert (v == s32_nums[i]);
498*7304104dSAndroid Build Coastguard Worker 	  v = read_4sbyte_unaligned_inc (&dbg_be, p_be);
499*7304104dSAndroid Build Coastguard Worker 	  assert (v == s32_nums[i]);
500*7304104dSAndroid Build Coastguard Worker 	}
501*7304104dSAndroid Build Coastguard Worker     }
502*7304104dSAndroid Build Coastguard Worker 
503*7304104dSAndroid Build Coastguard Worker   union u64 u64;
504*7304104dSAndroid Build Coastguard Worker   if (write)
505*7304104dSAndroid Build Coastguard Worker     printf ("    /* u64 */\n");
506*7304104dSAndroid Build Coastguard Worker   for (size_t i = 0; i < sizeof (u64_nums) / sizeof (u64); i++)
507*7304104dSAndroid Build Coastguard Worker     {
508*7304104dSAndroid Build Coastguard Worker       if (write)
509*7304104dSAndroid Build Coastguard Worker 	{
510*7304104dSAndroid Build Coastguard Worker 	  u64.v = u64_nums[i];
511*7304104dSAndroid Build Coastguard Worker 	  printf ("    0x%02" PRIx8 ", ", u64.c[0]);
512*7304104dSAndroid Build Coastguard Worker 	  printf ("0x%02" PRIx8 ", ", u64.c[1]);
513*7304104dSAndroid Build Coastguard Worker 	  printf ("0x%02" PRIx8 ", ", u64.c[2]);
514*7304104dSAndroid Build Coastguard Worker 	  printf ("0x%02" PRIx8 ", ", u64.c[3]);
515*7304104dSAndroid Build Coastguard Worker 	  printf ("0x%02" PRIx8 ", ", u64.c[4]);
516*7304104dSAndroid Build Coastguard Worker 	  printf ("0x%02" PRIx8 ", ", u64.c[5]);
517*7304104dSAndroid Build Coastguard Worker 	  printf ("0x%02" PRIx8 ", ", u64.c[6]);
518*7304104dSAndroid Build Coastguard Worker 	  printf ("0x%02" PRIx8 ",\n", u64.c[7]);
519*7304104dSAndroid Build Coastguard Worker 	}
520*7304104dSAndroid Build Coastguard Worker       else
521*7304104dSAndroid Build Coastguard Worker 	{
522*7304104dSAndroid Build Coastguard Worker 	  uint64_t v = read_8ubyte_unaligned_inc (&dbg_le, p_le);
523*7304104dSAndroid Build Coastguard Worker 	  assert (v == u64_nums[i]);
524*7304104dSAndroid Build Coastguard Worker 	  v = read_8ubyte_unaligned_inc (&dbg_be, p_be);
525*7304104dSAndroid Build Coastguard Worker 	  assert (v == u64_nums[i]);
526*7304104dSAndroid Build Coastguard Worker 	}
527*7304104dSAndroid Build Coastguard Worker     }
528*7304104dSAndroid Build Coastguard Worker 
529*7304104dSAndroid Build Coastguard Worker   union s64 s64;
530*7304104dSAndroid Build Coastguard Worker   if (write)
531*7304104dSAndroid Build Coastguard Worker     printf ("    /* s64 */\n");
532*7304104dSAndroid Build Coastguard Worker   for (size_t i = 0; i < sizeof (s64_nums) / sizeof (s64); i++)
533*7304104dSAndroid Build Coastguard Worker     {
534*7304104dSAndroid Build Coastguard Worker       if (write)
535*7304104dSAndroid Build Coastguard Worker 	{
536*7304104dSAndroid Build Coastguard Worker 	  s64.v = s64_nums[i];
537*7304104dSAndroid Build Coastguard Worker 	  printf ("    0x%02" PRIx8 ", ", s64.c[0]);
538*7304104dSAndroid Build Coastguard Worker 	  printf ("0x%02" PRIx8 ", ", s64.c[1]);
539*7304104dSAndroid Build Coastguard Worker 	  printf ("0x%02" PRIx8 ", ", s64.c[2]);
540*7304104dSAndroid Build Coastguard Worker 	  printf ("0x%02" PRIx8 ", ", s64.c[3]);
541*7304104dSAndroid Build Coastguard Worker 	  printf ("0x%02" PRIx8 ", ", s64.c[4]);
542*7304104dSAndroid Build Coastguard Worker 	  printf ("0x%02" PRIx8 ", ", s64.c[5]);
543*7304104dSAndroid Build Coastguard Worker 	  printf ("0x%02" PRIx8 ", ", s64.c[6]);
544*7304104dSAndroid Build Coastguard Worker 	  printf ("0x%02" PRIx8 ",\n", s64.c[7]);
545*7304104dSAndroid Build Coastguard Worker 	}
546*7304104dSAndroid Build Coastguard Worker       else
547*7304104dSAndroid Build Coastguard Worker 	{
548*7304104dSAndroid Build Coastguard Worker 	  int64_t v = read_8sbyte_unaligned_inc (&dbg_le, p_le);
549*7304104dSAndroid Build Coastguard Worker 	  assert (v == s64_nums[i]);
550*7304104dSAndroid Build Coastguard Worker 	  v = read_8sbyte_unaligned_inc (&dbg_be, p_be);
551*7304104dSAndroid Build Coastguard Worker 	  assert (v == s64_nums[i]);
552*7304104dSAndroid Build Coastguard Worker 	}
553*7304104dSAndroid Build Coastguard Worker     }
554*7304104dSAndroid Build Coastguard Worker 
555*7304104dSAndroid Build Coastguard Worker   if (write)
556*7304104dSAndroid Build Coastguard Worker     printf ("  };\n");
557*7304104dSAndroid Build Coastguard Worker   else
558*7304104dSAndroid Build Coastguard Worker     {
559*7304104dSAndroid Build Coastguard Worker       assert (p_le == le_mem + sizeof (le_mem));
560*7304104dSAndroid Build Coastguard Worker       assert (p_be == be_mem + sizeof (be_mem));
561*7304104dSAndroid Build Coastguard Worker     }
562*7304104dSAndroid Build Coastguard Worker 
563*7304104dSAndroid Build Coastguard Worker   return 0;
564*7304104dSAndroid Build Coastguard Worker }
565