Mercurial > pub > dyncall > dyncall
comparison dyncall/dyncall_call_arm32_arm.S @ 0:3e629dc19168
initial from svn dyncall-1745
author | Daniel Adler |
---|---|
date | Thu, 19 Mar 2015 22:24:28 +0100 |
parents | |
children | 2bce7629f541 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:3e629dc19168 |
---|---|
1 /* | |
2 | |
3 Package: dyncall | |
4 Library: dyncall | |
5 File: dyncall/dyncall_call_arm32_arm.S | |
6 Description: Call Kernel for ARM 32-bit ARM Architecture | |
7 License: | |
8 | |
9 Copyright (c) 2007-2015 Daniel Adler <dadler@uni-goettingen.de>, | |
10 Tassilo Philipp <tphilipp@potion-studios.com> | |
11 | |
12 Permission to use, copy, modify, and distribute this software for any | |
13 purpose with or without fee is hereby granted, provided that the above | |
14 copyright notice and this permission notice appear in all copies. | |
15 | |
16 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | |
17 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | |
18 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | |
19 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | |
20 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | |
21 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | |
22 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |
23 | |
24 */ | |
25 | |
26 | |
27 | |
28 #include "../portasm/portasm-arm.S" | |
29 | |
30 /* ============================================================================ | |
31 DynCall Call Kernel for ARM 32-bit ARM Architecture | |
32 ---------------------------------------------------------------------------- | |
33 C Interface: | |
34 dcCall_arm32_arm(DCpointer target, DCpointer argv, DCsize size); | |
35 | |
36 This Call Kernel works across multiple OS. | |
37 It has been tested on Nintendo DS, Linux and Darwin(iOS). | |
38 | |
39 */ | |
40 | |
41 .text | |
42 .code 32 /* ARM mode */ | |
43 .align 4 | |
44 GLOBAL_C(dcCall_arm32_arm) | |
45 ENTRY_C(dcCall_arm32_arm) | |
46 /* Prolog. This function never needs to spill inside its prolog, so just store the permanent registers. */ | |
47 mov r12, r13 /* Stack ptr (r13) -> temporary (r12). */ | |
48 stmdb r13!, {r4-r12, r14} /* Permanent registers and stack pointer (now in r12), etc... -> save area on stack (except counter). */ | |
49 mov r11, r12 /* Set frame ptr. */ | |
50 | |
51 /* Call. */ | |
52 mov r4, r0 /* r4 = 'fptr' (1st argument is passed in r0). */ | |
53 mov r5, r1 /* r5 = 'args' (2nd argument is passed in r1). */ | |
54 mov r6, r2 /* r6 = 'size' (3rd argument is passed in r2). */ | |
55 ldmia r5!, {r0-r3} /* Load first 4 arguments for new call into r0-r3. */ | |
56 | |
57 subs r6, r6, #16 /* Size of remaining arguments. */ | |
58 ble call /* Jump to call if no more arguments. */ | |
59 | |
60 sub r13, r13, r6 /* Set stack pointer to top of stack. */ | |
61 and r9, r6, #7 /* Align stack on 8 byte boundaries. */ | |
62 sub r13, r13, r9 | |
63 | |
64 mov r8, r13 /* Temp. destination pointer. */ | |
65 mov r9, #0 /* Init byte counter. */ | |
66 | |
67 pushArgs: | |
68 ldrb r7, [r5, r9] /* Load a byte into r7. */ | |
69 strb r7, [r8, r9] /* Push byte onto stack. */ | |
70 add r9, r9, #1 /* Increment byte counter. */ | |
71 cmp r9, r6 | |
72 bne pushArgs | |
73 | |
74 call: | |
75 /* 'blx %r4' workaround for ARMv4t: */ | |
76 mov r14, r15 /* Branch return address(r15) -> link register (r14) -- r15 always points to address of current + 2 instructions (= Epilog code). */ | |
77 bx r4 /* Call (ARM/THUMB), available for ARMv4t. */ | |
78 | |
79 /* Epilog. */ | |
80 ldmdb r11, {r4-r11, r13, r15} /* Restore permanent registers (ignore temporary (r12), restore stack ptr and program counter).@@@db not needed since we rewrite r13? */ | |
81 |