1f08c3bdfSopenharmony_ci#include "symbol.h"
2f08c3bdfSopenharmony_ci#include "target.h"
3f08c3bdfSopenharmony_ci#include "machine.h"
4f08c3bdfSopenharmony_ci#include "builtin.h"
5f08c3bdfSopenharmony_ci
6f08c3bdfSopenharmony_ci
7f08c3bdfSopenharmony_cistatic void predefine_i386(const struct target *self)
8f08c3bdfSopenharmony_ci{
9f08c3bdfSopenharmony_ci	predefine("__i386__", 1, "1");
10f08c3bdfSopenharmony_ci	predefine("__i386", 1, "1");
11f08c3bdfSopenharmony_ci	predefine_nostd("i386");
12f08c3bdfSopenharmony_ci}
13f08c3bdfSopenharmony_ci
14f08c3bdfSopenharmony_cistatic void predefine_x86_64(const struct target *self)
15f08c3bdfSopenharmony_ci{
16f08c3bdfSopenharmony_ci	predefine("__x86_64__", 1, "1");
17f08c3bdfSopenharmony_ci	predefine("__x86_64", 1, "1");
18f08c3bdfSopenharmony_ci	predefine("__amd64__", 1, "1");
19f08c3bdfSopenharmony_ci	predefine("__amd64", 1, "1");
20f08c3bdfSopenharmony_ci}
21f08c3bdfSopenharmony_ci
22f08c3bdfSopenharmony_ci
23f08c3bdfSopenharmony_cistatic void init_x86_common(const struct target *target)
24f08c3bdfSopenharmony_ci{
25f08c3bdfSopenharmony_ci	switch (arch_os) {
26f08c3bdfSopenharmony_ci	case OS_CYGWIN:
27f08c3bdfSopenharmony_ci		wchar_ctype = &ushort_ctype;
28f08c3bdfSopenharmony_ci		break;
29f08c3bdfSopenharmony_ci	case OS_FREEBSD:
30f08c3bdfSopenharmony_ci		wint_ctype = &int_ctype;
31f08c3bdfSopenharmony_ci		break;
32f08c3bdfSopenharmony_ci	case OS_OPENBSD:
33f08c3bdfSopenharmony_ci		size_t_ctype = &ulong_ctype;
34f08c3bdfSopenharmony_ci		ssize_t_ctype = &long_ctype;
35f08c3bdfSopenharmony_ci		wchar_ctype = &int_ctype;
36f08c3bdfSopenharmony_ci		wint_ctype = &int_ctype;
37f08c3bdfSopenharmony_ci		fast16_ctype = &short_ctype;
38f08c3bdfSopenharmony_ci		ufast16_ctype = &ushort_ctype;
39f08c3bdfSopenharmony_ci		break;
40f08c3bdfSopenharmony_ci	}
41f08c3bdfSopenharmony_ci}
42f08c3bdfSopenharmony_ci
43f08c3bdfSopenharmony_cistatic const struct builtin_fn builtins_x86_common[] = {
44f08c3bdfSopenharmony_ci	{ "__builtin_ia32_pause", &void_ctype, 0, },
45f08c3bdfSopenharmony_ci	{ }
46f08c3bdfSopenharmony_ci};
47f08c3bdfSopenharmony_ci
48f08c3bdfSopenharmony_ci
49f08c3bdfSopenharmony_cistatic void init_i386(const struct target *target)
50f08c3bdfSopenharmony_ci{
51f08c3bdfSopenharmony_ci	fast16_ctype = &int_ctype;
52f08c3bdfSopenharmony_ci	ufast16_ctype = &uint_ctype;
53f08c3bdfSopenharmony_ci	fast32_ctype = &int_ctype;
54f08c3bdfSopenharmony_ci	ufast32_ctype = &uint_ctype;
55f08c3bdfSopenharmony_ci
56f08c3bdfSopenharmony_ci	init_x86_common(target);
57f08c3bdfSopenharmony_ci}
58f08c3bdfSopenharmony_ci
59f08c3bdfSopenharmony_ciconst struct target target_i386 = {
60f08c3bdfSopenharmony_ci	.mach = MACH_I386,
61f08c3bdfSopenharmony_ci	.bitness = ARCH_LP32,
62f08c3bdfSopenharmony_ci	.big_endian = 0,
63f08c3bdfSopenharmony_ci	.unsigned_char = 0,
64f08c3bdfSopenharmony_ci
65f08c3bdfSopenharmony_ci	.wchar = &long_ctype,
66f08c3bdfSopenharmony_ci	.bits_in_longdouble = 96,
67f08c3bdfSopenharmony_ci	.max_fp_alignment = 4,
68f08c3bdfSopenharmony_ci
69f08c3bdfSopenharmony_ci	.target_64bit = &target_x86_64,
70f08c3bdfSopenharmony_ci
71f08c3bdfSopenharmony_ci	.init = init_i386,
72f08c3bdfSopenharmony_ci	.predefine = predefine_i386,
73f08c3bdfSopenharmony_ci	.builtins = builtins_x86_common,
74f08c3bdfSopenharmony_ci};
75f08c3bdfSopenharmony_ci
76f08c3bdfSopenharmony_ci
77f08c3bdfSopenharmony_cistatic void init_x86_x32(const struct target *target)
78f08c3bdfSopenharmony_ci{
79f08c3bdfSopenharmony_ci	init_x86_common(target);
80f08c3bdfSopenharmony_ci
81f08c3bdfSopenharmony_ci	max_int_alignment = 8;
82f08c3bdfSopenharmony_ci
83f08c3bdfSopenharmony_ci	fast16_ctype = &int_ctype;
84f08c3bdfSopenharmony_ci	ufast16_ctype = &uint_ctype;
85f08c3bdfSopenharmony_ci	fast32_ctype = &int_ctype;
86f08c3bdfSopenharmony_ci	ufast32_ctype = &uint_ctype;
87f08c3bdfSopenharmony_ci	wchar_ctype = &long_ctype;
88f08c3bdfSopenharmony_ci}
89f08c3bdfSopenharmony_ci
90f08c3bdfSopenharmony_cistatic const struct target target_x86_x32 = {
91f08c3bdfSopenharmony_ci	.mach = MACH_X86_64,
92f08c3bdfSopenharmony_ci	.bitness = ARCH_X32,
93f08c3bdfSopenharmony_ci	.big_endian = 0,
94f08c3bdfSopenharmony_ci	.unsigned_char = 0,
95f08c3bdfSopenharmony_ci	.has_int128 = 1,
96f08c3bdfSopenharmony_ci
97f08c3bdfSopenharmony_ci	.bits_in_longdouble = 128,
98f08c3bdfSopenharmony_ci	.max_fp_alignment = 16,
99f08c3bdfSopenharmony_ci
100f08c3bdfSopenharmony_ci	.target_32bit = &target_i386,
101f08c3bdfSopenharmony_ci	.target_64bit = &target_x86_64,
102f08c3bdfSopenharmony_ci
103f08c3bdfSopenharmony_ci	.init = init_x86_x32,
104f08c3bdfSopenharmony_ci	.predefine = predefine_x86_64,
105f08c3bdfSopenharmony_ci};
106f08c3bdfSopenharmony_ci
107f08c3bdfSopenharmony_ci
108f08c3bdfSopenharmony_cistatic void init_x86_64(const struct target *target)
109f08c3bdfSopenharmony_ci{
110f08c3bdfSopenharmony_ci	init_x86_common(target);
111f08c3bdfSopenharmony_ci
112f08c3bdfSopenharmony_ci	switch (arch_os) {
113f08c3bdfSopenharmony_ci	case OS_CYGWIN:
114f08c3bdfSopenharmony_ci		break;
115f08c3bdfSopenharmony_ci	case OS_DARWIN:
116f08c3bdfSopenharmony_ci		int64_ctype = &llong_ctype;
117f08c3bdfSopenharmony_ci		uint64_ctype = &ullong_ctype;
118f08c3bdfSopenharmony_ci		wint_ctype = &int_ctype;
119f08c3bdfSopenharmony_ci		fast16_ctype = &short_ctype;
120f08c3bdfSopenharmony_ci		ufast16_ctype = &ushort_ctype;
121f08c3bdfSopenharmony_ci		fast32_ctype = &int_ctype;
122f08c3bdfSopenharmony_ci		ufast32_ctype = &uint_ctype;
123f08c3bdfSopenharmony_ci		fast64_ctype = &llong_ctype;
124f08c3bdfSopenharmony_ci		ufast64_ctype = &ullong_ctype;
125f08c3bdfSopenharmony_ci		break;
126f08c3bdfSopenharmony_ci	case OS_FREEBSD:
127f08c3bdfSopenharmony_ci		fast16_ctype = &short_ctype;
128f08c3bdfSopenharmony_ci		ufast16_ctype = &ushort_ctype;
129f08c3bdfSopenharmony_ci		fast32_ctype = &int_ctype;
130f08c3bdfSopenharmony_ci		ufast32_ctype = &uint_ctype;
131f08c3bdfSopenharmony_ci		break;
132f08c3bdfSopenharmony_ci	case OS_NETBSD:
133f08c3bdfSopenharmony_ci		fast8_ctype = &int_ctype;
134f08c3bdfSopenharmony_ci		ufast8_ctype = &uint_ctype;
135f08c3bdfSopenharmony_ci		fast16_ctype = &int_ctype;
136f08c3bdfSopenharmony_ci		ufast16_ctype = &uint_ctype;
137f08c3bdfSopenharmony_ci		fast32_ctype = &int_ctype;
138f08c3bdfSopenharmony_ci		ufast32_ctype = &uint_ctype;
139f08c3bdfSopenharmony_ci		wint_ctype = &int_ctype;
140f08c3bdfSopenharmony_ci		break;
141f08c3bdfSopenharmony_ci	case OS_OPENBSD:
142f08c3bdfSopenharmony_ci		fast32_ctype = &int_ctype;
143f08c3bdfSopenharmony_ci		ufast32_ctype = &uint_ctype;
144f08c3bdfSopenharmony_ci		int64_ctype = &llong_ctype;
145f08c3bdfSopenharmony_ci		uint64_ctype = &ullong_ctype;
146f08c3bdfSopenharmony_ci		intmax_ctype = &llong_ctype;
147f08c3bdfSopenharmony_ci		uintmax_ctype = &ullong_ctype;
148f08c3bdfSopenharmony_ci		least64_ctype = &long_ctype;
149f08c3bdfSopenharmony_ci		uleast64_ctype = &ulong_ctype;
150f08c3bdfSopenharmony_ci		break;
151f08c3bdfSopenharmony_ci	}
152f08c3bdfSopenharmony_ci}
153f08c3bdfSopenharmony_ci
154f08c3bdfSopenharmony_ciconst struct target target_x86_64 = {
155f08c3bdfSopenharmony_ci	.mach = MACH_X86_64,
156f08c3bdfSopenharmony_ci	.bitness = ARCH_LP64,
157f08c3bdfSopenharmony_ci	.big_endian = 0,
158f08c3bdfSopenharmony_ci	.unsigned_char = 0,
159f08c3bdfSopenharmony_ci	.has_int128 = 1,
160f08c3bdfSopenharmony_ci
161f08c3bdfSopenharmony_ci	.bits_in_longdouble = 128,
162f08c3bdfSopenharmony_ci	.max_fp_alignment = 16,
163f08c3bdfSopenharmony_ci
164f08c3bdfSopenharmony_ci	.target_32bit = &target_i386,
165f08c3bdfSopenharmony_ci	.target_x32bit = &target_x86_x32,
166f08c3bdfSopenharmony_ci
167f08c3bdfSopenharmony_ci	.init = init_x86_64,
168f08c3bdfSopenharmony_ci	.predefine = predefine_x86_64,
169f08c3bdfSopenharmony_ci	.builtins = builtins_x86_common,
170f08c3bdfSopenharmony_ci};
171