summaryrefslogtreecommitdiff
path: root/lib/AsmJit/OperandX86X64.cpp
blob: 8c15d1cf8b5dec38ef5ab16c8a7a00f91515aaac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
// AsmJit - Complete JIT Assembler for C++ Language.

// Copyright (c) 2008-2010, Petr Kobalicek <kobalicek.petr@gmail.com>
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
// 
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
// 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.

// [Dependencies]
#include "Defs.h"
#include "Operand.h"

// [Api-Begin]
#include "ApiBegin.h"

namespace AsmJit {

// ============================================================================
// [AsmJit::Registers - no_reg]
// ============================================================================

const GPReg no_reg(_Initialize(), INVALID_VALUE);

// ============================================================================
// [AsmJit::Registers - 8-bit]
// ============================================================================

const GPReg al(_Initialize(), REG_AL);
const GPReg cl(_Initialize(), REG_CL);
const GPReg dl(_Initialize(), REG_DL);
const GPReg bl(_Initialize(), REG_BL);

#if defined(ASMJIT_X64)
const GPReg spl(_Initialize(), REG_SPL);
const GPReg bpl(_Initialize(), REG_BPL);
const GPReg sil(_Initialize(), REG_SIL);
const GPReg dil(_Initialize(), REG_DIL);

const GPReg r8b(_Initialize(), REG_R8B);
const GPReg r9b(_Initialize(), REG_R9B);
const GPReg r10b(_Initialize(), REG_R10B);
const GPReg r11b(_Initialize(), REG_R11B);
const GPReg r12b(_Initialize(), REG_R12B);
const GPReg r13b(_Initialize(), REG_R13B);
const GPReg r14b(_Initialize(), REG_R14B);
const GPReg r15b(_Initialize(), REG_R15B);
#endif // ASMJIT_X64

const GPReg ah(_Initialize(), REG_AH);
const GPReg ch(_Initialize(), REG_CH);
const GPReg dh(_Initialize(), REG_DH);
const GPReg bh(_Initialize(), REG_BH);

// ============================================================================
// [AsmJit::Registers - 16-bit]
// ============================================================================

const GPReg ax(_Initialize(), REG_AX);
const GPReg cx(_Initialize(), REG_CX);
const GPReg dx(_Initialize(), REG_DX);
const GPReg bx(_Initialize(), REG_BX);
const GPReg sp(_Initialize(), REG_SP);
const GPReg bp(_Initialize(), REG_BP);
const GPReg si(_Initialize(), REG_SI);
const GPReg di(_Initialize(), REG_DI);

#if defined(ASMJIT_X64)
const GPReg r8w(_Initialize(), REG_R8W);
const GPReg r9w(_Initialize(), REG_R9W);
const GPReg r10w(_Initialize(), REG_R10W);
const GPReg r11w(_Initialize(), REG_R11W);
const GPReg r12w(_Initialize(), REG_R12W);
const GPReg r13w(_Initialize(), REG_R13W);
const GPReg r14w(_Initialize(), REG_R14W);
const GPReg r15w(_Initialize(), REG_R15W);
#endif // ASMJIT_X64

// ============================================================================
// [AsmJit::Registers - 32-bit]
// ============================================================================

const GPReg eax(_Initialize(), REG_EAX);
const GPReg ecx(_Initialize(), REG_ECX);
const GPReg edx(_Initialize(), REG_EDX);
const GPReg ebx(_Initialize(), REG_EBX);
const GPReg esp(_Initialize(), REG_ESP);
const GPReg ebp(_Initialize(), REG_EBP);
const GPReg esi(_Initialize(), REG_ESI);
const GPReg edi(_Initialize(), REG_EDI);

#if defined(ASMJIT_X64)
const GPReg r8d(_Initialize(), REG_R8D);
const GPReg r9d(_Initialize(), REG_R9D);
const GPReg r10d(_Initialize(), REG_R10D);
const GPReg r11d(_Initialize(), REG_R11D);
const GPReg r12d(_Initialize(), REG_R12D);
const GPReg r13d(_Initialize(), REG_R13D);
const GPReg r14d(_Initialize(), REG_R14D);
const GPReg r15d(_Initialize(), REG_R15D);
#endif // ASMJIT_X64

// ============================================================================
// [AsmJit::Registers - 64-bit]
// ============================================================================

#if defined(ASMJIT_X64)
const GPReg rax(_Initialize(), REG_RAX);
const GPReg rcx(_Initialize(), REG_RCX);
const GPReg rdx(_Initialize(), REG_RDX);
const GPReg rbx(_Initialize(), REG_RBX);
const GPReg rsp(_Initialize(), REG_RSP);
const GPReg rbp(_Initialize(), REG_RBP);
const GPReg rsi(_Initialize(), REG_RSI);
const GPReg rdi(_Initialize(), REG_RDI);

const GPReg r8(_Initialize(), REG_R8);
const GPReg r9(_Initialize(), REG_R9);
const GPReg r10(_Initialize(), REG_R10);
const GPReg r11(_Initialize(), REG_R11);
const GPReg r12(_Initialize(), REG_R12);
const GPReg r13(_Initialize(), REG_R13);
const GPReg r14(_Initialize(), REG_R14);
const GPReg r15(_Initialize(), REG_R15);
#endif // ASMJIT_X64

// ============================================================================
// [AsmJit::Registers - Native (AsmJit extension)]
// ============================================================================

const GPReg nax(_Initialize(), REG_NAX);
const GPReg ncx(_Initialize(), REG_NCX);
const GPReg ndx(_Initialize(), REG_NDX);
const GPReg nbx(_Initialize(), REG_NBX);
const GPReg nsp(_Initialize(), REG_NSP);
const GPReg nbp(_Initialize(), REG_NBP);
const GPReg nsi(_Initialize(), REG_NSI);
const GPReg ndi(_Initialize(), REG_NDI);

// ============================================================================
// [AsmJit::Registers - MM]
// ============================================================================

const MMReg mm0(_Initialize(), REG_MM0);
const MMReg mm1(_Initialize(), REG_MM1);
const MMReg mm2(_Initialize(), REG_MM2);
const MMReg mm3(_Initialize(), REG_MM3);
const MMReg mm4(_Initialize(), REG_MM4);
const MMReg mm5(_Initialize(), REG_MM5);
const MMReg mm6(_Initialize(), REG_MM6);
const MMReg mm7(_Initialize(), REG_MM7);

// ============================================================================
// [AsmJit::Registers - XMM]
// ============================================================================

const XMMReg xmm0(_Initialize(), REG_XMM0);
const XMMReg xmm1(_Initialize(), REG_XMM1);
const XMMReg xmm2(_Initialize(), REG_XMM2);
const XMMReg xmm3(_Initialize(), REG_XMM3);
const XMMReg xmm4(_Initialize(), REG_XMM4);
const XMMReg xmm5(_Initialize(), REG_XMM5);
const XMMReg xmm6(_Initialize(), REG_XMM6);
const XMMReg xmm7(_Initialize(), REG_XMM7);

#if defined(ASMJIT_X64)
const XMMReg xmm8(_Initialize(), REG_XMM8);
const XMMReg xmm9(_Initialize(), REG_XMM9);
const XMMReg xmm10(_Initialize(), REG_XMM10);
const XMMReg xmm11(_Initialize(), REG_XMM11);
const XMMReg xmm12(_Initialize(), REG_XMM12);
const XMMReg xmm13(_Initialize(), REG_XMM13);
const XMMReg xmm14(_Initialize(), REG_XMM14);
const XMMReg xmm15(_Initialize(), REG_XMM15);
#endif // ASMJIT_X64

// ============================================================================
// [AsmJit::Immediate]
// ============================================================================

//! @brief Create signed immediate value operand.
Imm imm(sysint_t i) ASMJIT_NOTHROW
{ 
  return Imm(i, false);
}

//! @brief Create unsigned immediate value operand.
Imm uimm(sysuint_t i) ASMJIT_NOTHROW
{
  return Imm((sysint_t)i, true);
}

// ============================================================================
// [AsmJit::BaseVar]
// ============================================================================

Mem _baseVarMem(const BaseVar& var, uint32_t ptrSize) ASMJIT_NOTHROW
{
  Mem m; //(_DontInitialize());

  m._mem.op = OPERAND_MEM;
  m._mem.size = ptrSize == INVALID_VALUE ? var.getSize() : (uint8_t)ptrSize;
  m._mem.type = OPERAND_MEM_NATIVE;
  m._mem.segmentPrefix = SEGMENT_NONE;

  m._mem.id = var.getId();

  m._mem.base = INVALID_VALUE;
  m._mem.index = INVALID_VALUE;
  m._mem.shift = 0;

  m._mem.target = NULL;
  m._mem.displacement = 0;

  return m;
}


Mem _baseVarMem(const BaseVar& var, uint32_t ptrSize, sysint_t disp) ASMJIT_NOTHROW
{
  Mem m; //(_DontInitialize());

  m._mem.op = OPERAND_MEM;
  m._mem.size = ptrSize == INVALID_VALUE ? var.getSize() : (uint8_t)ptrSize;
  m._mem.type = OPERAND_MEM_NATIVE;
  m._mem.segmentPrefix = SEGMENT_NONE;

  m._mem.id = var.getId();

  m._mem.base = INVALID_VALUE;
  m._mem.index = INVALID_VALUE;
  m._mem.shift = 0;

  m._mem.target = NULL;
  m._mem.displacement = disp;

  return m;
}

Mem _baseVarMem(const BaseVar& var, uint32_t ptrSize, const GPVar& index, uint32_t shift, sysint_t disp) ASMJIT_NOTHROW
{
  Mem m; //(_DontInitialize());

  m._mem.op = OPERAND_MEM;
  m._mem.size = ptrSize == INVALID_VALUE ? var.getSize() : (uint8_t)ptrSize;
  m._mem.type = OPERAND_MEM_NATIVE;
  m._mem.segmentPrefix = SEGMENT_NONE;

  m._mem.id = var.getId();

  m._mem.base = INVALID_VALUE;
  m._mem.index = index.getId();
  m._mem.shift = shift;

  m._mem.target = NULL;
  m._mem.displacement = disp;

  return m;
}

// ============================================================================
// [AsmJit::Mem - ptr[]]
// ============================================================================

Mem _MemPtrBuild(
  const Label& label, sysint_t disp, uint32_t ptrSize)
  ASMJIT_NOTHROW
{
  return Mem(label, disp, ptrSize);
}

Mem _MemPtrBuild(
  const Label& label,
  const GPReg& index, uint32_t shift, sysint_t disp, uint32_t ptrSize)
  ASMJIT_NOTHROW
{
  Mem m(label, disp, ptrSize);

  m._mem.index = index.getRegIndex();
  m._mem.shift = shift;

  return m;
}

Mem _MemPtrBuild(
  const Label& label,
  const GPVar& index, uint32_t shift, sysint_t disp, uint32_t ptrSize)
  ASMJIT_NOTHROW
{
  Mem m(label, disp, ptrSize);

  m._mem.index = index.getId();
  m._mem.shift = shift;

  return m;
}

// ============================================================================
// [AsmJit::Mem - ptr[] - Absolute Addressing]
// ============================================================================

ASMJIT_API Mem _MemPtrAbs(
  void* target, sysint_t disp,
  uint32_t segmentPrefix, uint32_t ptrSize)
  ASMJIT_NOTHROW
{
  Mem m;

  m._mem.size = ptrSize;
  m._mem.type = OPERAND_MEM_ABSOLUTE;
  m._mem.segmentPrefix = segmentPrefix;

  m._mem.target = target;
  m._mem.displacement = disp;

  return m;
}

ASMJIT_API Mem _MemPtrAbs(
  void* target,
  const GPReg& index, uint32_t shift, sysint_t disp,
  uint32_t segmentPrefix, uint32_t ptrSize)
  ASMJIT_NOTHROW
{
  Mem m;// (_DontInitialize());

  m._mem.op = OPERAND_MEM;
  m._mem.size = ptrSize;
  m._mem.type = OPERAND_MEM_ABSOLUTE;
  m._mem.segmentPrefix = (uint8_t)segmentPrefix;

  m._mem.id = INVALID_VALUE;

  m._mem.base = INVALID_VALUE;
  m._mem.index = index.getRegIndex();
  m._mem.shift = shift;

  m._mem.target = target;
  m._mem.displacement = disp;

  return m;
}

ASMJIT_API Mem _MemPtrAbs(
  void* target,
  const GPVar& index, uint32_t shift, sysint_t disp,
  uint32_t segmentPrefix, uint32_t ptrSize)
  ASMJIT_NOTHROW
{
  Mem m;// (_DontInitialize());

  m._mem.op = OPERAND_MEM;
  m._mem.size = ptrSize;
  m._mem.type = OPERAND_MEM_ABSOLUTE;
  m._mem.segmentPrefix = (uint8_t)segmentPrefix;

  m._mem.id = INVALID_VALUE;

  m._mem.base = INVALID_VALUE;
  m._mem.index = index.getId();
  m._mem.shift = shift;

  m._mem.target = target;
  m._mem.displacement = disp;

  return m;
}

// ============================================================================
// [AsmJit::Mem - ptr[base + displacement]]
// ============================================================================

Mem _MemPtrBuild(
  const GPReg& base, sysint_t disp, uint32_t ptrSize)
  ASMJIT_NOTHROW
{
  return Mem(base, disp, ptrSize);
}

Mem _MemPtrBuild(
  const GPReg& base,
  const GPReg& index, uint32_t shift, sysint_t disp, uint32_t ptrSize)
  ASMJIT_NOTHROW
{
  return Mem(base, index, shift, disp, ptrSize);
}

Mem _MemPtrBuild(
  const GPVar& base, sysint_t disp, uint32_t ptrSize)
  ASMJIT_NOTHROW
{
  return Mem(base, disp, ptrSize);
}

Mem _MemPtrBuild(
  const GPVar& base,
  const GPVar& index, uint32_t shift, sysint_t disp, uint32_t ptrSize)
  ASMJIT_NOTHROW
{
  return Mem(base, index, shift, disp, ptrSize);
}

} // AsmJit namespace