Imported Upstream version 1.0.0
[platform/upstream/js.git] / js / src / methodjit / TrampolineSUNWX64.s
1 / -*- Mode: C++/ tab-width: 4/ indent-tabs-mode: nil/ c-basic-offset: 4 -*-
2 / ***** BEGIN LICENSE BLOCK *****
3 / Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 /
5 / The contents of this file are subject to the Mozilla Public License Version
6 / 1.1 (the "License")/ you may not use this file except in compliance with
7 / the License. You may obtain a copy of the License at
8 / http://www.mozilla.org/MPL/
9 /
10 / Software distributed under the License is distributed on an "AS IS" basis,
11 / WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 / for the specific language governing rights and limitations under the
13 / License.
14 /
15 / The Original Code is mozilla.org code.
16 /
17 / The Initial Developer of the Original Code is Mozilla Japan.
18 / Portions created by the Initial Developer are Copyright (C) 2010
19 / the Initial Developer. All Rights Reserved.
20 /
21 / Contributor(s):
22 /   Leon Sha <leon.sha@sun.com>
23 /
24 / Alternatively, the contents of this file may be used under the terms of
25 / either the GNU General Public License Version 2 or later (the "GPL"), or
26 / the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 / in which case the provisions of the GPL or the LGPL are applicable instead
28 / of those above. If you wish to allow use of your version of this file only
29 / under the terms of either the GPL or the LGPL, and not to allow others to
30 / use your version of this file under the terms of the MPL, indicate your
31 / decision by deleting the provisions above and replace them with the notice
32 / and other provisions required by the GPL or the LGPL. If you do not delete
33 / the provisions above, a recipient may use your version of this file under
34 / the terms of any one of the MPL, the GPL or the LGPL.
35 /
36 / ***** END LICENSE BLOCK *****
37
38 .text
39
40 / JSBool JaegerTrampoline(JSContext *cx, JSStackFrame *fp, void *code,
41 /                        JSFrameRegs *regs, uintptr_t inlineCallCount)
42 .global JaegerTrampoline
43 .type   JaegerTrampoline, @function
44 JaegerTrampoline:
45     /* Prologue. */
46     pushq %rbp
47     movq %rsp, %rbp
48     /* Save non-volatile registers. */
49     pushq %r12
50     pushq %r13
51     pushq %r14
52     pushq %r15
53     pushq %rbx
54
55     /* Load mask registers. */
56     movq $0xFFFF800000000000, %r13
57     movq $0x00007FFFFFFFFFFF, %r14
58
59     /* Build the JIT frame.
60      * rdi = cx
61      * rsi = fp
62      * rcx = inlineCallCount
63      * fp must go into rbx
64      */
65     pushq %rsi        /* entryFp */
66     pushq %rcx        /* inlineCallCount */
67     pushq %rdi        /* cx */
68     pushq %rsi        /* fp */
69     movq  %rsi, %rbx
70
71     /* Space for the rest of the VMFrame. */
72     subq  $0x28, %rsp
73
74     /* This is actually part of the VMFrame. */
75     pushq %r8
76
77     /* Set cx->regs and set the active frame. Save rdx and align frame in one. */
78     pushq %rdx
79     movq  %rsp, %rdi
80     call SetVMFrameRegs
81     movq  %rsp, %rdi
82     call PushActiveVMFrame
83
84     /* Jump into into the JIT'd code. */
85     jmp *0(%rsp)
86 .size   JaegerTrampoline, . - JaegerTrampoline
87
88 / void JaegerTrampolineReturn()
89 .global JaegerTrampolineReturn
90 .type   JaegerTrampolineReturn, @function
91 JaegerTrampolineReturn:
92     or   %rdx, %rcx
93     movq %rcx, 0x30(%rbx)
94     movq %rsp, %rdi
95     call PopActiveVMFrame
96
97     addq $0x58, %rsp
98     popq %rbx
99     popq %r15
100     popq %r14
101     popq %r13
102     popq %r12
103     popq %rbp
104     movq $1, %rax
105     ret
106 .size   JaegerTrampolineReturn, . - JaegerTrampolineReturn
107
108
109 / void *JaegerThrowpoline(js::VMFrame *vmFrame)
110 .global JaegerThrowpoline
111 .type   JaegerThrowpoline, @function
112 JaegerThrowpoline:
113     movq %rsp, %rdi
114     call js_InternalThrow
115     testq %rax, %rax
116     je   throwpoline_exit
117     jmp  *%rax
118   throwpoline_exit:
119     movq %rsp, %rdi
120     call PopActiveVMFrame
121     addq $0x58, %rsp
122     popq %rbx
123     popq %r15
124     popq %r14
125     popq %r13
126     popq %r12
127     popq %rbp
128     xorq %rax,%rax
129     ret
130 .size   JaegerThrowpoline, . - JaegerThrowpoline
131
132 .global InjectJaegerReturn
133 .type   InjectJaegerReturn, @function
134 InjectJaegerReturn:
135     movq 0x30(%rbx), %rcx        /* load fp->rval_ into typeReg */
136     movq 0x28(%rbx), %rax        /* fp->ncode_ */
137
138     /* Reimplementation of PunboxAssembler::loadValueAsComponents() */
139     movq %r14, %rdx              /* payloadReg = payloadMaskReg */
140     andq %rcx, %rdx
141     xorq %rdx, %rcx
142
143     movq 0x38(%rsp), %rbx        /* f.fp */
144     jmp *%rax                    /* return. */
145 .size   InjectJaegerReturn, . - InjectJaegerReturn