| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 // Create a code patcher. | 103 // Create a code patcher. |
| 104 CodePatcher patcher(pc_, code_size); | 104 CodePatcher patcher(pc_, code_size); |
| 105 | 105 |
| 106 // Add a label for checking the size of the code used for returning. | 106 // Add a label for checking the size of the code used for returning. |
| 107 #ifdef DEBUG | 107 #ifdef DEBUG |
| 108 Label check_codesize; | 108 Label check_codesize; |
| 109 patcher.masm()->bind(&check_codesize); | 109 patcher.masm()->bind(&check_codesize); |
| 110 #endif | 110 #endif |
| 111 | 111 |
| 112 // Patch the code. | 112 // Patch the code. |
| 113 patcher.masm()->movq(r10, target, RelocInfo::NONE64); | 113 patcher.masm()->movq(kScratchRegister, target, RelocInfo::NONE64); |
| 114 patcher.masm()->call(r10); | 114 patcher.masm()->call(kScratchRegister); |
| 115 | 115 |
| 116 // Check that the size of the code generated is as expected. | 116 // Check that the size of the code generated is as expected. |
| 117 ASSERT_EQ(Assembler::kCallSequenceLength, | 117 ASSERT_EQ(Assembler::kCallSequenceLength, |
| 118 patcher.masm()->SizeOfCodeGeneratedSince(&check_codesize)); | 118 patcher.masm()->SizeOfCodeGeneratedSince(&check_codesize)); |
| 119 | 119 |
| 120 // Add the requested number of int3 instructions after the call. | 120 // Add the requested number of int3 instructions after the call. |
| 121 for (int i = 0; i < guard_bytes; i++) { | 121 for (int i = 0; i < guard_bytes; i++) { |
| 122 patcher.masm()->int3(); | 122 patcher.masm()->int3(); |
| 123 } | 123 } |
| 124 } | 124 } |
| (...skipping 1333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1458 ASSERT(rmode > RelocInfo::LAST_GCED_ENUM); | 1458 ASSERT(rmode > RelocInfo::LAST_GCED_ENUM); |
| 1459 EnsureSpace ensure_space(this); | 1459 EnsureSpace ensure_space(this); |
| 1460 emit_rex_64(dst); | 1460 emit_rex_64(dst); |
| 1461 emit(0xB8 | dst.low_bits()); | 1461 emit(0xB8 | dst.low_bits()); |
| 1462 emitp(value, rmode); | 1462 emitp(value, rmode); |
| 1463 } | 1463 } |
| 1464 | 1464 |
| 1465 | 1465 |
| 1466 void Assembler::movq(Register dst, int64_t value, RelocInfo::Mode rmode) { | 1466 void Assembler::movq(Register dst, int64_t value, RelocInfo::Mode rmode) { |
| 1467 // Non-relocatable values might not need a 64-bit representation. | 1467 // Non-relocatable values might not need a 64-bit representation. |
| 1468 if (RelocInfo::IsNone(rmode)) { | 1468 ASSERT(RelocInfo::IsNone(rmode)); |
| 1469 if (is_uint32(value)) { | 1469 if (is_uint32(value)) { |
| 1470 movl(dst, Immediate(static_cast<int32_t>(value))); | 1470 movl(dst, Immediate(static_cast<int32_t>(value))); |
| 1471 return; | 1471 } else if (is_int32(value)) { |
| 1472 } else if (is_int32(value)) { | 1472 movq(dst, Immediate(static_cast<int32_t>(value))); |
| 1473 movq(dst, Immediate(static_cast<int32_t>(value))); | 1473 } else { |
| 1474 return; | |
| 1475 } | |
| 1476 // Value cannot be represented by 32 bits, so do a full 64 bit immediate | 1474 // Value cannot be represented by 32 bits, so do a full 64 bit immediate |
| 1477 // value. | 1475 // value. |
| 1476 EnsureSpace ensure_space(this); |
| 1477 emit_rex_64(dst); |
| 1478 emit(0xB8 | dst.low_bits()); |
| 1479 emitq(value); |
| 1478 } | 1480 } |
| 1479 EnsureSpace ensure_space(this); | |
| 1480 emit_rex_64(dst); | |
| 1481 emit(0xB8 | dst.low_bits()); | |
| 1482 emitq(value, rmode); | |
| 1483 } | 1481 } |
| 1484 | 1482 |
| 1485 | 1483 |
| 1486 void Assembler::movq(Register dst, ExternalReference ref) { | 1484 void Assembler::movq(Register dst, ExternalReference ref) { |
| 1487 int64_t value = reinterpret_cast<int64_t>(ref.address()); | 1485 Address value = reinterpret_cast<Address>(ref.address()); |
| 1488 movq(dst, value, RelocInfo::EXTERNAL_REFERENCE); | 1486 movq(dst, value, RelocInfo::EXTERNAL_REFERENCE); |
| 1489 } | 1487 } |
| 1490 | 1488 |
| 1491 | 1489 |
| 1492 void Assembler::movq(const Operand& dst, Immediate value) { | 1490 void Assembler::movq(const Operand& dst, Immediate value) { |
| 1493 EnsureSpace ensure_space(this); | 1491 EnsureSpace ensure_space(this); |
| 1494 emit_rex_64(dst); | 1492 emit_rex_64(dst); |
| 1495 emit(0xC7); | 1493 emit(0xC7); |
| 1496 emit_operand(0, dst); | 1494 emit_operand(0, dst); |
| 1497 emit(value); | 1495 emit(value); |
| (...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1892 | 1890 |
| 1893 void Assembler::shrd(Register dst, Register src) { | 1891 void Assembler::shrd(Register dst, Register src) { |
| 1894 EnsureSpace ensure_space(this); | 1892 EnsureSpace ensure_space(this); |
| 1895 emit_rex_64(src, dst); | 1893 emit_rex_64(src, dst); |
| 1896 emit(0x0F); | 1894 emit(0x0F); |
| 1897 emit(0xAD); | 1895 emit(0xAD); |
| 1898 emit_modrm(src, dst); | 1896 emit_modrm(src, dst); |
| 1899 } | 1897 } |
| 1900 | 1898 |
| 1901 | 1899 |
| 1902 void Assembler::xchg(Register dst, Register src) { | 1900 void Assembler::xchgq(Register dst, Register src) { |
| 1903 EnsureSpace ensure_space(this); | 1901 EnsureSpace ensure_space(this); |
| 1904 if (src.is(rax) || dst.is(rax)) { // Single-byte encoding | 1902 if (src.is(rax) || dst.is(rax)) { // Single-byte encoding |
| 1905 Register other = src.is(rax) ? dst : src; | 1903 Register other = src.is(rax) ? dst : src; |
| 1906 emit_rex_64(other); | 1904 emit_rex_64(other); |
| 1907 emit(0x90 | other.low_bits()); | 1905 emit(0x90 | other.low_bits()); |
| 1908 } else if (dst.low_bits() == 4) { | 1906 } else if (dst.low_bits() == 4) { |
| 1909 emit_rex_64(dst, src); | 1907 emit_rex_64(dst, src); |
| 1910 emit(0x87); | 1908 emit(0x87); |
| 1911 emit_modrm(dst, src); | 1909 emit_modrm(dst, src); |
| 1912 } else { | 1910 } else { |
| 1913 emit_rex_64(src, dst); | 1911 emit_rex_64(src, dst); |
| 1914 emit(0x87); | 1912 emit(0x87); |
| 1915 emit_modrm(src, dst); | 1913 emit_modrm(src, dst); |
| 1916 } | 1914 } |
| 1917 } | 1915 } |
| 1918 | 1916 |
| 1919 | 1917 |
| 1918 void Assembler::xchgl(Register dst, Register src) { |
| 1919 EnsureSpace ensure_space(this); |
| 1920 if (src.is(rax) || dst.is(rax)) { // Single-byte encoding |
| 1921 Register other = src.is(rax) ? dst : src; |
| 1922 emit_optional_rex_32(other); |
| 1923 emit(0x90 | other.low_bits()); |
| 1924 } else if (dst.low_bits() == 4) { |
| 1925 emit_optional_rex_32(dst, src); |
| 1926 emit(0x87); |
| 1927 emit_modrm(dst, src); |
| 1928 } else { |
| 1929 emit_optional_rex_32(src, dst); |
| 1930 emit(0x87); |
| 1931 emit_modrm(src, dst); |
| 1932 } |
| 1933 } |
| 1934 |
| 1935 |
| 1920 void Assembler::store_rax(void* dst, RelocInfo::Mode mode) { | 1936 void Assembler::store_rax(void* dst, RelocInfo::Mode mode) { |
| 1921 EnsureSpace ensure_space(this); | 1937 EnsureSpace ensure_space(this); |
| 1922 emit(0x48); // REX.W | 1938 emit(0x48); // REX.W |
| 1923 emit(0xA3); | 1939 emit(0xA3); |
| 1924 emitp(dst, mode); | 1940 emitp(dst, mode); |
| 1925 } | 1941 } |
| 1926 | 1942 |
| 1927 | 1943 |
| 1928 void Assembler::store_rax(ExternalReference ref) { | 1944 void Assembler::store_rax(ExternalReference ref) { |
| 1929 store_rax(ref.address(), RelocInfo::EXTERNAL_REFERENCE); | 1945 store_rax(ref.address(), RelocInfo::EXTERNAL_REFERENCE); |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2028 return; | 2044 return; |
| 2029 } | 2045 } |
| 2030 EnsureSpace ensure_space(this); | 2046 EnsureSpace ensure_space(this); |
| 2031 emit_optional_rex_32(rax, op); | 2047 emit_optional_rex_32(rax, op); |
| 2032 emit(0xF7); | 2048 emit(0xF7); |
| 2033 emit_operand(rax, op); // Operation code 0 | 2049 emit_operand(rax, op); // Operation code 0 |
| 2034 emit(mask); | 2050 emit(mask); |
| 2035 } | 2051 } |
| 2036 | 2052 |
| 2037 | 2053 |
| 2054 void Assembler::testl(const Operand& op, Register reg) { |
| 2055 EnsureSpace ensure_space(this); |
| 2056 emit_optional_rex_32(reg, op); |
| 2057 emit(0x85); |
| 2058 emit_operand(reg, op); |
| 2059 } |
| 2060 |
| 2061 |
| 2038 void Assembler::testq(const Operand& op, Register reg) { | 2062 void Assembler::testq(const Operand& op, Register reg) { |
| 2039 EnsureSpace ensure_space(this); | 2063 EnsureSpace ensure_space(this); |
| 2040 emit_rex_64(reg, op); | 2064 emit_rex_64(reg, op); |
| 2041 emit(0x85); | 2065 emit(0x85); |
| 2042 emit_operand(reg, op); | 2066 emit_operand(reg, op); |
| 2043 } | 2067 } |
| 2044 | 2068 |
| 2045 | 2069 |
| 2046 void Assembler::testq(Register dst, Register src) { | 2070 void Assembler::testq(Register dst, Register src) { |
| 2047 EnsureSpace ensure_space(this); | 2071 EnsureSpace ensure_space(this); |
| (...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2547 EnsureSpace ensure_space(this); | 2571 EnsureSpace ensure_space(this); |
| 2548 emit(0xF3); | 2572 emit(0xF3); |
| 2549 emit_rex_64(dst, src); | 2573 emit_rex_64(dst, src); |
| 2550 emit(0x0F); | 2574 emit(0x0F); |
| 2551 emit(0x6F); | 2575 emit(0x6F); |
| 2552 emit_sse_operand(dst, src); | 2576 emit_sse_operand(dst, src); |
| 2553 } | 2577 } |
| 2554 | 2578 |
| 2555 | 2579 |
| 2556 void Assembler::extractps(Register dst, XMMRegister src, byte imm8) { | 2580 void Assembler::extractps(Register dst, XMMRegister src, byte imm8) { |
| 2557 ASSERT(CpuFeatures::IsSupported(SSE4_1)); | 2581 ASSERT(IsEnabled(SSE4_1)); |
| 2558 ASSERT(is_uint8(imm8)); | 2582 ASSERT(is_uint8(imm8)); |
| 2559 EnsureSpace ensure_space(this); | 2583 EnsureSpace ensure_space(this); |
| 2560 emit(0x66); | 2584 emit(0x66); |
| 2561 emit_optional_rex_32(dst, src); | 2585 emit_optional_rex_32(src, dst); |
| 2562 emit(0x0F); | 2586 emit(0x0F); |
| 2563 emit(0x3A); | 2587 emit(0x3A); |
| 2564 emit(0x17); | 2588 emit(0x17); |
| 2565 emit_sse_operand(dst, src); | 2589 emit_sse_operand(src, dst); |
| 2566 emit(imm8); | 2590 emit(imm8); |
| 2567 } | 2591 } |
| 2568 | 2592 |
| 2569 | 2593 |
| 2570 void Assembler::movsd(const Operand& dst, XMMRegister src) { | 2594 void Assembler::movsd(const Operand& dst, XMMRegister src) { |
| 2571 EnsureSpace ensure_space(this); | 2595 EnsureSpace ensure_space(this); |
| 2572 emit(0xF2); // double | 2596 emit(0xF2); // double |
| 2573 emit_optional_rex_32(src, dst); | 2597 emit_optional_rex_32(src, dst); |
| 2574 emit(0x0F); | 2598 emit(0x0F); |
| 2575 emit(0x11); // store | 2599 emit(0x11); // store |
| (...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2997 void Assembler::dd(uint32_t data) { | 3021 void Assembler::dd(uint32_t data) { |
| 2998 EnsureSpace ensure_space(this); | 3022 EnsureSpace ensure_space(this); |
| 2999 emitl(data); | 3023 emitl(data); |
| 3000 } | 3024 } |
| 3001 | 3025 |
| 3002 | 3026 |
| 3003 // Relocation information implementations. | 3027 // Relocation information implementations. |
| 3004 | 3028 |
| 3005 void Assembler::RecordRelocInfo(RelocInfo::Mode rmode, intptr_t data) { | 3029 void Assembler::RecordRelocInfo(RelocInfo::Mode rmode, intptr_t data) { |
| 3006 ASSERT(!RelocInfo::IsNone(rmode)); | 3030 ASSERT(!RelocInfo::IsNone(rmode)); |
| 3007 // Don't record external references unless the heap will be serialized. | |
| 3008 if (rmode == RelocInfo::EXTERNAL_REFERENCE) { | 3031 if (rmode == RelocInfo::EXTERNAL_REFERENCE) { |
| 3032 // Don't record external references unless the heap will be serialized. |
| 3009 #ifdef DEBUG | 3033 #ifdef DEBUG |
| 3010 if (!Serializer::enabled()) { | 3034 if (!Serializer::enabled()) { |
| 3011 Serializer::TooLateToEnableNow(); | 3035 Serializer::TooLateToEnableNow(); |
| 3012 } | 3036 } |
| 3013 #endif | 3037 #endif |
| 3014 if (!Serializer::enabled() && !emit_debug_code()) { | 3038 if (!Serializer::enabled() && !emit_debug_code()) { |
| 3015 return; | 3039 return; |
| 3016 } | 3040 } |
| 3041 } else if (rmode == RelocInfo::CODE_AGE_SEQUENCE) { |
| 3042 // Don't record psuedo relocation info for code age sequence mode. |
| 3043 return; |
| 3017 } | 3044 } |
| 3018 RelocInfo rinfo(pc_, rmode, data, NULL); | 3045 RelocInfo rinfo(pc_, rmode, data, NULL); |
| 3019 reloc_info_writer.Write(&rinfo); | 3046 reloc_info_writer.Write(&rinfo); |
| 3020 } | 3047 } |
| 3021 | 3048 |
| 3022 | 3049 |
| 3023 void Assembler::RecordJSReturn() { | 3050 void Assembler::RecordJSReturn() { |
| 3024 positions_recorder()->WriteRecordedPositions(); | 3051 positions_recorder()->WriteRecordedPositions(); |
| 3025 EnsureSpace ensure_space(this); | 3052 EnsureSpace ensure_space(this); |
| 3026 RecordRelocInfo(RelocInfo::JS_RETURN); | 3053 RecordRelocInfo(RelocInfo::JS_RETURN); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 3051 bool RelocInfo::IsCodedSpecially() { | 3078 bool RelocInfo::IsCodedSpecially() { |
| 3052 // The deserializer needs to know whether a pointer is specially coded. Being | 3079 // The deserializer needs to know whether a pointer is specially coded. Being |
| 3053 // specially coded on x64 means that it is a relative 32 bit address, as used | 3080 // specially coded on x64 means that it is a relative 32 bit address, as used |
| 3054 // by branch instructions. | 3081 // by branch instructions. |
| 3055 return (1 << rmode_) & kApplyMask; | 3082 return (1 << rmode_) & kApplyMask; |
| 3056 } | 3083 } |
| 3057 | 3084 |
| 3058 } } // namespace v8::internal | 3085 } } // namespace v8::internal |
| 3059 | 3086 |
| 3060 #endif // V8_TARGET_ARCH_X64 | 3087 #endif // V8_TARGET_ARCH_X64 |
| OLD | NEW |