annotate dmd/backend/iasm.d @ 191:52188e7e3fb5

Fixed deprecated features, now compiles with DMD2.058 Also changed Array allocation policy: Now doesn't reallocate but malloc's, followed by a memcpy (no free). (this fixes a crash while compiling druntime. Same bug in dmd)
author korDen@korDen-pc
date Sun, 25 Mar 2012 03:11:12 +0400
parents 9f4e5ac4f0a3
children eb38fdcb3e62
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1 module dmd.backend.iasm;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2
114
e28b18c23469 added a module dmd.common for commonly used stuff
Trass3r
parents: 113
diff changeset
3 import dmd.common;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4 import dmd.Dsymbol;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5 import dmd.LabelDsymbol;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6 import dmd.AsmStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
7 import dmd.Type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
8 import dmd.Scope;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
9 import dmd.Loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
10 import dmd.Token;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
11 import dmd.TOK;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
12 import dmd.Identifier;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
13 import dmd.Declaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
14 import dmd.VarDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
15 import dmd.EnumMember;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
16 import dmd.ExpInitializer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
17 import dmd.Expression;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
18 import dmd.IdentifierExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
19 import dmd.StringExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
20 import dmd.Global;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
21 import dmd.WANT;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
22 import dmd.STC;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
23 import dmd.TY;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
24 import dmd.EnumUtils;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
25 import dmd.TupleDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
26 import dmd.VarExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
27 import dmd.Id;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
28 import dmd.FuncExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
29 import dmd.DotIdExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
30
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
31 import dmd.backend.code;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
32 import dmd.backend.Srcpos;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
33 import dmd.backend.FL;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
34 import dmd.backend.Util;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
35 import dmd.backend.regm_t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
36 import dmd.backend.Config;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
37 import dmd.backend.targ_types;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
38 import dmd.backend.elem;
140
31c086f76669 dmd.lib now only contains the backend
Trass3r
parents: 135
diff changeset
39 import dmd.backend.block;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
40 import dmd.Util;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
41
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
42 import std.stdio : writef, writefln;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
43 import std.string : toStringz;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
44 import std.algorithm : min;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
45
4
d706d958e4e8 Step 2 of restoring GC functionality.
korDen
parents: 2
diff changeset
46 import core.memory;
d706d958e4e8 Step 2 of restoring GC functionality.
korDen
parents: 2
diff changeset
47
d706d958e4e8 Step 2 of restoring GC functionality.
korDen
parents: 2
diff changeset
48 import core.stdc.stdio : printf;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
49 import core.stdc.string : strlen;
5
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
50 import core.stdc.stdlib : realloc;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
51 import core.stdc.limits;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
52
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
53 import std.bitmanip;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
54
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
55 alias int[10] jmp_buf;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
56
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
57 extern (C) extern
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
58 {
28
c369e9924151 Updated setjmp/longjmp prototypes to reflect recent static arrays change (they are now passed by value by default).
korDen
parents: 25
diff changeset
59 int setjmp(ref jmp_buf env);
c369e9924151 Updated setjmp/longjmp prototypes to reflect recent static arrays change (they are now passed by value by default).
korDen
parents: 25
diff changeset
60 void longjmp(ref jmp_buf env, int value);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
61
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
62 void cod3_set386();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
63 code* genlinnum(code*, Srcpos);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
64 code *code_calloc();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
65
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
66 __gshared int BPRM;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
67 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
68
175
94b6033c07f3 get rid of globals
korDen
parents: 174
diff changeset
69 enum const(char)*[ASMTK.ASMTKmax] apszAsmtk = [
94b6033c07f3 get rid of globals
korDen
parents: 174
diff changeset
70 "__LOCAL_SIZE".ptr,
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
71 "dword".ptr,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
72 "even".ptr,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
73 "far".ptr,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
74 "naked".ptr,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
75 "near".ptr,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
76 "ptr".ptr,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
77 "qword".ptr,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
78 "seg".ptr,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
79 "word".ptr,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
80 ];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
81
25
3f834bed4f13 FWindows linking issues fixed
korDen
parents: 22
diff changeset
82 version (Windows) {
3f834bed4f13 FWindows linking issues fixed
korDen
parents: 22
diff changeset
83 extern (Pascal) code * cat(code *c1,code *c2);
3f834bed4f13 FWindows linking issues fixed
korDen
parents: 22
diff changeset
84 } else {
3f834bed4f13 FWindows linking issues fixed
korDen
parents: 22
diff changeset
85 extern (C) code * cat(code *c1,code *c2);
3f834bed4f13 FWindows linking issues fixed
korDen
parents: 22
diff changeset
86 }
14
2cc604139636 Implemented Linux support for ddmd. Some parts are a bit hacky to just "get it working", that said, druntime and phobos compile, and unittests pass.
Robert Clipsham <robert@octarineparrot.com>
parents: 5
diff changeset
87
2cc604139636 Implemented Linux support for ddmd. Some parts are a bit hacky to just "get it working", that said, druntime and phobos compile, and unittests pass.
Robert Clipsham <robert@octarineparrot.com>
parents: 5
diff changeset
88 version (Bug4059)
2cc604139636 Implemented Linux support for ddmd. Some parts are a bit hacky to just "get it working", that said, druntime and phobos compile, and unittests pass.
Robert Clipsham <robert@octarineparrot.com>
parents: 5
diff changeset
89 {
2cc604139636 Implemented Linux support for ddmd. Some parts are a bit hacky to just "get it working", that said, druntime and phobos compile, and unittests pass.
Robert Clipsham <robert@octarineparrot.com>
parents: 5
diff changeset
90 private extern(C) OP* _Z13asm_op_lookupPKc(const(char)* s);
2cc604139636 Implemented Linux support for ddmd. Some parts are a bit hacky to just "get it working", that said, druntime and phobos compile, and unittests pass.
Robert Clipsham <robert@octarineparrot.com>
parents: 5
diff changeset
91 private extern(C) int _Z6binaryPKcPS0_i(const(char)* p , const(char)** tab, int high);
2cc604139636 Implemented Linux support for ddmd. Some parts are a bit hacky to just "get it working", that said, druntime and phobos compile, and unittests pass.
Robert Clipsham <robert@octarineparrot.com>
parents: 5
diff changeset
92 OP* asm_op_lookup(const(char)* s) { return _Z13asm_op_lookupPKc(s); }
2cc604139636 Implemented Linux support for ddmd. Some parts are a bit hacky to just "get it working", that said, druntime and phobos compile, and unittests pass.
Robert Clipsham <robert@octarineparrot.com>
parents: 5
diff changeset
93 int binary(const(char)* p , const(char)** tab, int high) { return _Z6binaryPKcPS0_i(p, tab, high); }
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
94 }
14
2cc604139636 Implemented Linux support for ddmd. Some parts are a bit hacky to just "get it working", that said, druntime and phobos compile, and unittests pass.
Robert Clipsham <robert@octarineparrot.com>
parents: 5
diff changeset
95 else
2cc604139636 Implemented Linux support for ddmd. Some parts are a bit hacky to just "get it working", that said, druntime and phobos compile, and unittests pass.
Robert Clipsham <robert@octarineparrot.com>
parents: 5
diff changeset
96 {
25
3f834bed4f13 FWindows linking issues fixed
korDen
parents: 22
diff changeset
97 extern (C++) {
3f834bed4f13 FWindows linking issues fixed
korDen
parents: 22
diff changeset
98 OP* asm_op_lookup(const(char)* s);
3f834bed4f13 FWindows linking issues fixed
korDen
parents: 22
diff changeset
99 int binary(const(char)* p , const(char)** tab, int high);
3f834bed4f13 FWindows linking issues fixed
korDen
parents: 22
diff changeset
100 }
14
2cc604139636 Implemented Linux support for ddmd. Some parts are a bit hacky to just "get it working", that said, druntime and phobos compile, and unittests pass.
Robert Clipsham <robert@octarineparrot.com>
parents: 5
diff changeset
101 }
2cc604139636 Implemented Linux support for ddmd. Some parts are a bit hacky to just "get it working", that said, druntime and phobos compile, and unittests pass.
Robert Clipsham <robert@octarineparrot.com>
parents: 5
diff changeset
102
2cc604139636 Implemented Linux support for ddmd. Some parts are a bit hacky to just "get it working", that said, druntime and phobos compile, and unittests pass.
Robert Clipsham <robert@octarineparrot.com>
parents: 5
diff changeset
103 extern (C++) //extern
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
104 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
105 void init_optab();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
106 const(char)* asm_opstr(OP* pop);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
107 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
108
176
fa9a71a9f5a8 Moved all the mutable globals to Global
korDen
parents: 175
diff changeset
109 __gshared ubyte asm_TKlbra_seen = 0;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
110
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
111 struct REG
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
112 {
54
f95140b40251 asm_reg_lookup bug fixed
korDen
parents: 28
diff changeset
113 string regstr;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
114 ubyte val;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
115 opflag_t ty;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
116 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
117
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
118 OP* asm_op_lookup(string s)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
119 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
120 return asm_op_lookup(toStringz(s));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
121 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
122
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
123 // For amod (3 bits)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
124 enum ASM_MODIFIERS : ubyte
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
125 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
126 _normal, // Normal register value
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
127 _rseg, // Segment registers
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
128 _rspecial, // Special registers
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
129 _addr16, // 16 bit address
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
130 _addr32, // 32 bit address
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
131 _fn16, // 16 bit function call
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
132 _fn32, // 32 bit function call
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
133 _flbl // Label
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
134 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
135
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
136 mixin(BringToCurrentScope!(ASM_MODIFIERS));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
137
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
138 // For aopty (3 bits)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
139 enum ASM_OPERAND_TYPE : ubyte
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
140 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
141 _reg, // _r8, _r16, _r32
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
142 _m, // _m8, _m16, _m32, _m48
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
143 _imm, // _imm8, _imm16, _imm32
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
144 _rel, // _rel8, _rel16, _rel32
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
145 _mnoi, // _m1616, _m1632
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
146 _p, // _p1616, _p1632
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
147 _rm, // _rm8, _rm16, _rm32
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
148 _float // Floating point operand, look at cRegmask for the
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
149 // actual size
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
150 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
151
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
152 mixin(BringToCurrentScope!(ASM_OPERAND_TYPE));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
153
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
154 /* Register definitions */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
155
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
156 enum AX = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
157 enum CX = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
158 enum DX = 2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
159 enum BX = 3;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
160 enum SP = 4;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
161 enum BP = 5;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
162 enum SI = 6;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
163 enum DI = 7;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
164
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
165 enum ES = 9;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
166 enum PSW = 10;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
167 enum STACK = 11; // top of stack
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
168 enum MEM = 12; // memory
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
169 enum OTHER = 13; // other things
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
170 enum ST0 = 14; // 8087 top of stack register
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
171 enum ST01 = 15; // top two 8087 registers; for complex types
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
172
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
173 enum NOREG = 100; // no register
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
174
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
175 enum AL = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
176 enum CL = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
177 enum DL = 2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
178 enum BL = 3;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
179 enum AH = 4;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
180 enum CH = 5;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
181 enum DH = 6;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
182 enum BH = 7;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
183
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
184 enum mAX = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
185 enum mCX = 2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
186 enum mDX = 4;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
187 enum mBX = 8;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
188 enum mSP = 0x10;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
189 enum mBP = 0x20;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
190 enum mSI = 0x40;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
191 enum mDI = 0x80;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
192 enum mES = (1 << ES); // 0x200
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
193 enum mPSW = (1 << PSW); // 0x400
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
194
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
195 enum mSTACK = (1 << STACK); // 0x800
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
196 enum mMEM = (1 << MEM); // 0x1000
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
197 enum mOTHER = (1 << OTHER); // 0x2000
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
198
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
199 enum mST0 = (1 << ST0); // 0x4000
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
200 enum mST01 = (1 << ST01); // 0x8000
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
201
22
fd4acc376c45 Implemented object file output and linking on linux.
Robert Clipsham <robert@octarineparrot.com>
parents: 20
diff changeset
202 version (POSIX) { ///TARGET_LINUX || TARGET_OSX || TARGET_FREEBSD || TARGET_SOLARIS
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
203 // To support positional independent code,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
204 // must be able to remove BX from available registers
22
fd4acc376c45 Implemented object file output and linking on linux.
Robert Clipsham <robert@octarineparrot.com>
parents: 20
diff changeset
205 extern (C) extern __gshared regm_t ALLREGS;
fd4acc376c45 Implemented object file output and linking on linux.
Robert Clipsham <robert@octarineparrot.com>
parents: 20
diff changeset
206 enum ALLREGS_INIT = (mAX|mBX|mCX|mDX|mSI|mDI);
fd4acc376c45 Implemented object file output and linking on linux.
Robert Clipsham <robert@octarineparrot.com>
parents: 20
diff changeset
207 enum ALLREGS_INIT_PIC = (mAX|mCX|mDX|mSI|mDI);
fd4acc376c45 Implemented object file output and linking on linux.
Robert Clipsham <robert@octarineparrot.com>
parents: 20
diff changeset
208 extern (C) extern regm_t BYTEREGS;
fd4acc376c45 Implemented object file output and linking on linux.
Robert Clipsham <robert@octarineparrot.com>
parents: 20
diff changeset
209 enum BYTEREGS_INIT = (mAX|mBX|mCX|mDX);
fd4acc376c45 Implemented object file output and linking on linux.
Robert Clipsham <robert@octarineparrot.com>
parents: 20
diff changeset
210 enum BYTEREGS_INIT_PIC = (mAX|mCX|mDX);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
211 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
212 enum ALLREGS = (mAX|mBX|mCX|mDX|mSI|mDI);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
213 ///#define ALLREGS_INIT ALLREGS
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
214 ///#undef BYTEREGS
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
215 ///#define BYTEREGS (mAX|mBX|mCX|mDX)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
216 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
217
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
218 //#define NPTRSIZE tysize[TYnptr]
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
219 enum NPTRSIZE = 4;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
220
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
221 uint ADDFWAIT() { return 0; }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
222
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
223 enum I16 = 0; // no 16 bit code for D
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
224 enum I32 = (NPTRSIZE == 4);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
225 enum I64 = (NPTRSIZE == 8); // true if generating 64 bit code
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
226
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
227 // For uRegmask (6 bits)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
228
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
229 // uRegmask flags when aopty == _float
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
230 enum _rst = 0x1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
231 enum _rsti = 0x2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
232 enum _64 = 0x4;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
233 enum _80 = 0x8;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
234 enum _128 = 0x40;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
235 enum _112 = 0x10;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
236 enum _224 = 0x20;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
237
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
238 ushort CONSTRUCT_FLAGS(ushort uSizemask, ubyte aopty, ubyte amod, ushort uRegmask ) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
239 return cast(ushort)( (uSizemask) | (aopty) << 4 | (amod) << 7 | (uRegmask) << 10);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
240 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
241
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
242 // _seg register values (amod == _rseg)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
243 //
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
244 enum _ds = CONSTRUCT_FLAGS( 0, 0, _rseg, 0x01 );
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
245 enum _es = CONSTRUCT_FLAGS( 0, 0, _rseg, 0x02 );
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
246 enum _ss = CONSTRUCT_FLAGS( 0, 0, _rseg, 0x04 );
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
247 enum _fs = CONSTRUCT_FLAGS( 0, 0, _rseg, 0x08 );
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
248 enum _gs = CONSTRUCT_FLAGS( 0, 0, _rseg, 0x10 );
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
249 enum _cs = CONSTRUCT_FLAGS( 0, 0, _rseg, 0x20 );
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
250
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
251 //
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
252 // _special register values
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
253 //
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
254 enum _crn = CONSTRUCT_FLAGS( 0, 0, ASM_MODIFIERS._rspecial, 0x01 ); // CRn register (0,2,3)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
255 enum _drn = CONSTRUCT_FLAGS( 0, 0, ASM_MODIFIERS._rspecial, 0x02 ); // DRn register (0-3,6-7)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
256 enum _trn = CONSTRUCT_FLAGS( 0, 0, ASM_MODIFIERS._rspecial, 0x04 ); // TRn register (3-7)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
257 enum _mm = CONSTRUCT_FLAGS( 0, 0, ASM_MODIFIERS._rspecial, 0x08 ); // MMn register (0-7)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
258 enum _xmm = CONSTRUCT_FLAGS( 0, 0, ASM_MODIFIERS._rspecial, 0x10 ); // XMMn register (0-7)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
259
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
260 //
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
261 // Default register values
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
262 //
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
263 enum _al = CONSTRUCT_FLAGS( 0, 0, ASM_MODIFIERS._normal, 0x01 ); // AL register
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
264 enum _ax = CONSTRUCT_FLAGS( 0, 0, ASM_MODIFIERS._normal, 0x02 ); // AX register
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
265 enum _eax = CONSTRUCT_FLAGS( 0, 0, ASM_MODIFIERS._normal, 0x04 ); // EAX register
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
266 enum _dx = CONSTRUCT_FLAGS( 0, 0, ASM_MODIFIERS._normal, 0x08 ); // DX register
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
267 enum _cl = CONSTRUCT_FLAGS( 0, 0, ASM_MODIFIERS._normal, 0x10 ); // CL register
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
268
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
269 enum _rplus_r = 0x20;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
270 //#define _plus_r CONSTRUCT_FLAGS( 0, 0, 0, _rplus_r )
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
271 // Add the register to the opcode (no mod r/m)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
272
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
273 ubyte ASM_GET_uSizemask(uint us) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
274 return ((us) & 0x0F);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
275 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
276
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
277 ASM_OPERAND_TYPE ASM_GET_aopty(uint us) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
278 return cast(ASM_OPERAND_TYPE)(((us) & 0x70) >> 4);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
279 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
280
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
281 ASM_MODIFIERS ASM_GET_amod(uint us) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
282 return (cast(ASM_MODIFIERS)(((us) & 0x380) >> 7));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
283 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
284
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
285 ubyte ASM_GET_uRegmask(uint us) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
286 return (((us) & 0xFC00) >> 10);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
287 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
288
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
289 enum _st = CONSTRUCT_FLAGS( 0, _float, 0, _rst ); // stack register 0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
290 enum _m112 = CONSTRUCT_FLAGS( 0, _m, 0, _112 );
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
291 enum _m224 = CONSTRUCT_FLAGS( 0, _m, 0, _224 );
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
292 enum _m512 = _m224;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
293 enum _sti = CONSTRUCT_FLAGS( 0, _float, 0, _rsti );
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
294
175
94b6033c07f3 get rid of globals
korDen
parents: 174
diff changeset
295 __gshared REG regFp = { "ST", 0, _st };
94b6033c07f3 get rid of globals
korDen
parents: 174
diff changeset
296
94b6033c07f3 get rid of globals
korDen
parents: 174
diff changeset
297 enum REG[8] aregFp = [
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
298 { "ST(0)", 0, _sti },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
299 { "ST(1)", 1, _sti },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
300 { "ST(2)", 2, _sti },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
301 { "ST(3)", 3, _sti },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
302 { "ST(4)", 4, _sti },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
303 { "ST(5)", 5, _sti },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
304 { "ST(6)", 6, _sti },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
305 { "ST(7)", 7, _sti }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
306 ];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
307
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
308 // For uSizemask (4 bits)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
309 enum _8 = 0x1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
310 enum _16 = 0x2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
311 enum _32 = 0x4;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
312 enum _48 = 0x8;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
313 enum _anysize = (_8 | _16 | _32 | _48 );
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
314
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
315 enum _modrm = 0x10;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
316
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
317 //// This is for when the reg field of modregrm specifies which instruction it is
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
318 enum NUM_MASK = 0x7;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
319 //#define _0 (0x0 | _modrm) // insure that some _modrm bit is set
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
320 //#define _1 0x1 // with _0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
321 //#define _2 0x2
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
322 //#define _3 0x3
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
323 //#define _4 0x4
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
324 //#define _5 0x5
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
325 //#define _6 0x6
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
326 //#define _7 0x7
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
327 //
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
328 //#define _modrm 0x10
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
329 //
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
330 //#define _r _modrm
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
331 //#define _cb _modrm
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
332 //#define _cw _modrm
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
333 //#define _cd _modrm
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
334 //#define _cp _modrm
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
335 //#define _ib 0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
336 //#define _iw 0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
337 //#define _id 0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
338 //#define _rb 0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
339 //#define _rw 0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
340 //#define _rd 0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
341 enum _16_bit = 0x20;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
342 enum _32_bit = 0x40;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
343 enum _I386 = 0x80; // opcode is only for 386 and later
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
344 enum _16_bit_addr = 0x100;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
345 enum _32_bit_addr = 0x200;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
346 enum _fwait = 0x400; // Add an FWAIT prior to the instruction opcode
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
347 enum _nfwait = 0x800; // Do not add an FWAIT prior to the instruction
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
348
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
349 enum MOD_MASK = 0xF000; // Mod mask
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
350 enum _modsi = 0x1000; // Instruction modifies SI
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
351 enum _moddx = 0x2000; // Instruction modifies DX
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
352 enum _mod2 = 0x3000; // Instruction modifies second operand
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
353 enum _modax = 0x4000; // Instruction modifies AX
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
354 enum _modnot1 = 0x5000; // Instruction does not modify first operand
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
355 enum _modaxdx = 0x6000; // instruction modifies AX and DX
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
356 enum _moddi = 0x7000; // Instruction modifies DI
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
357 enum _modsidi = 0x8000; // Instruction modifies SI and DI
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
358 enum _modcx = 0x9000; // Instruction modifies CX
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
359 enum _modes = 0xa000; // Instruction modifies ES
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
360 enum _modall = 0xb000; // Instruction modifies all register values
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
361 enum _modsiax = 0xc000; // Instruction modifies AX and SI
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
362 enum _modsinot1 = 0xd000; // Instruction modifies SI and not first param
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
363
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
364 /////////////////////////////////////////////////
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
365 // Operand flags - usOp1, usOp2, usOp3
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
366 //
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
367
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
368 alias ushort opflag_t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
369
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
370 // Operand flags for normal opcodes
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
371
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
372 enum _r8 = CONSTRUCT_FLAGS( _8, ASM_OPERAND_TYPE._reg, ASM_MODIFIERS._normal, 0 );
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
373 enum _r16 = CONSTRUCT_FLAGS(_16, ASM_OPERAND_TYPE._reg, ASM_MODIFIERS._normal, 0 );
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
374 enum _r32 = CONSTRUCT_FLAGS(_32, ASM_OPERAND_TYPE._reg, ASM_MODIFIERS._normal, 0 );
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
375 enum _m8 = CONSTRUCT_FLAGS(_8, ASM_OPERAND_TYPE._m, ASM_MODIFIERS._normal, 0 );
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
376 enum _m16 = CONSTRUCT_FLAGS(_16, ASM_OPERAND_TYPE._m, ASM_MODIFIERS._normal, 0 );
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
377 enum _m32 = CONSTRUCT_FLAGS(_32, ASM_OPERAND_TYPE._m, ASM_MODIFIERS._normal, 0 );
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
378 enum _m48 = CONSTRUCT_FLAGS( _48, ASM_OPERAND_TYPE._m, ASM_MODIFIERS._normal, 0 );
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
379 enum _m64 = CONSTRUCT_FLAGS( _anysize, ASM_OPERAND_TYPE._m, ASM_MODIFIERS._normal, 0 );
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
380 enum _m128 = CONSTRUCT_FLAGS( _anysize, ASM_OPERAND_TYPE._m, ASM_MODIFIERS._normal, 0 );
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
381 enum _rm8 = CONSTRUCT_FLAGS(_8, ASM_OPERAND_TYPE._rm, ASM_MODIFIERS._normal, 0 );
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
382 enum _rm16 = CONSTRUCT_FLAGS(_16, ASM_OPERAND_TYPE._rm, ASM_MODIFIERS._normal, 0 );
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
383 enum _rm32 = CONSTRUCT_FLAGS(_32, ASM_OPERAND_TYPE._rm, ASM_MODIFIERS._normal, 0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
384 enum _r32m16 = CONSTRUCT_FLAGS(_32|_16, ASM_OPERAND_TYPE._rm, ASM_MODIFIERS._normal, 0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
385 enum _imm8 = CONSTRUCT_FLAGS(_8, ASM_OPERAND_TYPE._imm, ASM_MODIFIERS._normal, 0 );
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
386 enum _imm16 = CONSTRUCT_FLAGS(_16, ASM_OPERAND_TYPE._imm, ASM_MODIFIERS._normal, 0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
387 enum _imm32 = CONSTRUCT_FLAGS(_32, ASM_OPERAND_TYPE._imm, ASM_MODIFIERS._normal, 0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
388 enum _rel8 = CONSTRUCT_FLAGS(_8, ASM_OPERAND_TYPE._rel, ASM_MODIFIERS._normal, 0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
389 enum _rel16 = CONSTRUCT_FLAGS(_16, ASM_OPERAND_TYPE._rel, ASM_MODIFIERS._normal, 0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
390 enum _rel32 = CONSTRUCT_FLAGS(_32, ASM_OPERAND_TYPE._rel, ASM_MODIFIERS._normal, 0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
391 enum _p1616 = CONSTRUCT_FLAGS(_32, ASM_OPERAND_TYPE._p, ASM_MODIFIERS._normal, 0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
392 enum _m1616 = CONSTRUCT_FLAGS(_32, ASM_OPERAND_TYPE._mnoi, ASM_MODIFIERS._normal, 0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
393 enum _p1632 = CONSTRUCT_FLAGS(_48, ASM_OPERAND_TYPE._p, ASM_MODIFIERS._normal, 0 );
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
394 enum _m1632 = CONSTRUCT_FLAGS(_48, ASM_OPERAND_TYPE._mnoi, ASM_MODIFIERS._normal, 0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
395 enum _special = CONSTRUCT_FLAGS( 0, 0, ASM_MODIFIERS._rspecial, 0 );
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
396 enum _seg = CONSTRUCT_FLAGS( 0, 0, ASM_MODIFIERS._rseg, 0 );
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
397 enum _a16 = CONSTRUCT_FLAGS( 0, 0, ASM_MODIFIERS._addr16, 0 );
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
398 enum _a32 = CONSTRUCT_FLAGS( 0, 0, ASM_MODIFIERS._addr32, 0 );
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
399 enum _f16 = CONSTRUCT_FLAGS( 0, 0, ASM_MODIFIERS._fn16, 0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
400 // Near function pointer
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
401 enum _f32 = CONSTRUCT_FLAGS( 0, 0, ASM_MODIFIERS._fn32, 0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
402 // Far function pointer
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
403 enum _lbl = CONSTRUCT_FLAGS( 0, 0, ASM_MODIFIERS._flbl, 0 );
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
404 // Label (in current function)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
405
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
406 enum _mmm32 = CONSTRUCT_FLAGS( 0, ASM_OPERAND_TYPE._m, 0, _32);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
407 enum _mmm64 = CONSTRUCT_FLAGS( 0, ASM_OPERAND_TYPE._m, 0, _64);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
408 enum _mmm128 = CONSTRUCT_FLAGS( 0, ASM_OPERAND_TYPE._m, 0, _128);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
409
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
410 enum _xmm_m32 = CONSTRUCT_FLAGS( _32, ASM_OPERAND_TYPE._m, ASM_MODIFIERS._rspecial, 0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
411 enum _xmm_m64 =CONSTRUCT_FLAGS( _anysize, ASM_OPERAND_TYPE._m, ASM_MODIFIERS._rspecial, 0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
412 enum _xmm_m128 =CONSTRUCT_FLAGS( _anysize, ASM_OPERAND_TYPE._m, ASM_MODIFIERS._rspecial, 0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
413
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
414 enum _moffs8 = (_rel8);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
415 enum _moffs16 = (_rel16 );
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
416 enum _moffs32 = (_rel32 );
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
417
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
418 ////////////////////////////////////////////////////////////////////
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
419 // Operand flags for floating point opcodes are all just aliases for
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
420 // normal opcode variants and only asm_determine_operator_flags should
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
421 // need to care.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
422 //
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
423 enum _fm80 = CONSTRUCT_FLAGS( 0, ASM_OPERAND_TYPE._m, 0, _80 );
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
424 enum _fm64 = CONSTRUCT_FLAGS( 0, ASM_OPERAND_TYPE._m, 0, _64 );
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
425 enum _fm128 = CONSTRUCT_FLAGS( 0, ASM_OPERAND_TYPE._m, 0, _128 );
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
426 enum _fanysize = (_64 | _80 | _112 | _224);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
427
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
428 enum _AL =0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
429 enum _AH =4;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
430 enum _AX =0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
431 enum _EAX =0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
432 enum _BL =3;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
433 enum _BH =7;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
434 enum _BX =3;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
435 enum _EBX =3;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
436 enum _CL =1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
437 enum _CH =5;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
438 enum _CX =1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
439 enum _ECX =1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
440 enum _DL =2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
441 enum _DH =6;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
442 enum _DX =2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
443 enum _EDX =2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
444 enum _BP =5;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
445 enum _EBP =5;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
446 enum _SP =4;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
447 enum _ESP =4;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
448 enum _DI =7;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
449 enum _EDI =7;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
450 enum _SI =6;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
451 enum _ESI =6;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
452 enum _ES =0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
453 enum _CS =1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
454 enum _SS =2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
455 enum _DS =3;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
456 enum _GS =5;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
457 enum _FS =4;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
458
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
459 enum ASM = 0x36; // string of asm bytes, actually an SS: opcode
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
460 enum ASM_END = 0xffff; // special opcode meaning end of table
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
461
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
462 struct PTRNTAB0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
463 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
464 uint usOpcode;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
465 // #define ASM_END 0xffff // special opcode meaning end of table
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
466 ushort usFlags;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
467 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
468
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
469 struct PTRNTAB1
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
470 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
471 uint usOpcode;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
472 ushort usFlags;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
473 opflag_t usOp1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
474 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
475
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
476 struct PTRNTAB2
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
477 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
478 uint usOpcode;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
479 ushort usFlags;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
480 opflag_t usOp1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
481 opflag_t usOp2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
482 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
483
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
484 struct PTRNTAB3
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
485 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
486 uint usOpcode;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
487 ushort usFlags;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
488 opflag_t usOp1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
489 opflag_t usOp2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
490 opflag_t usOp3;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
491 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
492
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
493 union PTRNTAB
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
494 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
495 PTRNTAB0 *pptb0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
496 PTRNTAB1 *pptb1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
497 PTRNTAB2 *pptb2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
498 PTRNTAB3 *pptb3;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
499 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
500
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
501 struct OP
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
502 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
503 ubyte usNumops;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
504 PTRNTAB ptb;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
505 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
506
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
507 enum ASM_JUMPTYPE
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
508 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
509 ASM_JUMPTYPE_UNSPECIFIED,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
510 ASM_JUMPTYPE_SHORT,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
511 ASM_JUMPTYPE_NEAR,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
512 ASM_JUMPTYPE_FAR
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
513 } // ajt
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
514
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
515 mixin(BringToCurrentScope!(ASM_JUMPTYPE));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
516
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
517 struct OPND
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
518 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
519 REG* base; // if plain register
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
520 REG* pregDisp1; // if [register1]
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
521 REG* pregDisp2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
522 REG* segreg; // if segment override
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
523 char indirect = 0; // if had a '*' or '.'
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
524 char bOffset = 0; // if 'offset' keyword
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
525 char bSeg = 0; // if 'segment' keyword
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
526 char bPtr = 0; // if 'ptr' keyword
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
527 uint uchMultiplier; // register multiplier; valid values are 0,1,2,4,8
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
528 opflag_t usFlags;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
529 Dsymbol s;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
530 int disp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
531 real real_ = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
532 Type ptype;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
533 ASM_JUMPTYPE ajt;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
534 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
535
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
536 struct ASM_STATE
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
537 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
538 ubyte ucItype; // Instruction type
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
539 Loc loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
540 ubyte bInit;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
541 LabelDsymbol psDollar;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
542 Dsymbol psLocalsize;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
543 jmp_buf env;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
544 ubyte bReturnax;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
545 AsmStatement statement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
546 Scope sc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
547 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
548
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
549 enum IT
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
550 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
551 ITprefix = 0x10, // special prefix
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
552 ITjump = 0x20, // jump instructions CALL, Jxx and LOOPxx
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
553 ITimmed = 0x30, // value of an immediate operand controls
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
554 // code generation
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
555 ITopt = 0x40, // not all operands are required
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
556 ITshift = 0x50, // rotate and shift instructions
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
557 ITfloat = 0x60, // floating point coprocessor instructions
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
558 ITdata = 0x70, // DB, DW, DD, DQ, DT pseudo-ops
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
559 ITaddr = 0x80, // DA (define addresss) pseudo-op
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
560 ITMASK = 0xF0,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
561 ITSIZE = 0x0F, // mask for size
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
562 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
563
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
564 alias IT.ITprefix ITprefix;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
565 alias IT.ITjump ITjump;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
566 alias IT.ITimmed ITimmed;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
567 alias IT.ITopt ITopt;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
568 alias IT.ITshift ITshift;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
569 alias IT.ITfloat ITfloat;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
570 alias IT.ITdata ITdata;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
571 alias IT.ITaddr ITaddr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
572 alias IT.ITMASK ITMASK;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
573 alias IT.ITSIZE ITSIZE;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
574
176
fa9a71a9f5a8 Moved all the mutable globals to Global
korDen
parents: 175
diff changeset
575 ref ASM_STATE asmstate()
fa9a71a9f5a8 Moved all the mutable globals to Global
korDen
parents: 175
diff changeset
576 {
fa9a71a9f5a8 Moved all the mutable globals to Global
korDen
parents: 175
diff changeset
577 return global.asmstate;
fa9a71a9f5a8 Moved all the mutable globals to Global
korDen
parents: 175
diff changeset
578 }
fa9a71a9f5a8 Moved all the mutable globals to Global
korDen
parents: 175
diff changeset
579
fa9a71a9f5a8 Moved all the mutable globals to Global
korDen
parents: 175
diff changeset
580 ref Token* asmtok()
fa9a71a9f5a8 Moved all the mutable globals to Global
korDen
parents: 175
diff changeset
581 {
fa9a71a9f5a8 Moved all the mutable globals to Global
korDen
parents: 175
diff changeset
582 return global.asmtok;
fa9a71a9f5a8 Moved all the mutable globals to Global
korDen
parents: 175
diff changeset
583 }
fa9a71a9f5a8 Moved all the mutable globals to Global
korDen
parents: 175
diff changeset
584
fa9a71a9f5a8 Moved all the mutable globals to Global
korDen
parents: 175
diff changeset
585 void asmtok(Token* value)
fa9a71a9f5a8 Moved all the mutable globals to Global
korDen
parents: 175
diff changeset
586 {
fa9a71a9f5a8 Moved all the mutable globals to Global
korDen
parents: 175
diff changeset
587 global.asmtok = value;
fa9a71a9f5a8 Moved all the mutable globals to Global
korDen
parents: 175
diff changeset
588 }
fa9a71a9f5a8 Moved all the mutable globals to Global
korDen
parents: 175
diff changeset
589
fa9a71a9f5a8 Moved all the mutable globals to Global
korDen
parents: 175
diff changeset
590 ref TOK tok_value()
fa9a71a9f5a8 Moved all the mutable globals to Global
korDen
parents: 175
diff changeset
591 {
fa9a71a9f5a8 Moved all the mutable globals to Global
korDen
parents: 175
diff changeset
592 return global.tok_value;
fa9a71a9f5a8 Moved all the mutable globals to Global
korDen
parents: 175
diff changeset
593 }
fa9a71a9f5a8 Moved all the mutable globals to Global
korDen
parents: 175
diff changeset
594
fa9a71a9f5a8 Moved all the mutable globals to Global
korDen
parents: 175
diff changeset
595 void tok_value(TOK value)
fa9a71a9f5a8 Moved all the mutable globals to Global
korDen
parents: 175
diff changeset
596 {
fa9a71a9f5a8 Moved all the mutable globals to Global
korDen
parents: 175
diff changeset
597 global.tok_value = value;
fa9a71a9f5a8 Moved all the mutable globals to Global
korDen
parents: 175
diff changeset
598 }
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
599
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
600 // Additional tokens for the inline assembler
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
601 enum ASMTK
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
602 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
603 ASMTKlocalsize = TOKMAX + 1,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
604 ASMTKdword,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
605 ASMTKeven,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
606 ASMTKfar,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
607 ASMTKnaked,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
608 ASMTKnear,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
609 ASMTKptr,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
610 ASMTKqword,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
611 ASMTKseg,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
612 ASMTKword,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
613 ASMTKmax = ASMTKword - (TOK.TOKMAX + 1) + 1
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
614 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
615
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
616 mixin(BringToCurrentScope!(ASMTK));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
617
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
618 enum OP_DB
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
619 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
620 ///version (SCPP) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
621 /// // These are the number of bytes
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
622 /// OPdb = 1,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
623 /// OPdw = 2,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
624 /// OPdd = 4,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
625 /// OPdq = 8,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
626 /// OPdt = 10,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
627 /// OPdf = 4,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
628 /// OPde = 10,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
629 /// OPds = 2,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
630 /// OPdi = 4,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
631 /// OPdl = 8,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
632 ///}
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
633 ///version (MARS) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
634 // Integral types
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
635 OPdb,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
636 OPds,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
637 OPdi,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
638 OPdl,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
639
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
640 // Float types
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
641 OPdf,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
642 OPdd,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
643 OPde,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
644
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
645 // Deprecated
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
646 OPdw = OPds,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
647 OPdq = OPdl,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
648 OPdt = OPde,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
649 ///}
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
650 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
651
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
652 OPND* opnd_calloc()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
653 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
654 return new OPND();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
655 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
656
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
657 void opnd_free(OPND* o)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
658 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
659 delete o;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
660 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
661
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
662 /******************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
663 * Convert assembly instruction into a code, and append
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
664 * it to the code generated for this block.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
665 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
666
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
667 code* asm_emit(Loc loc, uint usNumops, PTRNTAB ptb, OP* pop, OPND* popnd1, OPND* popnd2, OPND* popnd3)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
668 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
669 debug {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
670 ubyte auchOpcode[16];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
671 uint usIdx = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
672 void emit(ubyte op) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
673 auchOpcode[usIdx++] = op;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
674 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
675 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
676 void emit(ubyte op) {}
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
677 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
678 Identifier id;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
679 // ushort us;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
680 ubyte* puc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
681 uint usDefaultseg;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
682 code* pc = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
683 OPND* popndTmp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
684 ASM_OPERAND_TYPE aoptyTmp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
685 ushort uSizemaskTmp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
686 REG* pregSegment;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
687 code* pcPrefix = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
688
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
689 uint uSizemask1 = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
690 uint uSizemask2 = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
691 uint uSizemask3 = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
692
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
693 //ASM_OPERAND_TYPE aopty1 = ASM_OPERAND_TYPE._reg , aopty2 = 0, aopty3 = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
694 ASM_MODIFIERS amod1 = ASM_MODIFIERS._normal;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
695 ASM_MODIFIERS amod2 = ASM_MODIFIERS._normal;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
696 ASM_MODIFIERS amod3 = ASM_MODIFIERS._normal;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
697
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
698 uint uRegmask1 = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
699 uint uRegmask2 = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
700 uint uRegmask3 = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
701
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
702 uint uSizemaskTable1 = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
703 uint uSizemaskTable2 = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
704 uint uSizemaskTable3 = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
705
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
706 ASM_OPERAND_TYPE aoptyTable1 = ASM_OPERAND_TYPE._reg;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
707 ASM_OPERAND_TYPE aoptyTable2 = ASM_OPERAND_TYPE._reg;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
708 ASM_OPERAND_TYPE aoptyTable3 = ASM_OPERAND_TYPE._reg;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
709
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
710 ASM_MODIFIERS amodTable1 = ASM_MODIFIERS._normal;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
711 ASM_MODIFIERS amodTable2 = ASM_MODIFIERS._normal;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
712 ASM_MODIFIERS amodTable3 = ASM_MODIFIERS._normal;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
713
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
714 uint uRegmaskTable1 = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
715 uint uRegmaskTable2 = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
716 uint uRegmaskTable3 = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
717
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
718 pc = code_calloc();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
719 pc.Iflags |= CF.CFpsw; // assume we want to keep the flags
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
720
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
721 if (popnd1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
722 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
723 uSizemask1 = ASM_GET_uSizemask(popnd1.usFlags);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
724 //aopty1 = ASM_GET_aopty(popnd1.usFlags);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
725 amod1 = ASM_GET_amod(popnd1.usFlags);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
726 uRegmask1 = ASM_GET_uRegmask(popnd1.usFlags);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
727
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
728 uSizemaskTable1 = ASM_GET_uSizemask(ptb.pptb1.usOp1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
729 aoptyTable1 = ASM_GET_aopty(ptb.pptb1.usOp1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
730 amodTable1 = ASM_GET_amod(ptb.pptb1.usOp1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
731 uRegmaskTable1 = ASM_GET_uRegmask(ptb.pptb1.usOp1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
732
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
733 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
734
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
735 if (popnd2)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
736 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
737 static if (false) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
738 printf("\nasm_emit:\nop: ");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
739 asm_output_flags(popnd2.usFlags);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
740 printf("\ntb: ");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
741 asm_output_flags(ptb.pptb2.usOp2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
742 printf("\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
743 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
744 uSizemask2 = ASM_GET_uSizemask(popnd2.usFlags);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
745 //aopty2 = ASM_GET_aopty(popnd2.usFlags);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
746 amod2 = ASM_GET_amod(popnd2.usFlags);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
747 uRegmask2 = ASM_GET_uRegmask(popnd2.usFlags);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
748
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
749 uSizemaskTable2 = ASM_GET_uSizemask(ptb.pptb2.usOp2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
750 aoptyTable2 = ASM_GET_aopty(ptb.pptb2.usOp2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
751 amodTable2 = ASM_GET_amod(ptb.pptb2.usOp2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
752 uRegmaskTable2 = ASM_GET_uRegmask(ptb.pptb2.usOp2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
753 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
754 if (popnd3)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
755 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
756 uSizemask3 = ASM_GET_uSizemask(popnd3.usFlags);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
757 //aopty3 = ASM_GET_aopty(popnd3.usFlags);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
758 amod3 = ASM_GET_amod(popnd3.usFlags);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
759 uRegmask3 = ASM_GET_uRegmask(popnd3.usFlags);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
760
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
761 uSizemaskTable3 = ASM_GET_uSizemask(ptb.pptb3.usOp3);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
762 aoptyTable3 = ASM_GET_aopty(ptb.pptb3.usOp3);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
763 amodTable3 = ASM_GET_amod(ptb.pptb3.usOp3);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
764 uRegmaskTable3 = ASM_GET_uRegmask(ptb.pptb3.usOp3);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
765 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
766
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
767 asmstate.statement.regs |= asm_modify_regs(ptb, popnd1, popnd2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
768
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
769 if (!I32 && ptb.pptb0.usFlags & _I386)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
770 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
771 switch (usNumops)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
772 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
773 case 0:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
774 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
775
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
776 case 1:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
777 if (popnd1 && popnd1.s)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
778 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
779 L386_WARNING:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
780 id = popnd1.s.ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
781 L386_WARNING2:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
782 if (config.target_cpu < TARGET.TARGET_80386)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
783 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
784 // Reference to %s caused a 386 instruction to be generated
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
785 //warerr(WM_386_op, id.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
786 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
787 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
788 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
789
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
790 case 2:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
791 case 3: // The third operand is always an ASM_OPERAND_TYPE._imm
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
792 if (popnd1 && popnd1.s)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
793 goto L386_WARNING;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
794 if (popnd2 && popnd2.s)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
795 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
796 id = popnd2.s.ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
797 goto L386_WARNING2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
798 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
799 break;
191
52188e7e3fb5 Fixed deprecated features, now compiles with DMD2.058
korDen@korDen-pc
parents: 184
diff changeset
800
52188e7e3fb5 Fixed deprecated features, now compiles with DMD2.058
korDen@korDen-pc
parents: 184
diff changeset
801 default:
52188e7e3fb5 Fixed deprecated features, now compiles with DMD2.058
korDen@korDen-pc
parents: 184
diff changeset
802 assert(false);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
803 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
804 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
805
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
806 switch (usNumops)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
807 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
808 case 0:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
809 if ((I32 && (ptb.pptb0.usFlags & _16_bit)) || (!I32 && (ptb.pptb0.usFlags & _32_bit)))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
810 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
811 emit(0x66);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
812 pc.Iflags |= CF.CFopsize;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
813 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
814 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
815
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
816 // 3 and 2 are the same because the third operand is always
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
817 // an immediate and does not affect operation size
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
818 case 3:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
819 case 2:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
820 if ((I32 &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
821 (amod2 == ASM_MODIFIERS._addr16 ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
822 (uSizemaskTable2 & _16 && aoptyTable2 == ASM_OPERAND_TYPE._rel) ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
823 (uSizemaskTable2 & _32 && aoptyTable2 == ASM_OPERAND_TYPE._mnoi) ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
824 (ptb.pptb2.usFlags & _16_bit_addr)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
825 )
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
826 ) ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
827 (!I32 &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
828 (amod2 == ASM_MODIFIERS._addr32 ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
829 (uSizemaskTable2 & _32 && aoptyTable2 == ASM_OPERAND_TYPE._rel) ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
830 (uSizemaskTable2 & _48 && aoptyTable2 == ASM_OPERAND_TYPE._mnoi) ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
831 (ptb.pptb2.usFlags & _32_bit_addr)))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
832 )
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
833 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
834 emit(0x67);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
835 pc.Iflags |= CF.CFaddrsize;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
836
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
837 if (I32)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
838 amod2 = ASM_MODIFIERS._addr16;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
839 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
840 amod2 = ASM_MODIFIERS._addr32;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
841
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
842 popnd2.usFlags &= ~CONSTRUCT_FLAGS(0,0,7,0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
843 popnd2.usFlags |= CONSTRUCT_FLAGS(0,0,amod2,0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
844 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
845
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
846
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
847 /* Fall through, operand 1 controls the opsize, but the
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
848 address size can be in either operand 1 or operand 2,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
849 hence the extra checking the flags tested for SHOULD
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
850 be mutex on operand 1 and operand 2 because there is
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
851 only one MOD R/M byte
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
852 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
853
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
854 case 1:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
855 if ((I32 &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
856 (amod1 == ASM_MODIFIERS._addr16 ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
857 (uSizemaskTable1 & _16 && aoptyTable1 == ASM_OPERAND_TYPE._rel) ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
858 (uSizemaskTable1 & _32 && aoptyTable1 == ASM_OPERAND_TYPE._mnoi) ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
859 (ptb.pptb1.usFlags & _16_bit_addr))) ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
860 (!I32 &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
861 (amod1 == ASM_MODIFIERS._addr32 ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
862 (uSizemaskTable1 & _32 && aoptyTable1 == ASM_OPERAND_TYPE._rel) ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
863 (uSizemaskTable1 & _48 && aoptyTable1 == ASM_OPERAND_TYPE._mnoi) ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
864 (ptb.pptb1.usFlags & _32_bit_addr))))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
865 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
866 emit(0x67); // address size prefix
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
867 pc.Iflags |= CF.CFaddrsize;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
868 if (I32)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
869 amod1 = ASM_MODIFIERS._addr16;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
870 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
871 amod1 = ASM_MODIFIERS._addr32;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
872 popnd1.usFlags &= ~CONSTRUCT_FLAGS(0,0,7,0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
873 popnd1.usFlags |= CONSTRUCT_FLAGS(0,0,amod1,0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
874 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
875
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
876 // If the size of the operand is unknown, assume that it is
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
877 // the default size
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
878 if ((I32 && (ptb.pptb0.usFlags & _16_bit)) ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
879 (!I32 && (ptb.pptb0.usFlags & _32_bit)))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
880 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
881 //if (asmstate.ucItype != ITjump)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
882 { emit(0x66);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
883 pc.Iflags |= CF.CFopsize;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
884 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
885 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
886 if (((pregSegment = (popndTmp = popnd1).segreg) != null) ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
887 ((popndTmp = popnd2) != null &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
888 (pregSegment = popndTmp.segreg) != null)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
889 )
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
890 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
891 if ((popndTmp.pregDisp1 &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
892 popndTmp.pregDisp1.val == _BP) ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
893 popndTmp.pregDisp2 &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
894 popndTmp.pregDisp2.val == _BP)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
895 usDefaultseg = _SS;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
896 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
897 usDefaultseg = _DS;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
898 if (pregSegment.val != usDefaultseg)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
899 switch (pregSegment.val) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
900 case _CS:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
901 emit(0x2e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
902 pc.Iflags |= CF.CFcs;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
903 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
904 case _SS:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
905 emit(0x36);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
906 pc.Iflags |= CF.CFss;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
907 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
908 case _DS:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
909 emit(0x3e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
910 pc.Iflags |= CF.CFds;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
911 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
912 case _ES:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
913 emit(0x26);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
914 pc.Iflags |= CF.CFes;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
915 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
916 case _FS:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
917 emit(0x64);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
918 pc.Iflags |= CF.CFfs;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
919 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
920 case _GS:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
921 emit(0x65);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
922 pc.Iflags |= CF.CFgs;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
923 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
924 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
925 assert(0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
926 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
927 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
928 break;
191
52188e7e3fb5 Fixed deprecated features, now compiles with DMD2.058
korDen@korDen-pc
parents: 184
diff changeset
929
52188e7e3fb5 Fixed deprecated features, now compiles with DMD2.058
korDen@korDen-pc
parents: 184
diff changeset
930 default:
52188e7e3fb5 Fixed deprecated features, now compiles with DMD2.058
korDen@korDen-pc
parents: 184
diff changeset
931 assert(false);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
932 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
933 uint usOpcode = ptb.pptb0.usOpcode;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
934
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
935 if ((usOpcode & 0xFFFFFF00) == 0x660F3A00 || // SSE4
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
936 (usOpcode & 0xFFFFFF00) == 0x660F3800) // SSE4
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
937 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
938 pc.Iflags |= CF.CFopsize;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
939 pc.Iop = 0x0F;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
940 pc.Iop2 = (usOpcode >> 8) & 0xFF;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
941 pc.Iop3 = usOpcode & 0xFF;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
942 goto L3;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
943 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
944 switch (usOpcode & 0xFF0000)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
945 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
946 case 0:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
947 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
948
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
949 case 0x660000:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
950 pc.Iflags |= CF.CFopsize;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
951 usOpcode &= 0xFFFF;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
952 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
953
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
954 case 0xF20000: // REPNE
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
955 case 0xF30000: // REP/REPE
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
956 // BUG: What if there's an address size prefix or segment
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
957 // override prefix? Must the REP be adjacent to the rest
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
958 // of the opcode?
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
959 pcPrefix = code_calloc();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
960 pcPrefix.Iop = cast(ubyte)(usOpcode >> 16);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
961 usOpcode &= 0xFFFF;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
962 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
963
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
964 case 0x0F0000: // an AMD instruction
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
965 puc = (cast(ubyte*) &usOpcode);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
966 if (puc[1] != 0x0F) // if not AMD instruction 0x0F0F
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
967 goto L4;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
968 emit(puc[2]);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
969 emit(puc[1]);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
970 emit(puc[0]);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
971 pc.Iop = puc[2];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
972 pc.Iop2 = puc[1];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
973 pc.IEVint2() = puc[0];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
974 pc.IFL2 = FL.FLconst;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
975 goto L3;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
976
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
977 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
978 puc = (cast(ubyte*) &usOpcode);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
979 L4:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
980 emit(puc[2]);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
981 emit(puc[1]);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
982 emit(puc[0]);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
983 pc.Iop = puc[2];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
984 pc.Iop2 = puc[1];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
985 pc.Irm = puc[0];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
986 goto L3;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
987 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
988 if (usOpcode & 0xff00)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
989 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
990 puc = (cast(ubyte*) &(usOpcode));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
991 emit(puc[1]);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
992 emit(puc[0]);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
993 pc.Iop = puc[1];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
994 if (pc.Iop == 0x0f)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
995 pc.Iop2 = puc[0];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
996 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
997 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
998 if (usOpcode == 0xDFE0) // FSTSW AX
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
999 { pc.Irm = puc[0];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1000 goto L2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1001 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1002 if (asmstate.ucItype == IT.ITfloat)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1003 pc.Irm = puc[0];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1004 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1005 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1006 pc.IEVint2() = puc[0];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1007 pc.IFL2 = FL.FLconst;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1008 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1009 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1010 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1011 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1012 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1013 emit(cast(ubyte)usOpcode);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1014 pc.Iop = cast(ubyte)usOpcode;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1015 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1016 L3: ;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1017
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1018 // If CALL, Jxx or LOOPx to a symbolic location
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1019 if (/*asmstate.ucItype == ITjump &&*/
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1020 popnd1 && popnd1.s && popnd1.s.isLabel())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1021 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1022 Dsymbol s = popnd1.s;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1023 if (s == asmstate.psDollar)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1024 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1025 pc.IFL2 = FL.FLconst;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1026 if (uSizemaskTable1 & (_8 | _16))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1027 pc.IEVint2() = popnd1.disp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1028 else if (uSizemaskTable1 & _32)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1029 pc.IEVpointer2() = cast(targ_size_t) popnd1.disp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1030 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1031 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1032 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1033 LabelDsymbol label = s.isLabel();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1034 if (label)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1035 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1036 if ((pc.Iop & 0xF0) == 0x70)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1037 pc.Iflags |= CF.CFjmp16;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1038 if (usNumops == 1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1039 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1040 pc.IFL2 = FL.FLblock;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1041 pc.IEVlsym2() = label;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1042 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1043 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1044 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1045 pc.IFL1 = FL.FLblock;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1046 pc.IEVlsym1() = label;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1047 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1048 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1049 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1050 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1051
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1052 switch (usNumops)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1053 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1054 case 0:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1055 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1056
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1057 case 1:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1058 if (((aoptyTable1 == ASM_OPERAND_TYPE._reg || aoptyTable1 == ASM_OPERAND_TYPE._float) &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1059 amodTable1 == ASM_MODIFIERS._normal && (uRegmaskTable1 & _rplus_r)))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1060 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1061 if (asmstate.ucItype == IT.ITfloat)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1062 pc.Irm += popnd1.base.val;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1063 else if (pc.Iop == 0x0f)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1064 pc.Iop2 += popnd1.base.val;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1065 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1066 pc.Iop += popnd1.base.val;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1067 debug {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1068 auchOpcode[usIdx-1] += popnd1.base.val;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1069 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1070 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1071 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1072 {
20
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 14
diff changeset
1073 debug asm_make_modrm_byte(
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1074 auchOpcode, &usIdx,
20
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 14
diff changeset
1075 pc,
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 14
diff changeset
1076 ptb.pptb1.usFlags,
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 14
diff changeset
1077 popnd1, null);
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 14
diff changeset
1078 else asm_make_modrm_byte(
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1079 pc,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1080 ptb.pptb1.usFlags,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1081 popnd1, null);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1082 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1083
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1084 popndTmp = popnd1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1085 aoptyTmp = aoptyTable1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1086 uSizemaskTmp = cast(ushort)uSizemaskTable1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1087 L1:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1088 if (aoptyTmp == ASM_OPERAND_TYPE._imm)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1089 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1090 Declaration d = popndTmp.s ? popndTmp.s.isDeclaration() : null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1091 if (popndTmp.bSeg)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1092 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1093 if (!(d && d.isDataseg()))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1094 asmerr(ASMERRMSGS.EM_bad_addr_mode); // illegal addressing mode
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1095 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1096 switch (uSizemaskTmp)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1097 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1098 case _8:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1099 case _16:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1100 case _32:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1101 if (popndTmp.s is asmstate.psLocalsize)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1102 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1103 pc.IFL2 = FL.FLlocalsize;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1104 pc.IEVdsym2() = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1105 pc.Iflags |= CF.CFoff;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1106 pc.IEVoffset2() = popndTmp.disp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1107 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1108 else if (d)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1109 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1110 static if (false) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1111 if ((pc.IFL2 = d.Sfl) == 0)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1112 pc.IFL2 = FL.FLdsymbol;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1113 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1114 pc.IFL2 = FL.FLdsymbol;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1115 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1116 pc.Iflags &= ~(CF.CFseg | CF.CFoff);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1117 if (popndTmp.bSeg)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1118 pc.Iflags |= CF.CFseg;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1119 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1120 pc.Iflags |= CF.CFoff;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1121
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1122 pc.IEVoffset2() = popndTmp.disp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1123 pc.IEVdsym2() = d;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1124 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1125 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1126 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1127 pc.IEVint2() = popndTmp.disp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1128 pc.IFL2 = FL.FLconst;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1129 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1130 break;
191
52188e7e3fb5 Fixed deprecated features, now compiles with DMD2.058
korDen@korDen-pc
parents: 184
diff changeset
1131
52188e7e3fb5 Fixed deprecated features, now compiles with DMD2.058
korDen@korDen-pc
parents: 184
diff changeset
1132 default:
52188e7e3fb5 Fixed deprecated features, now compiles with DMD2.058
korDen@korDen-pc
parents: 184
diff changeset
1133 assert(false);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1134 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1135 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1136
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1137 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1138 case 2:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1139 //
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1140 // If there are two immediate operands then
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1141 //
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1142 if (aoptyTable1 == ASM_OPERAND_TYPE._imm && aoptyTable2 == ASM_OPERAND_TYPE._imm)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1143 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1144 pc.IEVint1() = popnd1.disp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1145 pc.IFL1 = FL.FLconst;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1146 pc.IEVint2() = popnd2.disp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1147 pc.IFL2 = FL.FLconst;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1148 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1149 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1150 if (aoptyTable2 == ASM_OPERAND_TYPE._m ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1151 aoptyTable2 == ASM_OPERAND_TYPE._rel ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1152 // If not MMX register (_mm) or XMM register (_xmm)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1153 (amodTable1 == ASM_MODIFIERS._rspecial && !(uRegmaskTable1 & (0x08 | 0x10)) && !uSizemaskTable1) ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1154 aoptyTable2 == ASM_OPERAND_TYPE._rm ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1155 (popnd1.usFlags == _r32 && popnd2.usFlags == _xmm) ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1156 (popnd1.usFlags == _r32 && popnd2.usFlags == _mm))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1157 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1158 static if (false) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1159 printf("test4 %d,%d,%d,%d\n",
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1160 (aoptyTable2 == ASM_OPERAND_TYPE._m),
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1161 (aoptyTable2 == ASM_OPERAND_TYPE._rel),
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1162 (amodTable1 == ASM_MODIFIERS._rspecial && !(uRegmaskTable1 & (0x08 | 0x10))),
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1163 (aoptyTable2 == ASM_OPERAND_TYPE._rm)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1164 );
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1165 printf("usOpcode = %x\n", usOpcode);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1166 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1167 if (ptb.pptb0.usOpcode == 0x0F7E || // MOVD _rm32,_mm
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1168 ptb.pptb0.usOpcode == 0x660F7E // MOVD _rm32,_xmm
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1169 )
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1170 {
20
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 14
diff changeset
1171 debug asm_make_modrm_byte(
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 14
diff changeset
1172 auchOpcode, &usIdx,
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 14
diff changeset
1173 pc,
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 14
diff changeset
1174 ptb.pptb1.usFlags,
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 14
diff changeset
1175 popnd1, popnd2);
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 14
diff changeset
1176 else asm_make_modrm_byte(pc, ptb.pptb1.usFlags, popnd1, popnd2);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1177 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1178 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1179 {
20
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 14
diff changeset
1180 debug asm_make_modrm_byte(
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 14
diff changeset
1181 auchOpcode, &usIdx,
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 14
diff changeset
1182 pc,
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 14
diff changeset
1183 ptb.pptb1.usFlags,
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 14
diff changeset
1184 popnd2, popnd1);
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 14
diff changeset
1185 else asm_make_modrm_byte(pc, ptb.pptb1.usFlags, popnd2, popnd1);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1186 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1187 popndTmp = popnd1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1188 aoptyTmp = aoptyTable1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1189 uSizemaskTmp = cast(ushort)uSizemaskTable1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1190 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1191 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1192 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1193 if (((aoptyTable1 == ASM_OPERAND_TYPE._reg || aoptyTable1 == ASM_OPERAND_TYPE._float) &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1194 amodTable1 == ASM_MODIFIERS._normal &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1195 (uRegmaskTable1 & _rplus_r)))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1196 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1197 if (asmstate.ucItype == IT.ITfloat)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1198 pc.Irm += popnd1.base.val;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1199 else if (pc.Iop == 0x0f)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1200 pc.Iop2 += popnd1.base.val;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1201 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1202 pc.Iop += popnd1.base.val;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1203 debug {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1204 auchOpcode[usIdx-1] += popnd1.base.val;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1205 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1206 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1207 else if (((aoptyTable2 == ASM_OPERAND_TYPE._reg || aoptyTable2 == ASM_OPERAND_TYPE._float) &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1208 amodTable2 == ASM_MODIFIERS._normal &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1209 (uRegmaskTable2 & _rplus_r)))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1210 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1211 if (asmstate.ucItype == IT.ITfloat)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1212 pc.Irm += popnd2.base.val;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1213 else if (pc.Iop == 0x0f)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1214 pc.Iop2 += popnd2.base.val;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1215 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1216 pc.Iop += popnd2.base.val;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1217 debug {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1218 auchOpcode[usIdx-1] += popnd2.base.val;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1219 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1220 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1221 else if (ptb.pptb0.usOpcode == 0xF30FD6 ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1222 ptb.pptb0.usOpcode == 0x0F12 ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1223 ptb.pptb0.usOpcode == 0x0F16 ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1224 ptb.pptb0.usOpcode == 0x660F50 ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1225 ptb.pptb0.usOpcode == 0x0F50 ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1226 ptb.pptb0.usOpcode == 0x660FD7 ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1227 ptb.pptb0.usOpcode == 0x0FD7)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1228 {
20
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 14
diff changeset
1229 debug asm_make_modrm_byte(
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1230 ///debug {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1231 auchOpcode, &usIdx,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1232 ///}
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1233 pc,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1234 ptb.pptb1.usFlags,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1235 popnd2, popnd1);
20
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 14
diff changeset
1236 else asm_make_modrm_byte(
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 14
diff changeset
1237 pc,
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 14
diff changeset
1238 ptb.pptb1.usFlags,
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 14
diff changeset
1239 popnd2, popnd1);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1240 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1241 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1242 {
20
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 14
diff changeset
1243 debug asm_make_modrm_byte(
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1244 ///debug {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1245 auchOpcode, &usIdx,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1246 ///}
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1247 pc,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1248 ptb.pptb1.usFlags,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1249 popnd1, popnd2);
20
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 14
diff changeset
1250 else asm_make_modrm_byte(
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 14
diff changeset
1251 pc,
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 14
diff changeset
1252 ptb.pptb1.usFlags,
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 14
diff changeset
1253 popnd1, popnd2);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1254
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1255 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1256 if (aoptyTable1 == ASM_OPERAND_TYPE._imm)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1257 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1258 popndTmp = popnd1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1259 aoptyTmp = aoptyTable1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1260 uSizemaskTmp = cast(ushort)uSizemaskTable1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1261 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1262 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1263 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1264 popndTmp = popnd2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1265 aoptyTmp = aoptyTable2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1266 uSizemaskTmp = cast(ushort)uSizemaskTable2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1267 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1268 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1269 goto L1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1270
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1271 case 3:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1272 if (aoptyTable2 == ASM_OPERAND_TYPE._m || aoptyTable2 == ASM_OPERAND_TYPE._rm ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1273 usOpcode == 0x0FC5) // PEXTRW
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1274 {
20
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 14
diff changeset
1275 debug asm_make_modrm_byte(
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1276 ///debug {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1277 auchOpcode, &usIdx,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1278 ///}
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1279 pc,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1280 ptb.pptb1.usFlags,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1281 popnd2, popnd1);
20
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 14
diff changeset
1282 else asm_make_modrm_byte(
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 14
diff changeset
1283 pc,
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 14
diff changeset
1284 ptb.pptb1.usFlags,
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 14
diff changeset
1285 popnd2, popnd1);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1286 popndTmp = popnd3;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1287 aoptyTmp = aoptyTable3;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1288 uSizemaskTmp = cast(ushort)uSizemaskTable3;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1289 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1290 if (((aoptyTable1 == ASM_OPERAND_TYPE._reg || aoptyTable1 == ASM_OPERAND_TYPE._float) &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1291 amodTable1 == ASM_MODIFIERS._normal &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1292 (uRegmaskTable1 &_rplus_r)))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1293 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1294 if (asmstate.ucItype == IT.ITfloat)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1295 pc.Irm += popnd1.base.val;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1296 else if (pc.Iop == 0x0f)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1297 pc.Iop2 += popnd1.base.val;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1298 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1299 pc.Iop += popnd1.base.val;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1300 debug {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1301 auchOpcode[usIdx-1] += popnd1.base.val;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1302 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1303 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1304 else if (((aoptyTable2 == ASM_OPERAND_TYPE._reg || aoptyTable2 == ASM_OPERAND_TYPE._float) &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1305 amodTable2 == ASM_MODIFIERS._normal &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1306 (uRegmaskTable2 &_rplus_r)))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1307 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1308 if (asmstate.ucItype == IT.ITfloat)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1309 pc.Irm += popnd1.base.val;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1310 else if (pc.Iop == 0x0f)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1311 pc.Iop2 += popnd1.base.val;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1312 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1313 pc.Iop += popnd2.base.val;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1314 debug {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1315 auchOpcode[usIdx-1] += popnd2.base.val;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1316 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1317 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1318 else
20
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 14
diff changeset
1319 {
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 14
diff changeset
1320 debug asm_make_modrm_byte(
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1321 ///debug {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1322 auchOpcode, &usIdx,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1323 ///}
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1324 pc,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1325 ptb.pptb1.usFlags,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1326 popnd1, popnd2);
20
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 14
diff changeset
1327 else asm_make_modrm_byte(
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 14
diff changeset
1328 pc,
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 14
diff changeset
1329 ptb.pptb1.usFlags,
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 14
diff changeset
1330 popnd1, popnd2);
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 14
diff changeset
1331 }
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1332 popndTmp = popnd3;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1333 aoptyTmp = aoptyTable3;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1334 uSizemaskTmp = cast(ushort)uSizemaskTable3;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1335 }
191
52188e7e3fb5 Fixed deprecated features, now compiles with DMD2.058
korDen@korDen-pc
parents: 184
diff changeset
1336 goto L1;
52188e7e3fb5 Fixed deprecated features, now compiles with DMD2.058
korDen@korDen-pc
parents: 184
diff changeset
1337
52188e7e3fb5 Fixed deprecated features, now compiles with DMD2.058
korDen@korDen-pc
parents: 184
diff changeset
1338 default:
52188e7e3fb5 Fixed deprecated features, now compiles with DMD2.058
korDen@korDen-pc
parents: 184
diff changeset
1339 assert(false);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1340 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1341 L2:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1342
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1343 if ((pc.Iop & 0xF8) == 0xD8 &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1344 ADDFWAIT() &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1345 !(ptb.pptb0.usFlags & _nfwait))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1346 pc.Iflags |= CF.CFwait;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1347 else if ((ptb.pptb0.usFlags & _fwait) &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1348 config.target_cpu >= TARGET.TARGET_80386)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1349 pc.Iflags |= CF.CFwait;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1350
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1351 debug {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1352 if (debuga)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1353 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1354 uint u;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1355
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1356 for (u = 0; u < usIdx; u++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1357 printf(" %02X", auchOpcode[u]);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1358
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1359 printf("\t%s\t", asm_opstr(pop));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1360 if (popnd1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1361 asm_output_popnd(popnd1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1362 if (popnd2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1363 printf(",");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1364 asm_output_popnd(popnd2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1365 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1366 if (popnd3) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1367 printf(",");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1368 asm_output_popnd(popnd3);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1369 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1370 printf("\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1371 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1372 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1373
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1374 pc = cat(pcPrefix, pc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1375 pc = asm_genloc(loc, pc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1376 return pc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1377 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1378
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1379 void asm_token_trans(Token* tok)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1380 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1381 tok_value = TOK.TOKeof;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1382
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1383 if (tok)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1384 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1385 tok_value = tok.value;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1386 if (tok_value == TOK.TOKidentifier)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1387 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1388 string id = tok.ident.toChars();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1389 size_t len = id.length;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1390 if (len < 20)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1391 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1392 ASMTK asmtk = cast(ASMTK) binary(toStringz(id), apszAsmtk.ptr, ASMTK.ASMTKmax);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1393 if (cast(int)asmtk >= 0)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1394 tok_value = cast(TOK)(asmtk + TOK.TOKMAX + 1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1395 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1396 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1397 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1398 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1399
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1400 void asm_token()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1401 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1402 if (asmtok)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1403 asmtok = asmtok.next;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1404
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1405 asm_token_trans(asmtok);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1406 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1407
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1408
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1409 /**********************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1410 * If c is a power of 2, return that power else -1.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1411 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1412
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1413 int ispow2(ulong c)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1414 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1415 int i;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1416
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1417 if (c == 0 || (c & (c - 1)))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1418 i = -1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1419 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1420 for (i = 0; c >>= 1; i++) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1421 ;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1422 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1423
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1424 return i;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1425 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1426
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1427 // Error numbers
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1428 enum ASMERRMSGS
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1429 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1430 EM_bad_float_op,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1431 EM_bad_addr_mode,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1432 EM_align,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1433 EM_opcode_exp,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1434 EM_prefix,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1435 EM_eol,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1436 EM_bad_operand,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1437 EM_bad_integral_operand,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1438 EM_ident_exp,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1439 EM_not_struct,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1440 EM_nops_expected,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1441 EM_bad_op,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1442 EM_const_init,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1443 EM_undefined,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1444 EM_pointer,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1445 EM_colon,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1446 EM_rbra,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1447 EM_rpar,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1448 EM_ptr_exp,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1449 EM_num,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1450 EM_float,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1451 EM_char,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1452 EM_label_expected,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1453 EM_uplevel,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1454 EM_type_as_operand,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1455 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1456
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1457 mixin(BringToCurrentScope!(ASMERRMSGS));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1458
175
94b6033c07f3 get rid of globals
korDen
parents: 174
diff changeset
1459 enum string[] asmerrmsgs =
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1460 [
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1461 "unknown operand for floating point instruction",
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1462 "bad addr mode",
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1463 "align %d must be a power of 2",
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1464 "opcode expected, not %s",
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1465 "prefix",
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1466 "end of instruction",
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1467 "bad operand",
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1468 "bad integral operand",
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1469 "identifier expected",
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1470 "not struct",
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1471 "nops expected",
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1472 "bad type/size of operands '%s'",
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1473 "constant initializer expected",
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1474 "undefined identifier '%s'",
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1475 "pointer",
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1476 "colon",
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1477 "] expected instead of '%s'",
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1478 ") expected instead of '%s'",
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1479 "ptr expected",
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1480 "integer expected",
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1481 "floating point expected",
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1482 "character is truncated",
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1483 "label expected",
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1484 "uplevel nested reference to variable %s",
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1485 "cannot use type %s as an operand"
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1486 ];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1487
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1488 void asmerr(T...)(int errnum, T t)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1489 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1490 string format = asmerrmsgs[errnum];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1491 asmerr(format, t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1492 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1493
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1494 void asmerr(T...)(string format, T t)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1495 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1496 string p = asmstate.loc.toChars();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1497 if (p.length != 0)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1498 writef("%s: ", p);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1499
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1500 writefln(format, t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1501
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1502 longjmp(asmstate.env,1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1503 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1504
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1505 PTRNTAB asm_classify(OP* pop, OPND* popnd1, OPND* popnd2, OPND* popnd3, uint* pusNumops)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1506 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1507 uint usNumops;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1508 uint usActual;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1509 PTRNTAB ptbRet = { null };
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1510 opflag_t usFlags1 = 0 ;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1511 opflag_t usFlags2 = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1512 opflag_t usFlags3 = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1513
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1514 PTRNTAB1 *pptb1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1515 PTRNTAB2 *pptb2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1516 PTRNTAB3 *pptb3;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1517
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1518 char bFake = false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1519
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1520 ubyte bMatch1, bMatch2, bMatch3, bRetry = false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1521
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1522 // How many arguments are there? the parser is strictly left to right
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1523 // so this should work.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1524
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1525 if (!popnd1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1526 usNumops = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1527 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1528 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1529 popnd1.usFlags = usFlags1 = asm_determine_operand_flags(popnd1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1530 if (!popnd2)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1531 usNumops = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1532 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1533 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1534 popnd2.usFlags = usFlags2 = asm_determine_operand_flags(popnd2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1535 if (!popnd3)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1536 usNumops = 2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1537 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1538 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1539 popnd3.usFlags = usFlags3 = asm_determine_operand_flags(popnd3);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1540 usNumops = 3;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1541 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1542 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1543 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1544
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1545 // Now check to insure that the number of operands is correct
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1546 usActual = (pop.usNumops & IT.ITSIZE);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1547 if (usActual != usNumops && asmstate.ucItype != IT.ITopt &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1548 asmstate.ucItype != IT.ITfloat)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1549 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1550 PARAM_ERROR:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1551 asmerr(ASMERRMSGS.EM_nops_expected, usActual, asm_opstr(pop), usNumops);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1552 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1553 *pusNumops = usNumops;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1554 //
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1555 // The number of arguments matches, now check to find the opcode
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1556 // in the associated opcode table
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1557 //
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1558 RETRY:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1559 //printf("usActual = %d\n", usActual);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1560 switch (usActual)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1561 {
191
52188e7e3fb5 Fixed deprecated features, now compiles with DMD2.058
korDen@korDen-pc
parents: 184
diff changeset
1562 default:
52188e7e3fb5 Fixed deprecated features, now compiles with DMD2.058
korDen@korDen-pc
parents: 184
diff changeset
1563 assert(false);
52188e7e3fb5 Fixed deprecated features, now compiles with DMD2.058
korDen@korDen-pc
parents: 184
diff changeset
1564
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1565 case 0:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1566 ptbRet = pop.ptb ;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1567 goto RETURN_IT;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1568
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1569 case 1:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1570 //printf("usFlags1 = "); asm_output_flags(usFlags1); printf("\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1571 for (pptb1 = pop.ptb.pptb1; pptb1.usOpcode != ASM_END;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1572 pptb1++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1573 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1574 //printf("table = "); asm_output_flags(pptb1.usOp1); printf("\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1575 bMatch1 = asm_match_flags(usFlags1, pptb1.usOp1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1576 if (bMatch1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1577 { if (pptb1.usOpcode == 0x68 &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1578 I32 &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1579 pptb1.usOp1 == _imm16
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1580 )
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1581 // Don't match PUSH imm16 in 32 bit code
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1582 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1583 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1584 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1585 if ((asmstate.ucItype == IT.ITimmed) &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1586 asm_match_flags(usFlags1,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1587 CONSTRUCT_FLAGS(_8 | _16 | _32, ASM_OPERAND_TYPE._imm, ASM_MODIFIERS._normal,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1588 0)) &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1589 popnd1.disp == pptb1.usFlags)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1590 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1591 if ((asmstate.ucItype == IT.ITopt ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1592 asmstate.ucItype == IT.ITfloat) &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1593 !usNumops &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1594 !pptb1.usOp1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1595 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1596 if (usNumops > 1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1597 goto PARAM_ERROR;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1598 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1599 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1600 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1601 if (pptb1.usOpcode == ASM_END)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1602 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1603 debug {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1604 if (debuga)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1605 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1606 printf("\t%s\t", asm_opstr(pop));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1607 if (popnd1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1608 asm_output_popnd(popnd1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1609 if (popnd2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1610 printf(",");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1611 asm_output_popnd(popnd2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1612 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1613 if (popnd3) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1614 printf(",");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1615 asm_output_popnd(popnd3);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1616 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1617 printf("\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1618
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1619 printf("OPCODE mism = ");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1620 if (popnd1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1621 asm_output_flags(popnd1.usFlags);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1622 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1623 printf("NONE");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1624 printf("\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1625 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1626 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1627 TYPE_SIZE_ERROR:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1628 if (popnd1 && ASM_GET_aopty(popnd1.usFlags) != ASM_OPERAND_TYPE._reg)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1629 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1630 usFlags1 = popnd1.usFlags |= _anysize;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1631 if (asmstate.ucItype == IT.ITjump)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1632 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1633 if (bRetry && popnd1.s && !popnd1.s.isLabel())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1634 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1635 asmerr(ASMERRMSGS.EM_label_expected, popnd1.s.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1636 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1637
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1638 popnd1.usFlags |= CONSTRUCT_FLAGS(0, 0, 0, _fanysize);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1639 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1640 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1641 if (popnd2 && ASM_GET_aopty(popnd2.usFlags) != ASM_OPERAND_TYPE._reg) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1642 usFlags2 = popnd2.usFlags |= (_anysize);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1643 if (asmstate.ucItype == IT.ITjump)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1644 popnd2.usFlags |= CONSTRUCT_FLAGS(0, 0, 0,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1645 _fanysize);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1646 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1647 if (popnd3 && ASM_GET_aopty(popnd3.usFlags) != ASM_OPERAND_TYPE._reg) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1648 usFlags3 = popnd3.usFlags |= (_anysize);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1649 if (asmstate.ucItype == IT.ITjump)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1650 popnd3.usFlags |= CONSTRUCT_FLAGS(0, 0, 0,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1651 _fanysize);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1652 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1653 if (bRetry)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1654 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1655 asmerr(ASMERRMSGS.EM_bad_op, fromStringz(asm_opstr(pop))); // illegal type/size of operands
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1656 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1657 bRetry = true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1658 goto RETRY;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1659 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1660 ptbRet.pptb1 = pptb1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1661 goto RETURN_IT;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1662
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1663 case 2:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1664 //printf("usFlags1 = "); asm_output_flags(usFlags1); printf(" ");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1665 //printf("usFlags2 = "); asm_output_flags(usFlags2); printf("\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1666 for (pptb2 = pop.ptb.pptb2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1667 pptb2.usOpcode != ASM_END;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1668 pptb2++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1669 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1670 //printf("table1 = "); asm_output_flags(pptb2.usOp1); printf(" ");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1671 //printf("table2 = "); asm_output_flags(pptb2.usOp2); printf("\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1672 bMatch1 = asm_match_flags(usFlags1, pptb2.usOp1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1673 bMatch2 = asm_match_flags(usFlags2, pptb2.usOp2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1674 //printf("match1 = %d, match2 = %d\n",bMatch1,bMatch2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1675 if (bMatch1 && bMatch2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1676
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1677 //printf("match\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1678
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1679 // OK, if they both match and the first op in the table is not AL
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1680 // or size of 8 and the second is immediate 8,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1681 // then check to see if the constant
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1682 // is a signed 8 bit constant. If so, then do not match, otherwise match
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1683 //
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1684 if (!bRetry &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1685 !((ASM_GET_uSizemask(pptb2.usOp1) & _8) ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1686 (ASM_GET_uRegmask(pptb2.usOp1) & _al)) &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1687 (ASM_GET_aopty(pptb2.usOp2) == ASM_OPERAND_TYPE._imm) &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1688 (ASM_GET_uSizemask(pptb2.usOp2) & _8))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1689 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1690 if (popnd2.disp <= char.max)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1691 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1692 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1693 bFake = true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1694 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1695 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1696 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1697 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1698 if (asmstate.ucItype == IT.ITopt || asmstate.ucItype == IT.ITfloat)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1699 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1700 switch (usNumops)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1701 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1702 case 0:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1703 if (!pptb2.usOp1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1704 goto Lfound2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1705 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1706 case 1:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1707 if (bMatch1 && !pptb2.usOp2)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1708 goto Lfound2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1709 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1710 case 2:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1711 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1712 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1713 goto PARAM_ERROR;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1714 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1715 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1716 static if (false) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1717 if (asmstate.ucItype == IT.ITshift &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1718 !pptb2.usOp2 &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1719 bMatch1 && popnd2.disp == 1 &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1720 asm_match_flags(usFlags2,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1721 CONSTRUCT_FLAGS(_8|_16|_32, ASM_OPERAND_TYPE._imm,ASM_MODIFIERS._normal,0))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1722 )
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1723 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1724 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1725 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1726 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1727 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1728 Lfound2:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1729 if (pptb2.usOpcode == ASM_END)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1730 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1731 debug {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1732 if (debuga)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1733 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1734 printf("\t%s\t", asm_opstr(pop));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1735 if (popnd1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1736 asm_output_popnd(popnd1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1737 if (popnd2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1738 printf(",");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1739 asm_output_popnd(popnd2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1740 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1741 if (popnd3) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1742 printf(",");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1743 asm_output_popnd(popnd3);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1744 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1745 printf("\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1746
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1747 printf("OPCODE mismatch = ");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1748 if (popnd1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1749 asm_output_flags(popnd1.usFlags);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1750 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1751 printf("NONE");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1752 printf( " Op2 = ");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1753 if (popnd2)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1754 asm_output_flags(popnd2.usFlags);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1755 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1756 printf("NONE");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1757 printf("\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1758 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1759 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1760 goto TYPE_SIZE_ERROR;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1761 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1762 ptbRet.pptb2 = pptb2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1763 goto RETURN_IT;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1764
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1765 case 3:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1766 for (pptb3 = pop.ptb.pptb3;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1767 pptb3.usOpcode != ASM_END;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1768 pptb3++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1769 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1770 bMatch1 = asm_match_flags(usFlags1, pptb3.usOp1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1771 bMatch2 = asm_match_flags(usFlags2, pptb3.usOp2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1772 bMatch3 = asm_match_flags(usFlags3, pptb3.usOp3);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1773 if (bMatch1 && bMatch2 && bMatch3)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1774 goto Lfound3;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1775
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1776 if (asmstate.ucItype == IT.ITopt)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1777 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1778 switch (usNumops)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1779 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1780 case 0:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1781 if (!pptb3.usOp1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1782 goto Lfound3;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1783 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1784 case 1:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1785 if (bMatch1 && !pptb3.usOp2)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1786 goto Lfound3;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1787 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1788 case 2:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1789 if (bMatch1 && bMatch2 && !pptb3.usOp3)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1790 goto Lfound3;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1791 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1792 case 3:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1793 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1794 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1795 goto PARAM_ERROR;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1796 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1797 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1798 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1799 Lfound3:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1800 if (pptb3.usOpcode == ASM_END)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1801 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1802 debug {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1803 if (debuga)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1804 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1805 printf("\t%s\t", asm_opstr(pop));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1806 if (popnd1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1807 asm_output_popnd(popnd1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1808 if (popnd2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1809 printf(",");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1810 asm_output_popnd(popnd2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1811 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1812 if (popnd3) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1813 printf(",");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1814 asm_output_popnd(popnd3);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1815 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1816 printf("\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1817
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1818 printf("OPCODE mismatch = ");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1819 if (popnd1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1820 asm_output_flags(popnd1.usFlags);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1821 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1822 printf("NONE");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1823 printf( " Op2 = ");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1824 if (popnd2)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1825 asm_output_flags(popnd2.usFlags);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1826 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1827 printf("NONE");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1828 if (popnd3)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1829 asm_output_flags(popnd3.usFlags);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1830 printf("\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1831 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1832 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1833 goto TYPE_SIZE_ERROR;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1834 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1835
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1836 ptbRet.pptb3 = pptb3;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1837 goto RETURN_IT;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1838 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1839
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1840 RETURN_IT:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1841 if (bRetry && !bFake)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1842 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1843 asmerr(ASMERRMSGS.EM_bad_op, fromStringz(asm_opstr(pop)));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1844 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1845 return ptbRet;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1846 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1847
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1848 /*******************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1849 * start of inline assemblers expression parser
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1850 * NOTE: functions in call order instead of alphabetical
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1851 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1852
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1853 /*******************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1854 * Parse DA expression
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1855 *
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1856 * Very limited define address to place a code
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1857 * address in the assembly
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1858 * Problems:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1859 * o Should use dw offset and dd offset instead,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1860 * for near/far support.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1861 * o Should be able to add an offset to the label address.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1862 * o Blocks addressed by DA should get their Bpred set correctly
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1863 * for optimizer.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1864 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1865
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1866 code* asm_da_parse(OP* pop)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1867 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1868 code* clst = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1869 elem* e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1870
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1871 while (1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1872 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1873 code* c;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1874
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1875 if (tok_value == TOK.TOKidentifier)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1876 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1877 LabelDsymbol label = asmstate.sc.func.searchLabel(asmtok.ident);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1878 if (!label)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1879 error(asmstate.loc, "label '%s' not found\n", asmtok.ident.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1880
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1881 c = code_calloc();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1882 c.Iop = ASM;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1883 c.Iflags = CF.CFaddrsize;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1884 c.IFL1 = FL.FLblockoff;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1885 c.IEVlsym1() = label;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1886 c = asm_genloc(asmstate.loc, c);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1887 clst = cat(clst,c);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1888 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1889 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1890 asmerr(ASMERRMSGS.EM_bad_addr_mode); // illegal addressing mode
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1891
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1892 asm_token();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1893 if (tok_value != TOK.TOKcomma)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1894 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1895
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1896 asm_token();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1897 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1898
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1899 asmstate.statement.regs |= mES | ALLREGS;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1900 asmstate.bReturnax = true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1901
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1902 return clst;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1903 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1904
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1905 /*******************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1906 * Parse DB, DW, DD, DQ and DT expressions.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1907 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1908
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1909 code* asm_db_parse(OP* pop)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1910 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1911 uint usSize;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1912 uint usMaxbytes;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1913 uint usBytes;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1914
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1915 union DT
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1916 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1917 targ_ullong ul;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1918 targ_float f;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1919 targ_double d;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1920 targ_ldouble ld;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1921 char value[10];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1922 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1923
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1924 DT dt;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1925
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1926 code* c;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1927 uint op;
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 146
diff changeset
1928 enum ubyte[7] opsize = [ 1,2,4,8,4,8,10 ];
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1929
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1930 op = pop.usNumops & IT.ITSIZE;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1931 usSize = opsize[op];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1932
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1933 usBytes = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1934 usMaxbytes = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1935 c = code_calloc();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1936 c.Iop = ASM;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1937
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1938 while (1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1939 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1940 size_t len;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1941 ubyte* q;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1942
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1943 if (usBytes+usSize > usMaxbytes)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1944 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1945 usMaxbytes = usBytes + usSize + 10;
5
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
1946 c.IEV1.as.bytes = cast(char*)realloc(c.IEV1.as.bytes,usMaxbytes);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1947 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1948 switch (tok_value)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1949 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1950 case TOK.TOKint32v:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1951 dt.ul = asmtok.int32value;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1952 goto L1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1953 case TOK.TOKuns32v:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1954 dt.ul = asmtok.uns32value;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1955 goto L1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1956 case TOK.TOKint64v:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1957 dt.ul = asmtok.int64value;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1958 goto L1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1959 case TOK.TOKuns64v:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1960 dt.ul = asmtok.uns64value;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1961 goto L1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1962 L1:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1963 switch (op)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1964 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1965 case OP_DB.OPdb:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1966 case OP_DB.OPds:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1967 case OP_DB.OPdi:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1968 case OP_DB.OPdl:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1969 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1970 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1971 asmerr(ASMERRMSGS.EM_float);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1972 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1973 goto L2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1974
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1975 case TOK.TOKfloat32v:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1976 case TOK.TOKfloat64v:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1977 case TOK.TOKfloat80v:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1978 switch (op)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1979 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1980 case OP_DB.OPdf:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1981 dt.f = asmtok.float80value;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1982 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1983 case OP_DB.OPdd:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1984 dt.d = asmtok.float80value;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1985 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1986 case OP_DB.OPde:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1987 dt.ld = asmtok.float80value;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1988 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1989 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1990 asmerr(ASMERRMSGS.EM_num);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1991 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1992 goto L2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1993
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1994 L2:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1995 memcpy(c.IEV1.as.bytes + usBytes,&dt,usSize);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1996 usBytes += usSize;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1997 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1998
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1999 case TOK.TOKstring:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2000 len = asmtok.len;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2001 q = cast(ubyte*)asmtok.ustring;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2002 L3:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2003 if (len)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2004 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2005 usMaxbytes += len * usSize;
5
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
2006 c.IEV1.as.bytes = cast(char*)realloc(c.IEV1.as.bytes,usMaxbytes);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2007 memcpy(c.IEV1.as.bytes + usBytes,asmtok.ustring,len);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2008
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2009 char* p = c.IEV1.as.bytes + usBytes;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2010 for (size_t i = 0; i < len; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2011 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2012 // Be careful that this works
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2013 memset(p, 0, usSize);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2014 switch (op)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2015 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2016 case OP_DB.OPdb:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2017 *p = cast(ubyte)*q;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2018 if (*p != *q)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2019 asmerr(ASMERRMSGS.EM_char);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2020 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2021
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2022 case OP_DB.OPds:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2023 *cast(short*)p = *cast(ubyte*)q;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2024 if (*cast(short*)p != *q)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2025 asmerr(ASMERRMSGS.EM_char);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2026 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2027
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2028 case OP_DB.OPdi:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2029 case OP_DB.OPdl:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2030 *cast(int*)p = *q;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2031 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2032
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2033 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2034 asmerr(ASMERRMSGS.EM_float);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2035 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2036 q++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2037 p += usSize;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2038 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2039
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2040 usBytes += len * usSize;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2041 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2042 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2043
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2044 case TOK.TOKidentifier:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2045 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2046 Expression e = new IdentifierExp(asmstate.loc, asmtok.ident);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2047 e = e.semantic(asmstate.sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2048 e = e.optimize(WANT.WANTvalue | WANT.WANTinterpret);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2049 if (e.op == TOK.TOKint64)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2050 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2051 dt.ul = e.toInteger();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2052 goto L2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2053 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2054 else if (e.op == TOK.TOKfloat64)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2055 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2056 switch (op)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2057 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2058 case OP_DB.OPdf:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2059 dt.f = e.toReal();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2060 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2061 case OP_DB.OPdd:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2062 dt.d = e.toReal();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2063 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2064 case OP_DB.OPde:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2065 dt.ld = e.toReal();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2066 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2067 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2068 asmerr(ASMERRMSGS.EM_num);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2069 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2070 goto L2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2071 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2072 else if (e.op == TOK.TOKstring)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2073 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2074 StringExp se = cast(StringExp)e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2075 q = cast(ubyte*)se.string_;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2076 len = se.len;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2077 goto L3;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2078 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2079 goto Ldefault;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2080 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2081
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2082 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2083 Ldefault:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2084 asmerr(ASMERRMSGS.EM_const_init); // constant initializer
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2085 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2086 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2087 c.IEV1.as.len = usBytes;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2088
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2089 asm_token();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2090 if (tok_value != TOK.TOKcomma)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2091 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2092
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2093 asm_token();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2094 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2095
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2096 c = asm_genloc(asmstate.loc, c);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2097
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2098 asmstate.statement.regs |= /* mES| */ ALLREGS;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2099 asmstate.bReturnax = true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2100
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2101 return c;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2102 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2103
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2104 /**********************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2105 * Parse and get integer expression.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2106 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2107
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2108 int asm_getnum()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2109 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2110 int v;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2111 long i;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2112
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2113 switch (tok_value)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2114 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2115 case TOK.TOKint32v:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2116 v = asmtok.int32value;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2117 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2118
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2119 case TOK.TOKuns32v:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2120 v = asmtok.uns32value;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2121 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2122
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2123 case TOK.TOKidentifier:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2124 Expression e = new IdentifierExp(asmstate.loc, asmtok.ident);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2125 e = e.semantic(asmstate.sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2126 e = e.optimize(WANT.WANTvalue | WANT.WANTinterpret);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2127 i = e.toInteger();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2128 v = cast(int) i;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2129 if (v != i)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2130 asmerr(ASMERRMSGS.EM_num);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2131 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2132
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2133 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2134 asmerr(ASMERRMSGS.EM_num);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2135 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2136 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2137
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2138 asm_token();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2139
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2140 return v;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2141 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2142
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2143
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2144 /*******************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2145 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2146
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2147 OPND* asm_cond_exp()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2148 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2149 OPND* o1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2150 OPND* o2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2151 OPND* o3;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2152
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2153 //printf("asm_cond_exp()\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2154 o1 = asm_log_or_exp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2155 if (tok_value == TOK.TOKquestion)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2156 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2157 asm_token();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2158 o2 = asm_cond_exp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2159 asm_token();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2160 asm_chktok(TOK.TOKcolon, ASMERRMSGS.EM_colon);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2161 o3 = asm_cond_exp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2162 o1 = (o1.disp) ? o2 : o3;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2163 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2164
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2165 return o1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2166 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2167
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2168 regm_t asm_modify_regs(PTRNTAB ptb, OPND* popnd1, OPND* popnd2)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2169 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2170 regm_t usRet = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2171
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2172 switch (ptb.pptb0.usFlags & MOD_MASK) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2173 case _modsi:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2174 usRet |= mSI;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2175 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2176 case _moddx:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2177 usRet |= mDX;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2178 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2179 case _mod2:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2180 if (popnd2)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2181 usRet |= asm_modify_regs(ptb, popnd2, null);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2182 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2183 case _modax:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2184 usRet |= mAX;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2185 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2186 case _modnot1:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2187 popnd1 = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2188 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2189 case _modaxdx:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2190 usRet |= (mAX | mDX);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2191 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2192 case _moddi:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2193 usRet |= mDI;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2194 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2195 case _modsidi:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2196 usRet |= (mSI | mDI);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2197 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2198 case _modcx:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2199 usRet |= mCX;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2200 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2201 case _modes:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2202 /*usRet |= mES;*/
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2203 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2204 case _modall:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2205 asmstate.bReturnax = true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2206 return /*mES |*/ ALLREGS;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2207 case _modsiax:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2208 usRet |= (mSI | mAX);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2209 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2210 case _modsinot1:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2211 usRet |= mSI;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2212 popnd1 = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2213 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2214 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2215 break; ///
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2216 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2217 if (popnd1 && ASM_GET_aopty(popnd1.usFlags) == ASM_OPERAND_TYPE._reg) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2218 switch (ASM_GET_amod(popnd1.usFlags)) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2219 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2220 if (ASM_GET_uSizemask(popnd1.usFlags) == _8) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2221 switch(popnd1.base.val) {
191
52188e7e3fb5 Fixed deprecated features, now compiles with DMD2.058
korDen@korDen-pc
parents: 184
diff changeset
2222 default:
52188e7e3fb5 Fixed deprecated features, now compiles with DMD2.058
korDen@korDen-pc
parents: 184
diff changeset
2223 assert(false);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2224 case _AL:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2225 case _AH:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2226 usRet |= mAX;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2227 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2228 case _BL:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2229 case _BH:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2230 usRet |= mBX;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2231 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2232 case _CL:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2233 case _CH:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2234 usRet |= mCX;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2235 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2236 case _DL:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2237 case _DH:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2238 usRet |= mDX;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2239 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2240 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2241 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2242 else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2243 switch (popnd1.base.val) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2244 case _AX:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2245 usRet |= mAX;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2246 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2247 case _BX:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2248 usRet |= mBX;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2249 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2250 case _CX:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2251 usRet |= mCX;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2252 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2253 case _DX:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2254 usRet |= mDX;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2255 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2256 case _SI:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2257 usRet |= mSI;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2258 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2259 case _DI:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2260 usRet |= mDI;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2261 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2262 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2263 break; ///
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2264 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2265 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2266 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2267
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2268 case ASM_MODIFIERS._rseg:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2269 //if (popnd1.base.val == _ES)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2270 //usRet |= mES;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2271 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2272
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2273 case ASM_MODIFIERS._rspecial:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2274 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2275 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2276 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2277 if (usRet & mAX)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2278 asmstate.bReturnax = true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2279
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2280 return usRet;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2281 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2282
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2283
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2284 /****************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2285 * Fill in the modregrm and sib bytes of code.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2286 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2287
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2288 uint X(ubyte r1, ubyte r2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2289 return (((r1) * 16) + (r2));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2290 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2291
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2292 uint Y(ubyte r1) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2293 return X(r1, 9);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2294 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2295
20
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 14
diff changeset
2296 // Save a copy/pasted function
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 14
diff changeset
2297 template Tuple(T...) { alias T Tuple; }
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 14
diff changeset
2298 debug alias Tuple!(ubyte[], uint*) asm_make_modrm_args;
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 14
diff changeset
2299 else alias Tuple!() asm_make_modrm_args;
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 14
diff changeset
2300
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 14
diff changeset
2301 void asm_make_modrm_byte(asm_make_modrm_args ocidx, code *pc, ushort usFlags, OPND *popnd, OPND *popnd2)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2302 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2303 /// #undef modregrm
20
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 14
diff changeset
2304 debug alias ocidx[0] puchOpcode;
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 14
diff changeset
2305 debug alias ocidx[1] pusIdx;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2306 union MODRM_BYTE // mrmb
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2307 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2308 struct MODRM
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2309 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2310 mixin(bitfields!(
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2311 uint, "rm", 3,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2312 uint, "reg", 3,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2313 uint, "mod", 2));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2314 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2315
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2316 ubyte uchOpcode;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2317 MODRM modregrm;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2318 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2319
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2320 union SIB_BYTE
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2321 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2322 struct SIB
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2323 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2324
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2325 mixin(bitfields!(
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2326 uint, "base", 3,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2327 uint, "index", 3,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2328 uint, "ss", 2));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2329 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2330
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2331 ubyte uchOpcode;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2332 SIB sib;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2333 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2334
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2335
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2336 MODRM_BYTE mrmb;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2337 SIB_BYTE sib;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2338 char bSib = false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2339 char bDisp = false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2340 char b32bit = false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2341 ubyte* puc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2342 char bModset = false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2343 Dsymbol s;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2344
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2345 uint uSizemask = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2346 ASM_OPERAND_TYPE aopty;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2347 ASM_MODIFIERS amod;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2348 ushort uRegmask;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2349 ubyte bOffsetsym = false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2350
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2351 static if (false) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2352 printf("asm_make_modrm_byte(usFlags = x%x)\n", usFlags);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2353 printf("op1: ");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2354 asm_output_flags(popnd.usFlags);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2355 if (popnd2)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2356 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2357 printf(" op2: ");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2358 asm_output_flags(popnd2.usFlags);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2359 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2360 printf("\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2361 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2362
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2363 uSizemask = ASM_GET_uSizemask(popnd.usFlags);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2364 aopty = ASM_GET_aopty(popnd.usFlags);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2365 amod = ASM_GET_amod(popnd.usFlags);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2366 uRegmask = ASM_GET_uRegmask(popnd.usFlags);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2367 s = popnd.s;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2368 if (s)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2369 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2370 Declaration d = s.isDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2371
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2372 if (amod == ASM_MODIFIERS._fn16 && aopty == ASM_OPERAND_TYPE._rel && popnd2)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2373 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2374 aopty = ASM_OPERAND_TYPE._m;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2375 goto L1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2376 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2377
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2378 if (amod == ASM_MODIFIERS._fn16 || amod == ASM_MODIFIERS._fn32)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2379 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2380 pc.Iflags |= CF.CFoff;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2381 debug {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2382 puchOpcode[(*pusIdx)++] = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2383 puchOpcode[(*pusIdx)++] = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2384 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2385 if (aopty == ASM_OPERAND_TYPE._m || aopty == ASM_OPERAND_TYPE._mnoi)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2386 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2387 pc.IFL1 = FL.FLdata;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2388 pc.IEVdsym1() = d;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2389 pc.IEVoffset1() = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2390 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2391 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2392 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2393 if (aopty == ASM_OPERAND_TYPE._p)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2394 pc.Iflags |= CF.CFseg;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2395
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2396 debug if (aopty == ASM_OPERAND_TYPE._p || aopty == ASM_OPERAND_TYPE._rel)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2397 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2398 puchOpcode[(*pusIdx)++] = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2399 puchOpcode[(*pusIdx)++] = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2400 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2401
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2402 pc.IFL2 = FL.FLfunc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2403 pc.IEVdsym2() = d;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2404 pc.IEVoffset2() = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2405 //return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2406 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2407 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2408 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2409 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2410 L1:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2411 LabelDsymbol label = s.isLabel();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2412 if (label)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2413 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2414 if (s == asmstate.psDollar)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2415 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2416 pc.IFL1 = FL.FLconst;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2417 if (uSizemask & (_8 | _16))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2418 pc.IEVint1() = popnd.disp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2419 else if (uSizemask & _32)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2420 pc.IEVpointer1() = cast(targ_size_t) popnd.disp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2421 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2422 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2423 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2424 pc.IFL1 = FL.FLblockoff;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2425 pc.IEVlsym1() = label;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2426 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2427 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2428 else if (s == asmstate.psLocalsize)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2429 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2430 pc.IFL1 = FL.FLlocalsize;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2431 pc.IEVdsym1() = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2432 pc.Iflags |= CF.CFoff;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2433 pc.IEVoffset1() = popnd.disp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2434 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2435 else if (s.isFuncDeclaration())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2436 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2437 pc.IFL1 = FL.FLfunc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2438 pc.IEVdsym1() = d;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2439 pc.IEVoffset1() = popnd.disp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2440 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2441 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2442 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2443 debug if (debuga)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2444 printf("Setting up symbol %s\n", d.ident.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2445
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2446 pc.IFL1 = FL.FLdsymbol;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2447 pc.IEVdsym1() = d;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2448 pc.Iflags |= CF.CFoff;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2449 pc.IEVoffset1() = popnd.disp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2450 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2451 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2452 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2453
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2454 mrmb.modregrm.reg = usFlags & NUM_MASK;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2455
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2456 if (s && (aopty == ASM_OPERAND_TYPE._m || aopty == ASM_OPERAND_TYPE._mnoi) && !s.isLabel())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2457 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2458 if (s == asmstate.psLocalsize)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2459 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2460 DATA_REF:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2461 mrmb.modregrm.rm = BPRM;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2462 if (amod == ASM_MODIFIERS._addr16 || amod == ASM_MODIFIERS._addr32)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2463 mrmb.modregrm.mod = 0x2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2464 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2465 mrmb.modregrm.mod = 0x0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2466 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2467 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2468 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2469 Declaration d = s.isDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2470 assert(d);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2471 if (d.isDataseg() || d.isCodeseg())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2472 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2473 if (( I32 && amod == ASM_MODIFIERS._addr16) ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2474 (!I32 && amod == ASM_MODIFIERS._addr32))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2475 asmerr(ASMERRMSGS.EM_bad_addr_mode); // illegal addressing mode
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2476 goto DATA_REF;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2477 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2478 mrmb.modregrm.rm = BPRM;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2479 mrmb.modregrm.mod = 0x2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2480 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2481 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2482
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2483 if (aopty == ASM_OPERAND_TYPE._reg || amod == ASM_MODIFIERS._rspecial) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2484 mrmb.modregrm.mod = 0x3;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2485 mrmb.modregrm.rm = mrmb.modregrm.rm | popnd.base.val;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2486 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2487 else if (amod == ASM_MODIFIERS._addr16 || (amod == ASM_MODIFIERS._flbl && !I32))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2488 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2489 uint rm;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2490
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2491 debug if (debuga)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2492 printf("This is an ADDR16\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2493
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2494 if (!popnd.pregDisp1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2495 { rm = 0x6;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2496 if (!s)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2497 bDisp = true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2498 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2499 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2500 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2501 uint r1r2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2502
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2503 if (popnd.pregDisp2)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2504 r1r2 = X(popnd.pregDisp1.val,popnd.pregDisp2.val);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2505 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2506 r1r2 = Y(popnd.pregDisp1.val);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2507
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2508 switch (r1r2)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2509 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2510 case X(_BX,_SI): rm = 0; break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2511 case X(_BX,_DI): rm = 1; break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2512 case Y(_BX): rm = 7; break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2513
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2514 case X(_BP,_SI): rm = 2; break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2515 case X(_BP,_DI): rm = 3; break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2516 case Y(_BP): rm = 6; bDisp = true; break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2517
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2518 case X(_SI,_BX): rm = 0; break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2519 case X(_SI,_BP): rm = 2; break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2520 case Y(_SI): rm = 4; break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2521
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2522 case X(_DI,_BX): rm = 1; break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2523 case X(_DI,_BP): rm = 3; break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2524 case Y(_DI): rm = 5; break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2525
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2526 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2527 asmerr(ASMERRMSGS.EM_bad_addr_mode); // illegal addressing mode
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2528 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2529 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2530 mrmb.modregrm.rm = rm;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2531
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2532 debug if (debuga)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2533 printf("This is an mod = %d, popnd.s =%ld, popnd.disp = %ld\n",
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2534 mrmb.modregrm.mod, s, popnd.disp);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2535
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2536 if (!s || (!mrmb.modregrm.mod && popnd.disp))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2537 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2538 if ((!popnd.disp && !bDisp) || !popnd.pregDisp1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2539 mrmb.modregrm.mod = 0x0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2540 else if (popnd.disp >= CHAR_MIN && popnd.disp <= SCHAR_MAX)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2541 mrmb.modregrm.mod = 0x1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2542 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2543 mrmb.modregrm.mod = 0X2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2544 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2545 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2546 bOffsetsym = true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2547
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2548 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2549 else if (amod == ASM_MODIFIERS._addr32 || (amod == ASM_MODIFIERS._flbl && I32))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2550 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2551 debug if (debuga)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2552 printf("This is an ADDR32\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2553
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2554 if (!popnd.pregDisp1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2555 mrmb.modregrm.rm = 0x5;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2556 else if (popnd.pregDisp2 ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2557 popnd.uchMultiplier ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2558 popnd.pregDisp1.val == _ESP)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2559 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2560 if (popnd.pregDisp2)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2561 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2562 if (popnd.pregDisp2.val == _ESP)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2563 asmerr(ASMERRMSGS.EM_bad_addr_mode); // illegal addressing mode
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2564 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2565 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2566 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2567 if (popnd.uchMultiplier && popnd.pregDisp1.val ==_ESP)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2568 asmerr(ASMERRMSGS.EM_bad_addr_mode); // illegal addressing mode
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2569 bDisp = true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2570 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2571
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2572 mrmb.modregrm.rm = 0x4;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2573 bSib = true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2574 if (bDisp)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2575 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2576 if (!popnd.uchMultiplier &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2577 popnd.pregDisp1.val==_ESP)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2578 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2579 sib.sib.base = popnd.pregDisp1.val;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2580 sib.sib.index = 0x4;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2581 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2582 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2583 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2584 debug if (debuga)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2585 printf("Resetting the mod to 0\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2586
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2587 if (popnd.pregDisp2)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2588 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2589 if (popnd.pregDisp2.val != _EBP)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2590 asmerr(ASMERRMSGS.EM_bad_addr_mode); // illegal addressing mode
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2591 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2592 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2593 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2594 mrmb.modregrm.mod = 0x0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2595 bModset = true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2596 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2597
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2598 sib.sib.base = 0x5;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2599 sib.sib.index = popnd.pregDisp1.val;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2600 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2601 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2602 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2603 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2604 sib.sib.base = popnd.pregDisp1.val;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2605 //
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2606 // This is to handle the special case
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2607 // of using the EBP register and no
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2608 // displacement. You must put in an
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2609 // 8 byte displacement in order to
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2610 // get the correct opcodes.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2611 //
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2612 if (popnd.pregDisp1.val == _EBP && (!popnd.disp && !s))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2613 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2614 debug if (debuga)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2615 printf("Setting the mod to 1 in the _EBP case\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2616
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2617 mrmb.modregrm.mod = 0x1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2618 bDisp = true; // Need a
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2619 // displacement
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2620 bModset = true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2621 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2622
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2623 sib.sib.index = popnd.pregDisp2.val;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2624 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2625 switch (popnd.uchMultiplier)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2626 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2627 case 0: sib.sib.ss = 0; break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2628 case 1: sib.sib.ss = 0; break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2629 case 2: sib.sib.ss = 1; break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2630 case 4: sib.sib.ss = 2; break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2631 case 8: sib.sib.ss = 3; break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2632
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2633 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2634 asmerr(ASMERRMSGS.EM_bad_addr_mode); // illegal addressing mode
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2635 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2636 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2637 if (bDisp && sib.sib.base == 0x5)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2638 b32bit = true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2639 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2640 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2641 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2642 uint rm;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2643
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2644 if (popnd.uchMultiplier)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2645 asmerr(ASMERRMSGS.EM_bad_addr_mode); // illegal addressing mode
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2646 switch (popnd.pregDisp1.val)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2647 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2648 case _EAX: rm = 0; break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2649 case _ECX: rm = 1; break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2650 case _EDX: rm = 2; break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2651 case _EBX: rm = 3; break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2652 case _ESI: rm = 6; break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2653 case _EDI: rm = 7; break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2654
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2655 case _EBP:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2656 if (!popnd.disp && !s)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2657 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2658 mrmb.modregrm.mod = 0x1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2659 bDisp = true; // Need a displacement
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2660 bModset = true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2661 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2662 rm = 5;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2663 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2664
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2665 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2666 asmerr(ASMERRMSGS.EM_bad_addr_mode); // illegal addressing mode
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2667 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2668 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2669 mrmb.modregrm.rm = rm;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2670 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2671 if (!bModset && (!s || (!mrmb.modregrm.mod && popnd.disp)))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2672 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2673 if ((!popnd.disp && !mrmb.modregrm.mod) ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2674 (!popnd.pregDisp1 && !popnd.pregDisp2))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2675 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2676 mrmb.modregrm.mod = 0x0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2677 bDisp = true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2678 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2679 else if (popnd.disp >= CHAR_MIN && popnd.disp <= SCHAR_MAX)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2680 mrmb.modregrm.mod = 0x1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2681 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2682 mrmb.modregrm.mod = 0x2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2683 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2684 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2685 bOffsetsym = true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2686 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2687 if (popnd2 && !mrmb.modregrm.reg &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2688 asmstate.ucItype != IT.ITshift &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2689 (ASM_GET_aopty(popnd2.usFlags) == ASM_OPERAND_TYPE._reg ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2690 ASM_GET_amod(popnd2.usFlags) == ASM_MODIFIERS._rseg ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2691 ASM_GET_amod(popnd2.usFlags) == ASM_MODIFIERS._rspecial))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2692 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2693 mrmb.modregrm.reg = popnd2.base.val;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2694 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2695 debug puchOpcode[ (*pusIdx)++ ] = mrmb.uchOpcode;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2696
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2697 pc.Irm = mrmb.uchOpcode;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2698 //printf("Irm = %02x\n", pc.Irm);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2699 if (bSib)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2700 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2701 debug puchOpcode[ (*pusIdx)++ ] = sib.uchOpcode;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2702 pc.Isib= sib.uchOpcode;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2703 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2704 if ((!s || (popnd.pregDisp1 && !bOffsetsym)) &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2705 aopty != ASM_OPERAND_TYPE._imm &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2706 (popnd.disp || bDisp))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2707 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2708 if (popnd.usFlags & _a16)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2709 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2710 debug {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2711 puc = (cast(ubyte*) &(popnd.disp));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2712 puchOpcode[(*pusIdx)++] = puc[1];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2713 puchOpcode[(*pusIdx)++] = puc[0];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2714 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2715 if (usFlags & (_modrm | NUM_MASK)) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2716 debug if (debuga)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2717 printf("Setting up value %ld\n", popnd.disp);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2718
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2719 pc.IEVint1() = popnd.disp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2720 pc.IFL1 = FL.FLconst;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2721 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2722 else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2723 pc.IEVint2() = popnd.disp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2724 pc.IFL2 = FL.FLconst;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2725 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2726
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2727 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2728 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2729 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2730 debug {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2731 puc = (cast(ubyte*) &(popnd.disp));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2732 puchOpcode[(*pusIdx)++] = puc[3];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2733 puchOpcode[(*pusIdx)++] = puc[2];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2734 puchOpcode[(*pusIdx)++] = puc[1];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2735 puchOpcode[(*pusIdx)++] = puc[0];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2736 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2737 if (usFlags & (_modrm | NUM_MASK)) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2738 debug if (debuga)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2739 printf("Setting up value %ld\n", popnd.disp);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2740
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2741 pc.IEVpointer1() = cast(targ_size_t) popnd.disp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2742 pc.IFL1 = FL.FLconst;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2743 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2744 pc.IEVpointer2() = cast(targ_size_t) popnd.disp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2745 pc.IFL2 = FL.FLconst;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2746 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2747 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2748 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2749 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2750
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2751 void asm_output_popnd(OPND* popnd)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2752 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2753 if (popnd.segreg)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2754 printf("%s:", popnd.segreg.regstr);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2755
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2756 if (popnd.s)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2757 writef("%s", popnd.s.ident.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2758
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2759 if (popnd.base)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2760 printf("%s", popnd.base.regstr);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2761
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2762 if (popnd.pregDisp1) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2763 if (popnd.pregDisp2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2764 if (popnd.usFlags & _a32)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2765 if (popnd.uchMultiplier)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2766 printf("[%s][%s*%d]",
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2767 popnd.pregDisp1.regstr,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2768 popnd.pregDisp2.regstr,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2769 popnd.uchMultiplier);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2770 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2771 printf("[%s][%s]",
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2772 popnd.pregDisp1.regstr,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2773 popnd.pregDisp2.regstr);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2774 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2775 printf("[%s+%s]",
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2776 popnd.pregDisp1.regstr,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2777 popnd.pregDisp2.regstr);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2778 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2779 else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2780 if (popnd.uchMultiplier)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2781 printf("[%s*%d]",
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2782 popnd.pregDisp1.regstr,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2783 popnd.uchMultiplier);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2784 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2785 printf("[%s]",
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2786 popnd.pregDisp1.regstr);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2787 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2788 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2789 if (ASM_GET_aopty(popnd.usFlags) == ASM_OPERAND_TYPE._imm)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2790 printf("%lxh", popnd.disp);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2791 else if (popnd.disp)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2792 printf("+%lxh", popnd.disp);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2793 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2794
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2795 /*******************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2796 * Prepend line number to c.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2797 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2798
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2799 code* asm_genloc(Loc loc, code* c)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2800 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2801 if (global.params.symdebug)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2802 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2803 code* pcLin;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2804 Srcpos srcpos;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2805
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2806 srcpos.Slinnum = loc.linnum;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2807 srcpos.Sfilename = cast(char*)toStringz(loc.filename);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2808 pcLin = genlinnum(null, srcpos);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2809
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2810 c = cat(pcLin, c);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2811 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2812
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2813 return c;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2814 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2815
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2816 opflag_t asm_determine_operand_flags(OPND* popnd)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2817 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2818 Dsymbol ps;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2819 int ty;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2820 opflag_t us;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2821 opflag_t sz;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2822 ASM_OPERAND_TYPE opty;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2823 ASM_MODIFIERS amod;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2824
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2825 // If specified 'offset' or 'segment' but no symbol
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2826 if ((popnd.bOffset || popnd.bSeg) && !popnd.s)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2827 asmerr(ASMERRMSGS.EM_bad_addr_mode); // illegal addressing mode
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2828
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2829 if (asmstate.ucItype == IT.ITfloat)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2830 return asm_determine_float_flags(popnd);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2831
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2832 // If just a register
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2833 if (popnd.base && !popnd.s && !popnd.disp && !popnd.real_)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2834 return popnd.base.ty;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2835
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2836 debug if (debuga)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2837 printf("popnd.base = %s\n, popnd.pregDisp1 = %ld\n", popnd.base ? popnd.base.regstr : "NONE", popnd.pregDisp1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2838
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2839 ps = popnd.s;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2840 Declaration ds = ps ? ps.isDeclaration() : null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2841 if (ds && ds.storage_class & STC.STClazy)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2842 sz = _anysize;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2843 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2844 sz = cast(ushort)asm_type_size((ds && ds.storage_class & (STC.STCout | STC.STCref)) ? popnd.ptype.pointerTo() : popnd.ptype);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2845 if (popnd.pregDisp1 && !popnd.base)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2846 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2847 if (ps && ps.isLabel() && sz == _anysize)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2848 sz = I32 ? _32 : _16;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2849 return (popnd.pregDisp1.ty & _r32)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2850 ? CONSTRUCT_FLAGS(sz, ASM_OPERAND_TYPE._m, ASM_MODIFIERS._addr32, 0)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2851 : CONSTRUCT_FLAGS(sz, ASM_OPERAND_TYPE._m, ASM_MODIFIERS._addr16, 0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2852 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2853 else if (ps)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2854 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2855 if (popnd.bOffset || popnd.bSeg || ps == asmstate.psLocalsize)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2856 return I32
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2857 ? CONSTRUCT_FLAGS(_32, ASM_OPERAND_TYPE._imm, ASM_MODIFIERS._normal, 0)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2858 : CONSTRUCT_FLAGS(_16, ASM_OPERAND_TYPE._imm, ASM_MODIFIERS._normal, 0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2859
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2860 if (ps.isLabel())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2861 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2862 switch (popnd.ajt)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2863 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2864 case ASM_JUMPTYPE.ASM_JUMPTYPE_UNSPECIFIED:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2865 if (ps == asmstate.psDollar)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2866 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2867 if (popnd.disp >= CHAR_MIN &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2868 popnd.disp <= CHAR_MAX)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2869 us = CONSTRUCT_FLAGS(_8, _rel, ASM_MODIFIERS._flbl,0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2870 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2871 if (popnd.disp >= SHRT_MIN &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2872 popnd.disp <= SHRT_MIN)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2873 us = CONSTRUCT_FLAGS(_16, _rel, ASM_MODIFIERS._flbl,0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2874 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2875 us = CONSTRUCT_FLAGS(_32, _rel, ASM_MODIFIERS._flbl,0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2876 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2877 else if (asmstate.ucItype != ITjump)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2878 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2879 if (sz == _8)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2880 { us = CONSTRUCT_FLAGS(_8,ASM_OPERAND_TYPE._rel,ASM_MODIFIERS._flbl,0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2881 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2882 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2883 goto case_near;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2884 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2885 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2886 us = I32
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2887 ? CONSTRUCT_FLAGS(_8|_32, ASM_OPERAND_TYPE._rel, ASM_MODIFIERS._flbl, 0)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2888 : CONSTRUCT_FLAGS(_8|_16, ASM_OPERAND_TYPE._rel, ASM_MODIFIERS._flbl, 0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2889 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2890
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2891 case ASM_JUMPTYPE.ASM_JUMPTYPE_NEAR:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2892 case_near:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2893 us = I32
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2894 ? CONSTRUCT_FLAGS(_32, _rel, _flbl, 0)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2895 : CONSTRUCT_FLAGS(_16, _rel, _flbl, 0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2896 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2897 case ASM_JUMPTYPE.ASM_JUMPTYPE_SHORT:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2898 us = CONSTRUCT_FLAGS(_8, _rel, _flbl, 0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2899 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2900 case ASM_JUMPTYPE.ASM_JUMPTYPE_FAR:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2901 us = I32
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2902 ? CONSTRUCT_FLAGS(_48, _rel, _flbl, 0)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2903 : CONSTRUCT_FLAGS(_32, _rel, _flbl, 0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2904 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2905 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2906 assert(0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2907 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2908 return us;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2909 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2910 if (!popnd.ptype)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2911 return CONSTRUCT_FLAGS(sz, _m, _normal, 0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2912 ty = popnd.ptype.ty;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2913 if (ty == Tpointer && popnd.ptype.nextOf().ty == Tfunction &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2914 !ps.isVarDeclaration())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2915 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2916 static if (true) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2917 return CONSTRUCT_FLAGS(_32, _m, _fn16, 0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2918 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2919 ty = popnd.ptype.Tnext.Tty;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2920 if (tyfarfunc(tybasic(ty))) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2921 return I32
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2922 ? CONSTRUCT_FLAGS(_48, _mnoi, _fn32, 0)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2923 : CONSTRUCT_FLAGS(_32, _mnoi, _fn32, 0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2924 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2925 else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2926 return I32
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2927 ? CONSTRUCT_FLAGS(_32, _m, _fn16, 0)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2928 : CONSTRUCT_FLAGS(_16, _m, _fn16, 0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2929 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2930 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2931 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2932 else if (ty == TY.Tfunction)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2933 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2934 static if (true) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2935 return CONSTRUCT_FLAGS(_32, _rel, _fn16, 0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2936 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2937 if (tyfarfunc(tybasic(ty)))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2938 return I32
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2939 ? CONSTRUCT_FLAGS(_48, _p, _fn32, 0)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2940 : CONSTRUCT_FLAGS(_32, _p, _fn32, 0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2941 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2942 return I32
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2943 ? CONSTRUCT_FLAGS(_32, _rel, _fn16, 0)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2944 : CONSTRUCT_FLAGS(_16, _rel, _fn16, 0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2945 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2946 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2947 else if (asmstate.ucItype == IT.ITjump)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2948 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2949 amod = _normal;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2950 goto L1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2951 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2952 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2953 return CONSTRUCT_FLAGS(sz, _m, _normal, 0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2954 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2955 if (popnd.segreg /*|| popnd.bPtr*/)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2956 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2957 amod = I32 ? _addr32 : _addr16;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2958 if (asmstate.ucItype == ITjump)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2959 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2960 L1:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2961 opty = _m;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2962 if (I32)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2963 { if (sz == _48)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2964 opty = _mnoi;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2965 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2966 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2967 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2968 if (sz == _32)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2969 opty = _mnoi;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2970 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2971 us = CONSTRUCT_FLAGS(sz,opty,amod,0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2972 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2973 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2974 us = CONSTRUCT_FLAGS(sz,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2975 // _rel, amod, 0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2976 _m, amod, 0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2977 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2978
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2979 else if (popnd.ptype)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2980 us = CONSTRUCT_FLAGS(sz, _imm, _normal, 0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2981
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2982 else if (popnd.disp >= CHAR_MIN && popnd.disp <= UCHAR_MAX)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2983 us = CONSTRUCT_FLAGS(_8 | _16 | _32, _imm, _normal, 0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2984 else if (popnd.disp >= SHRT_MIN && popnd.disp <= USHRT_MAX)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2985 us = CONSTRUCT_FLAGS(_16 | _32, _imm, _normal, 0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2986 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2987 us = CONSTRUCT_FLAGS(_32, _imm, _normal, 0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2988 return us;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2989 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2990
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2991 /*******************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2992 * Match flags in operand against flags in opcode table.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2993 * Returns:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2994 * !=0 if match
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2995 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2996
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2997 ubyte asm_match_flags(opflag_t usOp, opflag_t usTable)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2998 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2999 ASM_OPERAND_TYPE aoptyTable;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3000 ASM_OPERAND_TYPE aoptyOp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3001 ASM_MODIFIERS amodTable;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3002 ASM_MODIFIERS amodOp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3003 uint uRegmaskTable;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3004 uint uRegmaskOp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3005 ubyte bRegmatch;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3006 ubyte bRetval = false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3007 uint uSizemaskOp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3008 uint uSizemaskTable;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3009 ubyte bSizematch;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3010
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3011 //printf("asm_match_flags(usOp = x%x, usTable = x%x)\n", usOp, usTable);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3012 if (asmstate.ucItype == IT.ITfloat)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3013 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3014 bRetval = asm_match_float_flags(usOp, usTable);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3015 goto EXIT;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3016 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3017
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3018 uSizemaskOp = ASM_GET_uSizemask(usOp);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3019 uSizemaskTable = ASM_GET_uSizemask(usTable);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3020
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3021 // Check #1, if the sizes do not match, NO match
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3022 bSizematch = (uSizemaskOp & uSizemaskTable) != 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3023
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3024 amodOp = ASM_GET_amod(usOp);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3025
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3026 aoptyTable = ASM_GET_aopty(usTable);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3027 aoptyOp = ASM_GET_aopty(usOp);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3028
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3029 // _mmm64 matches with a 64 bit mem or an MMX register
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3030 if (usTable == _mmm64)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3031 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3032 if (usOp == _mm)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3033 goto Lmatch;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3034 if (aoptyOp == _m && (bSizematch || uSizemaskOp == _anysize))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3035 goto Lmatch;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3036 goto EXIT;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3037 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3038
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3039 // _xmm_m32, _xmm_m64, _xmm_m128 match with XMM register or memory
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3040 if (usTable == _xmm_m32 ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3041 usTable == _xmm_m64 ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3042 usTable == _xmm_m128)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3043 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3044 if (usOp == _xmm)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3045 goto Lmatch;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3046 if (aoptyOp == _m && (bSizematch || uSizemaskOp == _anysize))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3047 goto Lmatch;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3048 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3049
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3050 if (!bSizematch && uSizemaskTable)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3051 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3052 //printf("no size match\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3053 goto EXIT;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3054 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3055
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3056
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3057 //
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3058 // The operand types must match, otherwise return false.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3059 // There is one exception for the _rm which is a table entry which matches
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3060 // _reg or _m
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3061 //
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3062 if (aoptyTable != aoptyOp)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3063 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3064 if (aoptyTable == _rm && (aoptyOp == _reg ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3065 aoptyOp == _m ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3066 aoptyOp == _rel))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3067 goto Lok;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3068
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3069 if (aoptyTable == _mnoi && aoptyOp == _m &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3070 (uSizemaskOp == _32 && amodOp == _addr16 ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3071 uSizemaskOp == _48 && amodOp == _addr32 ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3072 uSizemaskOp == _48 && amodOp == _normal)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3073 )
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3074 goto Lok;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3075 goto EXIT;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3076 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3077 Lok:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3078
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3079 //
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3080 // Looks like a match so far, check to see if anything special is going on
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3081 //
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3082 amodTable = ASM_GET_amod(usTable);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3083 uRegmaskOp = ASM_GET_uRegmask(usOp);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3084 uRegmaskTable = ASM_GET_uRegmask(usTable);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3085 bRegmatch = ((!uRegmaskTable && !uRegmaskOp) ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3086 (uRegmaskTable & uRegmaskOp));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3087
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3088 switch (amodTable)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3089 {
191
52188e7e3fb5 Fixed deprecated features, now compiles with DMD2.058
korDen@korDen-pc
parents: 184
diff changeset
3090 default:
52188e7e3fb5 Fixed deprecated features, now compiles with DMD2.058
korDen@korDen-pc
parents: 184
diff changeset
3091 assert(false);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3092 case _normal: // Normal's match with normals
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3093 switch(amodOp) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3094 case _normal:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3095 case _addr16:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3096 case _addr32:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3097 case _fn16:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3098 case _fn32:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3099 case _flbl:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3100 bRetval = (bSizematch || bRegmatch);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3101 goto EXIT;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3102 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3103 goto EXIT;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3104 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3105 case _rseg:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3106 case _rspecial:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3107 bRetval = (amodOp == amodTable && bRegmatch);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3108 goto EXIT;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3109 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3110 EXIT:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3111 static if (false) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3112 printf("OP : ");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3113 asm_output_flags(usOp);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3114 printf("\nTBL: ");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3115 asm_output_flags(usTable);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3116 writef(": %s\n", bRetval ? "MATCH" : "NOMATCH");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3117 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3118 return bRetval;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3119
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3120 Lmatch:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3121 //printf("match\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3122 return 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3123 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3124
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3125 void asm_output_flags(opflag_t usFlags)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3126 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3127 ASM_OPERAND_TYPE aopty = ASM_GET_aopty(usFlags);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3128 ASM_MODIFIERS amod = ASM_GET_amod(usFlags);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3129 uint uRegmask = ASM_GET_uRegmask(usFlags);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3130 uint uSizemask = ASM_GET_uSizemask(usFlags);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3131
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3132 if (uSizemask == _anysize)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3133 printf("_anysize ");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3134 else if (uSizemask == 0)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3135 printf("0 ");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3136 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3137 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3138 if (uSizemask & _8)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3139 printf("_8 ");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3140 if (uSizemask & _16)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3141 printf("_16 ");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3142 if (uSizemask & _32)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3143 printf("_32 ");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3144 if (uSizemask & _48)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3145 printf("_48 ");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3146 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3147
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3148 printf("_");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3149 switch (aopty) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3150 case ASM_OPERAND_TYPE._reg:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3151 printf("reg ");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3152 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3153 case ASM_OPERAND_TYPE._m:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3154 printf("m ");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3155 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3156 case ASM_OPERAND_TYPE._imm:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3157 printf("imm ");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3158 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3159 case ASM_OPERAND_TYPE._rel:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3160 printf("rel ");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3161 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3162 case ASM_OPERAND_TYPE._mnoi:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3163 printf("mnoi ");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3164 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3165 case ASM_OPERAND_TYPE._p:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3166 printf("p ");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3167 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3168 case ASM_OPERAND_TYPE._rm:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3169 printf("rm ");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3170 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3171 case ASM_OPERAND_TYPE._float:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3172 printf("float ");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3173 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3174 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3175 printf(" UNKNOWN ");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3176 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3177
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3178 printf("_");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3179 switch (amod) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3180 case ASM_MODIFIERS._normal:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3181 printf("normal ");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3182 if (uRegmask & 1) printf("_al ");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3183 if (uRegmask & 2) printf("_ax ");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3184 if (uRegmask & 4) printf("_eax ");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3185 if (uRegmask & 8) printf("_dx ");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3186 if (uRegmask & 0x10) printf("_cl ");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3187 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3188 case ASM_MODIFIERS._rseg:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3189 printf("rseg ");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3190 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3191 case ASM_MODIFIERS._rspecial:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3192 printf("rspecial ");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3193 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3194 case ASM_MODIFIERS._addr16:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3195 printf("addr16 ");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3196 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3197 case ASM_MODIFIERS._addr32:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3198 printf("addr32 ");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3199 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3200 case ASM_MODIFIERS._fn16:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3201 printf("fn16 ");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3202 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3203 case ASM_MODIFIERS._fn32:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3204 printf("fn32 ");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3205 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3206 case ASM_MODIFIERS._flbl:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3207 printf("flbl ");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3208 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3209 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3210 printf("UNKNOWN ");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3211 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3212 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3213
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3214 printf("uRegmask=x%02x", uRegmask);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3215 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3216
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3217 OPND* asm_log_or_exp()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3218 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3219 OPND* o1 = asm_log_and_exp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3220 OPND* o2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3221
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3222 while (tok_value == TOK.TOKoror)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3223 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3224 asm_token();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3225 o2 = asm_log_and_exp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3226 if (asm_isint(o1) && asm_isint(o2))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3227 o1.disp = o1.disp || o2.disp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3228 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3229 asmerr(ASMERRMSGS.EM_bad_integral_operand); // illegal operand
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3230 o2.disp = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3231 o1 = asm_merge_opnds(o1, o2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3232 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3233 return o1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3234 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3235
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3236 void asm_chktok(TOK toknum, uint errnum)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3237 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3238 if (tok_value == toknum)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3239 asm_token(); // scan past token
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3240 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3241 /* When we run out of tokens, asmtok is null.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3242 * But when this happens when a ';' was hit.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3243 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3244 asmerr(errnum, asmtok ? asmtok.toChars() : ";");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3245 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3246
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3247 opflag_t asm_determine_float_flags(OPND* popnd)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3248 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3249 //printf("asm_determine_float_flags()\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3250
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3251 opflag_t us;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3252 opflag_t usFloat;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3253
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3254 // Insure that if it is a register, that it is not a normal processor
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3255 // register.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3256
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3257 if (popnd.base &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3258 !popnd.s && !popnd.disp && !popnd.real_
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3259 && !(popnd.base.ty & (_r8 | _r16 | _r32)))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3260 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3261 return popnd.base.ty;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3262 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3263 if (popnd.pregDisp1 && !popnd.base)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3264 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3265 us = asm_float_type_size(popnd.ptype, &usFloat);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3266 //printf("us = x%x, usFloat = x%x\n", us, usFloat);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3267 if (popnd.pregDisp1.ty & _r32)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3268 return(CONSTRUCT_FLAGS(us, _m, _addr32, usFloat));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3269 else if (popnd.pregDisp1.ty & _r16)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3270 return(CONSTRUCT_FLAGS(us, _m, _addr16, usFloat));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3271 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3272 else if (popnd.s !is null)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3273 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3274 us = asm_float_type_size(popnd.ptype, &usFloat);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3275 return CONSTRUCT_FLAGS(us, _m, _normal, usFloat);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3276 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3277
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3278 if (popnd.segreg)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3279 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3280 us = asm_float_type_size(popnd.ptype, &usFloat);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3281 if (I32)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3282 return(CONSTRUCT_FLAGS(us, _m, _addr32, usFloat));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3283 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3284 return(CONSTRUCT_FLAGS(us, _m, _addr16, usFloat));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3285 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3286
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3287 static if (false) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3288 if (popnd.real_)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3289 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3290 switch (popnd.ptype.ty)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3291 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3292 case TY.Tfloat32:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3293 popnd.s = fconst(popnd.real_);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3294 return(CONSTRUCT_FLAGS(_32, _m, _normal, 0));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3295
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3296 case TY.Tfloat64:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3297 popnd.s = dconst(popnd.real_);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3298 return(CONSTRUCT_FLAGS(0, _m, _normal, _64));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3299
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3300 case TY.Tfloat80:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3301 popnd.s = ldconst(popnd.real_);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3302 return(CONSTRUCT_FLAGS(0, _m, _normal, _80));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3303 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3304 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3305 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3306
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3307 asmerr(ASMERRMSGS.EM_bad_float_op); // unknown operand for floating point instruction
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3308 return 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3309 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3310
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3311 uint asm_type_size(Type ptype)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3312 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3313 //if (ptype) printf("asm_type_size('%s') = %d\n", ptype.toChars(), (int)ptype.size());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3314 uint u = _anysize;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3315 if (ptype && ptype.ty != TY.Tfunction /*&& ptype.isscalar()*/)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3316 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3317 switch (cast(int)ptype.size())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3318 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3319 case 0: asmerr(ASMERRMSGS.EM_bad_op, "0 size"); break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3320 case 1: u = _8; break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3321 case 2: u = _16; break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3322 case 4: u = _32; break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3323 case 6: u = _48; break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3324 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3325 break; ///
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3326 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3327 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3328 return u;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3329 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3330
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3331 bool asm_match_float_flags(opflag_t usOp, opflag_t usTable)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3332 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3333 ASM_OPERAND_TYPE aoptyTable;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3334 ASM_OPERAND_TYPE aoptyOp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3335 ASM_MODIFIERS amodTable;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3336 ASM_MODIFIERS amodOp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3337 uint uRegmaskTable;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3338 uint uRegmaskOp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3339 ubyte bRegmatch;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3340
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3341
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3342 //
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3343 // Check #1, if the sizes do not match, NO match
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3344 //
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3345 uRegmaskOp = ASM_GET_uRegmask(usOp);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3346 uRegmaskTable = ASM_GET_uRegmask(usTable);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3347 bRegmatch = (uRegmaskTable & uRegmaskOp) != 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3348
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3349 if (!(ASM_GET_uSizemask(usTable) & ASM_GET_uSizemask(usOp) || bRegmatch))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3350 return false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3351
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3352 aoptyTable = ASM_GET_aopty(usTable);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3353 aoptyOp = ASM_GET_aopty(usOp);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3354 //
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3355 // The operand types must match, otherwise return false.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3356 // There is one exception for the _rm which is a table entry which matches
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3357 // _reg or _m
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3358 //
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3359 if (aoptyTable != aoptyOp)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3360 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3361 if (aoptyOp != _float)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3362 return false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3363 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3364
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3365 //
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3366 // Looks like a match so far, check to see if anything special is going on
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3367 //
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3368 amodOp = ASM_GET_amod(usOp);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3369 amodTable = ASM_GET_amod(usTable);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3370 switch (amodTable)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3371 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3372 // Normal's match with normals
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3373 case _normal:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3374 switch(amodOp)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3375 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3376 case _normal:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3377 case _addr16:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3378 case _addr32:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3379 case _fn16:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3380 case _fn32:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3381 case _flbl:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3382 return true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3383
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3384 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3385 return false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3386 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3387
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3388 case _rseg:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3389 case _rspecial:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3390 return false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3391 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3392 assert(0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3393 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3394 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3395
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3396 OPND* asm_log_and_exp()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3397 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3398 OPND* o1 = asm_inc_or_exp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3399 OPND* o2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3400
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3401 while (tok_value == TOKandand)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3402 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3403 asm_token();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3404 o2 = asm_inc_or_exp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3405 if (asm_isint(o1) && asm_isint(o2))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3406 o1.disp = o1.disp && o2.disp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3407 else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3408 asmerr(EM_bad_integral_operand); // illegal operand
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3409 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3410 o2.disp = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3411 o1 = asm_merge_opnds(o1, o2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3412 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3413 return o1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3414 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3415
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3416 bool asm_isint(OPND *o)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3417 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3418 if (!o || o.base || o.s)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3419 return false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3420
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3421 //return o.disp != 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3422 return true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3423 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3424
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3425 /*******************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3426 * Merge operands o1 and o2 into a single operand.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3427 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3428
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3429 OPND* asm_merge_opnds(OPND* o1, OPND* o2)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3430 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3431 debug immutable(char)* psz;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3432 debug if (debuga)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3433 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3434 printf("asm_merge_opnds(o1 = ");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3435 if (o1) asm_output_popnd(o1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3436 printf(", o2 = ");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3437 if (o2) asm_output_popnd(o2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3438 printf(")\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3439 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3440
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3441 if (!o1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3442 return o2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3443 if (!o2)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3444 return o1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3445 version (EXTRA_DEBUG) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3446 printf("Combining Operands: mult1 = %d, mult2 = %d",
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3447 o1.uchMultiplier, o2.uchMultiplier);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3448 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3449 /* combine the OPND's disp field */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3450 if (o2.segreg) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3451 if (o1.segreg) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3452 debug psz = "o1.segment && o2.segreg".ptr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3453 goto ILLEGAL_ADDRESS_ERROR;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3454 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3455 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3456 o1.segreg = o2.segreg;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3457 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3458
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3459 // combine the OPND's symbol field
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3460 if (o1.s && o2.s)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3461 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3462 debug psz = "o1.s && os.s";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3463 ILLEGAL_ADDRESS_ERROR:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3464 debug printf("Invalid addr because /%s/\n", psz);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3465
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3466 asmerr(EM_bad_addr_mode); // illegal addressing mode
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3467 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3468 else if (o2.s)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3469 o1.s = o2.s;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3470 else if (o1.s && o1.s.isTupleDeclaration())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3471 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3472 TupleDeclaration tup = o1.s.isTupleDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3473
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3474 size_t index = o2.disp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3475 if (index >= tup.objects.dim)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3476 error(asmstate.loc, "tuple index %u exceeds %u", index, tup.objects.dim);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3477 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3478 {
113
3482c73a991b More cleanup for arrays
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 54
diff changeset
3479 Object o = tup.objects[index];
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3480 if (auto d = cast(Dsymbol)o)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3481 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3482 o1.s = d;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3483 return o1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3484 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3485 else if (auto e = cast(Expression)o)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3486 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3487 if (e.op == TOKvar)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3488 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3489 o1.s = (cast(VarExp)e).var;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3490 return o1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3491 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3492 else if (e.op == TOKfunction)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3493 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3494 o1.s = (cast(FuncExp)e).fd;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3495 return o1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3496 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3497 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3498 error(asmstate.loc, "invalid asm operand %s", o1.s.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3499 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3500 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3501
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3502 if (o1.disp && o2.disp)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3503 o1.disp += o2.disp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3504 else if (o2.disp)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3505 o1.disp = o2.disp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3506
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3507 /* combine the OPND's base field */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3508 if (o1.base !is null && o2.base !is null) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3509 debug psz = "o1.base != null && o2.base != null".ptr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3510 goto ILLEGAL_ADDRESS_ERROR;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3511 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3512 else if (o2.base)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3513 o1.base = o2.base;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3514
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3515 /* Combine the displacement register fields */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3516 if (o2.pregDisp1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3517 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3518 if (o1.pregDisp2)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3519 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3520 debug psz = "o2.pregDisp1 && o1.pregDisp2";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3521 goto ILLEGAL_ADDRESS_ERROR;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3522 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3523 else if (o1.pregDisp1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3524 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3525 if (o1.uchMultiplier ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3526 (o2.pregDisp1.val == _ESP &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3527 (o2.pregDisp1.ty & _r32) &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3528 !o2.uchMultiplier))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3529 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3530 o1.pregDisp2 = o1.pregDisp1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3531 o1.pregDisp1 = o2.pregDisp1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3532 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3533 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3534 o1.pregDisp2 = o2.pregDisp1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3535 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3536 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3537 o1.pregDisp1 = o2.pregDisp1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3538 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3539 if (o2.pregDisp2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3540 if (o1.pregDisp2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3541 debug psz = "o1.pregDisp2 && o2.pregDisp2";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3542 goto ILLEGAL_ADDRESS_ERROR;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3543 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3544 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3545 o1.pregDisp2 = o2.pregDisp2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3546 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3547 if (o2.uchMultiplier)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3548 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3549 if (o1.uchMultiplier)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3550 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3551 debug psz = "o1.uchMultiplier && o2.uchMultiplier";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3552 goto ILLEGAL_ADDRESS_ERROR;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3553 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3554 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3555 o1.uchMultiplier = o2.uchMultiplier;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3556 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3557 if (o2.ptype && !o1.ptype)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3558 o1.ptype = o2.ptype;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3559 if (o2.bOffset)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3560 o1.bOffset = o2.bOffset;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3561 if (o2.bSeg)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3562 o1.bSeg = o2.bSeg;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3563
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3564 if (o2.ajt && !o1.ajt)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3565 o1.ajt = o2.ajt;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3566
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3567 opnd_free(o2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3568 version (EXTRA_DEBUG) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3569 printf("Result = %d\n", o1.uchMultiplier);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3570 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3571 debug if (debuga)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3572 { printf("Merged result = /");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3573 asm_output_popnd(o1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3574 printf("/\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3575 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3576
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3577 return o1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3578 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3579
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3580 opflag_t asm_float_type_size(Type ptype, opflag_t* pusFloat)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3581 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3582 *pusFloat = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3583
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3584 //printf("asm_float_type_size('%s')\n", ptype.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3585 if (ptype && ptype.isscalar())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3586 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3587 int sz = cast(int)ptype.size();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3588 if (sz == REALSIZE)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3589 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3590 *pusFloat = _80;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3591 return 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3592 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3593 switch (sz)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3594 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3595 case 2:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3596 return _16;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3597 case 4:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3598 return _32;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3599 case 8:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3600 *pusFloat = _64;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3601 return 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3602 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3603 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3604 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3605 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3606
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3607 *pusFloat = _fanysize;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3608 return _anysize;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3609 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3610
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3611 OPND* asm_inc_or_exp()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3612 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3613 OPND* o1 = asm_xor_exp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3614 OPND* o2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3615
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3616 while (tok_value == TOKor)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3617 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3618 asm_token();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3619 o2 = asm_xor_exp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3620 if (asm_isint(o1) && asm_isint(o2))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3621 o1.disp |= o2.disp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3622 else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3623 asmerr(EM_bad_integral_operand); // illegal operand
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3624 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3625 o2.disp = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3626 o1 = asm_merge_opnds(o1, o2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3627 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3628 return o1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3629 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3630
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3631 OPND* asm_xor_exp()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3632 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3633 OPND* o1 = asm_and_exp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3634 OPND* o2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3635
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3636 while (tok_value == TOKxor)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3637 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3638 asm_token();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3639 o2 = asm_and_exp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3640 if (asm_isint(o1) && asm_isint(o2))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3641 o1.disp ^= o2.disp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3642 else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3643 asmerr(EM_bad_integral_operand); // illegal operand
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3644 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3645 o2.disp = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3646 o1 = asm_merge_opnds(o1, o2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3647 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3648 return o1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3649 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3650
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3651 OPND* asm_and_exp()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3652 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3653 OPND* o1 = asm_equal_exp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3654 OPND* o2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3655
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3656 while (tok_value == TOKand)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3657 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3658 asm_token();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3659 o2 = asm_equal_exp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3660 if (asm_isint(o1) && asm_isint(o2))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3661 o1.disp &= o2.disp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3662 else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3663 asmerr(EM_bad_integral_operand); // illegal operand
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3664 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3665 o2.disp = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3666 o1 = asm_merge_opnds(o1, o2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3667 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3668 return o1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3669 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3670
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3671 OPND* asm_equal_exp()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3672 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3673 OPND* o1 = asm_rel_exp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3674 OPND* o2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3675
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3676 while (1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3677 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3678 switch (tok_value)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3679 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3680 case TOKequal:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3681 asm_token();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3682 o2 = asm_rel_exp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3683 if (asm_isint(o1) && asm_isint(o2))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3684 o1.disp = o1.disp == o2.disp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3685 else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3686 asmerr(EM_bad_integral_operand); // illegal operand
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3687 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3688 o2.disp = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3689 o1 = asm_merge_opnds(o1, o2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3690 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3691
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3692 case TOKnotequal:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3693 asm_token();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3694 o2 = asm_rel_exp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3695 if (asm_isint(o1) && asm_isint(o2))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3696 o1.disp = o1.disp != o2.disp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3697 else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3698 asmerr(EM_bad_integral_operand);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3699 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3700 o2.disp = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3701 o1 = asm_merge_opnds(o1, o2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3702 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3703
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3704 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3705 return o1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3706 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3707 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3708
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3709 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3710 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3711
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3712 OPND* asm_rel_exp()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3713 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3714 OPND* o1 = asm_shift_exp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3715 OPND* o2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3716
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3717 TOK tok_save;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3718
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3719 while (1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3720 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3721 switch (tok_value)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3722 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3723 case TOKgt:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3724 case TOKge:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3725 case TOKlt:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3726 case TOKle:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3727 tok_save = tok_value;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3728 asm_token();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3729 o2 = asm_shift_exp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3730 if (asm_isint(o1) && asm_isint(o2))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3731 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3732 switch (tok_save)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3733 {
191
52188e7e3fb5 Fixed deprecated features, now compiles with DMD2.058
korDen@korDen-pc
parents: 184
diff changeset
3734 default:
52188e7e3fb5 Fixed deprecated features, now compiles with DMD2.058
korDen@korDen-pc
parents: 184
diff changeset
3735 assert(false);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3736 case TOKgt:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3737 o1.disp = o1.disp > o2.disp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3738 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3739 case TOKge:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3740 o1.disp = o1.disp >= o2.disp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3741 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3742 case TOKlt:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3743 o1.disp = o1.disp < o2.disp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3744 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3745 case TOKle:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3746 o1.disp = o1.disp <= o2.disp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3747 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3748 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3749 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3750 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3751 asmerr(EM_bad_integral_operand);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3752 o2.disp = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3753 o1 = asm_merge_opnds(o1, o2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3754 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3755
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3756 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3757 return o1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3758 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3759 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3760
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3761 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3762 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3763
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3764 OPND* asm_shift_exp()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3765 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3766 OPND* o1 = asm_add_exp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3767 OPND* o2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3768
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3769 int op;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3770 TOK tk;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3771
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3772 while (tok_value == TOKshl || tok_value == TOKshr || tok_value == TOKushr)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3773 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3774 tk = tok_value;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3775 asm_token();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3776 o2 = asm_add_exp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3777 if (asm_isint(o1) && asm_isint(o2))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3778 { if (tk == TOKshl)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3779 o1.disp <<= o2.disp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3780 else if (tk == TOKushr)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3781 o1.disp = cast(uint)o1.disp >> o2.disp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3782 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3783 o1.disp >>= o2.disp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3784 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3785 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3786 asmerr(EM_bad_integral_operand);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3787 o2.disp = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3788 o1 = asm_merge_opnds(o1, o2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3789 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3790 return o1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3791 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3792
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3793 /*******************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3794 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3795
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3796 OPND* asm_add_exp()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3797 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3798 OPND* o1 = asm_mul_exp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3799 OPND* o2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3800
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3801 while (1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3802 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3803 switch (tok_value)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3804 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3805 case TOKadd:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3806 asm_token();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3807 o2 = asm_mul_exp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3808 o1 = asm_merge_opnds(o1, o2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3809 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3810
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3811 case TOKmin:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3812 asm_token();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3813 o2 = asm_mul_exp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3814 if (asm_isint(o1) && asm_isint(o2))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3815 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3816 o1.disp -= o2.disp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3817 o2.disp = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3818 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3819 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3820 o2.disp = - o2.disp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3821 o1 = asm_merge_opnds(o1, o2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3822 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3823
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3824 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3825 return o1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3826 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3827 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3828
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3829 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3830 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3831
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3832 /*******************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3833 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3834
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3835 OPND* asm_mul_exp()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3836 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3837 OPND* o1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3838 OPND* o2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3839 OPND* popndTmp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3840
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3841 //printf("+asm_mul_exp()\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3842 o1 = asm_br_exp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3843 while (1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3844 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3845 switch (tok_value)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3846 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3847 case TOKmul:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3848 asm_token();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3849 o2 = asm_br_exp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3850 version (EXTRA_DEBUG) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3851 printf("Star o1.isint=%d, o2.isint=%d, lbra_seen=%d\n",
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3852 asm_isint(o1), asm_isint(o2), asm_TKlbra_seen );
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3853 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3854 if (asm_isNonZeroInt(o1) && asm_isNonZeroInt(o2))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3855 o1.disp *= o2.disp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3856 else if (asm_TKlbra_seen && o1.pregDisp1 && asm_isNonZeroInt(o2))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3857 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3858 o1.uchMultiplier = o2.disp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3859 version (EXTRA_DEBUG) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3860 printf("Multiplier: %d\n", o1.uchMultiplier);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3861 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3862 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3863 else if (asm_TKlbra_seen && o2.pregDisp1 && asm_isNonZeroInt(o1))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3864 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3865 popndTmp = o2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3866 o2 = o1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3867 o1 = popndTmp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3868 o1.uchMultiplier = o2.disp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3869 version (EXTRA_DEBUG) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3870 printf("Multiplier: %d\n",
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3871 o1.uchMultiplier);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3872 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3873 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3874 else if (asm_isint(o1) && asm_isint(o2))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3875 o1.disp *= o2.disp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3876 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3877 asmerr(EM_bad_operand);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3878 o2.disp = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3879 o1 = asm_merge_opnds(o1, o2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3880 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3881
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3882 case TOKdiv:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3883 asm_token();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3884 o2 = asm_br_exp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3885 if (asm_isint(o1) && asm_isint(o2))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3886 o1.disp /= o2.disp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3887 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3888 asmerr(EM_bad_integral_operand);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3889 o2.disp = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3890 o1 = asm_merge_opnds(o1, o2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3891 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3892
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3893 case TOKmod:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3894 asm_token();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3895 o2 = asm_br_exp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3896 if (asm_isint(o1) && asm_isint(o2))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3897 o1.disp %= o2.disp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3898 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3899 asmerr(EM_bad_integral_operand);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3900 o2.disp = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3901 o1 = asm_merge_opnds(o1, o2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3902 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3903
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3904 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3905 return o1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3906 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3907 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3908
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3909 return o1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3910 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3911
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3912 OPND* asm_br_exp()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3913 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3914 //printf("asm_br_exp()\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3915
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3916 OPND* o1 = asm_una_exp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3917 OPND* o2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3918 Declaration s;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3919
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3920 while (1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3921 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3922 switch (tok_value)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3923 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3924 case TOKlbracket:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3925 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3926 version (EXTRA_DEBUG) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3927 printf("Saw a left bracket\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3928 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3929 asm_token();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3930 asm_TKlbra_seen++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3931 o2 = asm_cond_exp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3932 asm_TKlbra_seen--;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3933 asm_chktok(TOKrbracket,EM_rbra);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3934 version (EXTRA_DEBUG) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3935 printf("Saw a right bracket\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3936 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3937 o1 = asm_merge_opnds(o1, o2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3938 if (tok_value == TOKidentifier)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3939 { o2 = asm_una_exp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3940 o1 = asm_merge_opnds(o1, o2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3941 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3942 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3943 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3944 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3945 return o1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3946 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3947 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3948
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3949 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3950 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3951
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3952 /*******************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3953 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3954
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3955 OPND* asm_una_exp()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3956 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3957 OPND* o1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3958 int op;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3959 Type ptype;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3960 Type ptypeSpec;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3961 ASM_JUMPTYPE ajt = ASM_JUMPTYPE_UNSPECIFIED;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3962 char bPtr = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3963
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3964 switch (cast(int)tok_value)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3965 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3966 static if (false) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3967 case TOKand:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3968 asm_token();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3969 o1 = asm_una_exp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3970 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3971
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3972 case TOKmul:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3973 asm_token();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3974 o1 = asm_una_exp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3975 ++o1.indirect;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3976 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3977 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3978 case TOKadd:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3979 asm_token();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3980 o1 = asm_una_exp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3981 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3982
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3983 case TOKmin:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3984 asm_token();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3985 o1 = asm_una_exp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3986 if (asm_isint(o1))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3987 o1.disp = -o1.disp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3988 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3989
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3990 case TOKnot:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3991 asm_token();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3992 o1 = asm_una_exp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3993 if (asm_isint(o1))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3994 o1.disp = !o1.disp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3995 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3996
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3997 case TOKtilde:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3998 asm_token();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3999 o1 = asm_una_exp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4000 if (asm_isint(o1))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4001 o1.disp = ~o1.disp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4002 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4003
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4004 static if (false) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4005 case TOKlparen:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4006 // stoken() is called directly here because we really
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4007 // want the INT token to be an INT.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4008 stoken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4009 if (type_specifier(&ptypeSpec)) /* if type_name */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4010 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4011 ptype = declar_abstract(ptypeSpec);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4012 /* read abstract_declarator */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4013 fixdeclar(ptype);/* fix declarator */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4014 type_free(ptypeSpec);/* the declar() function
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4015 allocates the typespec again */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4016 chktok(TOKrparen,EM_rpar);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4017 ptype.Tcount--;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4018 goto CAST_REF;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4019 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4020 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4021 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4022 type_free(ptypeSpec);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4023 o1 = asm_cond_exp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4024 chktok(TOKrparen, EM_rpar);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4025 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4026 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4027 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4028
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4029 case TOKidentifier:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4030 // Check for offset keyword
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4031 if (asmtok.ident == Id.offset)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4032 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4033 if (!global.params.useDeprecated)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4034 error(asmstate.loc, "offset deprecated, use offsetof");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4035 goto Loffset;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4036 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4037 if (asmtok.ident == Id.offsetof)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4038 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4039 Loffset:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4040 asm_token();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4041 o1 = asm_cond_exp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4042 if (!o1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4043 o1 = opnd_calloc();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4044 o1.bOffset= true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4045 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4046 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4047 o1 = asm_primary_exp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4048 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4049
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4050 case ASMTK.ASMTKseg:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4051 asm_token();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4052 o1 = asm_cond_exp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4053 if (!o1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4054 o1 = opnd_calloc();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4055 o1.bSeg= true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4056 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4057
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4058 case TOKint16:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4059 if (asmstate.ucItype != ITjump)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4060 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4061 ptype = Type.tint16;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4062 goto TYPE_REF;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4063 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4064 ajt = ASM_JUMPTYPE_SHORT;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4065 asm_token();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4066 goto JUMP_REF2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4067
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4068 case ASMTKnear:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4069 ajt = ASM_JUMPTYPE_NEAR;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4070 goto JUMP_REF;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4071
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4072 case ASMTKfar:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4073 ajt = ASM_JUMPTYPE_FAR;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4074 JUMP_REF:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4075 asm_token();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4076 asm_chktok(cast(TOK) ASMTKptr, EM_ptr_exp);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4077 JUMP_REF2:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4078 o1 = asm_cond_exp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4079 if (!o1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4080 o1 = opnd_calloc();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4081 o1.ajt= ajt;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4082 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4083
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4084 case TOKint8:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4085 ptype = Type.tint8;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4086 goto TYPE_REF;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4087 case TOKint32:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4088 case ASMTKdword:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4089 ptype = Type.tint32;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4090 goto TYPE_REF;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4091 case TOKfloat32:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4092 ptype = Type.tfloat32;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4093 goto TYPE_REF;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4094 case ASMTKqword:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4095 case TOKfloat64:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4096 ptype = Type.tfloat64;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4097 goto TYPE_REF;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4098 case TOKfloat80:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4099 ptype = Type.tfloat80;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4100 goto TYPE_REF;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4101 case ASMTKword:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4102 ptype = Type.tint16;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4103 TYPE_REF:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4104 bPtr = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4105 asm_token();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4106 asm_chktok(cast(TOK) ASMTKptr, EM_ptr_exp);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4107 CAST_REF:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4108 o1 = asm_cond_exp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4109 if (!o1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4110 o1 = opnd_calloc();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4111 o1.ptype = ptype;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4112 o1.bPtr = bPtr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4113 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4114
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4115 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4116 o1 = asm_primary_exp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4117 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4118 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4119 return o1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4120 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4121
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4122 bool asm_isNonZeroInt(OPND* o)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4123 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4124 if (!o || o.base || o.s)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4125 return false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4126
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4127 return o.disp != 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4128 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4129
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4130 OPND* asm_primary_exp()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4131 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4132 OPND* o1 = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4133 OPND* o2 = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4134 Type ptype;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4135 Dsymbol s;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4136 Dsymbol scopesym;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4137
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4138 TOK tkOld;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4139 int global;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4140 REG* regp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4141
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4142 global = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4143 switch (cast(int)tok_value)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4144 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4145 case TOKdollar:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4146 o1 = opnd_calloc();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4147 o1.s = asmstate.psDollar;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4148 asm_token();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4149 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4150
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4151 static if (false) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4152 case TOKthis:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4153 strcpy(tok.TKid,cpp_name_this);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4154 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4155 case TOKidentifier:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4156 case_ident:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4157 o1 = opnd_calloc();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4158 regp = asm_reg_lookup(asmtok.ident.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4159 if (regp !is null)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4160 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4161 asm_token();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4162 // see if it is segment override (like SS:)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4163 if (!asm_TKlbra_seen &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4164 (regp.ty & _seg) &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4165 tok_value == TOKcolon)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4166 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4167 o1.segreg = regp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4168 asm_token();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4169 o2 = asm_cond_exp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4170 o1 = asm_merge_opnds(o1, o2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4171 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4172 else if (asm_TKlbra_seen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4173 { // should be a register
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4174 if (o1.pregDisp1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4175 asmerr(EM_bad_operand);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4176 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4177 o1.pregDisp1 = regp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4178 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4179 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4180 { if (o1.base == null)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4181 o1.base = regp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4182 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4183 asmerr(EM_bad_operand);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4184 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4185 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4186 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4187 // If floating point instruction and id is a floating register
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4188 else if (asmstate.ucItype == ITfloat &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4189 asm_is_fpreg(asmtok.ident.toChars()))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4190 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4191 asm_token();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4192 if (tok_value == TOKlparen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4193 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4194 uint n;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4195
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4196 asm_token();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4197 asm_chktok(TOKint32v, EM_num);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4198 n = cast(uint)asmtok.uns64value;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4199 if (n > 7)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4200 asmerr(EM_bad_operand);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4201 o1.base = &(aregFp[n]);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4202 asm_chktok(TOKrparen, EM_rpar);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4203 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4204 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4205 o1.base = &regFp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4206 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4207 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4208 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4209 if (asmstate.ucItype == ITjump)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4210 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4211 s = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4212 if (asmstate.sc.func.labtab)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4213 s = asmstate.sc.func.labtab.lookup(asmtok.ident);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4214 if (!s)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4215 s = asmstate.sc.search(Loc(0), asmtok.ident, &scopesym);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4216 if (!s)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4217 { // Assume it is a label, and define that label
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4218 s = asmstate.sc.func.searchLabel(asmtok.ident);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4219 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4220 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4221 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4222 s = asmstate.sc.search(Loc(0), asmtok.ident, &scopesym);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4223
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4224 if (!s)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4225 asmerr(EM_undefined, asmtok.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4226
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4227 Identifier id = asmtok.ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4228 asm_token();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4229 if (tok_value == TOKdot)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4230 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4231 Expression e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4232 VarExp v;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4233
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4234 e = new IdentifierExp(asmstate.loc, id);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4235 while (1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4236 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4237 asm_token();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4238 if (tok_value == TOKidentifier)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4239 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4240 e = new DotIdExp(asmstate.loc, e, asmtok.ident);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4241 asm_token();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4242 if (tok_value != TOKdot)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4243 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4244 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4245 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4246 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4247 asmerr(EM_ident_exp);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4248 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4249 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4250 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4251 e = e.semantic(asmstate.sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4252 e = e.optimize(WANTvalue | WANTinterpret);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4253 if (e.isConst())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4254 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4255 if (e.type.isintegral())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4256 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4257 o1.disp = cast(int)e.toInteger();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4258 goto Lpost;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4259 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4260 else if (e.type.isreal())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4261 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4262 o1.real_ = e.toReal();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4263 o1.ptype = e.type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4264 goto Lpost;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4265 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4266 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4267 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4268 asmerr(EM_bad_op, e.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4269 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4270 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4271 else if (e.op == TOKvar)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4272 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4273 v = cast(VarExp)e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4274 s = v.var;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4275 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4276 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4277 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4278 asmerr(EM_bad_op, e.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4279 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4280 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4281
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4282 asm_merge_symbol(o1,s);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4283
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4284 /* This attempts to answer the question: is
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4285 * char[8] foo;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4286 * of size 1 or size 8? Presume it is 8 if foo
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4287 * is the last token of the operand.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4288 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4289 if (o1.ptype && tok_value != TOKcomma && tok_value != TOKeof)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4290 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4291 for (;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4292 o1.ptype.ty == Tsarray;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4293 o1.ptype = o1.ptype.nextOf())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4294 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4295 ;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4296 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4297 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4298
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4299 Lpost:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4300 static if (false) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4301 // for []
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4302 if (tok_value == TOKlbracket)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4303 o1 = asm_prim_post(o1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4304 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4305 goto Lret;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4306 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4307 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4308
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4309 case TOKint32v:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4310 case TOKuns32v:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4311 o1 = opnd_calloc();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4312 o1.disp = asmtok.int32value;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4313 asm_token();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4314 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4315
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4316 case TOKfloat32v:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4317 o1 = opnd_calloc();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4318 o1.real_ = asmtok.float80value;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4319 o1.ptype = Type.tfloat32;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4320 asm_token();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4321 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4322
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4323 case TOKfloat64v:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4324 o1 = opnd_calloc();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4325 o1.real_ = asmtok.float80value;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4326 o1.ptype = Type.tfloat64;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4327 asm_token();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4328 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4329
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4330 case TOKfloat80v:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4331 o1 = opnd_calloc();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4332 o1.real_ = asmtok.float80value;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4333 o1.ptype = Type.tfloat80;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4334 asm_token();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4335 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4336
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4337 case ASMTKlocalsize:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4338 o1 = opnd_calloc();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4339 o1.s = asmstate.psLocalsize;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4340 o1.ptype = Type.tint32;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4341 asm_token();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4342 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4343
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4344 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4345 break; ///
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4346 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4347 Lret:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4348 return o1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4349 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4350
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4351 void asm_merge_symbol(OPND* o1, Dsymbol s)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4352 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4353 Type ptype;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4354 VarDeclaration v;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4355 EnumMember em;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4356
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4357 //printf("asm_merge_symbol(s = %s %s)\n", s.kind(), s.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4358 s = s.toAlias();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4359 //printf("s = %s %s\n", s.kind(), s.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4360 if (s.isLabel())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4361 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4362 o1.s = s;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4363 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4364 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4365
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4366 v = s.isVarDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4367 if (v)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4368 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4369 if (v.isParameter())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4370 asmstate.statement.refparam = true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4371
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4372 v.checkNestedReference(asmstate.sc, asmstate.loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4373 static if (false) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4374 if (!v.isDataseg() && v.parent != asmstate.sc.parent && v.parent)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4375 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4376 asmerr(EM_uplevel, v.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4377 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4378 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4379 if (v.storage_class & STCfield)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4380 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4381 o1.disp += v.offset;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4382 goto L2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4383 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4384 if ((v.isConst()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4385 ///version (DMDV2) {
135
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
4386 || v.isImmutable() || v.storage_class & STCmanifest
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4387 ///}
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4388 ) && !v.type.isfloating() && v.init)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4389 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4390 ExpInitializer ei = v.init.isExpInitializer();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4391
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4392 if (ei)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4393 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4394 o1.disp = cast(int)ei.exp.toInteger();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4395 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4396 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4397 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4398 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4399 em = s.isEnumMember();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4400 if (em)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4401 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4402 o1.disp = cast(int)em.value.toInteger();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4403 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4404 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4405 o1.s = s; // a C identifier
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4406 L2:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4407 Declaration d = s.isDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4408 if (!d)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4409 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4410 asmerr("%s %s is not a declaration", s.kind(), s.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4411 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4412 else if (d.getType())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4413 asmerr(EM_type_as_operand, d.getType().toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4414 else if (d.isTupleDeclaration()) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4415 ;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4416 } else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4417 o1.ptype = d.type.toBasetype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4418 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4419
177
1475fd394c9e bug fixes
korDen
parents: 176
diff changeset
4420 __gshared REG[63] regtab =
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4421 [
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4422 {"AL", _AL, _r8 | _al,},
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4423 {"AH", _AH, _r8,},
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4424 {"AX", _AX, _r16 | _ax,},
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4425 {"EAX", _EAX, _r32 | _eax,},
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4426 {"BL", _BL, _r8,},
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4427 {"BH", _BH, _r8,},
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4428 {"BX", _BX, _r16,},
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4429 {"EBX", _EBX, _r32,},
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4430 {"CL", _CL, _r8 | _cl,},
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4431 {"CH", _CH, _r8,},
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4432 {"CX", _CX, _r16,},
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4433 {"ECX", _ECX, _r32,},
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4434 {"DL", _DL, _r8,},
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4435 {"DH", _DH, _r8,},
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4436 {"DX", _DX, _r16 | _dx,},
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4437 {"EDX", _EDX, _r32,},
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4438 {"BP", _BP, _r16,},
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4439 {"EBP", _EBP, _r32,},
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4440 {"SP", _SP, _r16,},
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4441 {"ESP", _ESP, _r32,},
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4442 {"DI", _DI, _r16,},
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4443 {"EDI", _EDI, _r32,},
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4444 {"SI", _SI, _r16,},
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4445 {"ESI", _ESI, _r32,},
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4446 {"ES", _ES, _seg | _es,},
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4447 {"CS", _CS, _seg | _cs,},
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4448 {"SS", _SS, _seg | _ss,},
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4449 {"DS", _DS, _seg | _ds,},
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4450 {"GS", _GS, _seg | _gs,},
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4451 {"FS", _FS, _seg | _fs,},
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4452 {"CR0", 0, _special | _crn,},
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4453 {"CR2", 2, _special | _crn,},
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4454 {"CR3", 3, _special | _crn,},
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4455 {"CR4", 4, _special | _crn,},
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4456 {"DR0", 0, _special | _drn,},
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4457 {"DR1", 1, _special | _drn,},
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4458 {"DR2", 2, _special | _drn,},
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4459 {"DR3", 3, _special | _drn,},
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4460 {"DR4", 4, _special | _drn,},
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4461 {"DR5", 5, _special | _drn,},
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4462 {"DR6", 6, _special | _drn,},
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4463 {"DR7", 7, _special | _drn,},
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4464 {"TR3", 3, _special | _trn,},
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4465 {"TR4", 4, _special | _trn,},
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4466 {"TR5", 5, _special | _trn,},
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4467 {"TR6", 6, _special | _trn,},
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4468 {"TR7", 7, _special | _trn,},
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4469 {"MM0", 0, _mm,},
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4470 {"MM1", 1, _mm,},
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4471 {"MM2", 2, _mm,},
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4472 {"MM3", 3, _mm,},
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4473 {"MM4", 4, _mm,},
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4474 {"MM5", 5, _mm,},
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4475 {"MM6", 6, _mm,},
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4476 {"MM7", 7, _mm,},
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4477 {"XMM0", 0, _xmm,},
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4478 {"XMM1", 1, _xmm,},
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4479 {"XMM2", 2, _xmm,},
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4480 {"XMM3", 3, _xmm,},
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4481 {"XMM4", 4, _xmm,},
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4482 {"XMM5", 5, _xmm,},
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4483 {"XMM6", 6, _xmm,},
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4484 {"XMM7", 7, _xmm,},
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4485 ];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4486
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4487 REG* asm_reg_lookup(string s)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4488 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4489 //dbg_printf("asm_reg_lookup('%s')\n",s);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4490
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4491 for (int i = 0; i < regtab.length; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4492 {
54
f95140b40251 asm_reg_lookup bug fixed
korDen
parents: 28
diff changeset
4493 if (regtab[i].regstr == s)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4494 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4495 return &regtab[i];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4496 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4497 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4498
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4499 return null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4500 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4501
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4502 int asm_is_fpreg(string szReg)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4503 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4504 static if (true) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4505 return(szReg.length == 2 && szReg[0] == 'S' &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4506 szReg[1] == 'T');
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4507 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4508 return(szReg.length == 2 && (szReg[0] == 's' || szReg[0] == 'S') &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4509 (szReg[1] == 't' || szReg[1] == 'T'));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4510 }
14
2cc604139636 Implemented Linux support for ddmd. Some parts are a bit hacky to just "get it working", that said, druntime and phobos compile, and unittests pass.
Robert Clipsham <robert@octarineparrot.com>
parents: 5
diff changeset
4511 }
140
31c086f76669 dmd.lib now only contains the backend
Trass3r
parents: 135
diff changeset
4512
184
9f4e5ac4f0a3 One step closer to building on posix.
Jacob Carlborg <doob@me.com>
parents: 183
diff changeset
4513 extern(C)
140
31c086f76669 dmd.lib now only contains the backend
Trass3r
parents: 135
diff changeset
4514 {
31c086f76669 dmd.lib now only contains the backend
Trass3r
parents: 135
diff changeset
4515 // backward reference from backend
31c086f76669 dmd.lib now only contains the backend
Trass3r
parents: 135
diff changeset
4516
184
9f4e5ac4f0a3 One step closer to building on posix.
Jacob Carlborg <doob@me.com>
parents: 183
diff changeset
4517 extern __gshared int refparam;
140
31c086f76669 dmd.lib now only contains the backend
Trass3r
parents: 135
diff changeset
4518
31c086f76669 dmd.lib now only contains the backend
Trass3r
parents: 135
diff changeset
4519 /**********************************
31c086f76669 dmd.lib now only contains the backend
Trass3r
parents: 135
diff changeset
4520 * Return mask of registers used by block bp.
31c086f76669 dmd.lib now only contains the backend
Trass3r
parents: 135
diff changeset
4521 */
31c086f76669 dmd.lib now only contains the backend
Trass3r
parents: 135
diff changeset
4522 regm_t iasm_regs(block *bp)
31c086f76669 dmd.lib now only contains the backend
Trass3r
parents: 135
diff changeset
4523 {
31c086f76669 dmd.lib now only contains the backend
Trass3r
parents: 135
diff changeset
4524 debug if (debuga)
31c086f76669 dmd.lib now only contains the backend
Trass3r
parents: 135
diff changeset
4525 printf("Block iasm regs = 0x%X\n", bp.usIasmregs);
31c086f76669 dmd.lib now only contains the backend
Trass3r
parents: 135
diff changeset
4526
31c086f76669 dmd.lib now only contains the backend
Trass3r
parents: 135
diff changeset
4527 refparam |= bp.bIasmrefparam;
31c086f76669 dmd.lib now only contains the backend
Trass3r
parents: 135
diff changeset
4528 return bp.usIasmregs;
31c086f76669 dmd.lib now only contains the backend
Trass3r
parents: 135
diff changeset
4529 }
31c086f76669 dmd.lib now only contains the backend
Trass3r
parents: 135
diff changeset
4530 }