0
|
1 /*
|
|
2
|
|
3 Package: dyncall
|
|
4 Library: dyncall
|
|
5 File: dyncall/dyncall_call_arm32_arm_armhf.S
|
|
6 Description: Call Kernel for ARM 32-bit ARM Architecture - Hard Float
|
|
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 Hard-Float
|
|
32 ----------------------------------------------------------------------------
|
|
33 C Interface:
|
|
34 dcCall_arm32_armhf (DCpointer target, DCpointer argv, DCsize size, DCfloat* regdata);
|
|
35
|
|
36 This Call Kernel was tested on Raspberry Pi/Raspbian (Debian)
|
|
37 */
|
|
38
|
|
39 .text
|
|
40 .code 32 /* ARM mode */
|
|
41 .arch armv6
|
|
42 .fpu vfp
|
|
43
|
36
|
44 /*
|
|
45 1st arg / r0 = funptr
|
|
46 2st arg / r1 = ptr to int args
|
|
47 3st arg / r2 = size
|
|
48 4st arg / r3 = ptr to float args
|
|
49 */
|
0
|
50 GLOBAL_C(dcCall_arm32_armhf)
|
|
51 ENTRY_C(dcCall_arm32_armhf)
|
|
52
|
|
53 /* Prolog. This function never needs to spill inside its prolog, so just store the permanent registers. */
|
|
54 mov r12 , r13 /* Stack ptr (r13) -> temporary (r12). */
|
|
55 stmdb r13!, {r4-r5, r11, r12, r14} /* Permanent registers and stack pointer (now in r12), etc... -> save area on stack (except counter). */
|
|
56
|
|
57 mov r11 , r12 /* Set frame ptr. */
|
|
58 mov r4 , r0 /* r4 = 'fptr' (1st argument is passed in r0). */
|
|
59 mov r5 , r1 /* r5 = 'args' (2nd argument is passed in r1). */
|
|
60
|
|
61 /* Load 16 single-precision registers (= 8 double-precision registers). */
|
36
|
62 fldmiad r3, {d0-d7}
|
0
|
63
|
|
64 sub r2 , r2 , #16
|
|
65 cmp r2, #0
|
|
66 ble armhf_call
|
|
67
|
|
68 sub r13, r13, r2
|
|
69 and r13, r13, #-8 /* align 8-byte. */
|
|
70
|
|
71 mov r3, #0 /* Init byte counter. */
|
|
72 add r1 , r1 , #16
|
|
73 armhf_pushArgs:
|
|
74 ldr r0, [r1, +r3] /* Load word into r0. */
|
|
75 str r0, [r13, +r3] /* Push word onto stack. */
|
|
76 add r3, r3, #4 /* Increment byte counter. */
|
|
77 cmp r2, r3
|
|
78 bne armhf_pushArgs
|
|
79
|
|
80 armhf_call:
|
|
81 ldmia r5, {r0-r3} /* Load first 4 arguments for new call into r0-r3. */
|
|
82 /* 'blx %r4' workaround for ARMv4t: */
|
|
83 mov r14, r15 /* Branch return address(r15) -> link register (r14) -- r15 always points to address of current + 2 instructions (= Epilog code). */
|
|
84 bx r4 /* Call (ARM/THUMB), available for ARMv4t. */
|
|
85
|
|
86 /* Epilog. */
|
|
87 ldmdb r11, {r4-r5, r11, r13, r15} /* Restore permanent registers (ignore temporary (r12), restore stack ptr and program counter).@@@db not needed since we rewrite r13? */
|
|
88
|