annotate dyncallback/dyncall_callback_riscv64.S @ 659:b8969b7b4876

riscv64 callbacks: - corrected frame pointer of callback code to args to handler (makes maybe some debuggers happier) - refactored, saving two instructions - simplified asm a bit, using more fitting instructions (and cleaned up comments)
author Tassilo Philipp
date Tue, 12 Mar 2024 23:12:15 +0100
parents 0c8838766866
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
653
0c8838766866 - riscv64 support for calls and callbacks (but lacking aggr and syscall support) - thanks Jun Jeon! :)
Tassilo Philipp
parents:
diff changeset
1 /*
0c8838766866 - riscv64 support for calls and callbacks (but lacking aggr and syscall support) - thanks Jun Jeon! :)
Tassilo Philipp
parents:
diff changeset
2
0c8838766866 - riscv64 support for calls and callbacks (but lacking aggr and syscall support) - thanks Jun Jeon! :)
Tassilo Philipp
parents:
diff changeset
3 Package: dyncall
0c8838766866 - riscv64 support for calls and callbacks (but lacking aggr and syscall support) - thanks Jun Jeon! :)
Tassilo Philipp
parents:
diff changeset
4 Library: dyncallback
0c8838766866 - riscv64 support for calls and callbacks (but lacking aggr and syscall support) - thanks Jun Jeon! :)
Tassilo Philipp
parents:
diff changeset
5 File: dyncallback/dyncall_callback_riscv64.S
0c8838766866 - riscv64 support for calls and callbacks (but lacking aggr and syscall support) - thanks Jun Jeon! :)
Tassilo Philipp
parents:
diff changeset
6 Description: Callback Thunk - Implementation for RISCV64
0c8838766866 - riscv64 support for calls and callbacks (but lacking aggr and syscall support) - thanks Jun Jeon! :)
Tassilo Philipp
parents:
diff changeset
7 License:
0c8838766866 - riscv64 support for calls and callbacks (but lacking aggr and syscall support) - thanks Jun Jeon! :)
Tassilo Philipp
parents:
diff changeset
8
0c8838766866 - riscv64 support for calls and callbacks (but lacking aggr and syscall support) - thanks Jun Jeon! :)
Tassilo Philipp
parents:
diff changeset
9 Copyright (c) 2023 Jun Jeon <yjeon@netflix.com>
0c8838766866 - riscv64 support for calls and callbacks (but lacking aggr and syscall support) - thanks Jun Jeon! :)
Tassilo Philipp
parents:
diff changeset
10
0c8838766866 - riscv64 support for calls and callbacks (but lacking aggr and syscall support) - thanks Jun Jeon! :)
Tassilo Philipp
parents:
diff changeset
11 Permission to use, copy, modify, and distribute this software for any
0c8838766866 - riscv64 support for calls and callbacks (but lacking aggr and syscall support) - thanks Jun Jeon! :)
Tassilo Philipp
parents:
diff changeset
12 purpose with or without fee is hereby granted, provided that the above
0c8838766866 - riscv64 support for calls and callbacks (but lacking aggr and syscall support) - thanks Jun Jeon! :)
Tassilo Philipp
parents:
diff changeset
13 copyright notice and this permission notice appear in all copies.
0c8838766866 - riscv64 support for calls and callbacks (but lacking aggr and syscall support) - thanks Jun Jeon! :)
Tassilo Philipp
parents:
diff changeset
14
0c8838766866 - riscv64 support for calls and callbacks (but lacking aggr and syscall support) - thanks Jun Jeon! :)
Tassilo Philipp
parents:
diff changeset
15 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
0c8838766866 - riscv64 support for calls and callbacks (but lacking aggr and syscall support) - thanks Jun Jeon! :)
Tassilo Philipp
parents:
diff changeset
16 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
0c8838766866 - riscv64 support for calls and callbacks (but lacking aggr and syscall support) - thanks Jun Jeon! :)
Tassilo Philipp
parents:
diff changeset
17 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
0c8838766866 - riscv64 support for calls and callbacks (but lacking aggr and syscall support) - thanks Jun Jeon! :)
Tassilo Philipp
parents:
diff changeset
18 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
0c8838766866 - riscv64 support for calls and callbacks (but lacking aggr and syscall support) - thanks Jun Jeon! :)
Tassilo Philipp
parents:
diff changeset
19 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
0c8838766866 - riscv64 support for calls and callbacks (but lacking aggr and syscall support) - thanks Jun Jeon! :)
Tassilo Philipp
parents:
diff changeset
20 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
0c8838766866 - riscv64 support for calls and callbacks (but lacking aggr and syscall support) - thanks Jun Jeon! :)
Tassilo Philipp
parents:
diff changeset
21 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
0c8838766866 - riscv64 support for calls and callbacks (but lacking aggr and syscall support) - thanks Jun Jeon! :)
Tassilo Philipp
parents:
diff changeset
22
0c8838766866 - riscv64 support for calls and callbacks (but lacking aggr and syscall support) - thanks Jun Jeon! :)
Tassilo Philipp
parents:
diff changeset
23 */
0c8838766866 - riscv64 support for calls and callbacks (but lacking aggr and syscall support) - thanks Jun Jeon! :)
Tassilo Philipp
parents:
diff changeset
24
0c8838766866 - riscv64 support for calls and callbacks (but lacking aggr and syscall support) - thanks Jun Jeon! :)
Tassilo Philipp
parents:
diff changeset
25 /* struct DCCallback
0c8838766866 - riscv64 support for calls and callbacks (but lacking aggr and syscall support) - thanks Jun Jeon! :)
Tassilo Philipp
parents:
diff changeset
26 type off size
0c8838766866 - riscv64 support for calls and callbacks (but lacking aggr and syscall support) - thanks Jun Jeon! :)
Tassilo Philipp
parents:
diff changeset
27 ---------|------|------
0c8838766866 - riscv64 support for calls and callbacks (but lacking aggr and syscall support) - thanks Jun Jeon! :)
Tassilo Philipp
parents:
diff changeset
28 DCThunk | 0 | 32
0c8838766866 - riscv64 support for calls and callbacks (but lacking aggr and syscall support) - thanks Jun Jeon! :)
Tassilo Philipp
parents:
diff changeset
29 handler | 32 | 8
0c8838766866 - riscv64 support for calls and callbacks (but lacking aggr and syscall support) - thanks Jun Jeon! :)
Tassilo Philipp
parents:
diff changeset
30 userdata | 40 | 8
0c8838766866 - riscv64 support for calls and callbacks (but lacking aggr and syscall support) - thanks Jun Jeon! :)
Tassilo Philipp
parents:
diff changeset
31 */
0c8838766866 - riscv64 support for calls and callbacks (but lacking aggr and syscall support) - thanks Jun Jeon! :)
Tassilo Philipp
parents:
diff changeset
32
0c8838766866 - riscv64 support for calls and callbacks (but lacking aggr and syscall support) - thanks Jun Jeon! :)
Tassilo Philipp
parents:
diff changeset
33 .align 4
0c8838766866 - riscv64 support for calls and callbacks (but lacking aggr and syscall support) - thanks Jun Jeon! :)
Tassilo Philipp
parents:
diff changeset
34 .globl dcCallbackThunkEntry
0c8838766866 - riscv64 support for calls and callbacks (but lacking aggr and syscall support) - thanks Jun Jeon! :)
Tassilo Philipp
parents:
diff changeset
35 dcCallbackThunkEntry:
0c8838766866 - riscv64 support for calls and callbacks (but lacking aggr and syscall support) - thanks Jun Jeon! :)
Tassilo Philipp
parents:
diff changeset
36
0c8838766866 - riscv64 support for calls and callbacks (but lacking aggr and syscall support) - thanks Jun Jeon! :)
Tassilo Philipp
parents:
diff changeset
37 /* called from dcbInitThunk() in dyncall_thunk_riscv64.c */
0c8838766866 - riscv64 support for calls and callbacks (but lacking aggr and syscall support) - thanks Jun Jeon! :)
Tassilo Philipp
parents:
diff changeset
38
0c8838766866 - riscv64 support for calls and callbacks (but lacking aggr and syscall support) - thanks Jun Jeon! :)
Tassilo Philipp
parents:
diff changeset
39 /* input:
0c8838766866 - riscv64 support for calls and callbacks (but lacking aggr and syscall support) - thanks Jun Jeon! :)
Tassilo Philipp
parents:
diff changeset
40 t5: DCCallback* pcb
0c8838766866 - riscv64 support for calls and callbacks (but lacking aggr and syscall support) - thanks Jun Jeon! :)
Tassilo Philipp
parents:
diff changeset
41 a0..a7 ?? GP regs
0c8838766866 - riscv64 support for calls and callbacks (but lacking aggr and syscall support) - thanks Jun Jeon! :)
Tassilo Philipp
parents:
diff changeset
42 fa0..fa7 ?? FP/SIMD regs
0c8838766866 - riscv64 support for calls and callbacks (but lacking aggr and syscall support) - thanks Jun Jeon! :)
Tassilo Philipp
parents:
diff changeset
43 sp... ?? arguments on stack
0c8838766866 - riscv64 support for calls and callbacks (but lacking aggr and syscall support) - thanks Jun Jeon! :)
Tassilo Philipp
parents:
diff changeset
44
0c8838766866 - riscv64 support for calls and callbacks (but lacking aggr and syscall support) - thanks Jun Jeon! :)
Tassilo Philipp
parents:
diff changeset
45 locals:
0c8838766866 - riscv64 support for calls and callbacks (but lacking aggr and syscall support) - thanks Jun Jeon! :)
Tassilo Philipp
parents:
diff changeset
46 type off size
0c8838766866 - riscv64 support for calls and callbacks (but lacking aggr and syscall support) - thanks Jun Jeon! :)
Tassilo Philipp
parents:
diff changeset
47 ---------|------|------
0c8838766866 - riscv64 support for calls and callbacks (but lacking aggr and syscall support) - thanks Jun Jeon! :)
Tassilo Philipp
parents:
diff changeset
48 Frame 0 16
0c8838766866 - riscv64 support for calls and callbacks (but lacking aggr and syscall support) - thanks Jun Jeon! :)
Tassilo Philipp
parents:
diff changeset
49 DCArgs 16 144
0c8838766866 - riscv64 support for calls and callbacks (but lacking aggr and syscall support) - thanks Jun Jeon! :)
Tassilo Philipp
parents:
diff changeset
50 DCValue 160 16
0c8838766866 - riscv64 support for calls and callbacks (but lacking aggr and syscall support) - thanks Jun Jeon! :)
Tassilo Philipp
parents:
diff changeset
51
0c8838766866 - riscv64 support for calls and callbacks (but lacking aggr and syscall support) - thanks Jun Jeon! :)
Tassilo Philipp
parents:
diff changeset
52 size 176
0c8838766866 - riscv64 support for calls and callbacks (but lacking aggr and syscall support) - thanks Jun Jeon! :)
Tassilo Philipp
parents:
diff changeset
53 aligned 176
0c8838766866 - riscv64 support for calls and callbacks (but lacking aggr and syscall support) - thanks Jun Jeon! :)
Tassilo Philipp
parents:
diff changeset
54
0c8838766866 - riscv64 support for calls and callbacks (but lacking aggr and syscall support) - thanks Jun Jeon! :)
Tassilo Philipp
parents:
diff changeset
55 ra - ret addr
0c8838766866 - riscv64 support for calls and callbacks (but lacking aggr and syscall support) - thanks Jun Jeon! :)
Tassilo Philipp
parents:
diff changeset
56 s0/fp - frame ptr
0c8838766866 - riscv64 support for calls and callbacks (but lacking aggr and syscall support) - thanks Jun Jeon! :)
Tassilo Philipp
parents:
diff changeset
57 */
0c8838766866 - riscv64 support for calls and callbacks (but lacking aggr and syscall support) - thanks Jun Jeon! :)
Tassilo Philipp
parents:
diff changeset
58
659
b8969b7b4876 riscv64 callbacks:
Tassilo Philipp
parents: 653
diff changeset
59 /* prolog */
653
0c8838766866 - riscv64 support for calls and callbacks (but lacking aggr and syscall support) - thanks Jun Jeon! :)
Tassilo Philipp
parents:
diff changeset
60
0c8838766866 - riscv64 support for calls and callbacks (but lacking aggr and syscall support) - thanks Jun Jeon! :)
Tassilo Philipp
parents:
diff changeset
61 add sp, sp, -176
659
b8969b7b4876 riscv64 callbacks:
Tassilo Philipp
parents: 653
diff changeset
62 sd ra, 168(sp)
b8969b7b4876 riscv64 callbacks:
Tassilo Philipp
parents: 653
diff changeset
63 sd s0, 160(sp)
b8969b7b4876 riscv64 callbacks:
Tassilo Philipp
parents: 653
diff changeset
64 add s0, sp, 176
653
0c8838766866 - riscv64 support for calls and callbacks (but lacking aggr and syscall support) - thanks Jun Jeon! :)
Tassilo Philipp
parents:
diff changeset
65
659
b8969b7b4876 riscv64 callbacks:
Tassilo Philipp
parents: 653
diff changeset
66 /* fill DCArgs data (see dyncall_args_riscv64.c) */
653
0c8838766866 - riscv64 support for calls and callbacks (but lacking aggr and syscall support) - thanks Jun Jeon! :)
Tassilo Philipp
parents:
diff changeset
67
659
b8969b7b4876 riscv64 callbacks:
Tassilo Philipp
parents: 653
diff changeset
68 sd a0, 0(sp) /* I */
b8969b7b4876 riscv64 callbacks:
Tassilo Philipp
parents: 653
diff changeset
69 sd a1, 8(sp)
b8969b7b4876 riscv64 callbacks:
Tassilo Philipp
parents: 653
diff changeset
70 sd a2, 16(sp)
b8969b7b4876 riscv64 callbacks:
Tassilo Philipp
parents: 653
diff changeset
71 sd a3, 24(sp)
b8969b7b4876 riscv64 callbacks:
Tassilo Philipp
parents: 653
diff changeset
72 sd a4, 32(sp)
b8969b7b4876 riscv64 callbacks:
Tassilo Philipp
parents: 653
diff changeset
73 sd a5, 40(sp)
b8969b7b4876 riscv64 callbacks:
Tassilo Philipp
parents: 653
diff changeset
74 sd a6, 48(sp)
b8969b7b4876 riscv64 callbacks:
Tassilo Philipp
parents: 653
diff changeset
75 sd a7, 56(sp)
653
0c8838766866 - riscv64 support for calls and callbacks (but lacking aggr and syscall support) - thanks Jun Jeon! :)
Tassilo Philipp
parents:
diff changeset
76
659
b8969b7b4876 riscv64 callbacks:
Tassilo Philipp
parents: 653
diff changeset
77 fsd fa0, 64(sp) /* F */
b8969b7b4876 riscv64 callbacks:
Tassilo Philipp
parents: 653
diff changeset
78 fsd fa1, 72(sp)
b8969b7b4876 riscv64 callbacks:
Tassilo Philipp
parents: 653
diff changeset
79 fsd fa2, 80(sp)
b8969b7b4876 riscv64 callbacks:
Tassilo Philipp
parents: 653
diff changeset
80 fsd fa3, 88(sp)
b8969b7b4876 riscv64 callbacks:
Tassilo Philipp
parents: 653
diff changeset
81 fsd fa4, 96(sp)
b8969b7b4876 riscv64 callbacks:
Tassilo Philipp
parents: 653
diff changeset
82 fsd fa5, 104(sp)
b8969b7b4876 riscv64 callbacks:
Tassilo Philipp
parents: 653
diff changeset
83 fsd fa6, 112(sp)
b8969b7b4876 riscv64 callbacks:
Tassilo Philipp
parents: 653
diff changeset
84 fsd fa7, 120(sp)
653
0c8838766866 - riscv64 support for calls and callbacks (but lacking aggr and syscall support) - thanks Jun Jeon! :)
Tassilo Philipp
parents:
diff changeset
85
659
b8969b7b4876 riscv64 callbacks:
Tassilo Philipp
parents: 653
diff changeset
86 sd s0, 128(sp) /* sp=sp */
b8969b7b4876 riscv64 callbacks:
Tassilo Philipp
parents: 653
diff changeset
87 sd zero, 136(sp) /* i=f=0 */
653
0c8838766866 - riscv64 support for calls and callbacks (but lacking aggr and syscall support) - thanks Jun Jeon! :)
Tassilo Philipp
parents:
diff changeset
88
0c8838766866 - riscv64 support for calls and callbacks (but lacking aggr and syscall support) - thanks Jun Jeon! :)
Tassilo Philipp
parents:
diff changeset
89 /* call handler/callback */
0c8838766866 - riscv64 support for calls and callbacks (but lacking aggr and syscall support) - thanks Jun Jeon! :)
Tassilo Philipp
parents:
diff changeset
90
659
b8969b7b4876 riscv64 callbacks:
Tassilo Philipp
parents: 653
diff changeset
91 mv a0, t5 /* DCCallback* pcb */
b8969b7b4876 riscv64 callbacks:
Tassilo Philipp
parents: 653
diff changeset
92 mv a1, sp /* DCArgs* args */
b8969b7b4876 riscv64 callbacks:
Tassilo Philipp
parents: 653
diff changeset
93 add a2, sp, 144 /* DCValue* result */
b8969b7b4876 riscv64 callbacks:
Tassilo Philipp
parents: 653
diff changeset
94 ld a3, 40(t5) /* void* userdata */
653
0c8838766866 - riscv64 support for calls and callbacks (but lacking aggr and syscall support) - thanks Jun Jeon! :)
Tassilo Philipp
parents:
diff changeset
95
0c8838766866 - riscv64 support for calls and callbacks (but lacking aggr and syscall support) - thanks Jun Jeon! :)
Tassilo Philipp
parents:
diff changeset
96 ld t2, 32(t5)
0c8838766866 - riscv64 support for calls and callbacks (but lacking aggr and syscall support) - thanks Jun Jeon! :)
Tassilo Philipp
parents:
diff changeset
97 jalr ra, 0(t2)
0c8838766866 - riscv64 support for calls and callbacks (but lacking aggr and syscall support) - thanks Jun Jeon! :)
Tassilo Philipp
parents:
diff changeset
98
0c8838766866 - riscv64 support for calls and callbacks (but lacking aggr and syscall support) - thanks Jun Jeon! :)
Tassilo Philipp
parents:
diff changeset
99 and t3, a0, 255
659
b8969b7b4876 riscv64 callbacks:
Tassilo Philipp
parents: 653
diff changeset
100 li t4, 'f' /* single prec floats need reg's 32 MSBs */
b8969b7b4876 riscv64 callbacks:
Tassilo Philipp
parents: 653
diff changeset
101 beq t3, t4, .retf /* all set (on riscv with the D extension) */
b8969b7b4876 riscv64 callbacks:
Tassilo Philipp
parents: 653
diff changeset
102 li t4, 'd'
653
0c8838766866 - riscv64 support for calls and callbacks (but lacking aggr and syscall support) - thanks Jun Jeon! :)
Tassilo Philipp
parents:
diff changeset
103 beq t3, t4, .retd
0c8838766866 - riscv64 support for calls and callbacks (but lacking aggr and syscall support) - thanks Jun Jeon! :)
Tassilo Philipp
parents:
diff changeset
104
0c8838766866 - riscv64 support for calls and callbacks (but lacking aggr and syscall support) - thanks Jun Jeon! :)
Tassilo Philipp
parents:
diff changeset
105 .reti:
659
b8969b7b4876 riscv64 callbacks:
Tassilo Philipp
parents: 653
diff changeset
106 ld a0, 144(sp)
653
0c8838766866 - riscv64 support for calls and callbacks (but lacking aggr and syscall support) - thanks Jun Jeon! :)
Tassilo Philipp
parents:
diff changeset
107 j .ret
0c8838766866 - riscv64 support for calls and callbacks (but lacking aggr and syscall support) - thanks Jun Jeon! :)
Tassilo Philipp
parents:
diff changeset
108 .retf:
659
b8969b7b4876 riscv64 callbacks:
Tassilo Philipp
parents: 653
diff changeset
109 flw fa0, 144(sp)
653
0c8838766866 - riscv64 support for calls and callbacks (but lacking aggr and syscall support) - thanks Jun Jeon! :)
Tassilo Philipp
parents:
diff changeset
110 j .ret
0c8838766866 - riscv64 support for calls and callbacks (but lacking aggr and syscall support) - thanks Jun Jeon! :)
Tassilo Philipp
parents:
diff changeset
111 .retd:
659
b8969b7b4876 riscv64 callbacks:
Tassilo Philipp
parents: 653
diff changeset
112 fld fa0, 144(sp)
653
0c8838766866 - riscv64 support for calls and callbacks (but lacking aggr and syscall support) - thanks Jun Jeon! :)
Tassilo Philipp
parents:
diff changeset
113 .ret:
659
b8969b7b4876 riscv64 callbacks:
Tassilo Philipp
parents: 653
diff changeset
114
b8969b7b4876 riscv64 callbacks:
Tassilo Philipp
parents: 653
diff changeset
115 /* epilog */
653
0c8838766866 - riscv64 support for calls and callbacks (but lacking aggr and syscall support) - thanks Jun Jeon! :)
Tassilo Philipp
parents:
diff changeset
116
659
b8969b7b4876 riscv64 callbacks:
Tassilo Philipp
parents: 653
diff changeset
117 ld ra, 168(sp)
b8969b7b4876 riscv64 callbacks:
Tassilo Philipp
parents: 653
diff changeset
118 ld s0, 160(sp)
653
0c8838766866 - riscv64 support for calls and callbacks (but lacking aggr and syscall support) - thanks Jun Jeon! :)
Tassilo Philipp
parents:
diff changeset
119 add sp, sp, 176
0c8838766866 - riscv64 support for calls and callbacks (but lacking aggr and syscall support) - thanks Jun Jeon! :)
Tassilo Philipp
parents:
diff changeset
120 ret
0c8838766866 - riscv64 support for calls and callbacks (but lacking aggr and syscall support) - thanks Jun Jeon! :)
Tassilo Philipp
parents:
diff changeset
121