Statistics
| Branch: | Revision:

root / tests / test-i386.c @ 379ca80d

History | View | Annotate | Download (5.6 kB)

1
#include <stdlib.h>
2
#include <stdio.h>
3
#include <math.h>
4

    
5
#define xglue(x, y) x ## y
6
#define glue(x, y) xglue(x, y)
7
#define stringify(s)        tostring(s)
8
#define tostring(s)        #s
9

    
10
#define CC_C           0x0001
11
#define CC_P         0x0004
12
#define CC_A        0x0010
13
#define CC_Z        0x0040
14
#define CC_S    0x0080
15
#define CC_O    0x0800
16

    
17
/* XXX: currently no A flag */
18
#define CC_MASK (CC_C | CC_P | CC_Z | CC_S | CC_O)
19

    
20
#define __init_call        __attribute__ ((unused,__section__ (".initcall.init")))
21

    
22
static void *call_start __init_call = NULL;
23

    
24
#define OP add
25
#include "test-i386.h"
26

    
27
#define OP sub
28
#include "test-i386.h"
29

    
30
#define OP xor
31
#include "test-i386.h"
32

    
33
#define OP and
34
#include "test-i386.h"
35

    
36
#define OP or
37
#include "test-i386.h"
38

    
39
#define OP cmp
40
#include "test-i386.h"
41

    
42
#define OP adc
43
#define OP_CC
44
#include "test-i386.h"
45

    
46
#define OP sbb
47
#define OP_CC
48
#include "test-i386.h"
49

    
50
#define OP inc
51
#define OP_CC
52
#define OP1
53
#include "test-i386.h"
54

    
55
#define OP dec
56
#define OP_CC
57
#define OP1
58
#include "test-i386.h"
59

    
60
#define OP neg
61
#define OP_CC
62
#define OP1
63
#include "test-i386.h"
64

    
65
#define OP not
66
#define OP_CC
67
#define OP1
68
#include "test-i386.h"
69

    
70
#define OP shl
71
#include "test-i386-shift.h"
72

    
73
#define OP shr
74
#include "test-i386-shift.h"
75

    
76
#define OP sar
77
#include "test-i386-shift.h"
78

    
79
#define OP rol
80
#include "test-i386-shift.h"
81

    
82
#define OP ror
83
#include "test-i386-shift.h"
84

    
85
#define OP rcr
86
#define OP_CC
87
#include "test-i386-shift.h"
88

    
89
#define OP rcl
90
#define OP_CC
91
#include "test-i386-shift.h"
92

    
93

    
94
/* lea test (modrm support) */
95
#define TEST_LEA(STR)\
96
{\
97
    asm("leal " STR ", %0"\
98
        : "=r" (res)\
99
        : "a" (eax), "b" (ebx), "c" (ecx), "d" (edx), "S" (esi), "D" (edi));\
100
    printf("lea %s = %08x\n", STR, res);\
101
}
102

    
103
#define TEST_LEA16(STR)\
104
{\
105
    asm(".code16 ; .byte 0x67 ; leal " STR ", %0 ; .code32"\
106
        : "=wq" (res)\
107
        : "a" (eax), "b" (ebx), "c" (ecx), "d" (edx), "S" (esi), "D" (edi));\
108
    printf("lea %s = %08x\n", STR, res);\
109
}
110

    
111

    
112
void test_lea(void)
113
{
114
    int eax, ebx, ecx, edx, esi, edi, res;
115
    eax = 0x0001;
116
    ebx = 0x0002;
117
    ecx = 0x0004;
118
    edx = 0x0008;
119
    esi = 0x0010;
120
    edi = 0x0020;
121

    
122
    TEST_LEA("0x4000");
123

    
124
    TEST_LEA("(%%eax)");
125
    TEST_LEA("(%%ebx)");
126
    TEST_LEA("(%%ecx)");
127
    TEST_LEA("(%%edx)");
128
    TEST_LEA("(%%esi)");
129
    TEST_LEA("(%%edi)");
130

    
131
    TEST_LEA("0x40(%%eax)");
132
    TEST_LEA("0x40(%%ebx)");
133
    TEST_LEA("0x40(%%ecx)");
134
    TEST_LEA("0x40(%%edx)");
135
    TEST_LEA("0x40(%%esi)");
136
    TEST_LEA("0x40(%%edi)");
137

    
138
    TEST_LEA("0x4000(%%eax)");
139
    TEST_LEA("0x4000(%%ebx)");
140
    TEST_LEA("0x4000(%%ecx)");
141
    TEST_LEA("0x4000(%%edx)");
142
    TEST_LEA("0x4000(%%esi)");
143
    TEST_LEA("0x4000(%%edi)");
144

    
145
    TEST_LEA("(%%eax, %%ecx)");
146
    TEST_LEA("(%%ebx, %%edx)");
147
    TEST_LEA("(%%ecx, %%ecx)");
148
    TEST_LEA("(%%edx, %%ecx)");
149
    TEST_LEA("(%%esi, %%ecx)");
150
    TEST_LEA("(%%edi, %%ecx)");
151

    
152
    TEST_LEA("0x40(%%eax, %%ecx)");
153
    TEST_LEA("0x4000(%%ebx, %%edx)");
154

    
155
    TEST_LEA("(%%ecx, %%ecx, 2)");
156
    TEST_LEA("(%%edx, %%ecx, 4)");
157
    TEST_LEA("(%%esi, %%ecx, 8)");
158

    
159
    TEST_LEA("(,%%eax, 2)");
160
    TEST_LEA("(,%%ebx, 4)");
161
    TEST_LEA("(,%%ecx, 8)");
162

    
163
    TEST_LEA("0x40(,%%eax, 2)");
164
    TEST_LEA("0x40(,%%ebx, 4)");
165
    TEST_LEA("0x40(,%%ecx, 8)");
166

    
167

    
168
    TEST_LEA("-10(%%ecx, %%ecx, 2)");
169
    TEST_LEA("-10(%%edx, %%ecx, 4)");
170
    TEST_LEA("-10(%%esi, %%ecx, 8)");
171

    
172
    TEST_LEA("0x4000(%%ecx, %%ecx, 2)");
173
    TEST_LEA("0x4000(%%edx, %%ecx, 4)");
174
    TEST_LEA("0x4000(%%esi, %%ecx, 8)");
175

    
176
    /* limited 16 bit addressing test */
177
    TEST_LEA16("0x4000");
178
    TEST_LEA16("(%%bx)");
179
    TEST_LEA16("(%%si)");
180
    TEST_LEA16("(%%di)");
181
    TEST_LEA16("0x40(%%bx)");
182
    TEST_LEA16("0x40(%%si)");
183
    TEST_LEA16("0x40(%%di)");
184
    TEST_LEA16("0x4000(%%bx)");
185
    TEST_LEA16("0x4000(%%si)");
186
    TEST_LEA16("(%%bx,%%si)");
187
    TEST_LEA16("(%%bx,%%di)");
188
    TEST_LEA16("0x40(%%bx,%%si)");
189
    TEST_LEA16("0x40(%%bx,%%di)");
190
    TEST_LEA16("0x4000(%%bx,%%si)");
191
    TEST_LEA16("0x4000(%%bx,%%di)");
192
}
193

    
194
#define TEST_JCC(JCC, v1, v2)\
195
{\
196
    asm("movl $1, %0\n\t"\
197
        "cmpl %2, %1\n\t"\
198
        JCC " 1f\n\t"\
199
        "movl $0, %0\n\t"\
200
        "1:\n\t"\
201
        : "=r" (res)\
202
        : "r" (v1), "r" (v2));\
203
    printf("%-10s %d\n", JCC, res);\
204
}
205

    
206
/* various jump tests */
207
void test_jcc(void)
208
{
209
    int res;
210

    
211
    TEST_JCC("jne", 1, 1);
212
    TEST_JCC("jne", 1, 0);
213

    
214
    TEST_JCC("je", 1, 1);
215
    TEST_JCC("je", 1, 0);
216

    
217
    TEST_JCC("jl", 1, 1);
218
    TEST_JCC("jl", 1, 0);
219
    TEST_JCC("jl", 1, -1);
220

    
221
    TEST_JCC("jle", 1, 1);
222
    TEST_JCC("jle", 1, 0);
223
    TEST_JCC("jle", 1, -1);
224

    
225
    TEST_JCC("jge", 1, 1);
226
    TEST_JCC("jge", 1, 0);
227
    TEST_JCC("jge", -1, 1);
228

    
229
    TEST_JCC("jg", 1, 1);
230
    TEST_JCC("jg", 1, 0);
231
    TEST_JCC("jg", 1, -1);
232

    
233
    TEST_JCC("jb", 1, 1);
234
    TEST_JCC("jb", 1, 0);
235
    TEST_JCC("jb", 1, -1);
236

    
237
    TEST_JCC("jbe", 1, 1);
238
    TEST_JCC("jbe", 1, 0);
239
    TEST_JCC("jbe", 1, -1);
240

    
241
    TEST_JCC("jae", 1, 1);
242
    TEST_JCC("jae", 1, 0);
243
    TEST_JCC("jae", 1, -1);
244

    
245
    TEST_JCC("ja", 1, 1);
246
    TEST_JCC("ja", 1, 0);
247
    TEST_JCC("ja", 1, -1);
248

    
249

    
250
    TEST_JCC("jp", 1, 1);
251
    TEST_JCC("jp", 1, 0);
252

    
253
    TEST_JCC("jnp", 1, 1);
254
    TEST_JCC("jnp", 1, 0);
255

    
256
    TEST_JCC("jo", 0x7fffffff, 0);
257
    TEST_JCC("jo", 0x7fffffff, -1);
258

    
259
    TEST_JCC("jno", 0x7fffffff, 0);
260
    TEST_JCC("jno", 0x7fffffff, -1);
261

    
262
    TEST_JCC("js", 0, 1);
263
    TEST_JCC("js", 0, -1);
264
    TEST_JCC("js", 0, 0);
265

    
266
    TEST_JCC("jns", 0, 1);
267
    TEST_JCC("jns", 0, -1);
268
    TEST_JCC("jns", 0, 0);
269
}
270

    
271
static void *call_end __init_call = NULL;
272

    
273
int main(int argc, char **argv)
274
{
275
    void **ptr;
276
    void (*func)(void);
277
    ptr = &call_start + 1;
278
    while (*ptr != NULL) {
279
        func = *ptr++;
280
        func();
281
    }
282
    test_lea();
283
    test_jcc();
284
    return 0;
285
}