comparison dyncallback/dyncall_thunk_arm64.c @ 0:3e629dc19168

initial from svn dyncall-1745
author Daniel Adler
date Thu, 19 Mar 2015 22:24:28 +0100
parents
children f5577f6bf97a
comparison
equal deleted inserted replaced
-1:000000000000 0:3e629dc19168
1 /*
2
3 Package: dyncall
4 Library: dyncallback
5 File: dyncallback/dyncall_thunk_arm64.c
6 Description: Thunk - Implementation for ARM64 / ARMv8 / AAPCS64
7 License:
8
9 Copyright (c) 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 "dyncall_thunk.h"
29
30 /*
31
32 Thunk Register: x9
33
34 Thunk:
35 adr x9, Thunk
36 ldr x10, .target
37 br x10
38 nop
39 .target:
40 .xword 0
41
42 -- Encoded in:
43
44 0000000000000000 <Thunk>:
45 0: 10000009 adr x9, 0 <Thunk>
46 4: 5800006a ldr x10, 10 <.target>
47 8: d61f0140 br x10
48 c: d503201f nop
49
50 0000000000000010 <.target>:
51 10: 76543210 .word 0x76543210
52 14: fedcba98 .word 0xfedcba98
53 */
54
55 void dcbInitThunk(DCThunk* p, void (*entry)())
56 {
57 p->code[0] = 0x10000009; // adr x9, 0
58 p->code[1] = 0x5800006a; // ldr x9, entry
59 p->code[2] = 0xd61f0140; // br x9
60 p->code[3] = 0xd503201f; // nop
61 p->entry = entry; // entry:
62 // .xword 0
63 }
64