annotate dyncallback/dyncall_thunk_sparc64.c @ 617:6a34dcb2bbd7

- test/syscalls: build fix for minix
author Tassilo Philipp
date Sun, 02 Oct 2022 16:45:06 +0200
parents 9d0eefb0e0f0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
1 /*
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
2
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
3 Package: dyncall
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
4 Library: dyncallback
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
5 File: dyncallback/dyncall_thunk_sparc64.c
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
6 Description: Thunk - Implementation for sparc64
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
7 License:
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
8
607
9d0eefb0e0f0 - sparc64 callback crash fix (local register wasn't preserved)
Tassilo Philipp
parents: 281
diff changeset
9 Copyright (c) 2007-2022 Daniel Adler <dadler@uni-goettingen.de>,
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
10 Tassilo Philipp <tphilipp@potion-studios.com>
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
11
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
12 Permission to use, copy, modify, and distribute this software for any
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
13 purpose with or without fee is hereby granted, provided that the above
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
14 copyright notice and this permission notice appear in all copies.
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
15
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
16 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
17 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
18 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
19 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
20 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
21 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
22 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
23
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
24 */
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
25
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
26
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
27 #include "dyncall_thunk.h"
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
28
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
29 void dcbInitThunk(DCThunk* p, void (*entry)())
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
30 {
189
b827c074b4da - first impl of sparc64 thunks
Tassilo Philipp
parents: 0
diff changeset
31 /* example
b827c074b4da - first impl of sparc64 thunks
Tassilo Philipp
parents: 0
diff changeset
32 ; put thunk pointer in g1
b827c074b4da - first impl of sparc64 thunks
Tassilo Philipp
parents: 0
diff changeset
33 0: 03 00 00 00 sethi %hi(0), %g1
b827c074b4da - first impl of sparc64 thunks
Tassilo Philipp
parents: 0
diff changeset
34 4: 82 10 60 00 or %g1, 0, %g1
b827c074b4da - first impl of sparc64 thunks
Tassilo Philipp
parents: 0
diff changeset
35 8: 83 28 70 20 sllx %g1, 0x20, %g1
607
9d0eefb0e0f0 - sparc64 callback crash fix (local register wasn't preserved)
Tassilo Philipp
parents: 281
diff changeset
36
9d0eefb0e0f0 - sparc64 callback crash fix (local register wasn't preserved)
Tassilo Philipp
parents: 281
diff changeset
37 12: 21 00 00 00 sethi %hi(0), %g3
9d0eefb0e0f0 - sparc64 callback crash fix (local register wasn't preserved)
Tassilo Philipp
parents: 281
diff changeset
38 16: a0 14 20 00 or %g3, 0, %g3
9d0eefb0e0f0 - sparc64 callback crash fix (local register wasn't preserved)
Tassilo Philipp
parents: 281
diff changeset
39 20: 82 04 00 01 add %g3, %g1, %g1
189
b827c074b4da - first impl of sparc64 thunks
Tassilo Philipp
parents: 0
diff changeset
40 ; use g2 for entry pointer and "call" it, b/c branch instructions can't handle 64bit addresses
b827c074b4da - first impl of sparc64 thunks
Tassilo Philipp
parents: 0
diff changeset
41 24: 05 00 00 00 sethi %hi(0), %g2
b827c074b4da - first impl of sparc64 thunks
Tassilo Philipp
parents: 0
diff changeset
42 28: 84 10 a0 00 or %g2, 0, %g2
b827c074b4da - first impl of sparc64 thunks
Tassilo Philipp
parents: 0
diff changeset
43 32: 85 28 b0 20 sllx %g2, 0x20, %g2
607
9d0eefb0e0f0 - sparc64 callback crash fix (local register wasn't preserved)
Tassilo Philipp
parents: 281
diff changeset
44
9d0eefb0e0f0 - sparc64 callback crash fix (local register wasn't preserved)
Tassilo Philipp
parents: 281
diff changeset
45 36: 21 00 00 00 sethi %hi(0), %g3
9d0eefb0e0f0 - sparc64 callback crash fix (local register wasn't preserved)
Tassilo Philipp
parents: 281
diff changeset
46 40: a0 14 20 00 or %g3, 0, %g3
9d0eefb0e0f0 - sparc64 callback crash fix (local register wasn't preserved)
Tassilo Philipp
parents: 281
diff changeset
47 44: 84 04 00 02 add %g3, %g2, %g2
189
b827c074b4da - first impl of sparc64 thunks
Tassilo Philipp
parents: 0
diff changeset
48 ; jump - write link to %g0, effectively discarding it; also nop for delay slot
b827c074b4da - first impl of sparc64 thunks
Tassilo Philipp
parents: 0
diff changeset
49 48: 81 c0 80 00 jmpl %g2, %g0
b827c074b4da - first impl of sparc64 thunks
Tassilo Philipp
parents: 0
diff changeset
50 52: 01 00 00 00 nop
b827c074b4da - first impl of sparc64 thunks
Tassilo Philipp
parents: 0
diff changeset
51 */
b827c074b4da - first impl of sparc64 thunks
Tassilo Philipp
parents: 0
diff changeset
52
607
9d0eefb0e0f0 - sparc64 callback crash fix (local register wasn't preserved)
Tassilo Philipp
parents: 281
diff changeset
53
189
b827c074b4da - first impl of sparc64 thunks
Tassilo Philipp
parents: 0
diff changeset
54 union {
b827c074b4da - first impl of sparc64 thunks
Tassilo Philipp
parents: 0
diff changeset
55 unsigned int x[2];
b827c074b4da - first impl of sparc64 thunks
Tassilo Philipp
parents: 0
diff changeset
56 void* p;
b827c074b4da - first impl of sparc64 thunks
Tassilo Philipp
parents: 0
diff changeset
57 } t, e;
b827c074b4da - first impl of sparc64 thunks
Tassilo Philipp
parents: 0
diff changeset
58 t.p = p;
b827c074b4da - first impl of sparc64 thunks
Tassilo Philipp
parents: 0
diff changeset
59 e.p = entry;
b827c074b4da - first impl of sparc64 thunks
Tassilo Philipp
parents: 0
diff changeset
60
b827c074b4da - first impl of sparc64 thunks
Tassilo Philipp
parents: 0
diff changeset
61 p->code[ 0] = 0x03000000 | (t.x[0] >> 10); /* sethi %hi(p), %g1 -- hi 22 bits */
b827c074b4da - first impl of sparc64 thunks
Tassilo Philipp
parents: 0
diff changeset
62 p->code[ 1] = 0x82106000 | (t.x[0] & 0x3ff); /* or %g1, <p&0x3ff>, %g1 -- lo 10 bits */
b827c074b4da - first impl of sparc64 thunks
Tassilo Philipp
parents: 0
diff changeset
63 p->code[ 2] = 0x83287020; /* sllx %g1, 0x20, %g1 */
607
9d0eefb0e0f0 - sparc64 callback crash fix (local register wasn't preserved)
Tassilo Philipp
parents: 281
diff changeset
64 p->code[ 3] = 0x07000000 | (t.x[1] >> 10); /* sethi %hi(p), %g3 */
9d0eefb0e0f0 - sparc64 callback crash fix (local register wasn't preserved)
Tassilo Philipp
parents: 281
diff changeset
65 p->code[ 4] = 0x8610e000 | (t.x[1] & 0x3ff); /* or %g3, <p&0x3ff>, %g3 */
9d0eefb0e0f0 - sparc64 callback crash fix (local register wasn't preserved)
Tassilo Philipp
parents: 281
diff changeset
66 p->code[ 5] = 0x8200c001; /* add %g3, %g1, %g1 */
189
b827c074b4da - first impl of sparc64 thunks
Tassilo Philipp
parents: 0
diff changeset
67 p->code[ 6] = 0x05000000 | (e.x[0] >> 10); /* sethi %hi(entry), %g2 */
b827c074b4da - first impl of sparc64 thunks
Tassilo Philipp
parents: 0
diff changeset
68 p->code[ 7] = 0x8410a000 | (e.x[0] & 0x3ff); /* or %g2, <entry&0x3ff>, %g2 */
b827c074b4da - first impl of sparc64 thunks
Tassilo Philipp
parents: 0
diff changeset
69 p->code[ 8] = 0x8528b020; /* sllx %g2, 0x20, %g2 */
607
9d0eefb0e0f0 - sparc64 callback crash fix (local register wasn't preserved)
Tassilo Philipp
parents: 281
diff changeset
70 p->code[ 9] = 0x07000000 | (e.x[1] >> 10); /* sethi %hi(entry), %g3 */
9d0eefb0e0f0 - sparc64 callback crash fix (local register wasn't preserved)
Tassilo Philipp
parents: 281
diff changeset
71 p->code[10] = 0x8610e000 | (e.x[1] & 0x3ff); /* or %g3, <entry&0x3ff>, %g3 */
9d0eefb0e0f0 - sparc64 callback crash fix (local register wasn't preserved)
Tassilo Philipp
parents: 281
diff changeset
72 p->code[11] = 0x8400c002; /* add %g3, %g2, %g2 */
189
b827c074b4da - first impl of sparc64 thunks
Tassilo Philipp
parents: 0
diff changeset
73 p->code[12] = 0x81c08000; /* jmpl %g2, %g0 -- discards link addr */
b827c074b4da - first impl of sparc64 thunks
Tassilo Philipp
parents: 0
diff changeset
74 p->code[13] = 0x01000000; /* nop */
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
75 }
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
76