blob: 70bd70c21130e582d5fb17b656302c1a0e144a4f [file] [log] [blame]
Elliott Hughes2faa5f12012-01-30 14:42:07 -08001/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -070016
17#ifndef ART_SRC_ASSEMBLER_X86_H_
18#define ART_SRC_ASSEMBLER_X86_H_
19
Ian Rogers0d666d82011-08-14 16:03:46 -070020#include <vector>
Brian Carlstrom578bbdc2011-07-21 14:07:47 -070021#include "assembler.h"
22#include "constants.h"
23#include "globals.h"
Ian Rogers2c8f6532011-09-02 17:16:34 -070024#include "managed_register_x86.h"
Brian Carlstrom578bbdc2011-07-21 14:07:47 -070025#include "macros.h"
26#include "offsets.h"
27#include "utils.h"
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -070028
Carl Shapiro6b6b5f02011-06-21 15:05:09 -070029namespace art {
Ian Rogers2c8f6532011-09-02 17:16:34 -070030namespace x86 {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -070031
32class Immediate {
33 public:
34 explicit Immediate(int32_t value) : value_(value) {}
35
36 int32_t value() const { return value_; }
37
38 bool is_int8() const { return IsInt(8, value_); }
39 bool is_uint8() const { return IsUint(8, value_); }
40 bool is_uint16() const { return IsUint(16, value_); }
41
42 private:
43 const int32_t value_;
44
Shih-wei Liao24782c62012-01-08 12:46:11 -080045 // TODO: Remove the #if when Mac OS build server no longer uses GCC 4.2.*.
46#if GCC_VERSION >= 40300
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -070047 DISALLOW_COPY_AND_ASSIGN(Immediate);
Shih-wei Liao24782c62012-01-08 12:46:11 -080048#endif
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -070049};
50
51
52class Operand {
53 public:
54 uint8_t mod() const {
55 return (encoding_at(0) >> 6) & 3;
56 }
57
58 Register rm() const {
59 return static_cast<Register>(encoding_at(0) & 7);
60 }
61
62 ScaleFactor scale() const {
63 return static_cast<ScaleFactor>((encoding_at(1) >> 6) & 3);
64 }
65
66 Register index() const {
67 return static_cast<Register>((encoding_at(1) >> 3) & 7);
68 }
69
70 Register base() const {
71 return static_cast<Register>(encoding_at(1) & 7);
72 }
73
74 int8_t disp8() const {
75 CHECK_GE(length_, 2);
76 return static_cast<int8_t>(encoding_[length_ - 1]);
77 }
78
79 int32_t disp32() const {
80 CHECK_GE(length_, 5);
81 int32_t value;
82 memcpy(&value, &encoding_[length_ - 4], sizeof(value));
83 return value;
84 }
85
86 bool IsRegister(Register reg) const {
87 return ((encoding_[0] & 0xF8) == 0xC0) // Addressing mode is register only.
88 && ((encoding_[0] & 0x07) == reg); // Register codes match.
89 }
90
91 protected:
92 // Operand can be sub classed (e.g: Address).
93 Operand() : length_(0) { }
94
95 void SetModRM(int mod, Register rm) {
96 CHECK_EQ(mod & ~3, 0);
97 encoding_[0] = (mod << 6) | rm;
98 length_ = 1;
99 }
100
101 void SetSIB(ScaleFactor scale, Register index, Register base) {
102 CHECK_EQ(length_, 1);
103 CHECK_EQ(scale & ~3, 0);
104 encoding_[1] = (scale << 6) | (index << 3) | base;
105 length_ = 2;
106 }
107
108 void SetDisp8(int8_t disp) {
109 CHECK(length_ == 1 || length_ == 2);
110 encoding_[length_++] = static_cast<uint8_t>(disp);
111 }
112
113 void SetDisp32(int32_t disp) {
114 CHECK(length_ == 1 || length_ == 2);
115 int disp_size = sizeof(disp);
116 memmove(&encoding_[length_], &disp, disp_size);
117 length_ += disp_size;
118 }
119
120 private:
121 byte length_;
122 byte encoding_[6];
123 byte padding_;
124
125 explicit Operand(Register reg) { SetModRM(3, reg); }
126
127 // Get the operand encoding byte at the given index.
128 uint8_t encoding_at(int index) const {
129 CHECK_GE(index, 0);
130 CHECK_LT(index, length_);
131 return encoding_[index];
132 }
133
Ian Rogers2c8f6532011-09-02 17:16:34 -0700134 friend class X86Assembler;
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700135
Shih-wei Liao24782c62012-01-08 12:46:11 -0800136 // TODO: Remove the #if when Mac OS build server no longer uses GCC 4.2.*.
137#if GCC_VERSION >= 40300
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700138 DISALLOW_COPY_AND_ASSIGN(Operand);
Shih-wei Liao24782c62012-01-08 12:46:11 -0800139#endif
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700140};
141
142
143class Address : public Operand {
144 public:
145 Address(Register base, int32_t disp) {
Ian Rogersb033c752011-07-20 12:22:35 -0700146 Init(base, disp);
147 }
148
Ian Rogersa04d3972011-08-17 11:33:44 -0700149 Address(Register base, Offset disp) {
150 Init(base, disp.Int32Value());
151 }
152
Ian Rogersb033c752011-07-20 12:22:35 -0700153 Address(Register base, FrameOffset disp) {
154 CHECK_EQ(base, ESP);
155 Init(ESP, disp.Int32Value());
156 }
157
158 Address(Register base, MemberOffset disp) {
159 Init(base, disp.Int32Value());
160 }
161
162 void Init(Register base, int32_t disp) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700163 if (disp == 0 && base != EBP) {
164 SetModRM(0, base);
165 if (base == ESP) SetSIB(TIMES_1, ESP, base);
166 } else if (disp >= -128 && disp <= 127) {
167 SetModRM(1, base);
168 if (base == ESP) SetSIB(TIMES_1, ESP, base);
169 SetDisp8(disp);
170 } else {
171 SetModRM(2, base);
172 if (base == ESP) SetSIB(TIMES_1, ESP, base);
173 SetDisp32(disp);
174 }
175 }
176
Ian Rogersb033c752011-07-20 12:22:35 -0700177
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700178 Address(Register index, ScaleFactor scale, int32_t disp) {
179 CHECK_NE(index, ESP); // Illegal addressing mode.
180 SetModRM(0, ESP);
181 SetSIB(scale, index, EBP);
182 SetDisp32(disp);
183 }
184
185 Address(Register base, Register index, ScaleFactor scale, int32_t disp) {
186 CHECK_NE(index, ESP); // Illegal addressing mode.
187 if (disp == 0 && base != EBP) {
188 SetModRM(0, ESP);
189 SetSIB(scale, index, base);
190 } else if (disp >= -128 && disp <= 127) {
191 SetModRM(1, ESP);
192 SetSIB(scale, index, base);
193 SetDisp8(disp);
194 } else {
195 SetModRM(2, ESP);
196 SetSIB(scale, index, base);
197 SetDisp32(disp);
198 }
199 }
200
Carl Shapiro69759ea2011-07-21 18:13:35 -0700201 static Address Absolute(uword addr) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700202 Address result;
203 result.SetModRM(0, EBP);
204 result.SetDisp32(addr);
205 return result;
206 }
207
Ian Rogersb033c752011-07-20 12:22:35 -0700208 static Address Absolute(ThreadOffset addr) {
209 return Absolute(addr.Int32Value());
210 }
211
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700212 private:
213 Address() {}
214
Shih-wei Liao24782c62012-01-08 12:46:11 -0800215 // TODO: Remove the #if when Mac OS build server no longer uses GCC 4.2.*.
216#if GCC_VERSION >= 40300
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700217 DISALLOW_COPY_AND_ASSIGN(Address);
Shih-wei Liao24782c62012-01-08 12:46:11 -0800218#endif
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700219};
220
221
Ian Rogers2c8f6532011-09-02 17:16:34 -0700222class X86Assembler : public Assembler {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700223 public:
Ian Rogers2c8f6532011-09-02 17:16:34 -0700224 X86Assembler() {}
225 virtual ~X86Assembler() {}
buzbeec143c552011-08-20 17:38:58 -0700226
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700227 /*
228 * Emit Machine Instructions.
229 */
230 void call(Register reg);
231 void call(const Address& address);
232 void call(Label* label);
233
234 void pushl(Register reg);
235 void pushl(const Address& address);
236 void pushl(const Immediate& imm);
237
238 void popl(Register reg);
239 void popl(const Address& address);
240
241 void movl(Register dst, const Immediate& src);
242 void movl(Register dst, Register src);
243
244 void movl(Register dst, const Address& src);
245 void movl(const Address& dst, Register src);
246 void movl(const Address& dst, const Immediate& imm);
Ian Rogersbdb03912011-09-14 00:55:44 -0700247 void movl(const Address& dst, Label* lbl);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700248
249 void movzxb(Register dst, ByteRegister src);
250 void movzxb(Register dst, const Address& src);
251 void movsxb(Register dst, ByteRegister src);
252 void movsxb(Register dst, const Address& src);
253 void movb(Register dst, const Address& src);
254 void movb(const Address& dst, ByteRegister src);
255 void movb(const Address& dst, const Immediate& imm);
256
257 void movzxw(Register dst, Register src);
258 void movzxw(Register dst, const Address& src);
259 void movsxw(Register dst, Register src);
260 void movsxw(Register dst, const Address& src);
261 void movw(Register dst, const Address& src);
262 void movw(const Address& dst, Register src);
263
264 void leal(Register dst, const Address& src);
265
Ian Rogersb033c752011-07-20 12:22:35 -0700266 void cmovl(Condition condition, Register dst, Register src);
267
268 void setb(Condition condition, Register dst);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700269
270 void movss(XmmRegister dst, const Address& src);
271 void movss(const Address& dst, XmmRegister src);
272 void movss(XmmRegister dst, XmmRegister src);
273
274 void movd(XmmRegister dst, Register src);
275 void movd(Register dst, XmmRegister src);
276
277 void addss(XmmRegister dst, XmmRegister src);
278 void addss(XmmRegister dst, const Address& src);
279 void subss(XmmRegister dst, XmmRegister src);
280 void subss(XmmRegister dst, const Address& src);
281 void mulss(XmmRegister dst, XmmRegister src);
282 void mulss(XmmRegister dst, const Address& src);
283 void divss(XmmRegister dst, XmmRegister src);
284 void divss(XmmRegister dst, const Address& src);
285
286 void movsd(XmmRegister dst, const Address& src);
287 void movsd(const Address& dst, XmmRegister src);
288 void movsd(XmmRegister dst, XmmRegister src);
289
290 void addsd(XmmRegister dst, XmmRegister src);
291 void addsd(XmmRegister dst, const Address& src);
292 void subsd(XmmRegister dst, XmmRegister src);
293 void subsd(XmmRegister dst, const Address& src);
294 void mulsd(XmmRegister dst, XmmRegister src);
295 void mulsd(XmmRegister dst, const Address& src);
296 void divsd(XmmRegister dst, XmmRegister src);
297 void divsd(XmmRegister dst, const Address& src);
298
299 void cvtsi2ss(XmmRegister dst, Register src);
300 void cvtsi2sd(XmmRegister dst, Register src);
301
302 void cvtss2si(Register dst, XmmRegister src);
303 void cvtss2sd(XmmRegister dst, XmmRegister src);
304
305 void cvtsd2si(Register dst, XmmRegister src);
306 void cvtsd2ss(XmmRegister dst, XmmRegister src);
307
308 void cvttss2si(Register dst, XmmRegister src);
309 void cvttsd2si(Register dst, XmmRegister src);
310
311 void cvtdq2pd(XmmRegister dst, XmmRegister src);
312
313 void comiss(XmmRegister a, XmmRegister b);
314 void comisd(XmmRegister a, XmmRegister b);
315
316 void sqrtsd(XmmRegister dst, XmmRegister src);
317 void sqrtss(XmmRegister dst, XmmRegister src);
318
319 void xorpd(XmmRegister dst, const Address& src);
320 void xorpd(XmmRegister dst, XmmRegister src);
321 void xorps(XmmRegister dst, const Address& src);
322 void xorps(XmmRegister dst, XmmRegister src);
323
324 void andpd(XmmRegister dst, const Address& src);
325
326 void flds(const Address& src);
327 void fstps(const Address& dst);
328
329 void fldl(const Address& src);
330 void fstpl(const Address& dst);
331
332 void fnstcw(const Address& dst);
333 void fldcw(const Address& src);
334
335 void fistpl(const Address& dst);
336 void fistps(const Address& dst);
337 void fildl(const Address& src);
338
339 void fincstp();
340 void ffree(const Immediate& index);
341
342 void fsin();
343 void fcos();
344 void fptan();
345
346 void xchgl(Register dst, Register src);
347
348 void cmpl(Register reg, const Immediate& imm);
349 void cmpl(Register reg0, Register reg1);
350 void cmpl(Register reg, const Address& address);
351
352 void cmpl(const Address& address, Register reg);
353 void cmpl(const Address& address, const Immediate& imm);
354
355 void testl(Register reg1, Register reg2);
356 void testl(Register reg, const Immediate& imm);
357
358 void andl(Register dst, const Immediate& imm);
359 void andl(Register dst, Register src);
360
361 void orl(Register dst, const Immediate& imm);
362 void orl(Register dst, Register src);
363
364 void xorl(Register dst, Register src);
365
366 void addl(Register dst, Register src);
367 void addl(Register reg, const Immediate& imm);
368 void addl(Register reg, const Address& address);
369
370 void addl(const Address& address, Register reg);
371 void addl(const Address& address, const Immediate& imm);
372
373 void adcl(Register dst, Register src);
374 void adcl(Register reg, const Immediate& imm);
375 void adcl(Register dst, const Address& address);
376
377 void subl(Register dst, Register src);
378 void subl(Register reg, const Immediate& imm);
379 void subl(Register reg, const Address& address);
380
381 void cdq();
382
383 void idivl(Register reg);
384
385 void imull(Register dst, Register src);
386 void imull(Register reg, const Immediate& imm);
387 void imull(Register reg, const Address& address);
388
389 void imull(Register reg);
390 void imull(const Address& address);
391
392 void mull(Register reg);
393 void mull(const Address& address);
394
395 void sbbl(Register dst, Register src);
396 void sbbl(Register reg, const Immediate& imm);
397 void sbbl(Register reg, const Address& address);
398
399 void incl(Register reg);
400 void incl(const Address& address);
401
402 void decl(Register reg);
403 void decl(const Address& address);
404
405 void shll(Register reg, const Immediate& imm);
406 void shll(Register operand, Register shifter);
407 void shrl(Register reg, const Immediate& imm);
408 void shrl(Register operand, Register shifter);
409 void sarl(Register reg, const Immediate& imm);
410 void sarl(Register operand, Register shifter);
411 void shld(Register dst, Register src);
412
413 void negl(Register reg);
414 void notl(Register reg);
415
416 void enter(const Immediate& imm);
417 void leave();
418
419 void ret();
420 void ret(const Immediate& imm);
421
422 void nop();
423 void int3();
424 void hlt();
425
426 void j(Condition condition, Label* label);
427
428 void jmp(Register reg);
429 void jmp(Label* label);
430
Ian Rogers2c8f6532011-09-02 17:16:34 -0700431 X86Assembler* lock();
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700432 void cmpxchgl(const Address& address, Register reg);
433
Ian Rogers2c8f6532011-09-02 17:16:34 -0700434 X86Assembler* fs();
Ian Rogersb033c752011-07-20 12:22:35 -0700435
436 //
437 // Macros for High-level operations.
438 //
439
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700440 void AddImmediate(Register reg, const Immediate& imm);
441
442 void LoadDoubleConstant(XmmRegister dst, double value);
443
444 void DoubleNegate(XmmRegister d);
445 void FloatNegate(XmmRegister f);
446
447 void DoubleAbs(XmmRegister reg);
448
449 void LockCmpxchgl(const Address& address, Register reg) {
Ian Rogers0d666d82011-08-14 16:03:46 -0700450 lock()->cmpxchgl(address, reg);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700451 }
452
Ian Rogersb033c752011-07-20 12:22:35 -0700453 //
454 // Misc. functionality
455 //
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700456 int PreferredLoopAlignment() { return 16; }
457 void Align(int alignment, int offset);
458 void Bind(Label* label);
459
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700460 // Debugging and bringup support.
461 void Stop(const char* message);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700462
463 static void InitializeMemoryWithBreakpoints(byte* data, size_t length);
464
Ian Rogers2c8f6532011-09-02 17:16:34 -0700465 //
466 // Overridden common assembler high-level functionality
467 //
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700468
Ian Rogers2c8f6532011-09-02 17:16:34 -0700469 // Emit code that will create an activation on the stack
470 virtual void BuildFrame(size_t frame_size, ManagedRegister method_reg,
Ian Rogersbdb03912011-09-14 00:55:44 -0700471 const std::vector<ManagedRegister>& callee_save_regs);
Ian Rogers2c8f6532011-09-02 17:16:34 -0700472
473 // Emit code that will remove an activation from the stack
474 virtual void RemoveFrame(size_t frame_size,
Ian Rogersbdb03912011-09-14 00:55:44 -0700475 const std::vector<ManagedRegister>& callee_save_regs);
Ian Rogers2c8f6532011-09-02 17:16:34 -0700476
477 virtual void IncreaseFrameSize(size_t adjust);
478 virtual void DecreaseFrameSize(size_t adjust);
479
480 // Store routines
481 virtual void Store(FrameOffset offs, ManagedRegister src, size_t size);
482 virtual void StoreRef(FrameOffset dest, ManagedRegister src);
483 virtual void StoreRawPtr(FrameOffset dest, ManagedRegister src);
484
485 virtual void StoreImmediateToFrame(FrameOffset dest, uint32_t imm,
486 ManagedRegister scratch);
487
488 virtual void StoreImmediateToThread(ThreadOffset dest, uint32_t imm,
489 ManagedRegister scratch);
490
491 virtual void StoreStackOffsetToThread(ThreadOffset thr_offs,
492 FrameOffset fr_offs,
493 ManagedRegister scratch);
494
495 virtual void StoreStackPointerToThread(ThreadOffset thr_offs);
496
Ian Rogersbdb03912011-09-14 00:55:44 -0700497 void StoreLabelToThread(ThreadOffset thr_offs, Label* lbl);
498
Ian Rogers2c8f6532011-09-02 17:16:34 -0700499 virtual void StoreSpanning(FrameOffset dest, ManagedRegister src,
500 FrameOffset in_off, ManagedRegister scratch);
501
502 // Load routines
503 virtual void Load(ManagedRegister dest, FrameOffset src, size_t size);
504
Ian Rogers5a7a74a2011-09-26 16:32:29 -0700505 virtual void Load(ManagedRegister dest, ThreadOffset src, size_t size);
506
Ian Rogers2c8f6532011-09-02 17:16:34 -0700507 virtual void LoadRef(ManagedRegister dest, FrameOffset src);
508
509 virtual void LoadRef(ManagedRegister dest, ManagedRegister base,
510 MemberOffset offs);
511
512 virtual void LoadRawPtr(ManagedRegister dest, ManagedRegister base,
513 Offset offs);
514
515 virtual void LoadRawPtrFromThread(ManagedRegister dest,
516 ThreadOffset offs);
517
518 // Copying routines
519 virtual void Move(ManagedRegister dest, ManagedRegister src);
520
521 virtual void CopyRawPtrFromThread(FrameOffset fr_offs, ThreadOffset thr_offs,
522 ManagedRegister scratch);
523
524 virtual void CopyRawPtrToThread(ThreadOffset thr_offs, FrameOffset fr_offs,
525 ManagedRegister scratch);
526
527 virtual void CopyRef(FrameOffset dest, FrameOffset src,
528 ManagedRegister scratch);
529
Elliott Hughesa09aea22012-01-06 18:58:27 -0800530 virtual void Copy(FrameOffset dest, FrameOffset src, ManagedRegister scratch, size_t size);
Ian Rogers2c8f6532011-09-02 17:16:34 -0700531
Ian Rogersdc51b792011-09-22 20:41:37 -0700532 virtual void Copy(FrameOffset dest, ManagedRegister src_base, Offset src_offset,
533 ManagedRegister scratch, size_t size);
534
Ian Rogers5a7a74a2011-09-26 16:32:29 -0700535 virtual void Copy(ManagedRegister dest_base, Offset dest_offset, FrameOffset src,
536 ManagedRegister scratch, size_t size);
537
Ian Rogersdc51b792011-09-22 20:41:37 -0700538 virtual void Copy(FrameOffset dest, FrameOffset src_base, Offset src_offset,
539 ManagedRegister scratch, size_t size);
540
Ian Rogers5a7a74a2011-09-26 16:32:29 -0700541 virtual void Copy(ManagedRegister dest, Offset dest_offset,
542 ManagedRegister src, Offset src_offset,
543 ManagedRegister scratch, size_t size);
544
545 virtual void Copy(FrameOffset dest, Offset dest_offset, FrameOffset src, Offset src_offset,
546 ManagedRegister scratch, size_t size);
Ian Rogersdc51b792011-09-22 20:41:37 -0700547
Ian Rogerse5de95b2011-09-18 20:31:38 -0700548 virtual void MemoryBarrier(ManagedRegister);
549
Ian Rogers2c8f6532011-09-02 17:16:34 -0700550 // Exploit fast access in managed code to Thread::Current()
551 virtual void GetCurrentThread(ManagedRegister tr);
552 virtual void GetCurrentThread(FrameOffset dest_offset,
553 ManagedRegister scratch);
554
555 // Set up out_reg to hold a Object** into the SIRT, or to be NULL if the
556 // value is null and null_allowed. in_reg holds a possibly stale reference
557 // that can be used to avoid loading the SIRT entry to see if the value is
558 // NULL.
559 virtual void CreateSirtEntry(ManagedRegister out_reg, FrameOffset sirt_offset,
560 ManagedRegister in_reg, bool null_allowed);
561
562 // Set up out_off to hold a Object** into the SIRT, or to be NULL if the
563 // value is null and null_allowed.
564 virtual void CreateSirtEntry(FrameOffset out_off, FrameOffset sirt_offset,
565 ManagedRegister scratch, bool null_allowed);
566
567 // src holds a SIRT entry (Object**) load this into dst
568 virtual void LoadReferenceFromSirt(ManagedRegister dst,
569 ManagedRegister src);
570
571 // Heap::VerifyObject on src. In some cases (such as a reference to this) we
572 // know that src may not be null.
573 virtual void VerifyObject(ManagedRegister src, bool could_be_null);
574 virtual void VerifyObject(FrameOffset src, bool could_be_null);
575
576 // Call to address held at [base+offset]
577 virtual void Call(ManagedRegister base, Offset offset,
578 ManagedRegister scratch);
579 virtual void Call(FrameOffset base, Offset offset,
580 ManagedRegister scratch);
Ian Rogersbdb03912011-09-14 00:55:44 -0700581 virtual void Call(ThreadOffset offset, ManagedRegister scratch);
Ian Rogers2c8f6532011-09-02 17:16:34 -0700582
583 // Generate code to check if Thread::Current()->suspend_count_ is non-zero
584 // and branch to a SuspendSlowPath if it is. The SuspendSlowPath will continue
585 // at the next instruction.
586 virtual void SuspendPoll(ManagedRegister scratch, ManagedRegister return_reg,
587 FrameOffset return_save_location,
588 size_t return_size);
589
590 // Generate code to check if Thread::Current()->exception_ is non-null
591 // and branch to a ExceptionSlowPath if it is.
592 virtual void ExceptionPoll(ManagedRegister scratch);
593
594 private:
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700595 inline void EmitUint8(uint8_t value);
596 inline void EmitInt32(int32_t value);
597 inline void EmitRegisterOperand(int rm, int reg);
598 inline void EmitXmmRegisterOperand(int rm, XmmRegister reg);
599 inline void EmitFixup(AssemblerFixup* fixup);
600 inline void EmitOperandSizeOverride();
601
602 void EmitOperand(int rm, const Operand& operand);
603 void EmitImmediate(const Immediate& imm);
604 void EmitComplex(int rm, const Operand& operand, const Immediate& immediate);
605 void EmitLabel(Label* label, int instruction_size);
606 void EmitLabelLink(Label* label);
607 void EmitNearLabelLink(Label* label);
608
609 void EmitGenericShift(int rm, Register reg, const Immediate& imm);
610 void EmitGenericShift(int rm, Register operand, Register shifter);
611
Ian Rogers2c8f6532011-09-02 17:16:34 -0700612 DISALLOW_COPY_AND_ASSIGN(X86Assembler);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700613};
614
Ian Rogers2c8f6532011-09-02 17:16:34 -0700615inline void X86Assembler::EmitUint8(uint8_t value) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700616 buffer_.Emit<uint8_t>(value);
617}
618
Ian Rogers2c8f6532011-09-02 17:16:34 -0700619inline void X86Assembler::EmitInt32(int32_t value) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700620 buffer_.Emit<int32_t>(value);
621}
622
Ian Rogers2c8f6532011-09-02 17:16:34 -0700623inline void X86Assembler::EmitRegisterOperand(int rm, int reg) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700624 CHECK_GE(rm, 0);
625 CHECK_LT(rm, 8);
626 buffer_.Emit<uint8_t>(0xC0 + (rm << 3) + reg);
627}
628
Ian Rogers2c8f6532011-09-02 17:16:34 -0700629inline void X86Assembler::EmitXmmRegisterOperand(int rm, XmmRegister reg) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700630 EmitRegisterOperand(rm, static_cast<Register>(reg));
631}
632
Ian Rogers2c8f6532011-09-02 17:16:34 -0700633inline void X86Assembler::EmitFixup(AssemblerFixup* fixup) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700634 buffer_.EmitFixup(fixup);
635}
636
Ian Rogers2c8f6532011-09-02 17:16:34 -0700637inline void X86Assembler::EmitOperandSizeOverride() {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700638 EmitUint8(0x66);
639}
640
Ian Rogers2c8f6532011-09-02 17:16:34 -0700641// Slowpath entered when Thread::Current()->_exception is non-null
642class X86ExceptionSlowPath : public SlowPath {
643 public:
644 X86ExceptionSlowPath() {}
645 virtual void Emit(Assembler *sp_asm);
646};
647
648// Slowpath entered when Thread::Current()->_suspend_count is non-zero
649class X86SuspendCountSlowPath : public SlowPath {
650 public:
651 X86SuspendCountSlowPath(X86ManagedRegister return_reg,
652 FrameOffset return_save_location,
653 size_t return_size) :
654 return_register_(return_reg), return_save_location_(return_save_location),
655 return_size_(return_size) {}
656 virtual void Emit(Assembler *sp_asm);
657
658 private:
659 // Remember how to save the return value
660 const X86ManagedRegister return_register_;
661 const FrameOffset return_save_location_;
662 const size_t return_size_;
663};
664
665} // namespace x86
Carl Shapiro6b6b5f02011-06-21 15:05:09 -0700666} // namespace art
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700667
668#endif // ART_SRC_ASSEMBLER_X86_H_