aboutsummaryrefslogtreecommitdiffstats
path: root/target-x86.c
blob: 9d82869a27b8dcee48257ad75ebcdc75320ef71c (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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#include "symbol.h"
#include "target.h"
#include "machine.h"
#include "builtin.h"


static void predefine_i386(const struct target *self)
{
	predefine("__i386__", 1, "1");
	predefine("__i386", 1, "1");
	predefine_nostd("i386");
}

static void predefine_x86_64(const struct target *self)
{
	predefine("__x86_64__", 1, "1");
	predefine("__x86_64", 1, "1");
	predefine("__amd64__", 1, "1");
	predefine("__amd64", 1, "1");
}


static void init_x86_common(const struct target *target)
{
	switch (arch_os) {
	case OS_CYGWIN:
		wchar_ctype = &ushort_ctype;
		break;
	case OS_FREEBSD:
		wint_ctype = &int_ctype;
		break;
	case OS_OPENBSD:
		size_t_ctype = &ulong_ctype;
		ssize_t_ctype = &long_ctype;
		wchar_ctype = &int_ctype;
		wint_ctype = &int_ctype;
		fast16_ctype = &short_ctype;
		ufast16_ctype = &ushort_ctype;
		break;
	}
}

static const struct builtin_fn builtins_x86_common[] = {
	{ "__builtin_ia32_pause", &void_ctype, 0, },
	{ }
};


static void init_i386(const struct target *target)
{
	fast16_ctype = &int_ctype;
	ufast16_ctype = &uint_ctype;
	fast32_ctype = &int_ctype;
	ufast32_ctype = &uint_ctype;

	init_x86_common(target);
}

const struct target target_i386 = {
	.mach = MACH_I386,
	.bitness = ARCH_LP32,
	.big_endian = 0,
	.unsigned_char = 0,

	.wchar = &long_ctype,
	.bits_in_longdouble = 96,
	.max_fp_alignment = 4,

	.target_64bit = &target_x86_64,

	.init = init_i386,
	.predefine = predefine_i386,
	.builtins = builtins_x86_common,
};


static void init_x86_x32(const struct target *target)
{
	init_x86_common(target);

	max_int_alignment = 8;

	fast16_ctype = &int_ctype;
	ufast16_ctype = &uint_ctype;
	fast32_ctype = &int_ctype;
	ufast32_ctype = &uint_ctype;
	wchar_ctype = &long_ctype;
}

static const struct target target_x86_x32 = {
	.mach = MACH_X86_64,
	.bitness = ARCH_X32,
	.big_endian = 0,
	.unsigned_char = 0,
	.has_int128 = 1,

	.bits_in_longdouble = 128,
	.max_fp_alignment = 16,

	.target_32bit = &target_i386,
	.target_64bit = &target_x86_64,

	.init = init_x86_x32,
	.predefine = predefine_x86_64,
};


static void init_x86_64(const struct target *target)
{
	init_x86_common(target);

	switch (arch_os) {
	case OS_CYGWIN:
		break;
	case OS_DARWIN:
		int64_ctype = &llong_ctype;
		uint64_ctype = &ullong_ctype;
		wint_ctype = &int_ctype;
		fast16_ctype = &short_ctype;
		ufast16_ctype = &ushort_ctype;
		fast32_ctype = &int_ctype;
		ufast32_ctype = &uint_ctype;
		fast64_ctype = &llong_ctype;
		ufast64_ctype = &ullong_ctype;
		break;
	case OS_FREEBSD:
		fast16_ctype = &short_ctype;
		ufast16_ctype = &ushort_ctype;
		fast32_ctype = &int_ctype;
		ufast32_ctype = &uint_ctype;
		break;
	case OS_NETBSD:
		fast8_ctype = &int_ctype;
		ufast8_ctype = &uint_ctype;
		fast16_ctype = &int_ctype;
		ufast16_ctype = &uint_ctype;
		fast32_ctype = &int_ctype;
		ufast32_ctype = &uint_ctype;
		wint_ctype = &int_ctype;
		break;
	case OS_OPENBSD:
		fast32_ctype = &int_ctype;
		ufast32_ctype = &uint_ctype;
		int64_ctype = &llong_ctype;
		uint64_ctype = &ullong_ctype;
		intmax_ctype = &llong_ctype;
		uintmax_ctype = &ullong_ctype;
		least64_ctype = &long_ctype;
		uleast64_ctype = &ulong_ctype;
		break;
	}
}

const struct target target_x86_64 = {
	.mach = MACH_X86_64,
	.bitness = ARCH_LP64,
	.big_endian = 0,
	.unsigned_char = 0,
	.has_int128 = 1,

	.bits_in_longdouble = 128,
	.max_fp_alignment = 16,

	.target_32bit = &target_i386,
	.target_x32bit = &target_x86_x32,

	.init = init_x86_64,
	.predefine = predefine_x86_64,
	.builtins = builtins_x86_common,
};