| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "vm/globals.h" | 5 #include "vm/globals.h" |
| 6 #if defined(TARGET_ARCH_ARM) | 6 #if defined(TARGET_ARCH_ARM) |
| 7 | 7 |
| 8 #include "vm/assembler.h" | 8 #include "vm/assembler.h" |
| 9 #include "vm/cpu.h" | 9 #include "vm/cpu.h" |
| 10 #include "vm/instructions.h" | 10 #include "vm/instructions.h" |
| 11 #include "vm/stub_code.h" | 11 #include "vm/stub_code.h" |
| 12 #include "vm/unit_test.h" | 12 #include "vm/unit_test.h" |
| 13 | 13 |
| 14 namespace dart { | 14 namespace dart { |
| 15 | 15 |
| 16 #define __ assembler-> | 16 #define __ assembler-> |
| 17 | 17 |
| 18 ASSEMBLER_TEST_GENERATE(Call, assembler) { | 18 ASSEMBLER_TEST_GENERATE(Call, assembler) { |
| 19 // Code accessing pp is generated, but not executed. Uninitialized pp is OK. | 19 // Code accessing pp is generated, but not executed. Uninitialized pp is OK. |
| 20 __ set_constant_pool_allowed(true); | 20 __ set_constant_pool_allowed(true); |
| 21 __ BranchLinkPatchable(&StubCode::InvokeDartCodeLabel()); | 21 __ BranchLinkPatchable(*StubCode::InvokeDartCode_entry()); |
| 22 __ Ret(); | 22 __ Ret(); |
| 23 } | 23 } |
| 24 | 24 |
| 25 | 25 |
| 26 ASSEMBLER_TEST_RUN(Call, test) { | 26 ASSEMBLER_TEST_RUN(Call, test) { |
| 27 // The return address, which must be the address of an instruction contained | 27 // The return address, which must be the address of an instruction contained |
| 28 // in the code, points to the Ret instruction above, i.e. one instruction | 28 // in the code, points to the Ret instruction above, i.e. one instruction |
| 29 // before the end of the code buffer. | 29 // before the end of the code buffer. |
| 30 CallPattern call(test->entry() + test->code().Size() - Instr::kInstrSize, | 30 CallPattern call(test->entry() + test->code().Size() - Instr::kInstrSize, |
| 31 test->code()); | 31 test->code()); |
| 32 EXPECT_EQ(StubCode::InvokeDartCodeLabel().address(), | 32 EXPECT_EQ(StubCode::InvokeDartCode_entry()->label().address(), |
| 33 call.TargetAddress()); | 33 call.TargetAddress()); |
| 34 } | 34 } |
| 35 | 35 |
| 36 | 36 |
| 37 ASSEMBLER_TEST_GENERATE(Jump, assembler) { | 37 ASSEMBLER_TEST_GENERATE(Jump, assembler) { |
| 38 __ BranchPatchable(&StubCode::InvokeDartCodeLabel()); | 38 __ BranchPatchable(*StubCode::InvokeDartCode_entry()); |
| 39 const ExternalLabel array_label(StubCode::AllocateArrayEntryPoint()); | 39 __ BranchPatchable(*StubCode::AllocateArray_entry()); |
| 40 __ BranchPatchable(&array_label); | |
| 41 } | 40 } |
| 42 | 41 |
| 43 | 42 |
| 44 ASSEMBLER_TEST_RUN(Jump, test) { | 43 ASSEMBLER_TEST_RUN(Jump, test) { |
| 45 const Code& code = test->code(); | 44 const Code& code = test->code(); |
| 46 const Instructions& instrs = Instructions::Handle(code.instructions()); | 45 const Instructions& instrs = Instructions::Handle(code.instructions()); |
| 47 bool status = | 46 bool status = |
| 48 VirtualMemory::Protect(reinterpret_cast<void*>(instrs.EntryPoint()), | 47 VirtualMemory::Protect(reinterpret_cast<void*>(instrs.EntryPoint()), |
| 49 instrs.size(), | 48 instrs.size(), |
| 50 VirtualMemory::kReadWrite); | 49 VirtualMemory::kReadWrite); |
| 51 EXPECT(status); | 50 EXPECT(status); |
| 52 JumpPattern jump1(test->entry(), test->code()); | 51 JumpPattern jump1(test->entry(), test->code()); |
| 53 EXPECT_EQ(StubCode::InvokeDartCodeLabel().address(), | 52 EXPECT_EQ(StubCode::InvokeDartCode_entry()->label().address(), |
| 54 jump1.TargetAddress()); | 53 jump1.TargetAddress()); |
| 55 JumpPattern jump2(test->entry() + jump1.pattern_length_in_bytes(), | 54 JumpPattern jump2(test->entry() + jump1.pattern_length_in_bytes(), |
| 56 test->code()); | 55 test->code()); |
| 57 const Code& array_stub = | 56 const Code& array_stub = |
| 58 Code::Handle(StubCode::AllocateArray_entry()->code()); | 57 Code::Handle(StubCode::AllocateArray_entry()->code()); |
| 59 EXPECT_EQ(array_stub.EntryPoint(), jump2.TargetAddress()); | 58 EXPECT_EQ(array_stub.EntryPoint(), jump2.TargetAddress()); |
| 60 uword target1 = jump1.TargetAddress(); | 59 uword target1 = jump1.TargetAddress(); |
| 61 uword target2 = jump2.TargetAddress(); | 60 uword target2 = jump2.TargetAddress(); |
| 62 jump1.SetTargetAddress(target2); | 61 jump1.SetTargetAddress(target2); |
| 63 jump2.SetTargetAddress(target1); | 62 jump2.SetTargetAddress(target1); |
| 64 EXPECT_EQ(array_stub.EntryPoint(), jump1.TargetAddress()); | 63 EXPECT_EQ(array_stub.EntryPoint(), jump1.TargetAddress()); |
| 65 EXPECT_EQ(StubCode::InvokeDartCodeLabel().address(), | 64 EXPECT_EQ(StubCode::InvokeDartCode_entry()->label().address(), |
| 66 jump2.TargetAddress()); | 65 jump2.TargetAddress()); |
| 67 } | 66 } |
| 68 | 67 |
| 69 | 68 |
| 70 #if defined(USING_SIMULATOR) | 69 #if defined(USING_SIMULATOR) |
| 71 ASSEMBLER_TEST_GENERATE(JumpARMv6, assembler) { | 70 ASSEMBLER_TEST_GENERATE(JumpARMv6, assembler) { |
| 72 // ARMv7 is the default. | 71 // ARMv7 is the default. |
| 73 HostCPUFeatures::set_arm_version(ARMv6); | 72 HostCPUFeatures::set_arm_version(ARMv6); |
| 74 __ BranchPatchable(&StubCode::InvokeDartCodeLabel()); | 73 __ BranchPatchable(*StubCode::InvokeDartCode_entry()); |
| 75 const ExternalLabel array_label(StubCode::AllocateArrayEntryPoint()); | 74 __ BranchPatchable(*StubCode::AllocateArray_entry()); |
| 76 __ BranchPatchable(&array_label); | |
| 77 HostCPUFeatures::set_arm_version(ARMv7); | 75 HostCPUFeatures::set_arm_version(ARMv7); |
| 78 } | 76 } |
| 79 | 77 |
| 80 | 78 |
| 81 ASSEMBLER_TEST_RUN(JumpARMv6, test) { | 79 ASSEMBLER_TEST_RUN(JumpARMv6, test) { |
| 82 HostCPUFeatures::set_arm_version(ARMv6); | 80 HostCPUFeatures::set_arm_version(ARMv6); |
| 83 const Code& code = test->code(); | 81 const Code& code = test->code(); |
| 84 const Instructions& instrs = Instructions::Handle(code.instructions()); | 82 const Instructions& instrs = Instructions::Handle(code.instructions()); |
| 85 bool status = | 83 bool status = |
| 86 VirtualMemory::Protect(reinterpret_cast<void*>(instrs.EntryPoint()), | 84 VirtualMemory::Protect(reinterpret_cast<void*>(instrs.EntryPoint()), |
| 87 instrs.size(), | 85 instrs.size(), |
| 88 VirtualMemory::kReadWrite); | 86 VirtualMemory::kReadWrite); |
| 89 EXPECT(status); | 87 EXPECT(status); |
| 90 JumpPattern jump1(test->entry(), test->code()); | 88 JumpPattern jump1(test->entry(), test->code()); |
| 91 EXPECT_EQ(StubCode::InvokeDartCodeLabel().address(), | 89 EXPECT_EQ(StubCode::InvokeDartCode_entry()->label().address(), |
| 92 jump1.TargetAddress()); | 90 jump1.TargetAddress()); |
| 93 JumpPattern jump2(test->entry() + jump1.pattern_length_in_bytes(), | 91 JumpPattern jump2(test->entry() + jump1.pattern_length_in_bytes(), |
| 94 test->code()); | 92 test->code()); |
| 95 const Code& array_stub = | 93 const Code& array_stub = |
| 96 Code::Handle(StubCode::AllocateArray_entry()->code()); | 94 Code::Handle(StubCode::AllocateArray_entry()->code()); |
| 97 EXPECT_EQ(array_stub.EntryPoint(), jump2.TargetAddress()); | 95 EXPECT_EQ(array_stub.EntryPoint(), jump2.TargetAddress()); |
| 98 uword target1 = jump1.TargetAddress(); | 96 uword target1 = jump1.TargetAddress(); |
| 99 uword target2 = jump2.TargetAddress(); | 97 uword target2 = jump2.TargetAddress(); |
| 100 jump1.SetTargetAddress(target2); | 98 jump1.SetTargetAddress(target2); |
| 101 jump2.SetTargetAddress(target1); | 99 jump2.SetTargetAddress(target1); |
| 102 EXPECT_EQ(array_stub.EntryPoint(), jump1.TargetAddress()); | 100 EXPECT_EQ(array_stub.EntryPoint(), jump1.TargetAddress()); |
| 103 EXPECT_EQ(StubCode::InvokeDartCodeLabel().address(), | 101 EXPECT_EQ(StubCode::InvokeDartCode_entry()->label().address(), |
| 104 jump2.TargetAddress()); | 102 jump2.TargetAddress()); |
| 105 HostCPUFeatures::set_arm_version(ARMv7); | 103 HostCPUFeatures::set_arm_version(ARMv7); |
| 106 } | 104 } |
| 107 #endif | 105 #endif |
| 108 | 106 |
| 109 } // namespace dart | 107 } // namespace dart |
| 110 | 108 |
| 111 #endif // defined TARGET_ARCH_ARM | 109 #endif // defined TARGET_ARCH_ARM |
| OLD | NEW |