Files

131 lines
3.5 KiB
C

/* M7.1 `.data` initializer gate driver.
*
* Every global below is `volatile` so the reads at -O0/-O2 really come from
* the linked `.data` image rather than from a folded constant.
*
* The initializers exercise the M7.1 emitter recursion:
* - a 64-bit scalar (LSW first in memory);
* - the 1987 bitfield struct s { a:3; b:5; c:4; d:20; e:4; } (5 bytes,
* Clang's byte storage);
* - a packed record with an interior i64 (<{ i8, i32, i64 }>, 13 bytes);
* - an array of packed records (3 x 6 bytes);
* - a union whose active member is the 6-byte struct and whose allocation
* is the 8-byte i64 (the trailing two bytes are zero);
* - a pointer global, a pointer with a +3-byte addend, and a packed record
* with a pointer field between two scalar fields (the TI-COFF relocation
* and the GSPA `.long _x`).
*
* Markers are at 0x018A8000 + n*0x20; the raw object bytes are at
* 0x018A9000 + n*8. data-check.lua compares them with the exact expected
* values, so both the field reads and the byte image are checked in MAME.
*/
typedef unsigned int u32;
#define MARK(n) (*(volatile u32 *)(0x018A8000u + (u32)(n) * 0x20u))
#define OUTB(n) (*(volatile unsigned char *)(0x018A9000u + (u32)(n) * 8u))
volatile long long x = 0x1122334455667788LL;
struct s {
unsigned a:3;
unsigned b:5;
int c:4;
unsigned d:20;
unsigned e:4;
};
volatile struct s s = { 5, 17, -3, 0xABCDE, 9 };
struct p {
char a;
int b;
long long c;
};
volatile struct p p = { 0x11, 0x22334455, 0x66778899AABBCCDDLL };
struct rec {
int a;
short b;
};
volatile struct rec arr[3] = {
{ 0x11223344, 0x5566 },
{ 0x778899AA, 0xBBCC },
{ 0xDDEEFF00, 0x1122 },
};
union u {
long long l;
char c[6];
struct { int i; short h; } s;
};
volatile union u u = { .s = { 0x12345678, 0x9ABC } };
long long *volatile pp = (long long *)&x;
char *volatile cp = (char *)&x + 3;
struct pt {
int tag;
long long *p;
char c;
};
volatile struct pt pt = { 0x1234, (long long *)&x, 0x5A };
static void dump(const volatile unsigned char *src, u32 n, u32 *out)
{
u32 i;
for (i = 0; i < n; i++)
OUTB((*out)++) = src[i];
}
void data_run(void)
{
u32 o;
MARK(0) = (u32)(unsigned long long)x;
MARK(1) = (u32)((unsigned long long)x >> 32);
MARK(2) = (u32)s.a;
MARK(3) = (u32)s.b;
MARK(4) = (u32)s.c;
MARK(5) = (u32)s.d;
MARK(6) = (u32)s.e;
MARK(7) = (u32)p.a;
MARK(8) = (u32)p.b;
MARK(9) = (u32)p.c;
MARK(10) = (u32)((unsigned long long)p.c >> 32);
MARK(11) = (u32)arr[0].a;
MARK(12) = (u32)arr[1].a;
MARK(13) = (u32)arr[2].a;
MARK(14) = (u32)(unsigned short)arr[0].b;
MARK(24) = (u32)(unsigned short)arr[1].b;
MARK(23) = (u32)(unsigned short)arr[2].b;
MARK(15) = (u32)u.s.i;
MARK(16) = (u32)(unsigned short)u.s.h;
MARK(17) = (u32)((pp == &x) && (*pp == x));
MARK(18) = (u32)(cp - (char *)&x);
MARK(19) = (u32)pt.tag;
MARK(20) = (u32)((pt.p == &x) && (pt.c == 0x5A));
MARK(21) = (u32)u.l;
MARK(22) = (u32)((unsigned long long)u.l >> 32);
/* The linked address of x, for the pointer bytes in the raw image. */
MARK(25) = (u32)(unsigned long)&x;
/* Raw bytes: x, s, p, arr, u are contiguous; pt starts at byte 64. */
o = 0;
dump((const volatile unsigned char *)&x, (u32)sizeof(x), &o);
dump((const volatile unsigned char *)&s, (u32)sizeof(s), &o);
dump((const volatile unsigned char *)&p, (u32)sizeof(p), &o);
dump((const volatile unsigned char *)&arr, (u32)sizeof(arr), &o);
dump((const volatile unsigned char *)&u, (u32)sizeof(u), &o);
o = 64;
dump((const volatile unsigned char *)&pt, (u32)sizeof(pt), &o);
}