1 // Copyright 2011 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided
11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission.
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 #include "src/debug.h"
33 #include "src/disasm.h"
34 #include "src/disassembler.h"
35 #include "src/ic/ic.h"
36 #include "src/macro-assembler.h"
37 #include "test/cctest/cctest.h"
39 using namespace v8::internal;
45 static void DummyStaticFunction(Object* result) {
50 CcTest::InitializeVM();
51 Isolate* isolate = CcTest::i_isolate();
52 HandleScope scope(isolate);
53 v8::internal::byte buffer[2048];
54 Assembler assm(isolate, buffer, sizeof buffer);
55 DummyStaticFunction(NULL); // just bloody use it (DELETE; debugging)
57 // Short immediate instructions
58 __ adc(eax, 12345678);
59 __ add(eax, Immediate(12345678));
60 __ or_(eax, 12345678);
61 __ sub(eax, Immediate(12345678));
62 __ xor_(eax, 12345678);
63 __ and_(eax, 12345678);
64 Handle<FixedArray> foo = isolate->factory()->NewFixedArray(10, TENURED);
67 // ---- This one caused crash
68 __ mov(ebx, Operand(esp, ecx, times_2, 0)); // [esp+ecx*4]
70 // ---- All instructions that I can think of
72 __ add(edx, Operand(12, RelocInfo::NONE32));
73 __ add(edx, Operand(ebx, 0));
74 __ add(edx, Operand(ebx, 16));
75 __ add(edx, Operand(ebx, 1999));
76 __ add(edx, Operand(ebx, -4));
77 __ add(edx, Operand(ebx, -1999));
78 __ add(edx, Operand(esp, 0));
79 __ add(edx, Operand(esp, 16));
80 __ add(edx, Operand(esp, 1999));
81 __ add(edx, Operand(esp, -4));
82 __ add(edx, Operand(esp, -1999));
84 __ add(esi, Operand(ecx, times_4, 0));
85 __ add(esi, Operand(ecx, times_4, 24));
86 __ add(esi, Operand(ecx, times_4, -4));
87 __ add(esi, Operand(ecx, times_4, -1999));
89 __ add(edi, Operand(ebp, ecx, times_4, 0));
90 __ add(edi, Operand(ebp, ecx, times_4, 12));
91 __ add(edi, Operand(ebp, ecx, times_4, -8));
92 __ add(edi, Operand(ebp, ecx, times_4, -3999));
93 __ add(Operand(ebp, ecx, times_4, 12), Immediate(12));
96 __ add(ebx, Immediate(12));
102 __ and_(edx, Operand(esp, 4));
104 __ cmp(edx, Operand(esp, 4));
105 __ cmp(Operand(ebp, ecx, times_4, 0), Immediate(1000));
106 Handle<FixedArray> foo2 = isolate->factory()->NewFixedArray(10, TENURED);
108 __ cmpb(ebx, Operand(ebp, ecx, times_2, 0));
109 __ cmpb(Operand(ebp, ecx, times_2, 0), ebx);
114 __ movsx_b(edx, ecx);
115 __ movsx_w(edx, ecx);
116 __ movzx_b(edx, ecx);
117 __ movzx_w(edx, ecx);
124 __ bts(Operand(ebx, ecx, times_4, 0), ecx);
130 __ push(Immediate(12));
131 __ push(Immediate(23456));
134 __ push(Operand(ebp, JavaScriptFrameConstants::kFunctionOffset));
135 __ push(Operand(ebx, ecx, times_4, 0));
136 __ push(Operand(ebx, ecx, times_4, 0));
137 __ push(Operand(ebx, ecx, times_4, 10000));
140 __ pop(Operand(ebx, ecx, times_4, 0));
143 __ add(edx, Operand(esp, 16));
147 __ mov_b(Operand(ebx, ecx, times_4, 10000), 6);
148 __ mov_b(Operand(esp, 16), edx);
149 __ mov_w(edx, Operand(esp, 16));
150 __ mov_w(Operand(esp, 16), edx);
152 __ movsx_w(edx, Operand(esp, 12));
153 __ movsx_b(edx, Operand(esp, 12));
154 __ movzx_w(edx, Operand(esp, 12));
155 __ movzx_b(edx, Operand(esp, 12));
157 __ mov(edx, 1234567);
158 __ mov(edx, Operand(esp, 12));
159 __ mov(Operand(ebx, ecx, times_4, 10000), Immediate(12345));
160 __ mov(Operand(ebx, ecx, times_4, 10000), edx);
163 __ dec_b(Operand(eax, 10));
164 __ dec_b(Operand(ebx, ecx, times_4, 10000));
170 __ idiv(Operand(edx, ecx, times_1, 1));
171 __ idiv(Operand(esp, 12));
173 __ div(Operand(edx, ecx, times_1, 1));
174 __ div(Operand(esp, 12));
178 __ test(Operand(ebx, ecx, times_4, 10000), Immediate(123456));
180 __ imul(edx, Operand(ebx, ecx, times_4, 10000));
181 __ imul(edx, ecx, 12);
182 __ imul(edx, Operand(edx, eax, times_2, 42), 8);
183 __ imul(edx, ecx, 1000);
184 __ imul(edx, Operand(ebx, ecx, times_4, 1), 9000);
187 __ inc(Operand(ebx, ecx, times_4, 10000));
188 __ push(Operand(ebx, ecx, times_4, 10000));
189 __ pop(Operand(ebx, ecx, times_4, 10000));
190 __ call(Operand(ebx, ecx, times_4, 10000));
191 __ jmp(Operand(ebx, ecx, times_4, 10000));
193 __ lea(edx, Operand(ebx, ecx, times_4, 10000));
195 __ or_(edx, Operand(ebx, ecx, times_4, 10000));
206 __ ror(Operand(ebx, ecx, times_4, 10000), 1);
207 __ ror(Operand(ebx, ecx, times_4, 10000), 6);
208 __ ror_cl(Operand(ebx, ecx, times_4, 10000));
212 __ sar(Operand(ebx, ecx, times_4, 10000), 1);
213 __ sar(Operand(ebx, ecx, times_4, 10000), 6);
214 __ sar_cl(Operand(ebx, ecx, times_4, 10000));
215 __ sbb(edx, Operand(ebx, ecx, times_4, 10000));
216 __ shld(edx, Operand(ebx, ecx, times_4, 10000));
220 __ shl(Operand(ebx, ecx, times_4, 10000), 1);
221 __ shl(Operand(ebx, ecx, times_4, 10000), 6);
222 __ shl_cl(Operand(ebx, ecx, times_4, 10000));
223 __ shrd(edx, Operand(ebx, ecx, times_4, 10000));
227 __ shr(Operand(ebx, ecx, times_4, 10000), 1);
228 __ shr(Operand(ebx, ecx, times_4, 10000), 6);
229 __ shr_cl(Operand(ebx, ecx, times_4, 10000));
236 __ add(ebx, Immediate(12));
237 __ add(Operand(edx, ecx, times_4, 10000), Immediate(12));
242 __ cmp(ebx, Immediate(12));
243 __ cmp(Operand(edx, ecx, times_4, 10000), Immediate(12));
248 __ sub(ebx, Immediate(12));
249 __ sub(Operand(edx, ecx, times_4, 10000), Immediate(12));
253 __ imul(edx, ecx, 12);
254 __ imul(edx, ecx, 1000);
261 __ sub(edx, Operand(ebx, ecx, times_4, 10000));
264 __ test(edx, Immediate(12345));
265 __ test(edx, Operand(ebx, ecx, times_8, 10000));
266 __ test(Operand(esi, edi, times_1, -20000000), Immediate(300000000));
267 __ test_b(edx, Operand(ecx, ebx, times_2, 1000));
268 __ test_b(Operand(eax, -20), 0x9A);
272 __ xor_(edx, Operand(ebx, ecx, times_8, 10000));
273 __ bts(Operand(ebx, ecx, times_8, 10000), edx);
288 __ call(Operand(ebx, ecx, times_4, 10000));
290 Handle<Code> ic(LoadIC::initialize_stub(isolate, NOT_CONTEXTUAL));
291 __ call(ic, RelocInfo::CODE_TARGET);
293 __ call(FUNCTION_ADDR(DummyStaticFunction), RelocInfo::RUNTIME_ENTRY);
297 __ jmp(Operand(ebx, ecx, times_4, 10000));
298 ExternalReference after_break_target =
299 ExternalReference::debug_after_break_target_address(isolate);
300 __ jmp(Operand::StaticVariable(after_break_target));
301 __ jmp(ic, RelocInfo::CODE_TARGET);
308 __ j(overflow, &Ljcc);
309 __ j(no_overflow, &Ljcc);
311 __ j(above_equal, &Ljcc);
313 __ j(not_equal, &Ljcc);
314 __ j(below_equal, &Ljcc);
317 __ j(not_sign, &Ljcc);
318 __ j(parity_even, &Ljcc);
319 __ j(parity_odd, &Ljcc);
321 __ j(greater_equal, &Ljcc);
322 __ j(less_equal, &Ljcc);
323 __ j(greater, &Ljcc);
327 __ j(overflow, &Ljcc);
328 __ j(no_overflow, &Ljcc);
330 __ j(above_equal, &Ljcc);
332 __ j(not_equal, &Ljcc);
333 __ j(below_equal, &Ljcc);
336 __ j(not_sign, &Ljcc);
337 __ j(parity_even, &Ljcc);
338 __ j(parity_odd, &Ljcc);
340 __ j(greater_equal, &Ljcc);
341 __ j(less_equal, &Ljcc);
342 __ j(greater, &Ljcc);
359 __ fld_s(Operand(ebx, ecx, times_4, 10000));
360 __ fstp_s(Operand(ebx, ecx, times_4, 10000));
362 __ fld_d(Operand(ebx, ecx, times_4, 10000));
363 __ fstp_d(Operand(ebx, ecx, times_4, 10000));
366 __ fild_s(Operand(ebx, ecx, times_4, 10000));
367 __ fistp_s(Operand(ebx, ecx, times_4, 10000));
368 __ fild_d(Operand(ebx, ecx, times_4, 10000));
369 __ fistp_d(Operand(ebx, ecx, times_4, 10000));
387 __ fldcw(Operand(ebx, ecx, times_4, 10000));
388 __ fnstcw(Operand(ebx, ecx, times_4, 10000));
389 __ fadd_d(Operand(ebx, ecx, times_4, 10000));
390 __ fnsave(Operand(ebx, ecx, times_4, 10000));
391 __ frstor(Operand(ebx, ecx, times_4, 10000));
398 __ xchg(ebx, Operand(esp, 12));
402 for (int i = 0; i < 16; i++) {
410 Handle<Code> code = isolate->factory()->NewCode(
411 desc, Code::ComputeFlags(Code::STUB), Handle<Code>());
416 byte* begin = code->instruction_start();
417 byte* end = begin + code->instruction_size();
418 disasm::Disassembler::Disassemble(stdout, begin, end);