source: project/chicken/trunk/apply-hack.x86-64.s @ 7044

Last change on this file since 7044 was 7044, checked in by Jim Ursetto, 12 years ago

Add x86-64 support for OS X.

File size: 2.4 KB
Line 
1/* Apply-hack.x86-64.s
2;
3; Copyright (c) 2007, Felix L. Winkelmann
4; All rights reserved.
5;
6; Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following
7; conditions are met:
8;
9;   Redistributions of source code must retain the above copyright notice, this list of conditions and the following
10;     disclaimer.
11;   Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following
12;     disclaimer in the documentation and/or other materials provided with the distribution.
13;   Neither the name of the author nor the names of its contributors may be used to endorse or promote
14;     products derived from this software without specific prior written permission.
15;
16; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
17; OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
18; AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
19; CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20; CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21; SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23; OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
24; POSSIBILITY OF SUCH DAMAGE.
25;
26; Send bugs, suggestions and ideas to: 
27;
28; felix@call-with-current-continuation.org
29;
30; Felix L. Winkelmann
31; Unter den Gleichen 1
32; 37130 Gleichen
33; Germany
34*/
35
36        .text
37
38        .globl _C_do_apply_hack
39#ifndef __APPLE__
40        .type _C_do_apply_hack, @function
41#endif
42
43_C_do_apply_hack:
44        subq $8, %rsp           /* force non-16 byte alignment */
45        movq %rdi, %r11         /* get proc */
46        movq %rsi, %r10         /* save buffer address, before we clobber %rsi */
47        cmpl $6, %edx           /* clamp at 6 */
48        ja l2
49        je l3
50        movq $6, %rbx           /* (6 - count) * 4 gives instruction address */
51        subq %rdx, %rbx
52        shlq $2, %rbx
53        lea l3(%rip), %rdx
54        addq %rdx, %rbx
55        jmp *%rbx
56l2:     lea 48(%r10), %rsp      /* %r10 must be 16-byte aligned at this point */
57l3:     movq 40(%r10), %r9      /* fill registers... */
58        movq 32(%r10), %r8
59        movq 24(%r10), %rcx
60        movq 16(%r10), %rdx
61        movq 8(%r10), %rsi
62        movq (%r10), %rdi
63        xorq %rax, %rax
64        call *%r11
Note: See TracBrowser for help on using the repository browser.