blob: a283299f90663f09f102acea288d1747ed04b8ee [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
Ian Rogers2c8f6532011-09-02 17:16:34 -070017#include "assembler_x86.h"
18
Brian Carlstrom578bbdc2011-07-21 14:07:47 -070019#include "casts.h"
Brian Carlstrom578bbdc2011-07-21 14:07:47 -070020#include "memory_region.h"
Brian Carlstrom578bbdc2011-07-21 14:07:47 -070021#include "thread.h"
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -070022
Carl Shapiro6b6b5f02011-06-21 15:05:09 -070023namespace art {
Ian Rogers2c8f6532011-09-02 17:16:34 -070024namespace x86 {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -070025
26class DirectCallRelocation : public AssemblerFixup {
27 public:
28 void Process(const MemoryRegion& region, int position) {
29 // Direct calls are relative to the following instruction on x86.
30 int32_t pointer = region.Load<int32_t>(position);
31 int32_t start = reinterpret_cast<int32_t>(region.start());
32 int32_t delta = start + position + sizeof(int32_t);
33 region.Store<int32_t>(position, pointer - delta);
34 }
35};
36
Elliott Hughes1f359b02011-07-17 14:27:17 -070037static const char* kRegisterNames[] = {
38 "eax", "ecx", "edx", "ebx", "esp", "ebp", "esi", "edi",
39};
40std::ostream& operator<<(std::ostream& os, const Register& rhs) {
41 if (rhs >= EAX && rhs <= EDI) {
42 os << kRegisterNames[rhs];
43 } else {
Ian Rogersb033c752011-07-20 12:22:35 -070044 os << "Register[" << static_cast<int>(rhs) << "]";
Elliott Hughes1f359b02011-07-17 14:27:17 -070045 }
46 return os;
47}
48
Ian Rogersb033c752011-07-20 12:22:35 -070049std::ostream& operator<<(std::ostream& os, const XmmRegister& reg) {
50 return os << "XMM" << static_cast<int>(reg);
51}
52
53std::ostream& operator<<(std::ostream& os, const X87Register& reg) {
54 return os << "ST" << static_cast<int>(reg);
55}
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -070056
Ian Rogers2c8f6532011-09-02 17:16:34 -070057void X86Assembler::InitializeMemoryWithBreakpoints(byte* data, size_t length) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -070058 memset(reinterpret_cast<void*>(data), Instr::kBreakPointInstruction, length);
59}
60
Ian Rogers2c8f6532011-09-02 17:16:34 -070061void X86Assembler::call(Register reg) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -070062 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
63 EmitUint8(0xFF);
64 EmitRegisterOperand(2, reg);
65}
66
67
Ian Rogers2c8f6532011-09-02 17:16:34 -070068void X86Assembler::call(const Address& address) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -070069 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
70 EmitUint8(0xFF);
71 EmitOperand(2, address);
72}
73
74
Ian Rogers2c8f6532011-09-02 17:16:34 -070075void X86Assembler::call(Label* label) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -070076 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
77 EmitUint8(0xE8);
78 static const int kSize = 5;
79 EmitLabel(label, kSize);
80}
81
82
Ian Rogers2c8f6532011-09-02 17:16:34 -070083void X86Assembler::pushl(Register reg) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -070084 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
85 EmitUint8(0x50 + reg);
86}
87
88
Ian Rogers2c8f6532011-09-02 17:16:34 -070089void X86Assembler::pushl(const Address& address) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -070090 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
91 EmitUint8(0xFF);
92 EmitOperand(6, address);
93}
94
95
Ian Rogers2c8f6532011-09-02 17:16:34 -070096void X86Assembler::pushl(const Immediate& imm) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -070097 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
98 EmitUint8(0x68);
99 EmitImmediate(imm);
100}
101
102
Ian Rogers2c8f6532011-09-02 17:16:34 -0700103void X86Assembler::popl(Register reg) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700104 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
105 EmitUint8(0x58 + reg);
106}
107
108
Ian Rogers2c8f6532011-09-02 17:16:34 -0700109void X86Assembler::popl(const Address& address) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700110 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
111 EmitUint8(0x8F);
112 EmitOperand(0, address);
113}
114
115
Ian Rogers2c8f6532011-09-02 17:16:34 -0700116void X86Assembler::movl(Register dst, const Immediate& imm) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700117 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
118 EmitUint8(0xB8 + dst);
119 EmitImmediate(imm);
120}
121
122
Ian Rogers2c8f6532011-09-02 17:16:34 -0700123void X86Assembler::movl(Register dst, Register src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700124 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
125 EmitUint8(0x89);
126 EmitRegisterOperand(src, dst);
127}
128
129
Ian Rogers2c8f6532011-09-02 17:16:34 -0700130void X86Assembler::movl(Register dst, const Address& src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700131 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
132 EmitUint8(0x8B);
133 EmitOperand(dst, src);
134}
135
136
Ian Rogers2c8f6532011-09-02 17:16:34 -0700137void X86Assembler::movl(const Address& dst, Register src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700138 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
139 EmitUint8(0x89);
140 EmitOperand(src, dst);
141}
142
143
Ian Rogers2c8f6532011-09-02 17:16:34 -0700144void X86Assembler::movl(const Address& dst, const Immediate& imm) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700145 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
146 EmitUint8(0xC7);
147 EmitOperand(0, dst);
148 EmitImmediate(imm);
149}
150
Ian Rogersbdb03912011-09-14 00:55:44 -0700151void X86Assembler::movl(const Address& dst, Label* lbl) {
152 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
153 EmitUint8(0xC7);
154 EmitOperand(0, dst);
155 EmitLabel(lbl, dst.length_ + 5);
156}
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700157
Ian Rogers2c8f6532011-09-02 17:16:34 -0700158void X86Assembler::movzxb(Register dst, ByteRegister src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700159 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
160 EmitUint8(0x0F);
161 EmitUint8(0xB6);
162 EmitRegisterOperand(dst, src);
163}
164
165
Ian Rogers2c8f6532011-09-02 17:16:34 -0700166void X86Assembler::movzxb(Register dst, const Address& src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700167 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
168 EmitUint8(0x0F);
169 EmitUint8(0xB6);
170 EmitOperand(dst, src);
171}
172
173
Ian Rogers2c8f6532011-09-02 17:16:34 -0700174void X86Assembler::movsxb(Register dst, ByteRegister src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700175 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
176 EmitUint8(0x0F);
177 EmitUint8(0xBE);
178 EmitRegisterOperand(dst, src);
179}
180
181
Ian Rogers2c8f6532011-09-02 17:16:34 -0700182void X86Assembler::movsxb(Register dst, const Address& src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700183 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
184 EmitUint8(0x0F);
185 EmitUint8(0xBE);
186 EmitOperand(dst, src);
187}
188
189
Ian Rogers2c8f6532011-09-02 17:16:34 -0700190void X86Assembler::movb(Register dst, const Address& src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700191 LOG(FATAL) << "Use movzxb or movsxb instead.";
192}
193
194
Ian Rogers2c8f6532011-09-02 17:16:34 -0700195void X86Assembler::movb(const Address& dst, ByteRegister src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700196 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
197 EmitUint8(0x88);
198 EmitOperand(src, dst);
199}
200
201
Ian Rogers2c8f6532011-09-02 17:16:34 -0700202void X86Assembler::movb(const Address& dst, const Immediate& imm) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700203 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
204 EmitUint8(0xC6);
205 EmitOperand(EAX, dst);
206 CHECK(imm.is_int8());
207 EmitUint8(imm.value() & 0xFF);
208}
209
210
Ian Rogers2c8f6532011-09-02 17:16:34 -0700211void X86Assembler::movzxw(Register dst, Register src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700212 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
213 EmitUint8(0x0F);
214 EmitUint8(0xB7);
215 EmitRegisterOperand(dst, src);
216}
217
218
Ian Rogers2c8f6532011-09-02 17:16:34 -0700219void X86Assembler::movzxw(Register dst, const Address& src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700220 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
221 EmitUint8(0x0F);
222 EmitUint8(0xB7);
223 EmitOperand(dst, src);
224}
225
226
Ian Rogers2c8f6532011-09-02 17:16:34 -0700227void X86Assembler::movsxw(Register dst, Register src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700228 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
229 EmitUint8(0x0F);
230 EmitUint8(0xBF);
231 EmitRegisterOperand(dst, src);
232}
233
234
Ian Rogers2c8f6532011-09-02 17:16:34 -0700235void X86Assembler::movsxw(Register dst, const Address& src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700236 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
237 EmitUint8(0x0F);
238 EmitUint8(0xBF);
239 EmitOperand(dst, src);
240}
241
242
Ian Rogers2c8f6532011-09-02 17:16:34 -0700243void X86Assembler::movw(Register dst, const Address& src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700244 LOG(FATAL) << "Use movzxw or movsxw instead.";
245}
246
247
Ian Rogers2c8f6532011-09-02 17:16:34 -0700248void X86Assembler::movw(const Address& dst, Register src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700249 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
250 EmitOperandSizeOverride();
251 EmitUint8(0x89);
252 EmitOperand(src, dst);
253}
254
255
Ian Rogers2c8f6532011-09-02 17:16:34 -0700256void X86Assembler::leal(Register dst, const Address& src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700257 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
258 EmitUint8(0x8D);
259 EmitOperand(dst, src);
260}
261
262
Ian Rogers2c8f6532011-09-02 17:16:34 -0700263void X86Assembler::cmovl(Condition condition, Register dst, Register src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700264 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
265 EmitUint8(0x0F);
Ian Rogersb033c752011-07-20 12:22:35 -0700266 EmitUint8(0x40 + condition);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700267 EmitRegisterOperand(dst, src);
268}
269
270
Ian Rogers2c8f6532011-09-02 17:16:34 -0700271void X86Assembler::setb(Condition condition, Register dst) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700272 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
273 EmitUint8(0x0F);
Ian Rogersb033c752011-07-20 12:22:35 -0700274 EmitUint8(0x90 + condition);
275 EmitOperand(0, Operand(dst));
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700276}
277
278
Ian Rogers2c8f6532011-09-02 17:16:34 -0700279void X86Assembler::movss(XmmRegister dst, const Address& src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700280 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
281 EmitUint8(0xF3);
282 EmitUint8(0x0F);
283 EmitUint8(0x10);
284 EmitOperand(dst, src);
285}
286
287
Ian Rogers2c8f6532011-09-02 17:16:34 -0700288void X86Assembler::movss(const Address& dst, XmmRegister src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700289 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
290 EmitUint8(0xF3);
291 EmitUint8(0x0F);
292 EmitUint8(0x11);
293 EmitOperand(src, dst);
294}
295
296
Ian Rogers2c8f6532011-09-02 17:16:34 -0700297void X86Assembler::movss(XmmRegister dst, XmmRegister src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700298 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
299 EmitUint8(0xF3);
300 EmitUint8(0x0F);
301 EmitUint8(0x11);
302 EmitXmmRegisterOperand(src, dst);
303}
304
305
Ian Rogers2c8f6532011-09-02 17:16:34 -0700306void X86Assembler::movd(XmmRegister dst, Register src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700307 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
308 EmitUint8(0x66);
309 EmitUint8(0x0F);
310 EmitUint8(0x6E);
311 EmitOperand(dst, Operand(src));
312}
313
314
Ian Rogers2c8f6532011-09-02 17:16:34 -0700315void X86Assembler::movd(Register dst, XmmRegister src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700316 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
317 EmitUint8(0x66);
318 EmitUint8(0x0F);
319 EmitUint8(0x7E);
320 EmitOperand(src, Operand(dst));
321}
322
323
Ian Rogers2c8f6532011-09-02 17:16:34 -0700324void X86Assembler::addss(XmmRegister dst, XmmRegister src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700325 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
326 EmitUint8(0xF3);
327 EmitUint8(0x0F);
328 EmitUint8(0x58);
329 EmitXmmRegisterOperand(dst, src);
330}
331
332
Ian Rogers2c8f6532011-09-02 17:16:34 -0700333void X86Assembler::addss(XmmRegister dst, const Address& src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700334 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
335 EmitUint8(0xF3);
336 EmitUint8(0x0F);
337 EmitUint8(0x58);
338 EmitOperand(dst, src);
339}
340
341
Ian Rogers2c8f6532011-09-02 17:16:34 -0700342void X86Assembler::subss(XmmRegister dst, XmmRegister src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700343 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
344 EmitUint8(0xF3);
345 EmitUint8(0x0F);
346 EmitUint8(0x5C);
347 EmitXmmRegisterOperand(dst, src);
348}
349
350
Ian Rogers2c8f6532011-09-02 17:16:34 -0700351void X86Assembler::subss(XmmRegister dst, const Address& src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700352 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
353 EmitUint8(0xF3);
354 EmitUint8(0x0F);
355 EmitUint8(0x5C);
356 EmitOperand(dst, src);
357}
358
359
Ian Rogers2c8f6532011-09-02 17:16:34 -0700360void X86Assembler::mulss(XmmRegister dst, XmmRegister src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700361 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
362 EmitUint8(0xF3);
363 EmitUint8(0x0F);
364 EmitUint8(0x59);
365 EmitXmmRegisterOperand(dst, src);
366}
367
368
Ian Rogers2c8f6532011-09-02 17:16:34 -0700369void X86Assembler::mulss(XmmRegister dst, const Address& src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700370 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
371 EmitUint8(0xF3);
372 EmitUint8(0x0F);
373 EmitUint8(0x59);
374 EmitOperand(dst, src);
375}
376
377
Ian Rogers2c8f6532011-09-02 17:16:34 -0700378void X86Assembler::divss(XmmRegister dst, XmmRegister src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700379 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
380 EmitUint8(0xF3);
381 EmitUint8(0x0F);
382 EmitUint8(0x5E);
383 EmitXmmRegisterOperand(dst, src);
384}
385
386
Ian Rogers2c8f6532011-09-02 17:16:34 -0700387void X86Assembler::divss(XmmRegister dst, const Address& src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700388 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
389 EmitUint8(0xF3);
390 EmitUint8(0x0F);
391 EmitUint8(0x5E);
392 EmitOperand(dst, src);
393}
394
395
Ian Rogers2c8f6532011-09-02 17:16:34 -0700396void X86Assembler::flds(const Address& src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700397 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
398 EmitUint8(0xD9);
399 EmitOperand(0, src);
400}
401
402
Ian Rogers2c8f6532011-09-02 17:16:34 -0700403void X86Assembler::fstps(const Address& dst) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700404 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
405 EmitUint8(0xD9);
406 EmitOperand(3, dst);
407}
408
409
Ian Rogers2c8f6532011-09-02 17:16:34 -0700410void X86Assembler::movsd(XmmRegister dst, const Address& src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700411 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
412 EmitUint8(0xF2);
413 EmitUint8(0x0F);
414 EmitUint8(0x10);
415 EmitOperand(dst, src);
416}
417
418
Ian Rogers2c8f6532011-09-02 17:16:34 -0700419void X86Assembler::movsd(const Address& dst, XmmRegister src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700420 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
421 EmitUint8(0xF2);
422 EmitUint8(0x0F);
423 EmitUint8(0x11);
424 EmitOperand(src, dst);
425}
426
427
Ian Rogers2c8f6532011-09-02 17:16:34 -0700428void X86Assembler::movsd(XmmRegister dst, XmmRegister src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700429 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
430 EmitUint8(0xF2);
431 EmitUint8(0x0F);
432 EmitUint8(0x11);
433 EmitXmmRegisterOperand(src, dst);
434}
435
436
Ian Rogers2c8f6532011-09-02 17:16:34 -0700437void X86Assembler::addsd(XmmRegister dst, XmmRegister src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700438 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
439 EmitUint8(0xF2);
440 EmitUint8(0x0F);
441 EmitUint8(0x58);
442 EmitXmmRegisterOperand(dst, src);
443}
444
445
Ian Rogers2c8f6532011-09-02 17:16:34 -0700446void X86Assembler::addsd(XmmRegister dst, const Address& src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700447 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
448 EmitUint8(0xF2);
449 EmitUint8(0x0F);
450 EmitUint8(0x58);
451 EmitOperand(dst, src);
452}
453
454
Ian Rogers2c8f6532011-09-02 17:16:34 -0700455void X86Assembler::subsd(XmmRegister dst, XmmRegister src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700456 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
457 EmitUint8(0xF2);
458 EmitUint8(0x0F);
459 EmitUint8(0x5C);
460 EmitXmmRegisterOperand(dst, src);
461}
462
463
Ian Rogers2c8f6532011-09-02 17:16:34 -0700464void X86Assembler::subsd(XmmRegister dst, const Address& src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700465 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
466 EmitUint8(0xF2);
467 EmitUint8(0x0F);
468 EmitUint8(0x5C);
469 EmitOperand(dst, src);
470}
471
472
Ian Rogers2c8f6532011-09-02 17:16:34 -0700473void X86Assembler::mulsd(XmmRegister dst, XmmRegister src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700474 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
475 EmitUint8(0xF2);
476 EmitUint8(0x0F);
477 EmitUint8(0x59);
478 EmitXmmRegisterOperand(dst, src);
479}
480
481
Ian Rogers2c8f6532011-09-02 17:16:34 -0700482void X86Assembler::mulsd(XmmRegister dst, const Address& src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700483 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
484 EmitUint8(0xF2);
485 EmitUint8(0x0F);
486 EmitUint8(0x59);
487 EmitOperand(dst, src);
488}
489
490
Ian Rogers2c8f6532011-09-02 17:16:34 -0700491void X86Assembler::divsd(XmmRegister dst, XmmRegister src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700492 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
493 EmitUint8(0xF2);
494 EmitUint8(0x0F);
495 EmitUint8(0x5E);
496 EmitXmmRegisterOperand(dst, src);
497}
498
499
Ian Rogers2c8f6532011-09-02 17:16:34 -0700500void X86Assembler::divsd(XmmRegister dst, const Address& src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700501 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
502 EmitUint8(0xF2);
503 EmitUint8(0x0F);
504 EmitUint8(0x5E);
505 EmitOperand(dst, src);
506}
507
508
Ian Rogers2c8f6532011-09-02 17:16:34 -0700509void X86Assembler::cvtsi2ss(XmmRegister dst, Register src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700510 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
511 EmitUint8(0xF3);
512 EmitUint8(0x0F);
513 EmitUint8(0x2A);
514 EmitOperand(dst, Operand(src));
515}
516
517
Ian Rogers2c8f6532011-09-02 17:16:34 -0700518void X86Assembler::cvtsi2sd(XmmRegister dst, Register src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700519 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
520 EmitUint8(0xF2);
521 EmitUint8(0x0F);
522 EmitUint8(0x2A);
523 EmitOperand(dst, Operand(src));
524}
525
526
Ian Rogers2c8f6532011-09-02 17:16:34 -0700527void X86Assembler::cvtss2si(Register dst, XmmRegister src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700528 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
529 EmitUint8(0xF3);
530 EmitUint8(0x0F);
531 EmitUint8(0x2D);
532 EmitXmmRegisterOperand(dst, src);
533}
534
535
Ian Rogers2c8f6532011-09-02 17:16:34 -0700536void X86Assembler::cvtss2sd(XmmRegister dst, XmmRegister src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700537 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
538 EmitUint8(0xF3);
539 EmitUint8(0x0F);
540 EmitUint8(0x5A);
541 EmitXmmRegisterOperand(dst, src);
542}
543
544
Ian Rogers2c8f6532011-09-02 17:16:34 -0700545void X86Assembler::cvtsd2si(Register dst, XmmRegister src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700546 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
547 EmitUint8(0xF2);
548 EmitUint8(0x0F);
549 EmitUint8(0x2D);
550 EmitXmmRegisterOperand(dst, src);
551}
552
553
Ian Rogers2c8f6532011-09-02 17:16:34 -0700554void X86Assembler::cvttss2si(Register dst, XmmRegister src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700555 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
556 EmitUint8(0xF3);
557 EmitUint8(0x0F);
558 EmitUint8(0x2C);
559 EmitXmmRegisterOperand(dst, src);
560}
561
562
Ian Rogers2c8f6532011-09-02 17:16:34 -0700563void X86Assembler::cvttsd2si(Register dst, XmmRegister src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700564 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
565 EmitUint8(0xF2);
566 EmitUint8(0x0F);
567 EmitUint8(0x2C);
568 EmitXmmRegisterOperand(dst, src);
569}
570
571
Ian Rogers2c8f6532011-09-02 17:16:34 -0700572void X86Assembler::cvtsd2ss(XmmRegister dst, XmmRegister src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700573 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
574 EmitUint8(0xF2);
575 EmitUint8(0x0F);
576 EmitUint8(0x5A);
577 EmitXmmRegisterOperand(dst, src);
578}
579
580
Ian Rogers2c8f6532011-09-02 17:16:34 -0700581void X86Assembler::cvtdq2pd(XmmRegister dst, XmmRegister src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700582 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
583 EmitUint8(0xF3);
584 EmitUint8(0x0F);
585 EmitUint8(0xE6);
586 EmitXmmRegisterOperand(dst, src);
587}
588
589
Ian Rogers2c8f6532011-09-02 17:16:34 -0700590void X86Assembler::comiss(XmmRegister a, XmmRegister b) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700591 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
592 EmitUint8(0x0F);
593 EmitUint8(0x2F);
594 EmitXmmRegisterOperand(a, b);
595}
596
597
Ian Rogers2c8f6532011-09-02 17:16:34 -0700598void X86Assembler::comisd(XmmRegister a, XmmRegister b) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700599 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
600 EmitUint8(0x66);
601 EmitUint8(0x0F);
602 EmitUint8(0x2F);
603 EmitXmmRegisterOperand(a, b);
604}
605
606
Ian Rogers2c8f6532011-09-02 17:16:34 -0700607void X86Assembler::sqrtsd(XmmRegister dst, XmmRegister src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700608 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
609 EmitUint8(0xF2);
610 EmitUint8(0x0F);
611 EmitUint8(0x51);
612 EmitXmmRegisterOperand(dst, src);
613}
614
615
Ian Rogers2c8f6532011-09-02 17:16:34 -0700616void X86Assembler::sqrtss(XmmRegister dst, XmmRegister src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700617 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
618 EmitUint8(0xF3);
619 EmitUint8(0x0F);
620 EmitUint8(0x51);
621 EmitXmmRegisterOperand(dst, src);
622}
623
624
Ian Rogers2c8f6532011-09-02 17:16:34 -0700625void X86Assembler::xorpd(XmmRegister dst, const Address& src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700626 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
627 EmitUint8(0x66);
628 EmitUint8(0x0F);
629 EmitUint8(0x57);
630 EmitOperand(dst, src);
631}
632
633
Ian Rogers2c8f6532011-09-02 17:16:34 -0700634void X86Assembler::xorpd(XmmRegister dst, XmmRegister src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700635 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
636 EmitUint8(0x66);
637 EmitUint8(0x0F);
638 EmitUint8(0x57);
639 EmitXmmRegisterOperand(dst, src);
640}
641
642
Ian Rogers2c8f6532011-09-02 17:16:34 -0700643void X86Assembler::xorps(XmmRegister dst, const Address& src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700644 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
645 EmitUint8(0x0F);
646 EmitUint8(0x57);
647 EmitOperand(dst, src);
648}
649
650
Ian Rogers2c8f6532011-09-02 17:16:34 -0700651void X86Assembler::xorps(XmmRegister dst, XmmRegister src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700652 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
653 EmitUint8(0x0F);
654 EmitUint8(0x57);
655 EmitXmmRegisterOperand(dst, src);
656}
657
658
Ian Rogers2c8f6532011-09-02 17:16:34 -0700659void X86Assembler::andpd(XmmRegister dst, const Address& src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700660 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
661 EmitUint8(0x66);
662 EmitUint8(0x0F);
663 EmitUint8(0x54);
664 EmitOperand(dst, src);
665}
666
667
Ian Rogers2c8f6532011-09-02 17:16:34 -0700668void X86Assembler::fldl(const Address& src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700669 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
670 EmitUint8(0xDD);
671 EmitOperand(0, src);
672}
673
674
Ian Rogers2c8f6532011-09-02 17:16:34 -0700675void X86Assembler::fstpl(const Address& dst) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700676 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
677 EmitUint8(0xDD);
678 EmitOperand(3, dst);
679}
680
681
Ian Rogers2c8f6532011-09-02 17:16:34 -0700682void X86Assembler::fnstcw(const Address& dst) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700683 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
684 EmitUint8(0xD9);
685 EmitOperand(7, dst);
686}
687
688
Ian Rogers2c8f6532011-09-02 17:16:34 -0700689void X86Assembler::fldcw(const Address& src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700690 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
691 EmitUint8(0xD9);
692 EmitOperand(5, src);
693}
694
695
Ian Rogers2c8f6532011-09-02 17:16:34 -0700696void X86Assembler::fistpl(const Address& dst) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700697 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
698 EmitUint8(0xDF);
699 EmitOperand(7, dst);
700}
701
702
Ian Rogers2c8f6532011-09-02 17:16:34 -0700703void X86Assembler::fistps(const Address& dst) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700704 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
705 EmitUint8(0xDB);
706 EmitOperand(3, dst);
707}
708
709
Ian Rogers2c8f6532011-09-02 17:16:34 -0700710void X86Assembler::fildl(const Address& src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700711 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
712 EmitUint8(0xDF);
713 EmitOperand(5, src);
714}
715
716
Ian Rogers2c8f6532011-09-02 17:16:34 -0700717void X86Assembler::fincstp() {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700718 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
719 EmitUint8(0xD9);
720 EmitUint8(0xF7);
721}
722
723
Ian Rogers2c8f6532011-09-02 17:16:34 -0700724void X86Assembler::ffree(const Immediate& index) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700725 CHECK_LT(index.value(), 7);
726 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
727 EmitUint8(0xDD);
728 EmitUint8(0xC0 + index.value());
729}
730
731
Ian Rogers2c8f6532011-09-02 17:16:34 -0700732void X86Assembler::fsin() {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700733 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
734 EmitUint8(0xD9);
735 EmitUint8(0xFE);
736}
737
738
Ian Rogers2c8f6532011-09-02 17:16:34 -0700739void X86Assembler::fcos() {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700740 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
741 EmitUint8(0xD9);
742 EmitUint8(0xFF);
743}
744
745
Ian Rogers2c8f6532011-09-02 17:16:34 -0700746void X86Assembler::fptan() {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700747 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
748 EmitUint8(0xD9);
749 EmitUint8(0xF2);
750}
751
752
Ian Rogers2c8f6532011-09-02 17:16:34 -0700753void X86Assembler::xchgl(Register dst, Register src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700754 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
755 EmitUint8(0x87);
756 EmitRegisterOperand(dst, src);
757}
758
759
Ian Rogers2c8f6532011-09-02 17:16:34 -0700760void X86Assembler::cmpl(Register reg, const Immediate& imm) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700761 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
762 EmitComplex(7, Operand(reg), imm);
763}
764
765
Ian Rogers2c8f6532011-09-02 17:16:34 -0700766void X86Assembler::cmpl(Register reg0, Register reg1) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700767 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
768 EmitUint8(0x3B);
769 EmitOperand(reg0, Operand(reg1));
770}
771
772
Ian Rogers2c8f6532011-09-02 17:16:34 -0700773void X86Assembler::cmpl(Register reg, const Address& address) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700774 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
775 EmitUint8(0x3B);
776 EmitOperand(reg, address);
777}
778
779
Ian Rogers2c8f6532011-09-02 17:16:34 -0700780void X86Assembler::addl(Register dst, Register src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700781 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
782 EmitUint8(0x03);
783 EmitRegisterOperand(dst, src);
784}
785
786
Ian Rogers2c8f6532011-09-02 17:16:34 -0700787void X86Assembler::addl(Register reg, const Address& address) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700788 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
789 EmitUint8(0x03);
790 EmitOperand(reg, address);
791}
792
793
Ian Rogers2c8f6532011-09-02 17:16:34 -0700794void X86Assembler::cmpl(const Address& address, Register reg) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700795 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
796 EmitUint8(0x39);
797 EmitOperand(reg, address);
798}
799
800
Ian Rogers2c8f6532011-09-02 17:16:34 -0700801void X86Assembler::cmpl(const Address& address, const Immediate& imm) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700802 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
803 EmitComplex(7, address, imm);
804}
805
806
Ian Rogers2c8f6532011-09-02 17:16:34 -0700807void X86Assembler::testl(Register reg1, Register reg2) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700808 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
809 EmitUint8(0x85);
810 EmitRegisterOperand(reg1, reg2);
811}
812
813
Ian Rogers2c8f6532011-09-02 17:16:34 -0700814void X86Assembler::testl(Register reg, const Immediate& immediate) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700815 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
816 // For registers that have a byte variant (EAX, EBX, ECX, and EDX)
817 // we only test the byte register to keep the encoding short.
818 if (immediate.is_uint8() && reg < 4) {
819 // Use zero-extended 8-bit immediate.
820 if (reg == EAX) {
821 EmitUint8(0xA8);
822 } else {
823 EmitUint8(0xF6);
824 EmitUint8(0xC0 + reg);
825 }
826 EmitUint8(immediate.value() & 0xFF);
827 } else if (reg == EAX) {
828 // Use short form if the destination is EAX.
829 EmitUint8(0xA9);
830 EmitImmediate(immediate);
831 } else {
832 EmitUint8(0xF7);
833 EmitOperand(0, Operand(reg));
834 EmitImmediate(immediate);
835 }
836}
837
838
Ian Rogers2c8f6532011-09-02 17:16:34 -0700839void X86Assembler::andl(Register dst, Register src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700840 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
841 EmitUint8(0x23);
842 EmitOperand(dst, Operand(src));
843}
844
845
Ian Rogers2c8f6532011-09-02 17:16:34 -0700846void X86Assembler::andl(Register dst, const Immediate& imm) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700847 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
848 EmitComplex(4, Operand(dst), imm);
849}
850
851
Ian Rogers2c8f6532011-09-02 17:16:34 -0700852void X86Assembler::orl(Register dst, Register src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700853 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
854 EmitUint8(0x0B);
855 EmitOperand(dst, Operand(src));
856}
857
858
Ian Rogers2c8f6532011-09-02 17:16:34 -0700859void X86Assembler::orl(Register dst, const Immediate& imm) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700860 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
861 EmitComplex(1, Operand(dst), imm);
862}
863
864
Ian Rogers2c8f6532011-09-02 17:16:34 -0700865void X86Assembler::xorl(Register dst, Register src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700866 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
867 EmitUint8(0x33);
868 EmitOperand(dst, Operand(src));
869}
870
871
Ian Rogers2c8f6532011-09-02 17:16:34 -0700872void X86Assembler::addl(Register reg, const Immediate& imm) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700873 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
874 EmitComplex(0, Operand(reg), imm);
875}
876
877
Ian Rogers2c8f6532011-09-02 17:16:34 -0700878void X86Assembler::addl(const Address& address, Register reg) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700879 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
880 EmitUint8(0x01);
881 EmitOperand(reg, address);
882}
883
884
Ian Rogers2c8f6532011-09-02 17:16:34 -0700885void X86Assembler::addl(const Address& address, const Immediate& imm) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700886 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
887 EmitComplex(0, address, imm);
888}
889
890
Ian Rogers2c8f6532011-09-02 17:16:34 -0700891void X86Assembler::adcl(Register reg, const Immediate& imm) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700892 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
893 EmitComplex(2, Operand(reg), imm);
894}
895
896
Ian Rogers2c8f6532011-09-02 17:16:34 -0700897void X86Assembler::adcl(Register dst, Register src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700898 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
899 EmitUint8(0x13);
900 EmitOperand(dst, Operand(src));
901}
902
903
Ian Rogers2c8f6532011-09-02 17:16:34 -0700904void X86Assembler::adcl(Register dst, const Address& address) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700905 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
906 EmitUint8(0x13);
907 EmitOperand(dst, address);
908}
909
910
Ian Rogers2c8f6532011-09-02 17:16:34 -0700911void X86Assembler::subl(Register dst, Register src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700912 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
913 EmitUint8(0x2B);
914 EmitOperand(dst, Operand(src));
915}
916
917
Ian Rogers2c8f6532011-09-02 17:16:34 -0700918void X86Assembler::subl(Register reg, const Immediate& imm) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700919 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
920 EmitComplex(5, Operand(reg), imm);
921}
922
923
Ian Rogers2c8f6532011-09-02 17:16:34 -0700924void X86Assembler::subl(Register reg, const Address& address) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700925 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
926 EmitUint8(0x2B);
927 EmitOperand(reg, address);
928}
929
930
Ian Rogers2c8f6532011-09-02 17:16:34 -0700931void X86Assembler::cdq() {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700932 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
933 EmitUint8(0x99);
934}
935
936
Ian Rogers2c8f6532011-09-02 17:16:34 -0700937void X86Assembler::idivl(Register reg) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700938 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
939 EmitUint8(0xF7);
940 EmitUint8(0xF8 | reg);
941}
942
943
Ian Rogers2c8f6532011-09-02 17:16:34 -0700944void X86Assembler::imull(Register dst, Register src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700945 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
946 EmitUint8(0x0F);
947 EmitUint8(0xAF);
948 EmitOperand(dst, Operand(src));
949}
950
951
Ian Rogers2c8f6532011-09-02 17:16:34 -0700952void X86Assembler::imull(Register reg, const Immediate& imm) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700953 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
954 EmitUint8(0x69);
955 EmitOperand(reg, Operand(reg));
956 EmitImmediate(imm);
957}
958
959
Ian Rogers2c8f6532011-09-02 17:16:34 -0700960void X86Assembler::imull(Register reg, const Address& address) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700961 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
962 EmitUint8(0x0F);
963 EmitUint8(0xAF);
964 EmitOperand(reg, address);
965}
966
967
Ian Rogers2c8f6532011-09-02 17:16:34 -0700968void X86Assembler::imull(Register reg) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700969 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
970 EmitUint8(0xF7);
971 EmitOperand(5, Operand(reg));
972}
973
974
Ian Rogers2c8f6532011-09-02 17:16:34 -0700975void X86Assembler::imull(const Address& address) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700976 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
977 EmitUint8(0xF7);
978 EmitOperand(5, address);
979}
980
981
Ian Rogers2c8f6532011-09-02 17:16:34 -0700982void X86Assembler::mull(Register reg) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700983 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
984 EmitUint8(0xF7);
985 EmitOperand(4, Operand(reg));
986}
987
988
Ian Rogers2c8f6532011-09-02 17:16:34 -0700989void X86Assembler::mull(const Address& address) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700990 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
991 EmitUint8(0xF7);
992 EmitOperand(4, address);
993}
994
995
Ian Rogers2c8f6532011-09-02 17:16:34 -0700996void X86Assembler::sbbl(Register dst, Register src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700997 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
998 EmitUint8(0x1B);
999 EmitOperand(dst, Operand(src));
1000}
1001
1002
Ian Rogers2c8f6532011-09-02 17:16:34 -07001003void X86Assembler::sbbl(Register reg, const Immediate& imm) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001004 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1005 EmitComplex(3, Operand(reg), imm);
1006}
1007
1008
Ian Rogers2c8f6532011-09-02 17:16:34 -07001009void X86Assembler::sbbl(Register dst, const Address& address) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001010 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1011 EmitUint8(0x1B);
1012 EmitOperand(dst, address);
1013}
1014
1015
Ian Rogers2c8f6532011-09-02 17:16:34 -07001016void X86Assembler::incl(Register reg) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001017 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1018 EmitUint8(0x40 + reg);
1019}
1020
1021
Ian Rogers2c8f6532011-09-02 17:16:34 -07001022void X86Assembler::incl(const Address& address) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001023 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1024 EmitUint8(0xFF);
1025 EmitOperand(0, address);
1026}
1027
1028
Ian Rogers2c8f6532011-09-02 17:16:34 -07001029void X86Assembler::decl(Register reg) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001030 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1031 EmitUint8(0x48 + reg);
1032}
1033
1034
Ian Rogers2c8f6532011-09-02 17:16:34 -07001035void X86Assembler::decl(const Address& address) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001036 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1037 EmitUint8(0xFF);
1038 EmitOperand(1, address);
1039}
1040
1041
Ian Rogers2c8f6532011-09-02 17:16:34 -07001042void X86Assembler::shll(Register reg, const Immediate& imm) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001043 EmitGenericShift(4, reg, imm);
1044}
1045
1046
Ian Rogers2c8f6532011-09-02 17:16:34 -07001047void X86Assembler::shll(Register operand, Register shifter) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001048 EmitGenericShift(4, operand, shifter);
1049}
1050
1051
Ian Rogers2c8f6532011-09-02 17:16:34 -07001052void X86Assembler::shrl(Register reg, const Immediate& imm) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001053 EmitGenericShift(5, reg, imm);
1054}
1055
1056
Ian Rogers2c8f6532011-09-02 17:16:34 -07001057void X86Assembler::shrl(Register operand, Register shifter) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001058 EmitGenericShift(5, operand, shifter);
1059}
1060
1061
Ian Rogers2c8f6532011-09-02 17:16:34 -07001062void X86Assembler::sarl(Register reg, const Immediate& imm) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001063 EmitGenericShift(7, reg, imm);
1064}
1065
1066
Ian Rogers2c8f6532011-09-02 17:16:34 -07001067void X86Assembler::sarl(Register operand, Register shifter) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001068 EmitGenericShift(7, operand, shifter);
1069}
1070
1071
Ian Rogers2c8f6532011-09-02 17:16:34 -07001072void X86Assembler::shld(Register dst, Register src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001073 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1074 EmitUint8(0x0F);
1075 EmitUint8(0xA5);
1076 EmitRegisterOperand(src, dst);
1077}
1078
1079
Ian Rogers2c8f6532011-09-02 17:16:34 -07001080void X86Assembler::negl(Register reg) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001081 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1082 EmitUint8(0xF7);
1083 EmitOperand(3, Operand(reg));
1084}
1085
1086
Ian Rogers2c8f6532011-09-02 17:16:34 -07001087void X86Assembler::notl(Register reg) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001088 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1089 EmitUint8(0xF7);
1090 EmitUint8(0xD0 | reg);
1091}
1092
1093
Ian Rogers2c8f6532011-09-02 17:16:34 -07001094void X86Assembler::enter(const Immediate& imm) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001095 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1096 EmitUint8(0xC8);
1097 CHECK(imm.is_uint16());
1098 EmitUint8(imm.value() & 0xFF);
1099 EmitUint8((imm.value() >> 8) & 0xFF);
1100 EmitUint8(0x00);
1101}
1102
1103
Ian Rogers2c8f6532011-09-02 17:16:34 -07001104void X86Assembler::leave() {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001105 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1106 EmitUint8(0xC9);
1107}
1108
1109
Ian Rogers2c8f6532011-09-02 17:16:34 -07001110void X86Assembler::ret() {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001111 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1112 EmitUint8(0xC3);
1113}
1114
1115
Ian Rogers2c8f6532011-09-02 17:16:34 -07001116void X86Assembler::ret(const Immediate& imm) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001117 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1118 EmitUint8(0xC2);
1119 CHECK(imm.is_uint16());
1120 EmitUint8(imm.value() & 0xFF);
1121 EmitUint8((imm.value() >> 8) & 0xFF);
1122}
1123
1124
1125
Ian Rogers2c8f6532011-09-02 17:16:34 -07001126void X86Assembler::nop() {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001127 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1128 EmitUint8(0x90);
1129}
1130
1131
Ian Rogers2c8f6532011-09-02 17:16:34 -07001132void X86Assembler::int3() {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001133 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1134 EmitUint8(0xCC);
1135}
1136
1137
Ian Rogers2c8f6532011-09-02 17:16:34 -07001138void X86Assembler::hlt() {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001139 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1140 EmitUint8(0xF4);
1141}
1142
1143
Ian Rogers2c8f6532011-09-02 17:16:34 -07001144void X86Assembler::j(Condition condition, Label* label) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001145 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1146 if (label->IsBound()) {
1147 static const int kShortSize = 2;
1148 static const int kLongSize = 6;
1149 int offset = label->Position() - buffer_.Size();
1150 CHECK_LE(offset, 0);
1151 if (IsInt(8, offset - kShortSize)) {
1152 EmitUint8(0x70 + condition);
1153 EmitUint8((offset - kShortSize) & 0xFF);
1154 } else {
1155 EmitUint8(0x0F);
1156 EmitUint8(0x80 + condition);
1157 EmitInt32(offset - kLongSize);
1158 }
1159 } else {
1160 EmitUint8(0x0F);
1161 EmitUint8(0x80 + condition);
1162 EmitLabelLink(label);
1163 }
1164}
1165
1166
Ian Rogers2c8f6532011-09-02 17:16:34 -07001167void X86Assembler::jmp(Register reg) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001168 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1169 EmitUint8(0xFF);
1170 EmitRegisterOperand(4, reg);
1171}
1172
1173
Ian Rogers2c8f6532011-09-02 17:16:34 -07001174void X86Assembler::jmp(Label* label) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001175 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1176 if (label->IsBound()) {
1177 static const int kShortSize = 2;
1178 static const int kLongSize = 5;
1179 int offset = label->Position() - buffer_.Size();
1180 CHECK_LE(offset, 0);
1181 if (IsInt(8, offset - kShortSize)) {
1182 EmitUint8(0xEB);
1183 EmitUint8((offset - kShortSize) & 0xFF);
1184 } else {
1185 EmitUint8(0xE9);
1186 EmitInt32(offset - kLongSize);
1187 }
1188 } else {
1189 EmitUint8(0xE9);
1190 EmitLabelLink(label);
1191 }
1192}
1193
1194
Ian Rogers2c8f6532011-09-02 17:16:34 -07001195X86Assembler* X86Assembler::lock() {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001196 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1197 EmitUint8(0xF0);
Ian Rogers0d666d82011-08-14 16:03:46 -07001198 return this;
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001199}
1200
1201
Ian Rogers2c8f6532011-09-02 17:16:34 -07001202void X86Assembler::cmpxchgl(const Address& address, Register reg) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001203 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1204 EmitUint8(0x0F);
1205 EmitUint8(0xB1);
1206 EmitOperand(reg, address);
1207}
1208
Ian Rogers2c8f6532011-09-02 17:16:34 -07001209X86Assembler* X86Assembler::fs() {
Ian Rogersb033c752011-07-20 12:22:35 -07001210 // TODO: fs is a prefix and not an instruction
1211 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1212 EmitUint8(0x64);
Ian Rogers0d666d82011-08-14 16:03:46 -07001213 return this;
Ian Rogersb033c752011-07-20 12:22:35 -07001214}
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001215
Ian Rogers2c8f6532011-09-02 17:16:34 -07001216void X86Assembler::AddImmediate(Register reg, const Immediate& imm) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001217 int value = imm.value();
1218 if (value > 0) {
1219 if (value == 1) {
1220 incl(reg);
1221 } else if (value != 0) {
1222 addl(reg, imm);
1223 }
1224 } else if (value < 0) {
1225 value = -value;
1226 if (value == 1) {
1227 decl(reg);
1228 } else if (value != 0) {
1229 subl(reg, Immediate(value));
1230 }
1231 }
1232}
1233
1234
Ian Rogers2c8f6532011-09-02 17:16:34 -07001235void X86Assembler::LoadDoubleConstant(XmmRegister dst, double value) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001236 // TODO: Need to have a code constants table.
1237 int64_t constant = bit_cast<int64_t, double>(value);
1238 pushl(Immediate(High32Bits(constant)));
1239 pushl(Immediate(Low32Bits(constant)));
1240 movsd(dst, Address(ESP, 0));
1241 addl(ESP, Immediate(2 * kWordSize));
1242}
1243
1244
Ian Rogers2c8f6532011-09-02 17:16:34 -07001245void X86Assembler::FloatNegate(XmmRegister f) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001246 static const struct {
1247 uint32_t a;
1248 uint32_t b;
1249 uint32_t c;
1250 uint32_t d;
1251 } float_negate_constant __attribute__((aligned(16))) =
1252 { 0x80000000, 0x00000000, 0x80000000, 0x00000000 };
1253 xorps(f, Address::Absolute(reinterpret_cast<uword>(&float_negate_constant)));
1254}
1255
1256
Ian Rogers2c8f6532011-09-02 17:16:34 -07001257void X86Assembler::DoubleNegate(XmmRegister d) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001258 static const struct {
1259 uint64_t a;
1260 uint64_t b;
1261 } double_negate_constant __attribute__((aligned(16))) =
1262 {0x8000000000000000LL, 0x8000000000000000LL};
1263 xorpd(d, Address::Absolute(reinterpret_cast<uword>(&double_negate_constant)));
1264}
1265
1266
Ian Rogers2c8f6532011-09-02 17:16:34 -07001267void X86Assembler::DoubleAbs(XmmRegister reg) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001268 static const struct {
1269 uint64_t a;
1270 uint64_t b;
1271 } double_abs_constant __attribute__((aligned(16))) =
1272 {0x7FFFFFFFFFFFFFFFLL, 0x7FFFFFFFFFFFFFFFLL};
1273 andpd(reg, Address::Absolute(reinterpret_cast<uword>(&double_abs_constant)));
1274}
1275
1276
Ian Rogers2c8f6532011-09-02 17:16:34 -07001277void X86Assembler::Align(int alignment, int offset) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001278 CHECK(IsPowerOfTwo(alignment));
1279 // Emit nop instruction until the real position is aligned.
1280 while (((offset + buffer_.GetPosition()) & (alignment-1)) != 0) {
1281 nop();
1282 }
1283}
1284
1285
Ian Rogers2c8f6532011-09-02 17:16:34 -07001286void X86Assembler::Bind(Label* label) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001287 int bound = buffer_.Size();
1288 CHECK(!label->IsBound()); // Labels can only be bound once.
1289 while (label->IsLinked()) {
1290 int position = label->LinkPosition();
1291 int next = buffer_.Load<int32_t>(position);
1292 buffer_.Store<int32_t>(position, bound - (position + 4));
1293 label->position_ = next;
1294 }
1295 label->BindTo(bound);
1296}
1297
1298
Ian Rogers2c8f6532011-09-02 17:16:34 -07001299void X86Assembler::Stop(const char* message) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001300 // Emit the message address as immediate operand in the test rax instruction,
1301 // followed by the int3 instruction.
1302 // Execution can be resumed with the 'cont' command in gdb.
1303 testl(EAX, Immediate(reinterpret_cast<int32_t>(message)));
1304 int3();
1305}
1306
1307
Ian Rogers2c8f6532011-09-02 17:16:34 -07001308void X86Assembler::EmitOperand(int rm, const Operand& operand) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001309 CHECK_GE(rm, 0);
1310 CHECK_LT(rm, 8);
1311 const int length = operand.length_;
1312 CHECK_GT(length, 0);
1313 // Emit the ModRM byte updated with the given RM value.
1314 CHECK_EQ(operand.encoding_[0] & 0x38, 0);
1315 EmitUint8(operand.encoding_[0] + (rm << 3));
1316 // Emit the rest of the encoded operand.
1317 for (int i = 1; i < length; i++) {
1318 EmitUint8(operand.encoding_[i]);
1319 }
1320}
1321
1322
Ian Rogers2c8f6532011-09-02 17:16:34 -07001323void X86Assembler::EmitImmediate(const Immediate& imm) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001324 EmitInt32(imm.value());
1325}
1326
1327
Ian Rogers2c8f6532011-09-02 17:16:34 -07001328void X86Assembler::EmitComplex(int rm,
1329 const Operand& operand,
1330 const Immediate& immediate) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001331 CHECK_GE(rm, 0);
1332 CHECK_LT(rm, 8);
1333 if (immediate.is_int8()) {
1334 // Use sign-extended 8-bit immediate.
1335 EmitUint8(0x83);
1336 EmitOperand(rm, operand);
1337 EmitUint8(immediate.value() & 0xFF);
1338 } else if (operand.IsRegister(EAX)) {
1339 // Use short form if the destination is eax.
1340 EmitUint8(0x05 + (rm << 3));
1341 EmitImmediate(immediate);
1342 } else {
1343 EmitUint8(0x81);
1344 EmitOperand(rm, operand);
1345 EmitImmediate(immediate);
1346 }
1347}
1348
1349
Ian Rogers2c8f6532011-09-02 17:16:34 -07001350void X86Assembler::EmitLabel(Label* label, int instruction_size) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001351 if (label->IsBound()) {
1352 int offset = label->Position() - buffer_.Size();
1353 CHECK_LE(offset, 0);
1354 EmitInt32(offset - instruction_size);
1355 } else {
1356 EmitLabelLink(label);
1357 }
1358}
1359
1360
Ian Rogers2c8f6532011-09-02 17:16:34 -07001361void X86Assembler::EmitLabelLink(Label* label) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001362 CHECK(!label->IsBound());
1363 int position = buffer_.Size();
1364 EmitInt32(label->position_);
1365 label->LinkTo(position);
1366}
1367
1368
Ian Rogers2c8f6532011-09-02 17:16:34 -07001369void X86Assembler::EmitGenericShift(int rm,
1370 Register reg,
1371 const Immediate& imm) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001372 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1373 CHECK(imm.is_int8());
1374 if (imm.value() == 1) {
1375 EmitUint8(0xD1);
1376 EmitOperand(rm, Operand(reg));
1377 } else {
1378 EmitUint8(0xC1);
1379 EmitOperand(rm, Operand(reg));
1380 EmitUint8(imm.value() & 0xFF);
1381 }
1382}
1383
1384
Ian Rogers2c8f6532011-09-02 17:16:34 -07001385void X86Assembler::EmitGenericShift(int rm,
1386 Register operand,
1387 Register shifter) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001388 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1389 CHECK_EQ(shifter, ECX);
1390 EmitUint8(0xD3);
1391 EmitOperand(rm, Operand(operand));
1392}
1393
Ian Rogers2c8f6532011-09-02 17:16:34 -07001394void X86Assembler::BuildFrame(size_t frame_size, ManagedRegister method_reg,
1395 const std::vector<ManagedRegister>& spill_regs) {
Elliott Hughes06b37d92011-10-16 11:51:29 -07001396 CHECK_ALIGNED(frame_size, kStackAlignment);
Ian Rogers0d666d82011-08-14 16:03:46 -07001397 CHECK_EQ(0u, spill_regs.size()); // no spilled regs on x86
Ian Rogersb033c752011-07-20 12:22:35 -07001398 // return address then method on stack
Ian Rogers0d666d82011-08-14 16:03:46 -07001399 addl(ESP, Immediate(-frame_size + kPointerSize /*method*/ +
1400 kPointerSize /*return address*/));
Ian Rogers2c8f6532011-09-02 17:16:34 -07001401 pushl(method_reg.AsX86().AsCpuRegister());
Ian Rogersb033c752011-07-20 12:22:35 -07001402}
1403
Ian Rogers2c8f6532011-09-02 17:16:34 -07001404void X86Assembler::RemoveFrame(size_t frame_size,
Ian Rogers0d666d82011-08-14 16:03:46 -07001405 const std::vector<ManagedRegister>& spill_regs) {
Elliott Hughes06b37d92011-10-16 11:51:29 -07001406 CHECK_ALIGNED(frame_size, kStackAlignment);
Ian Rogers0d666d82011-08-14 16:03:46 -07001407 CHECK_EQ(0u, spill_regs.size()); // no spilled regs on x86
1408 addl(ESP, Immediate(frame_size - kPointerSize));
Ian Rogersb033c752011-07-20 12:22:35 -07001409 ret();
1410}
1411
Ian Rogers2c8f6532011-09-02 17:16:34 -07001412void X86Assembler::IncreaseFrameSize(size_t adjust) {
Elliott Hughes06b37d92011-10-16 11:51:29 -07001413 CHECK_ALIGNED(adjust, kStackAlignment);
Ian Rogersb033c752011-07-20 12:22:35 -07001414 addl(ESP, Immediate(-adjust));
1415}
1416
Ian Rogers2c8f6532011-09-02 17:16:34 -07001417void X86Assembler::DecreaseFrameSize(size_t adjust) {
Elliott Hughes06b37d92011-10-16 11:51:29 -07001418 CHECK_ALIGNED(adjust, kStackAlignment);
Ian Rogersb033c752011-07-20 12:22:35 -07001419 addl(ESP, Immediate(adjust));
1420}
1421
Ian Rogers2c8f6532011-09-02 17:16:34 -07001422void X86Assembler::Store(FrameOffset offs, ManagedRegister msrc, size_t size) {
1423 X86ManagedRegister src = msrc.AsX86();
Ian Rogers45a76cb2011-07-21 22:00:15 -07001424 if (src.IsNoRegister()) {
1425 CHECK_EQ(0u, size);
1426 } else if (src.IsCpuRegister()) {
Ian Rogersb033c752011-07-20 12:22:35 -07001427 CHECK_EQ(4u, size);
1428 movl(Address(ESP, offs), src.AsCpuRegister());
Ian Rogers9b269d22011-09-04 14:06:05 -07001429 } else if (src.IsRegisterPair()) {
1430 CHECK_EQ(8u, size);
1431 movl(Address(ESP, offs), src.AsRegisterPairLow());
1432 movl(Address(ESP, FrameOffset(offs.Int32Value()+4)),
1433 src.AsRegisterPairHigh());
Ian Rogers45a76cb2011-07-21 22:00:15 -07001434 } else if (src.IsX87Register()) {
1435 if (size == 4) {
1436 fstps(Address(ESP, offs));
1437 } else {
1438 fstpl(Address(ESP, offs));
1439 }
1440 } else {
1441 CHECK(src.IsXmmRegister());
Ian Rogersb033c752011-07-20 12:22:35 -07001442 if (size == 4) {
1443 movss(Address(ESP, offs), src.AsXmmRegister());
1444 } else {
1445 movsd(Address(ESP, offs), src.AsXmmRegister());
1446 }
1447 }
1448}
1449
Ian Rogers2c8f6532011-09-02 17:16:34 -07001450void X86Assembler::StoreRef(FrameOffset dest, ManagedRegister msrc) {
1451 X86ManagedRegister src = msrc.AsX86();
Ian Rogersb033c752011-07-20 12:22:35 -07001452 CHECK(src.IsCpuRegister());
1453 movl(Address(ESP, dest), src.AsCpuRegister());
1454}
1455
Ian Rogers2c8f6532011-09-02 17:16:34 -07001456void X86Assembler::StoreRawPtr(FrameOffset dest, ManagedRegister msrc) {
1457 X86ManagedRegister src = msrc.AsX86();
Ian Rogersdf20fe02011-07-20 20:34:16 -07001458 CHECK(src.IsCpuRegister());
1459 movl(Address(ESP, dest), src.AsCpuRegister());
1460}
1461
Ian Rogers2c8f6532011-09-02 17:16:34 -07001462void X86Assembler::StoreImmediateToFrame(FrameOffset dest, uint32_t imm,
1463 ManagedRegister) {
Ian Rogersb033c752011-07-20 12:22:35 -07001464 movl(Address(ESP, dest), Immediate(imm));
1465}
1466
Ian Rogers2c8f6532011-09-02 17:16:34 -07001467void X86Assembler::StoreImmediateToThread(ThreadOffset dest, uint32_t imm,
1468 ManagedRegister) {
Ian Rogers0d666d82011-08-14 16:03:46 -07001469 fs()->movl(Address::Absolute(dest), Immediate(imm));
Ian Rogersb033c752011-07-20 12:22:35 -07001470}
1471
Ian Rogers2c8f6532011-09-02 17:16:34 -07001472void X86Assembler::StoreStackOffsetToThread(ThreadOffset thr_offs,
1473 FrameOffset fr_offs,
1474 ManagedRegister mscratch) {
1475 X86ManagedRegister scratch = mscratch.AsX86();
1476 CHECK(scratch.IsCpuRegister());
1477 leal(scratch.AsCpuRegister(), Address(ESP, fr_offs));
1478 fs()->movl(Address::Absolute(thr_offs), scratch.AsCpuRegister());
1479}
1480
1481void X86Assembler::StoreStackPointerToThread(ThreadOffset thr_offs) {
1482 fs()->movl(Address::Absolute(thr_offs), ESP);
1483}
1484
Ian Rogersbdb03912011-09-14 00:55:44 -07001485void X86Assembler::StoreLabelToThread(ThreadOffset thr_offs, Label* lbl) {
1486 fs()->movl(Address::Absolute(thr_offs), lbl);
1487}
1488
Ian Rogers2c8f6532011-09-02 17:16:34 -07001489void X86Assembler::StoreSpanning(FrameOffset dest, ManagedRegister src,
1490 FrameOffset in_off, ManagedRegister scratch) {
1491 UNIMPLEMENTED(FATAL); // this case only currently exists for ARM
1492}
1493
1494void X86Assembler::Load(ManagedRegister mdest, FrameOffset src, size_t size) {
1495 X86ManagedRegister dest = mdest.AsX86();
Ian Rogers45a76cb2011-07-21 22:00:15 -07001496 if (dest.IsNoRegister()) {
1497 CHECK_EQ(0u, size);
1498 } else if (dest.IsCpuRegister()) {
Ian Rogersb033c752011-07-20 12:22:35 -07001499 CHECK_EQ(4u, size);
1500 movl(dest.AsCpuRegister(), Address(ESP, src));
Ian Rogers9b269d22011-09-04 14:06:05 -07001501 } else if (dest.IsRegisterPair()) {
1502 CHECK_EQ(8u, size);
1503 movl(dest.AsRegisterPairLow(), Address(ESP, src));
1504 movl(dest.AsRegisterPairHigh(), Address(ESP, FrameOffset(src.Int32Value()+4)));
Ian Rogers45a76cb2011-07-21 22:00:15 -07001505 } else if (dest.IsX87Register()) {
1506 if (size == 4) {
1507 flds(Address(ESP, src));
1508 } else {
1509 fldl(Address(ESP, src));
1510 }
Ian Rogersb033c752011-07-20 12:22:35 -07001511 } else {
Ian Rogers45a76cb2011-07-21 22:00:15 -07001512 CHECK(dest.IsXmmRegister());
1513 if (size == 4) {
1514 movss(dest.AsXmmRegister(), Address(ESP, src));
1515 } else {
1516 movsd(dest.AsXmmRegister(), Address(ESP, src));
1517 }
Ian Rogersb033c752011-07-20 12:22:35 -07001518 }
1519}
1520
Ian Rogers5a7a74a2011-09-26 16:32:29 -07001521void X86Assembler::Load(ManagedRegister mdest, ThreadOffset src, size_t size) {
1522 X86ManagedRegister dest = mdest.AsX86();
1523 if (dest.IsNoRegister()) {
1524 CHECK_EQ(0u, size);
1525 } else if (dest.IsCpuRegister()) {
1526 CHECK_EQ(4u, size);
1527 fs()->movl(dest.AsCpuRegister(), Address::Absolute(src));
1528 } else if (dest.IsRegisterPair()) {
1529 CHECK_EQ(8u, size);
1530 fs()->movl(dest.AsRegisterPairLow(), Address::Absolute(src));
1531 fs()->movl(dest.AsRegisterPairHigh(), Address::Absolute(ThreadOffset(src.Int32Value()+4)));
1532 } else if (dest.IsX87Register()) {
1533 if (size == 4) {
1534 fs()->flds(Address::Absolute(src));
1535 } else {
1536 fs()->fldl(Address::Absolute(src));
1537 }
1538 } else {
1539 CHECK(dest.IsXmmRegister());
1540 if (size == 4) {
1541 fs()->movss(dest.AsXmmRegister(), Address::Absolute(src));
1542 } else {
1543 fs()->movsd(dest.AsXmmRegister(), Address::Absolute(src));
1544 }
1545 }
1546}
1547
Ian Rogers2c8f6532011-09-02 17:16:34 -07001548void X86Assembler::LoadRef(ManagedRegister mdest, FrameOffset src) {
1549 X86ManagedRegister dest = mdest.AsX86();
Ian Rogersb033c752011-07-20 12:22:35 -07001550 CHECK(dest.IsCpuRegister());
1551 movl(dest.AsCpuRegister(), Address(ESP, src));
1552}
1553
Ian Rogers2c8f6532011-09-02 17:16:34 -07001554void X86Assembler::LoadRef(ManagedRegister mdest, ManagedRegister base,
1555 MemberOffset offs) {
1556 X86ManagedRegister dest = mdest.AsX86();
Ian Rogersb033c752011-07-20 12:22:35 -07001557 CHECK(dest.IsCpuRegister() && dest.IsCpuRegister());
Ian Rogers2c8f6532011-09-02 17:16:34 -07001558 movl(dest.AsCpuRegister(), Address(base.AsX86().AsCpuRegister(), offs));
Ian Rogersb033c752011-07-20 12:22:35 -07001559}
1560
Ian Rogers2c8f6532011-09-02 17:16:34 -07001561void X86Assembler::LoadRawPtr(ManagedRegister mdest, ManagedRegister base,
1562 Offset offs) {
1563 X86ManagedRegister dest = mdest.AsX86();
Ian Rogersa04d3972011-08-17 11:33:44 -07001564 CHECK(dest.IsCpuRegister() && dest.IsCpuRegister());
Ian Rogers2c8f6532011-09-02 17:16:34 -07001565 movl(dest.AsCpuRegister(), Address(base.AsX86().AsCpuRegister(), offs));
Ian Rogersa04d3972011-08-17 11:33:44 -07001566}
1567
Ian Rogers2c8f6532011-09-02 17:16:34 -07001568void X86Assembler::LoadRawPtrFromThread(ManagedRegister mdest,
1569 ThreadOffset offs) {
1570 X86ManagedRegister dest = mdest.AsX86();
Ian Rogersb033c752011-07-20 12:22:35 -07001571 CHECK(dest.IsCpuRegister());
Ian Rogers0d666d82011-08-14 16:03:46 -07001572 fs()->movl(dest.AsCpuRegister(), Address::Absolute(offs));
Ian Rogersb033c752011-07-20 12:22:35 -07001573}
1574
Ian Rogers2c8f6532011-09-02 17:16:34 -07001575void X86Assembler::Move(ManagedRegister mdest, ManagedRegister msrc) {
1576 X86ManagedRegister dest = mdest.AsX86();
1577 X86ManagedRegister src = msrc.AsX86();
Ian Rogersb033c752011-07-20 12:22:35 -07001578 if (!dest.Equals(src)) {
1579 if (dest.IsCpuRegister() && src.IsCpuRegister()) {
1580 movl(dest.AsCpuRegister(), src.AsCpuRegister());
1581 } else {
1582 // TODO: x87, SSE
Ian Rogers2c8f6532011-09-02 17:16:34 -07001583 UNIMPLEMENTED(FATAL) << ": Move " << dest << ", " << src;
Ian Rogersb033c752011-07-20 12:22:35 -07001584 }
1585 }
1586}
1587
Ian Rogers2c8f6532011-09-02 17:16:34 -07001588void X86Assembler::CopyRef(FrameOffset dest, FrameOffset src,
1589 ManagedRegister mscratch) {
1590 X86ManagedRegister scratch = mscratch.AsX86();
1591 CHECK(scratch.IsCpuRegister());
1592 movl(scratch.AsCpuRegister(), Address(ESP, src));
1593 movl(Address(ESP, dest), scratch.AsCpuRegister());
1594}
1595
1596void X86Assembler::CopyRawPtrFromThread(FrameOffset fr_offs,
1597 ThreadOffset thr_offs,
1598 ManagedRegister mscratch) {
1599 X86ManagedRegister scratch = mscratch.AsX86();
1600 CHECK(scratch.IsCpuRegister());
1601 fs()->movl(scratch.AsCpuRegister(), Address::Absolute(thr_offs));
1602 Store(fr_offs, scratch, 4);
1603}
1604
1605void X86Assembler::CopyRawPtrToThread(ThreadOffset thr_offs,
1606 FrameOffset fr_offs,
1607 ManagedRegister mscratch) {
1608 X86ManagedRegister scratch = mscratch.AsX86();
1609 CHECK(scratch.IsCpuRegister());
1610 Load(scratch, fr_offs, 4);
1611 fs()->movl(Address::Absolute(thr_offs), scratch.AsCpuRegister());
1612}
1613
1614void X86Assembler::Copy(FrameOffset dest, FrameOffset src,
1615 ManagedRegister mscratch,
1616 size_t size) {
1617 X86ManagedRegister scratch = mscratch.AsX86();
Ian Rogersb033c752011-07-20 12:22:35 -07001618 if (scratch.IsCpuRegister() && size == 8) {
1619 Load(scratch, src, 4);
1620 Store(dest, scratch, 4);
1621 Load(scratch, FrameOffset(src.Int32Value() + 4), 4);
1622 Store(FrameOffset(dest.Int32Value() + 4), scratch, 4);
1623 } else {
1624 Load(scratch, src, size);
1625 Store(dest, scratch, size);
1626 }
1627}
1628
Ian Rogersdc51b792011-09-22 20:41:37 -07001629void X86Assembler::Copy(FrameOffset dest, ManagedRegister src_base, Offset src_offset,
1630 ManagedRegister scratch, size_t size) {
1631 UNIMPLEMENTED(FATAL);
1632}
1633
Ian Rogers5a7a74a2011-09-26 16:32:29 -07001634void X86Assembler::Copy(ManagedRegister dest_base, Offset dest_offset, FrameOffset src,
1635 ManagedRegister scratch, size_t size) {
1636 CHECK(scratch.IsNoRegister());
1637 CHECK_EQ(size, 4u);
1638 pushl(Address(ESP, src));
1639 popl(Address(dest_base.AsX86().AsCpuRegister(), dest_offset));
1640}
1641
Ian Rogersdc51b792011-09-22 20:41:37 -07001642void X86Assembler::Copy(FrameOffset dest, FrameOffset src_base, Offset src_offset,
1643 ManagedRegister mscratch, size_t size) {
1644 Register scratch = mscratch.AsX86().AsCpuRegister();
1645 CHECK_EQ(size, 4u);
1646 movl(scratch, Address(ESP, src_base));
1647 movl(scratch, Address(scratch, src_offset));
1648 movl(Address(ESP, dest), scratch);
1649}
1650
Ian Rogers5a7a74a2011-09-26 16:32:29 -07001651void X86Assembler::Copy(ManagedRegister dest, Offset dest_offset,
1652 ManagedRegister src, Offset src_offset,
1653 ManagedRegister scratch, size_t size) {
Ian Rogersdc51b792011-09-22 20:41:37 -07001654 CHECK_EQ(size, 4u);
Ian Rogers5a7a74a2011-09-26 16:32:29 -07001655 CHECK(scratch.IsNoRegister());
1656 pushl(Address(src.AsX86().AsCpuRegister(), src_offset));
1657 popl(Address(dest.AsX86().AsCpuRegister(), dest_offset));
1658}
1659
1660void X86Assembler::Copy(FrameOffset dest, Offset dest_offset, FrameOffset src, Offset src_offset,
1661 ManagedRegister mscratch, size_t size) {
1662 Register scratch = mscratch.AsX86().AsCpuRegister();
1663 CHECK_EQ(size, 4u);
1664 CHECK_EQ(dest.Int32Value(), src.Int32Value());
1665 movl(scratch, Address(ESP, src));
1666 pushl(Address(scratch, src_offset));
Ian Rogersdc51b792011-09-22 20:41:37 -07001667 popl(Address(scratch, dest_offset));
1668}
1669
Ian Rogerse5de95b2011-09-18 20:31:38 -07001670void X86Assembler::MemoryBarrier(ManagedRegister) {
1671#if ANDROID_SMP != 0
1672 EmitUint8(0x0F); // mfence
1673 EmitUint8(0xAE);
Ian Rogerse007b102011-09-19 09:47:09 -07001674 EmitUint8(0xF0);
Ian Rogerse5de95b2011-09-18 20:31:38 -07001675#endif
1676}
1677
Ian Rogers2c8f6532011-09-02 17:16:34 -07001678void X86Assembler::CreateSirtEntry(ManagedRegister mout_reg,
1679 FrameOffset sirt_offset,
1680 ManagedRegister min_reg, bool null_allowed) {
1681 X86ManagedRegister out_reg = mout_reg.AsX86();
1682 X86ManagedRegister in_reg = min_reg.AsX86();
Ian Rogersb033c752011-07-20 12:22:35 -07001683 CHECK(in_reg.IsCpuRegister());
1684 CHECK(out_reg.IsCpuRegister());
Ian Rogers408f79a2011-08-23 18:22:33 -07001685 VerifyObject(in_reg, null_allowed);
Ian Rogersb033c752011-07-20 12:22:35 -07001686 if (null_allowed) {
1687 Label null_arg;
1688 if (!out_reg.Equals(in_reg)) {
1689 xorl(out_reg.AsCpuRegister(), out_reg.AsCpuRegister());
1690 }
1691 testl(in_reg.AsCpuRegister(), in_reg.AsCpuRegister());
Elliott Hughes18c07532011-08-18 15:50:51 -07001692 j(kZero, &null_arg);
Ian Rogers408f79a2011-08-23 18:22:33 -07001693 leal(out_reg.AsCpuRegister(), Address(ESP, sirt_offset));
Ian Rogersb033c752011-07-20 12:22:35 -07001694 Bind(&null_arg);
1695 } else {
Ian Rogers408f79a2011-08-23 18:22:33 -07001696 leal(out_reg.AsCpuRegister(), Address(ESP, sirt_offset));
Ian Rogersb033c752011-07-20 12:22:35 -07001697 }
1698}
1699
Ian Rogers2c8f6532011-09-02 17:16:34 -07001700void X86Assembler::CreateSirtEntry(FrameOffset out_off,
1701 FrameOffset sirt_offset,
1702 ManagedRegister mscratch,
1703 bool null_allowed) {
1704 X86ManagedRegister scratch = mscratch.AsX86();
Ian Rogersb033c752011-07-20 12:22:35 -07001705 CHECK(scratch.IsCpuRegister());
1706 if (null_allowed) {
1707 Label null_arg;
Ian Rogers408f79a2011-08-23 18:22:33 -07001708 movl(scratch.AsCpuRegister(), Address(ESP, sirt_offset));
Ian Rogersb033c752011-07-20 12:22:35 -07001709 testl(scratch.AsCpuRegister(), scratch.AsCpuRegister());
Elliott Hughes18c07532011-08-18 15:50:51 -07001710 j(kZero, &null_arg);
Ian Rogers408f79a2011-08-23 18:22:33 -07001711 leal(scratch.AsCpuRegister(), Address(ESP, sirt_offset));
Ian Rogersb033c752011-07-20 12:22:35 -07001712 Bind(&null_arg);
1713 } else {
Ian Rogers408f79a2011-08-23 18:22:33 -07001714 leal(scratch.AsCpuRegister(), Address(ESP, sirt_offset));
Ian Rogersb033c752011-07-20 12:22:35 -07001715 }
1716 Store(out_off, scratch, 4);
1717}
1718
Ian Rogers408f79a2011-08-23 18:22:33 -07001719// Given a SIRT entry, load the associated reference.
Ian Rogers2c8f6532011-09-02 17:16:34 -07001720void X86Assembler::LoadReferenceFromSirt(ManagedRegister mout_reg,
1721 ManagedRegister min_reg) {
1722 X86ManagedRegister out_reg = mout_reg.AsX86();
1723 X86ManagedRegister in_reg = min_reg.AsX86();
Ian Rogersb033c752011-07-20 12:22:35 -07001724 CHECK(out_reg.IsCpuRegister());
1725 CHECK(in_reg.IsCpuRegister());
1726 Label null_arg;
1727 if (!out_reg.Equals(in_reg)) {
1728 xorl(out_reg.AsCpuRegister(), out_reg.AsCpuRegister());
1729 }
1730 testl(in_reg.AsCpuRegister(), in_reg.AsCpuRegister());
Elliott Hughes18c07532011-08-18 15:50:51 -07001731 j(kZero, &null_arg);
Ian Rogersb033c752011-07-20 12:22:35 -07001732 movl(out_reg.AsCpuRegister(), Address(in_reg.AsCpuRegister(), 0));
1733 Bind(&null_arg);
1734}
1735
Ian Rogers2c8f6532011-09-02 17:16:34 -07001736void X86Assembler::VerifyObject(ManagedRegister src, bool could_be_null) {
Ian Rogersb033c752011-07-20 12:22:35 -07001737 // TODO: not validating references
1738}
1739
Ian Rogers2c8f6532011-09-02 17:16:34 -07001740void X86Assembler::VerifyObject(FrameOffset src, bool could_be_null) {
Ian Rogersb033c752011-07-20 12:22:35 -07001741 // TODO: not validating references
1742}
1743
Ian Rogers2c8f6532011-09-02 17:16:34 -07001744void X86Assembler::Call(ManagedRegister mbase, Offset offset, ManagedRegister) {
1745 X86ManagedRegister base = mbase.AsX86();
Ian Rogersb033c752011-07-20 12:22:35 -07001746 CHECK(base.IsCpuRegister());
Ian Rogersdf20fe02011-07-20 20:34:16 -07001747 call(Address(base.AsCpuRegister(), offset.Int32Value()));
Ian Rogersb033c752011-07-20 12:22:35 -07001748 // TODO: place reference map on call
1749}
1750
Ian Rogers67375ac2011-09-14 00:55:44 -07001751void X86Assembler::Call(FrameOffset base, Offset offset, ManagedRegister mscratch) {
1752 Register scratch = mscratch.AsX86().AsCpuRegister();
1753 movl(scratch, Address(ESP, base));
1754 call(Address(scratch, offset));
Carl Shapiroe2d373e2011-07-25 15:20:06 -07001755}
1756
Ian Rogersbdb03912011-09-14 00:55:44 -07001757void X86Assembler::Call(ThreadOffset offset, ManagedRegister mscratch) {
1758 fs()->call(Address::Absolute(offset));
Shih-wei Liao668512a2011-09-01 14:18:34 -07001759}
1760
Ian Rogers2c8f6532011-09-02 17:16:34 -07001761void X86Assembler::GetCurrentThread(ManagedRegister tr) {
1762 fs()->movl(tr.AsX86().AsCpuRegister(),
1763 Address::Absolute(Thread::SelfOffset()));
Shih-wei Liao668512a2011-09-01 14:18:34 -07001764}
1765
Ian Rogers2c8f6532011-09-02 17:16:34 -07001766void X86Assembler::GetCurrentThread(FrameOffset offset,
1767 ManagedRegister mscratch) {
1768 X86ManagedRegister scratch = mscratch.AsX86();
Shih-wei Liao668512a2011-09-01 14:18:34 -07001769 fs()->movl(scratch.AsCpuRegister(), Address::Absolute(Thread::SelfOffset()));
1770 movl(Address(ESP, offset), scratch.AsCpuRegister());
1771}
1772
Ian Rogers2c8f6532011-09-02 17:16:34 -07001773void X86Assembler::SuspendPoll(ManagedRegister scratch,
1774 ManagedRegister return_reg,
1775 FrameOffset return_save_location,
1776 size_t return_size) {
1777 X86SuspendCountSlowPath* slow =
1778 new X86SuspendCountSlowPath(return_reg.AsX86(), return_save_location,
1779 return_size);
Ian Rogers45a76cb2011-07-21 22:00:15 -07001780 buffer_.EnqueueSlowPath(slow);
Ian Rogers0d666d82011-08-14 16:03:46 -07001781 fs()->cmpl(Address::Absolute(Thread::SuspendCountOffset()), Immediate(0));
Elliott Hughes18c07532011-08-18 15:50:51 -07001782 j(kNotEqual, slow->Entry());
Ian Rogers45a76cb2011-07-21 22:00:15 -07001783 Bind(slow->Continuation());
1784}
Ian Rogers0d666d82011-08-14 16:03:46 -07001785
Ian Rogers2c8f6532011-09-02 17:16:34 -07001786void X86SuspendCountSlowPath::Emit(Assembler *sasm) {
1787 X86Assembler* sp_asm = down_cast<X86Assembler*>(sasm);
Ian Rogers0d666d82011-08-14 16:03:46 -07001788#define __ sp_asm->
1789 __ Bind(&entry_);
Ian Rogers45a76cb2011-07-21 22:00:15 -07001790 // Save return value
Ian Rogers0d666d82011-08-14 16:03:46 -07001791 __ Store(return_save_location_, return_register_, return_size_);
Ian Rogerse5de95b2011-09-18 20:31:38 -07001792 // Pass Thread::Current as argument
1793 __ fs()->pushl(Address::Absolute(Thread::SelfOffset()));
1794 __ fs()->call(Address::Absolute(OFFSETOF_MEMBER(Thread, pCheckSuspendFromCode)));
Ian Rogers45a76cb2011-07-21 22:00:15 -07001795 // Release argument
Ian Rogers0d666d82011-08-14 16:03:46 -07001796 __ addl(ESP, Immediate(kPointerSize));
Ian Rogers45a76cb2011-07-21 22:00:15 -07001797 // Reload return value
Ian Rogers0d666d82011-08-14 16:03:46 -07001798 __ Load(return_register_, return_save_location_, return_size_);
1799 __ jmp(&continuation_);
1800#undef __
Ian Rogers45a76cb2011-07-21 22:00:15 -07001801}
1802
Ian Rogers2c8f6532011-09-02 17:16:34 -07001803void X86Assembler::ExceptionPoll(ManagedRegister scratch) {
1804 X86ExceptionSlowPath* slow = new X86ExceptionSlowPath();
Ian Rogers45a76cb2011-07-21 22:00:15 -07001805 buffer_.EnqueueSlowPath(slow);
Ian Rogers0d666d82011-08-14 16:03:46 -07001806 fs()->cmpl(Address::Absolute(Thread::ExceptionOffset()), Immediate(0));
Elliott Hughes18c07532011-08-18 15:50:51 -07001807 j(kNotEqual, slow->Entry());
Ian Rogers45a76cb2011-07-21 22:00:15 -07001808}
Ian Rogers0d666d82011-08-14 16:03:46 -07001809
Ian Rogers2c8f6532011-09-02 17:16:34 -07001810void X86ExceptionSlowPath::Emit(Assembler *sasm) {
1811 X86Assembler* sp_asm = down_cast<X86Assembler*>(sasm);
Ian Rogers0d666d82011-08-14 16:03:46 -07001812#define __ sp_asm->
1813 __ Bind(&entry_);
Elliott Hughes20cde902011-10-04 17:37:27 -07001814 // Note: the return value is dead
Ian Rogers67375ac2011-09-14 00:55:44 -07001815 // Pass exception as argument in EAX
1816 __ fs()->movl(EAX, Address::Absolute(Thread::ExceptionOffset()));
1817 __ fs()->call(Address::Absolute(OFFSETOF_MEMBER(Thread, pDeliverException)));
1818 // this call should never return
1819 __ int3();
Ian Rogers0d666d82011-08-14 16:03:46 -07001820#undef __
Ian Rogers45a76cb2011-07-21 22:00:15 -07001821}
1822
Ian Rogers2c8f6532011-09-02 17:16:34 -07001823} // namespace x86
Ian Rogersb033c752011-07-20 12:22:35 -07001824} // namespace art