1 |
|
---|
2 | #define exec_op glue(exec_, OP)
|
---|
3 | #define exec_opl glue(glue(exec_, OP), l)
|
---|
4 | #define exec_opw glue(glue(exec_, OP), w)
|
---|
5 | #define exec_opb glue(glue(exec_, OP), b)
|
---|
6 |
|
---|
7 | #define EXECOP2(size, res, s1, flags) \
|
---|
8 | asm ("push %4\n\t"\
|
---|
9 | "popf\n\t"\
|
---|
10 | stringify(OP) size " %" size "2, %" size "0\n\t" \
|
---|
11 | "pushf\n\t"\
|
---|
12 | "popl %1\n\t"\
|
---|
13 | : "=q" (res), "=g" (flags)\
|
---|
14 | : "q" (s1), "0" (res), "1" (flags));
|
---|
15 |
|
---|
16 | #define EXECOP1(size, res, flags) \
|
---|
17 | asm ("push %3\n\t"\
|
---|
18 | "popf\n\t"\
|
---|
19 | stringify(OP) size " %" size "0\n\t" \
|
---|
20 | "pushf\n\t"\
|
---|
21 | "popl %1\n\t"\
|
---|
22 | : "=q" (res), "=g" (flags)\
|
---|
23 | : "0" (res), "1" (flags));
|
---|
24 |
|
---|
25 | #ifdef OP1
|
---|
26 | void exec_opl(int s0, int s1, int iflags)
|
---|
27 | {
|
---|
28 | int res, flags;
|
---|
29 | res = s0;
|
---|
30 | flags = iflags;
|
---|
31 | EXECOP1("", res, flags);
|
---|
32 | printf("%-10s A=%08x R=%08x CCIN=%04x CC=%04x\n",
|
---|
33 | stringify(OP) "l", s0, res, iflags, flags & CC_MASK);
|
---|
34 | }
|
---|
35 |
|
---|
36 | void exec_opw(int s0, int s1, int iflags)
|
---|
37 | {
|
---|
38 | int res, flags;
|
---|
39 | res = s0;
|
---|
40 | flags = iflags;
|
---|
41 | EXECOP1("w", res, flags);
|
---|
42 | printf("%-10s A=%08x R=%08x CCIN=%04x CC=%04x\n",
|
---|
43 | stringify(OP) "w", s0, res, iflags, flags & CC_MASK);
|
---|
44 | }
|
---|
45 |
|
---|
46 | void exec_opb(int s0, int s1, int iflags)
|
---|
47 | {
|
---|
48 | int res, flags;
|
---|
49 | res = s0;
|
---|
50 | flags = iflags;
|
---|
51 | EXECOP1("b", res, flags);
|
---|
52 | printf("%-10s A=%08x R=%08x CCIN=%04x CC=%04x\n",
|
---|
53 | stringify(OP) "b", s0, res, iflags, flags & CC_MASK);
|
---|
54 | }
|
---|
55 | #else
|
---|
56 | void exec_opl(int s0, int s1, int iflags)
|
---|
57 | {
|
---|
58 | int res, flags;
|
---|
59 | res = s0;
|
---|
60 | flags = iflags;
|
---|
61 | EXECOP2("", res, s1, flags);
|
---|
62 | printf("%-10s A=%08x B=%08x R=%08x CCIN=%04x CC=%04x\n",
|
---|
63 | stringify(OP) "l", s0, s1, res, iflags, flags & CC_MASK);
|
---|
64 | }
|
---|
65 |
|
---|
66 | void exec_opw(int s0, int s1, int iflags)
|
---|
67 | {
|
---|
68 | int res, flags;
|
---|
69 | res = s0;
|
---|
70 | flags = iflags;
|
---|
71 | EXECOP2("w", res, s1, flags);
|
---|
72 | printf("%-10s A=%08x B=%08x R=%08x CCIN=%04x CC=%04x\n",
|
---|
73 | stringify(OP) "w", s0, s1, res, iflags, flags & CC_MASK);
|
---|
74 | }
|
---|
75 |
|
---|
76 | void exec_opb(int s0, int s1, int iflags)
|
---|
77 | {
|
---|
78 | int res, flags;
|
---|
79 | res = s0;
|
---|
80 | flags = iflags;
|
---|
81 | EXECOP2("b", res, s1, flags);
|
---|
82 | printf("%-10s A=%08x B=%08x R=%08x CCIN=%04x CC=%04x\n",
|
---|
83 | stringify(OP) "b", s0, s1, res, iflags, flags & CC_MASK);
|
---|
84 | }
|
---|
85 | #endif
|
---|
86 |
|
---|
87 | void exec_op(int s0, int s1)
|
---|
88 | {
|
---|
89 | exec_opl(s0, s1, 0);
|
---|
90 | exec_opw(s0, s1, 0);
|
---|
91 | exec_opb(s0, s1, 0);
|
---|
92 | #ifdef OP_CC
|
---|
93 | exec_opl(s0, s1, CC_C);
|
---|
94 | exec_opw(s0, s1, CC_C);
|
---|
95 | exec_opb(s0, s1, CC_C);
|
---|
96 | #endif
|
---|
97 | }
|
---|
98 |
|
---|
99 | void glue(test_, OP)(void)
|
---|
100 | {
|
---|
101 | exec_op(0x12345678, 0x812FADA);
|
---|
102 | exec_op(0x12341, 0x12341);
|
---|
103 | exec_op(0x12341, -0x12341);
|
---|
104 | exec_op(0xffffffff, 0);
|
---|
105 | exec_op(0xffffffff, -1);
|
---|
106 | exec_op(0xffffffff, 1);
|
---|
107 | exec_op(0xffffffff, 2);
|
---|
108 | exec_op(0x7fffffff, 0);
|
---|
109 | exec_op(0x7fffffff, 1);
|
---|
110 | exec_op(0x7fffffff, -1);
|
---|
111 | exec_op(0x80000000, -1);
|
---|
112 | exec_op(0x80000000, 1);
|
---|
113 | exec_op(0x80000000, -2);
|
---|
114 | exec_op(0x12347fff, 0);
|
---|
115 | exec_op(0x12347fff, 1);
|
---|
116 | exec_op(0x12347fff, -1);
|
---|
117 | exec_op(0x12348000, -1);
|
---|
118 | exec_op(0x12348000, 1);
|
---|
119 | exec_op(0x12348000, -2);
|
---|
120 | exec_op(0x12347f7f, 0);
|
---|
121 | exec_op(0x12347f7f, 1);
|
---|
122 | exec_op(0x12347f7f, -1);
|
---|
123 | exec_op(0x12348080, -1);
|
---|
124 | exec_op(0x12348080, 1);
|
---|
125 | exec_op(0x12348080, -2);
|
---|
126 | }
|
---|
127 |
|
---|
128 | void *glue(_test_, OP) __init_call = glue(test_, OP);
|
---|
129 |
|
---|
130 | #undef OP
|
---|
131 | #undef OP_CC
|
---|