| 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 778 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 789 // The lr and pc are initialized to a known bad value that will cause an | 789 // The lr and pc are initialized to a known bad value that will cause an |
| 790 // access violation if the simulator ever tries to execute it. | 790 // access violation if the simulator ever tries to execute it. |
| 791 registers_[pc] = bad_lr; | 791 registers_[pc] = bad_lr; |
| 792 registers_[lr] = bad_lr; | 792 registers_[lr] = bad_lr; |
| 793 InitializeCoverage(); | 793 InitializeCoverage(); |
| 794 | 794 |
| 795 last_debugger_input_ = NULL; | 795 last_debugger_input_ = NULL; |
| 796 } | 796 } |
| 797 | 797 |
| 798 | 798 |
| 799 Simulator::~Simulator() { |
| 800 } |
| 801 |
| 802 |
| 799 // When the generated code calls an external reference we need to catch that in | 803 // When the generated code calls an external reference we need to catch that in |
| 800 // the simulator. The external reference will be a function compiled for the | 804 // the simulator. The external reference will be a function compiled for the |
| 801 // host architecture. We need to call that function instead of trying to | 805 // host architecture. We need to call that function instead of trying to |
| 802 // execute it with the simulator. We do that by redirecting the external | 806 // execute it with the simulator. We do that by redirecting the external |
| 803 // reference to a svc (Supervisor Call) instruction that is handled by | 807 // reference to a svc (Supervisor Call) instruction that is handled by |
| 804 // the simulator. We write the original destination of the jump just at a known | 808 // the simulator. We write the original destination of the jump just at a known |
| 805 // offset from the svc instruction so the simulator knows what to call. | 809 // offset from the svc instruction so the simulator knows what to call. |
| 806 class Redirection { | 810 class Redirection { |
| 807 public: | 811 public: |
| 808 Redirection(void* external_function, ExternalReference::Type type) | 812 Redirection(void* external_function, ExternalReference::Type type) |
| (...skipping 30 matching lines...) Expand all Loading... |
| 839 return new Redirection(external_function, type); | 843 return new Redirection(external_function, type); |
| 840 } | 844 } |
| 841 | 845 |
| 842 static Redirection* FromSwiInstruction(Instruction* swi_instruction) { | 846 static Redirection* FromSwiInstruction(Instruction* swi_instruction) { |
| 843 char* addr_of_swi = reinterpret_cast<char*>(swi_instruction); | 847 char* addr_of_swi = reinterpret_cast<char*>(swi_instruction); |
| 844 char* addr_of_redirection = | 848 char* addr_of_redirection = |
| 845 addr_of_swi - OFFSET_OF(Redirection, swi_instruction_); | 849 addr_of_swi - OFFSET_OF(Redirection, swi_instruction_); |
| 846 return reinterpret_cast<Redirection*>(addr_of_redirection); | 850 return reinterpret_cast<Redirection*>(addr_of_redirection); |
| 847 } | 851 } |
| 848 | 852 |
| 853 static void* ReverseRedirection(int32_t reg) { |
| 854 Redirection* redirection = FromSwiInstruction( |
| 855 reinterpret_cast<Instruction*>(reinterpret_cast<void*>(reg))); |
| 856 return redirection->external_function(); |
| 857 } |
| 858 |
| 849 private: | 859 private: |
| 850 void* external_function_; | 860 void* external_function_; |
| 851 uint32_t swi_instruction_; | 861 uint32_t swi_instruction_; |
| 852 ExternalReference::Type type_; | 862 ExternalReference::Type type_; |
| 853 Redirection* next_; | 863 Redirection* next_; |
| 854 }; | 864 }; |
| 855 | 865 |
| 856 | 866 |
| 857 void* Simulator::RedirectExternalReference(void* external_function, | 867 void* Simulator::RedirectExternalReference(void* external_function, |
| 858 ExternalReference::Type type) { | 868 ExternalReference::Type type) { |
| (...skipping 823 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1682 | 1692 |
| 1683 // These prototypes handle the four types of FP calls. | 1693 // These prototypes handle the four types of FP calls. |
| 1684 typedef int64_t (*SimulatorRuntimeCompareCall)(double darg0, double darg1); | 1694 typedef int64_t (*SimulatorRuntimeCompareCall)(double darg0, double darg1); |
| 1685 typedef double (*SimulatorRuntimeFPFPCall)(double darg0, double darg1); | 1695 typedef double (*SimulatorRuntimeFPFPCall)(double darg0, double darg1); |
| 1686 typedef double (*SimulatorRuntimeFPCall)(double darg0); | 1696 typedef double (*SimulatorRuntimeFPCall)(double darg0); |
| 1687 typedef double (*SimulatorRuntimeFPIntCall)(double darg0, int32_t arg0); | 1697 typedef double (*SimulatorRuntimeFPIntCall)(double darg0, int32_t arg0); |
| 1688 | 1698 |
| 1689 // This signature supports direct call in to API function native callback | 1699 // This signature supports direct call in to API function native callback |
| 1690 // (refer to InvocationCallback in v8.h). | 1700 // (refer to InvocationCallback in v8.h). |
| 1691 typedef void (*SimulatorRuntimeDirectApiCall)(int32_t arg0); | 1701 typedef void (*SimulatorRuntimeDirectApiCall)(int32_t arg0); |
| 1692 typedef void (*SimulatorRuntimeProfilingApiCall)(int32_t arg0, int32_t arg1); | 1702 typedef void (*SimulatorRuntimeProfilingApiCall)(int32_t arg0, void* arg1); |
| 1693 | 1703 |
| 1694 // This signature supports direct call to accessor getter callback. | 1704 // This signature supports direct call to accessor getter callback. |
| 1695 typedef void (*SimulatorRuntimeDirectGetterCall)(int32_t arg0, int32_t arg1); | 1705 typedef void (*SimulatorRuntimeDirectGetterCall)(int32_t arg0, int32_t arg1); |
| 1696 typedef void (*SimulatorRuntimeProfilingGetterCall)( | 1706 typedef void (*SimulatorRuntimeProfilingGetterCall)( |
| 1697 int32_t arg0, int32_t arg1, int32_t arg2); | 1707 int32_t arg0, int32_t arg1, void* arg2); |
| 1698 | 1708 |
| 1699 // Software interrupt instructions are used by the simulator to call into the | 1709 // Software interrupt instructions are used by the simulator to call into the |
| 1700 // C-based V8 runtime. | 1710 // C-based V8 runtime. |
| 1701 void Simulator::SoftwareInterrupt(Instruction* instr) { | 1711 void Simulator::SoftwareInterrupt(Instruction* instr) { |
| 1702 int svc = instr->SvcValue(); | 1712 int svc = instr->SvcValue(); |
| 1703 switch (svc) { | 1713 switch (svc) { |
| 1704 case kCallRtRedirected: { | 1714 case kCallRtRedirected: { |
| 1705 // Check if stack is aligned. Error if not aligned is reported below to | 1715 // Check if stack is aligned. Error if not aligned is reported below to |
| 1706 // include information on the function called. | 1716 // include information on the function called. |
| 1707 bool stack_aligned = | 1717 bool stack_aligned = |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1826 PrintF("Call to host function at %p args %08x %08x", | 1836 PrintF("Call to host function at %p args %08x %08x", |
| 1827 reinterpret_cast<void*>(external), arg0, arg1); | 1837 reinterpret_cast<void*>(external), arg0, arg1); |
| 1828 if (!stack_aligned) { | 1838 if (!stack_aligned) { |
| 1829 PrintF(" with unaligned stack %08x\n", get_register(sp)); | 1839 PrintF(" with unaligned stack %08x\n", get_register(sp)); |
| 1830 } | 1840 } |
| 1831 PrintF("\n"); | 1841 PrintF("\n"); |
| 1832 } | 1842 } |
| 1833 CHECK(stack_aligned); | 1843 CHECK(stack_aligned); |
| 1834 SimulatorRuntimeProfilingApiCall target = | 1844 SimulatorRuntimeProfilingApiCall target = |
| 1835 reinterpret_cast<SimulatorRuntimeProfilingApiCall>(external); | 1845 reinterpret_cast<SimulatorRuntimeProfilingApiCall>(external); |
| 1836 target(arg0, arg1); | 1846 target(arg0, Redirection::ReverseRedirection(arg1)); |
| 1837 } else if ( | 1847 } else if ( |
| 1838 redirection->type() == ExternalReference::DIRECT_GETTER_CALL) { | 1848 redirection->type() == ExternalReference::DIRECT_GETTER_CALL) { |
| 1839 if (::v8::internal::FLAG_trace_sim || !stack_aligned) { | 1849 if (::v8::internal::FLAG_trace_sim || !stack_aligned) { |
| 1840 PrintF("Call to host function at %p args %08x %08x", | 1850 PrintF("Call to host function at %p args %08x %08x", |
| 1841 reinterpret_cast<void*>(external), arg0, arg1); | 1851 reinterpret_cast<void*>(external), arg0, arg1); |
| 1842 if (!stack_aligned) { | 1852 if (!stack_aligned) { |
| 1843 PrintF(" with unaligned stack %08x\n", get_register(sp)); | 1853 PrintF(" with unaligned stack %08x\n", get_register(sp)); |
| 1844 } | 1854 } |
| 1845 PrintF("\n"); | 1855 PrintF("\n"); |
| 1846 } | 1856 } |
| 1847 CHECK(stack_aligned); | 1857 CHECK(stack_aligned); |
| 1848 SimulatorRuntimeDirectGetterCall target = | 1858 SimulatorRuntimeDirectGetterCall target = |
| 1849 reinterpret_cast<SimulatorRuntimeDirectGetterCall>(external); | 1859 reinterpret_cast<SimulatorRuntimeDirectGetterCall>(external); |
| 1850 target(arg0, arg1); | 1860 target(arg0, arg1); |
| 1851 } else if ( | 1861 } else if ( |
| 1852 redirection->type() == ExternalReference::PROFILING_GETTER_CALL) { | 1862 redirection->type() == ExternalReference::PROFILING_GETTER_CALL) { |
| 1853 if (::v8::internal::FLAG_trace_sim || !stack_aligned) { | 1863 if (::v8::internal::FLAG_trace_sim || !stack_aligned) { |
| 1854 PrintF("Call to host function at %p args %08x %08x %08x", | 1864 PrintF("Call to host function at %p args %08x %08x %08x", |
| 1855 reinterpret_cast<void*>(external), arg0, arg1, arg2); | 1865 reinterpret_cast<void*>(external), arg0, arg1, arg2); |
| 1856 if (!stack_aligned) { | 1866 if (!stack_aligned) { |
| 1857 PrintF(" with unaligned stack %08x\n", get_register(sp)); | 1867 PrintF(" with unaligned stack %08x\n", get_register(sp)); |
| 1858 } | 1868 } |
| 1859 PrintF("\n"); | 1869 PrintF("\n"); |
| 1860 } | 1870 } |
| 1861 CHECK(stack_aligned); | 1871 CHECK(stack_aligned); |
| 1862 SimulatorRuntimeProfilingGetterCall target = | 1872 SimulatorRuntimeProfilingGetterCall target = |
| 1863 reinterpret_cast<SimulatorRuntimeProfilingGetterCall>( | 1873 reinterpret_cast<SimulatorRuntimeProfilingGetterCall>( |
| 1864 external); | 1874 external); |
| 1865 target(arg0, arg1, arg2); | 1875 target(arg0, arg1, Redirection::ReverseRedirection(arg2)); |
| 1866 } else { | 1876 } else { |
| 1867 // builtin call. | 1877 // builtin call. |
| 1868 ASSERT(redirection->type() == ExternalReference::BUILTIN_CALL); | 1878 ASSERT(redirection->type() == ExternalReference::BUILTIN_CALL); |
| 1869 SimulatorRuntimeCall target = | 1879 SimulatorRuntimeCall target = |
| 1870 reinterpret_cast<SimulatorRuntimeCall>(external); | 1880 reinterpret_cast<SimulatorRuntimeCall>(external); |
| 1871 if (::v8::internal::FLAG_trace_sim || !stack_aligned) { | 1881 if (::v8::internal::FLAG_trace_sim || !stack_aligned) { |
| 1872 PrintF( | 1882 PrintF( |
| 1873 "Call to host function at %p " | 1883 "Call to host function at %p " |
| 1874 "args %08x, %08x, %08x, %08x, %08x, %08x", | 1884 "args %08x, %08x, %08x, %08x, %08x, %08x", |
| 1875 FUNCTION_ADDR(target), | 1885 FUNCTION_ADDR(target), |
| (...skipping 1964 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3840 uintptr_t address = *stack_slot; | 3850 uintptr_t address = *stack_slot; |
| 3841 set_register(sp, current_sp + sizeof(uintptr_t)); | 3851 set_register(sp, current_sp + sizeof(uintptr_t)); |
| 3842 return address; | 3852 return address; |
| 3843 } | 3853 } |
| 3844 | 3854 |
| 3845 } } // namespace v8::internal | 3855 } } // namespace v8::internal |
| 3846 | 3856 |
| 3847 #endif // USE_SIMULATOR | 3857 #endif // USE_SIMULATOR |
| 3848 | 3858 |
| 3849 #endif // V8_TARGET_ARCH_ARM | 3859 #endif // V8_TARGET_ARCH_ARM |
| OLD | NEW |