• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/* Copyright JS Foundation and other contributors, http://js.foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16.macro func _name
17.global \_name
18.type \_name, %function
19\_name:
20.endm
21.macro endfunc _name
22.size \_name, .-\_name
23.endm
24
25/**
26 * setjmp (jmp_buf env)
27 *
28 * See also:
29 *          longjmp
30 *
31 * @return 0 - if returns from direct call,
32 *         nonzero - if returns after longjmp.
33 */
34func setjmp
35  mov    %eax,(%eax);
36  mov    %ebx,0x4(%eax);
37  mov    %ecx,0x8(%eax);
38  mov    %edx,0xc(%eax);
39  mov    %esi,0x10(%eax);
40  mov    %edi,0x14(%eax);
41  mov    %ebp,0x18(%eax);
42  mov    %esp,0x1c(%eax);
43  push   %edx;
44  mov    0x4(%esp),%edx;
45  mov    %edx,0x20(%eax);
46  pop    %edx;
47  xor    %eax,%eax;
48  ret
49endfunc setjmp
50
51/**
52 * longjmp (jmp_buf env, int val)
53 *
54 * Note:
55 *      if val is not 0, then it would be returned from setjmp,
56 *      otherwise - 0 would be returned.
57 *
58 * See also:
59 *          setjmp
60 */
61func longjmp
62  test   %edx, %edx;
63  jne    . + 0x3;
64  inc    %edx;
65  mov    0x4(%eax),%ebx;
66  mov    0x8(%eax),%ecx;
67  mov    0x10(%eax),%esi;
68  mov    0x14(%eax),%edi;
69  mov    0x18(%eax),%ebp;
70  mov    0x1c(%eax),%esp;
71  push   %edx;
72  mov    0x20(%eax),%edx;
73  mov    %edx,0x4(%esp);
74  mov    0xc(%eax),%edx;
75  pop    %eax;
76  ret
77endfunc longjmp
78