Mercurial > pub > dyncall > dyncall
annotate dyncall/dyncall_call_arm32_arm.S @ 663:127b569978cc default tip
- another tweak handling clang trying to be too smart (see last commit)
author | Tassilo Philipp |
---|---|
date | Sun, 24 Mar 2024 13:52:44 +0100 |
parents | 351bb41d3bb1 |
children |
rev | line source |
---|---|
0 | 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 | |
281 | 9 Copyright (c) 2007-2018 Daniel Adler <dadler@uni-goettingen.de>, |
0 | 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 | |
38 */ | |
39 | |
40 .text | |
41 .code 32 /* ARM mode */ | |
42 .align 4 | |
43 GLOBAL_C(dcCall_arm32_arm) | |
44 ENTRY_C(dcCall_arm32_arm) | |
45 /* Prolog. This function never needs to spill inside its prolog, so just store the permanent registers. */ | |
46 mov r12, r13 /* Stack ptr (r13) -> temporary (r12). */ | |
47 stmdb r13!, {r4-r12, r14} /* Permanent registers and stack pointer (now in r12), etc... -> save area on stack (except counter). */ | |
48 mov r11, r12 /* Set frame ptr. */ | |
49 | |
50 /* Call. */ | |
51 mov r4, r0 /* r4 = 'fptr' (1st argument is passed in r0). */ | |
52 mov r5, r1 /* r5 = 'args' (2nd argument is passed in r1). */ | |
53 mov r6, r2 /* r6 = 'size' (3rd argument is passed in r2). */ | |
54 ldmia r5!, {r0-r3} /* Load first 4 arguments for new call into r0-r3. */ | |
55 | |
56 subs r6, r6, #16 /* Size of remaining arguments. */ | |
57 ble call /* Jump to call if no more arguments. */ | |
58 | |
59 sub r13, r13, r6 /* Set stack pointer to top of stack. */ | |
60 and r9, r6, #7 /* Align stack on 8 byte boundaries. */ | |
61 sub r13, r13, r9 | |
62 | |
63 mov r8, r13 /* Temp. destination pointer. */ | |
64 mov r9, #0 /* Init byte counter. */ | |
65 | |
66 pushArgs: | |
67 ldrb r7, [r5, r9] /* Load a byte into r7. */ | |
68 strb r7, [r8, r9] /* Push byte onto stack. */ | |
69 add r9, r9, #1 /* Increment byte counter. */ | |
70 cmp r9, r6 | |
71 bne pushArgs | |
72 | |
73 call: | |
406
351bb41d3bb1
- removed %-prefixes for register names from arm assembly files (was wrong to begin with, gas accepted them but the clang integrated assembler does not)
Tassilo Philipp
parents:
281
diff
changeset
|
74 /* 'blx r4' workaround for ARMv4t: */ |
0 | 75 mov r14, r15 /* Branch return address(r15) -> link register (r14) -- r15 always points to address of current + 2 instructions (= Epilog code). */ |
76 bx r4 /* Call (ARM/THUMB), available for ARMv4t. */ | |
77 | |
78 /* Epilog. */ | |
79 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? */ | |
80 |