1/*
2 * Copyright (C) 2012 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#include "HostCallReturnValue.h"
28
29#if !ENABLE(C_LOOP)
30
31#include "CallFrame.h"
32#include "JSCJSValueInlines.h"
33#include "JSObject.h"
34#include "JSCInlines.h"
35#include <wtf/InlineASM.h>
36
37
38namespace JSC {
39
40// Note: getHostCallReturnValueWithExecState() needs to be placed before the
41// definition of getHostCallReturnValue() below because the Windows build
42// requires it.
43extern "C" EncodedJSValue HOST_CALL_RETURN_VALUE_OPTION getHostCallReturnValueWithExecState(ExecState* exec)
44{
45 if (!exec)
46 return JSValue::encode(JSValue());
47 return JSValue::encode(exec->vm().hostCallReturnValue);
48}
49
50#if COMPILER(GCC_COMPATIBLE) && CPU(X86_64)
51asm (
52".globl " SYMBOL_STRING(getHostCallReturnValue) "\n"
53HIDE_SYMBOL(getHostCallReturnValue) "\n"
54SYMBOL_STRING(getHostCallReturnValue) ":" "\n"
55 "lea -8(%rsp), %rdi\n"
56 "jmp " LOCAL_REFERENCE(getHostCallReturnValueWithExecState) "\n"
57);
58
59#elif COMPILER(GCC_COMPATIBLE) && CPU(X86)
60asm (
61".text" "\n" \
62".globl " SYMBOL_STRING(getHostCallReturnValue) "\n"
63HIDE_SYMBOL(getHostCallReturnValue) "\n"
64SYMBOL_STRING(getHostCallReturnValue) ":" "\n"
65 "push %ebp\n"
66 "mov %esp, %eax\n"
67 "leal -4(%esp), %esp\n"
68 "push %eax\n"
69 "call " LOCAL_REFERENCE(getHostCallReturnValueWithExecState) "\n"
70 "leal 8(%esp), %esp\n"
71 "pop %ebp\n"
72 "ret\n"
73);
74
75#elif COMPILER(GCC_COMPATIBLE) && CPU(ARM_THUMB2)
76asm (
77".text" "\n"
78".align 2" "\n"
79".globl " SYMBOL_STRING(getHostCallReturnValue) "\n"
80HIDE_SYMBOL(getHostCallReturnValue) "\n"
81".thumb" "\n"
82".thumb_func " THUMB_FUNC_PARAM(getHostCallReturnValue) "\n"
83SYMBOL_STRING(getHostCallReturnValue) ":" "\n"
84 "sub r0, sp, #8" "\n"
85 "b " LOCAL_REFERENCE(getHostCallReturnValueWithExecState) "\n"
86);
87
88#elif CPU(ARM64)
89asm (
90".text" "\n"
91".align 2" "\n"
92".globl " SYMBOL_STRING(getHostCallReturnValue) "\n"
93HIDE_SYMBOL(getHostCallReturnValue) "\n"
94SYMBOL_STRING(getHostCallReturnValue) ":" "\n"
95 "sub x0, sp, #16" "\n"
96 "b " LOCAL_REFERENCE(getHostCallReturnValueWithExecState) "\n"
97);
98
99#elif COMPILER(GCC_COMPATIBLE) && CPU(MIPS)
100
101#if WTF_MIPS_PIC
102#define LOAD_FUNCTION_TO_T9(function) \
103 ".set noreorder" "\n" \
104 ".cpload $25" "\n" \
105 ".set reorder" "\n" \
106 "la $t9, " LOCAL_REFERENCE(function) "\n"
107#else
108#define LOAD_FUNCTION_TO_T9(function) "" "\n"
109#endif
110
111asm (
112".text" "\n"
113".globl " SYMBOL_STRING(getHostCallReturnValue) "\n"
114HIDE_SYMBOL(getHostCallReturnValue) "\n"
115SYMBOL_STRING(getHostCallReturnValue) ":" "\n"
116 LOAD_FUNCTION_TO_T9(getHostCallReturnValueWithExecState)
117 "addi $a0, $sp, -8" "\n"
118 "b " LOCAL_REFERENCE(getHostCallReturnValueWithExecState) "\n"
119);
120
121#elif COMPILER(MSVC) && CPU(X86)
122extern "C" {
123 __declspec(naked) EncodedJSValue HOST_CALL_RETURN_VALUE_OPTION getHostCallReturnValue()
124 {
125 __asm lea eax, [esp - 4]
126 __asm mov [esp + 4], eax;
127 __asm jmp getHostCallReturnValueWithExecState
128 }
129}
130#endif
131
132} // namespace JSC
133
134#endif // !ENABLE(C_LOOP)
135