]> git.saurik.com Git - apple/javascriptcore.git/blob - assembler/MacroAssemblerARMv7.cpp
JavaScriptCore-7601.1.46.3.tar.gz
[apple/javascriptcore.git] / assembler / MacroAssemblerARMv7.cpp
1 /*
2 * Copyright (C) 2013, 2014 Apple Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26 #include "config.h"
27
28 #if ENABLE(ASSEMBLER) && CPU(ARM_THUMB2)
29 #include "MacroAssemblerARMv7.h"
30
31 namespace JSC {
32
33 #if ENABLE(MASM_PROBE)
34
35 #define INDENT printIndent(indentation)
36
37 void MacroAssemblerARMv7::printCPURegisters(CPUState& cpu, int indentation)
38 {
39 #define PRINT_GPREGISTER(_type, _regName) { \
40 int32_t value = reinterpret_cast<int32_t>(cpu._regName); \
41 INDENT, dataLogF("%5s: 0x%08x %d\n", #_regName, value, value) ; \
42 }
43 FOR_EACH_CPU_GPREGISTER(PRINT_GPREGISTER)
44 FOR_EACH_CPU_SPECIAL_REGISTER(PRINT_GPREGISTER)
45 #undef PRINT_GPREGISTER
46
47 #define PRINT_FPREGISTER(_type, _regName) { \
48 uint64_t* u = reinterpret_cast<uint64_t*>(&cpu._regName); \
49 double* d = reinterpret_cast<double*>(&cpu._regName); \
50 INDENT, dataLogF("%5s: 0x%016llx %.13g\n", #_regName, *u, *d); \
51 }
52 FOR_EACH_CPU_FPREGISTER(PRINT_FPREGISTER)
53 #undef PRINT_FPREGISTER
54 }
55
56 #undef INDENT
57
58 void MacroAssemblerARMv7::printRegister(MacroAssemblerARMv7::CPUState& cpu, RegisterID regID)
59 {
60 const char* name = CPUState::registerName(regID);
61 union {
62 void* voidPtr;
63 intptr_t intptrValue;
64 } u;
65 u.voidPtr = cpu.registerValue(regID);
66 dataLogF("%s:<%p %ld>", name, u.voidPtr, u.intptrValue);
67 }
68
69 void MacroAssemblerARMv7::printRegister(MacroAssemblerARMv7::CPUState& cpu, FPRegisterID regID)
70 {
71 const char* name = CPUState::registerName(regID);
72 union {
73 double doubleValue;
74 uint64_t uint64Value;
75 } u;
76 u.doubleValue = cpu.registerValue(regID);
77 dataLogF("%s:<0x%016llx %.13g>", name, u.uint64Value, u.doubleValue);
78 }
79
80 extern "C" void ctiMasmProbeTrampoline();
81
82 // For details on "What code is emitted for the probe?" and "What values are in
83 // the saved registers?", see comment for MacroAssemblerX86Common::probe() in
84 // MacroAssemblerX86Common.cpp.
85
86 void MacroAssemblerARMv7::probe(MacroAssemblerARMv7::ProbeFunction function, void* arg1, void* arg2)
87 {
88 push(RegisterID::lr);
89 push(RegisterID::lr);
90 add32(TrustedImm32(8), RegisterID::sp, RegisterID::lr);
91 store32(RegisterID::lr, ArmAddress(RegisterID::sp, 4));
92 push(RegisterID::ip);
93 push(RegisterID::r0);
94 // The following uses RegisterID::ip. So, they must come after we push ip above.
95 push(trustedImm32FromPtr(arg2));
96 push(trustedImm32FromPtr(arg1));
97 push(trustedImm32FromPtr(function));
98
99 move(trustedImm32FromPtr(ctiMasmProbeTrampoline), RegisterID::ip);
100 m_assembler.blx(RegisterID::ip);
101 }
102 #endif // ENABLE(MASM_PROBE)
103
104 } // namespace JSC
105
106 #endif // ENABLE(ASSEMBLER)
107