summaryrefslogtreecommitdiffstats
path: root/debug/testfilegen-arm64.c
blob: 88cadcaae18986015ac45f75e5d1823edb54f887 (plain)
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
// SPDX-License-Identifier: 0BSD

///////////////////////////////////////////////////////////////////////////////
//
/// \file       testfilegen-arm64.c
/// \brief      Generates uncompressed test file for the ARM64 filter
//
//  Author:     Lasse Collin
//
///////////////////////////////////////////////////////////////////////////////

#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>


static uint32_t pc4 = 0;


static void
put32le(uint32_t v)
{
	putchar((v >> 0) & 0xFF);
	putchar((v >> 8) & 0xFF);
	putchar((v >> 16) & 0xFF);
	putchar((v >> 24) & 0xFF);
	++pc4;
}


static void
putbl(uint32_t imm)
{
	imm &= (1U << 26) - 1;
	imm |= 0x25U << 26;
	put32le(imm);
}


static void
putadrp32(uint32_t imm)
{
	imm &= 0x1FFFFFU;

	// fprintf(stderr, "ADRP 0x%08X\n", imm);

	uint32_t instr = 0x90000000;
	instr |= (pc4 * 5 + 11) & 0x1F;
	instr |= (imm & 3) << 29;
	instr |= (imm >> 2) << 5;

	put32le(instr);
}


extern int
main(void)
{
	putbl(0);
	putbl(0x03FFFFFF);
	putbl(0x03FFFFFE);
	putbl(0x03FFFFFD);

	putbl(3);
	putbl(2);
	putbl(1);
	putbl(0);


	putbl(0x02000001);
	putbl(0x02000000);
	putbl(0x01FFFFFF);
	putbl(0x01FFFFFE);

	putbl(0x01111117);
	putbl(0x01111116);
	putbl(0x01111115);
	putbl(0x01111114);


	putbl(0x02222227);
	putbl(0x02222226);
	putbl(0x02222225);
	putbl(0x02222224);

	putbl(0U - pc4);
	putbl(0U - pc4);
	putbl(0U - pc4);
	putbl(0U - pc4);

	putadrp32(0x00);
	putadrp32(0x05);
	putadrp32(0x15);
	putadrp32(0x25);

	for (unsigned rep = 0; rep < 2; ++rep) {
		while ((pc4 << 2) & 4095)
			put32le(0x55555555U);

		for (unsigned i = 10; i <= 21; ++i) {
			const uint32_t neg = (0x1FFF00 >> (21 - i)) & ~255U;
			const uint32_t plus = 1U << (i - 1);
			putadrp32(0x000000 | plus);
			putadrp32(0x000005 | plus);
			putadrp32(0x0000FE | plus);
			putadrp32(0x0000FF | plus);

			putadrp32(0x000000 | neg);
			putadrp32(0x000005 | neg);
			putadrp32(0x0000FE | neg);
			putadrp32(0x0000FF | neg);
		}
	}

	return 0;
}