annotate dyncallback/dyncall_callback_ppc32.S @ 357:d982a00c2177

- PPC64 asm syntax fix, specifying explicitly comparison mode for cmpi (newer toolchains complain, older ones took optional field of instruction which happened to be same value)
author Tassilo Philipp
date Tue, 25 Feb 2020 18:16:13 +0100
parents f5577f6bf97a
children f28b7f4f5749
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_callback_ppc32.S
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
6 Description: Callback Thunk Entry for PowerPC 32-bit System V Big-Endian ABI
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
281
f5577f6bf97a - file header cleanups for release
Tassilo Philipp
parents: 240
diff changeset
9 Copyright (c) 2015-2018 Daniel Adler <dadler@uni-goettingen.de>
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
10
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
11 Permission to use, copy, modify, and distribute this software for any
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
12 purpose with or without fee is hereby granted, provided that the above
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
13 copyright notice and this permission notice appear in all copies.
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
14
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
15 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
16 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
17 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
18 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
19 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
20 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
21 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
22
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 #include "../portasm/portasm-ppc.S"
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
27
239
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 0
diff changeset
28 .machine ppc
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 0
diff changeset
29 .text
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 0
diff changeset
30 .align 2
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
31
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
32 /* Struct DCCallback */
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
33
239
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 0
diff changeset
34 DCB_THUNK = 0
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 0
diff changeset
35 DCB_HANDLER = 24
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 0
diff changeset
36 DCB_CLEANUP = 28
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 0
diff changeset
37 DCB_USERDATA = 32
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
38
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
39 /* Struct DCArgs */
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
40
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
41 ARGS_IREGS = 0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
42 ARGS_FREGS = ARGS_IREGS + 4*8
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
43 ARGS_SP = ARGS_FREGS + 8*13
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
44 ARGS_ICNT = ARGS_SP + 4
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
45 ARGS_FCNT = ARGS_ICNT + 4
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
46 ARGS_SIZE = ARGS_FCNT + 4
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
47
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
48 /* Struct DCValue */
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
49
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
50 RESULT_SIZE = 8
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
51
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
52 /* Stack Offsets: */
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
53
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
54 SP_PREV = 0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
55 SP_LR = (SP_PREV + 4)
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
56 SP_PAR = SP_LR + 4
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
57 PAR_SZ = 0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
58 SP_ARGS = SP_PAR + PAR_SZ
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
59 SP_IREGS = SP_ARGS + ARGS_IREGS
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
60 SP_FREGS = SP_ARGS + ARGS_FREGS
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
61 SP_SP = SP_ARGS + ARGS_SP
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
62 SP_ICNT = SP_ARGS + ARGS_ICNT
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
63 SP_FCNT = SP_ARGS + ARGS_FCNT
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
64 SP_RESULT = SP_ARGS + ARGS_SIZE
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
65 SP_SIZE = SP_RESULT + RESULT_SIZE
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
66
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
67 #define ALIGN(M,X) ( M+(X-1) & (-X) )
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
68
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
69 FRAMESIZE = ALIGN(SP_SIZE,16)
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
70
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
71 GLOBAL_C(dcCallbackThunkEntry)
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
72 ENTRY_C(dcCallbackThunkEntry)
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
73
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
74 /* --------------------------------------------------------------------------
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
75
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
76 Input:
239
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 0
diff changeset
77 r1 Stack Pointer
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 0
diff changeset
78 r3-r10 Integer Arguments
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 0
diff changeset
79 f1-f8 Floating-point Arguments
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 0
diff changeset
80 r11 Thunk Pointer
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
81
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
82 */
239
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 0
diff changeset
83
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
84 /* prolog */
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
85
239
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 0
diff changeset
86 mflr r0
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 0
diff changeset
87 stw r0, SP_LR(r1) /* store return address */
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 0
diff changeset
88 addi r12,r1, SP_PAR /* temporary r12: parameter area on callers stack frame */
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
89 stwu r1, -FRAMESIZE(r1)
239
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 0
diff changeset
90
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 0
diff changeset
91 stw r3, SP_IREGS + 0*4(r1) /* spill 8 integer parameter registers */
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 0
diff changeset
92 stw r4, SP_IREGS + 1*4(r1)
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 0
diff changeset
93 stw r5, SP_IREGS + 2*4(r1)
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
94 stw r6, SP_IREGS + 3*4(r1)
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
95 stw r7, SP_IREGS + 4*4(r1)
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
96 stw r8, SP_IREGS + 5*4(r1)
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
97 stw r9, SP_IREGS + 6*4(r1)
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
98 stw r10,SP_IREGS + 7*4(r1)
239
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 0
diff changeset
99
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 0
diff changeset
100 stfd f1, SP_FREGS + 0*8(r1) /* spill 8 (of 13) float parameter registers */
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
101 stfd f2, SP_FREGS + 1*8(r1)
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
102 stfd f3, SP_FREGS + 2*8(r1)
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
103 stfd f4, SP_FREGS + 3*8(r1)
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
104 stfd f5, SP_FREGS + 4*8(r1)
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
105 stfd f6, SP_FREGS + 5*8(r1)
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
106 stfd f7, SP_FREGS + 6*8(r1)
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
107 stfd f8, SP_FREGS + 7*8(r1)
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
108
239
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 0
diff changeset
109 stw r12,SP_SP(r1) /* init stack pointer */
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 0
diff changeset
110 xor r0, r0, r0 /* init register counters */
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 0
diff changeset
111 stw r0, SP_ICNT(r1)
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 0
diff changeset
112 stw r0, SP_FCNT(r1)
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 0
diff changeset
113 stw r0, SP_RESULT(r1) /* init result object */
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 0
diff changeset
114 stw r0, SP_RESULT + 4(r1)
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 0
diff changeset
115 /* invoke callback handler */
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 0
diff changeset
116 mr r3, r11 /* arg 1: DCCallback* pcb (r11 = thunk ptr) */
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 0
diff changeset
117 addi r4, r1, SP_ARGS /* arg 2: DCArgs* args */
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 0
diff changeset
118 addi r5, r1, SP_RESULT /* arg 3: DCValue* result */
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 0
diff changeset
119 lwz r6, DCB_USERDATA(r11) /* arg 4: void* userdata */
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
120
239
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 0
diff changeset
121 /* branch-and-link to DCCallback.handler */
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 0
diff changeset
122 lwz r12, DCB_HANDLER(r11)
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 0
diff changeset
123 mtctr r12
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
124 bctrl
239
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 0
diff changeset
125 /* check result type */
357
d982a00c2177 - PPC64 asm syntax fix, specifying explicitly comparison mode for cmpi (newer toolchains complain, older ones took optional field of instruction which happened to be same value)
Tassilo Philipp
parents: 281
diff changeset
126 cmpi cr0, 0, r3, 0x66 /* 'f */
239
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 0
diff changeset
127 beq .f32
357
d982a00c2177 - PPC64 asm syntax fix, specifying explicitly comparison mode for cmpi (newer toolchains complain, older ones took optional field of instruction which happened to be same value)
Tassilo Philipp
parents: 281
diff changeset
128 cmpi cr0, 0, r3, 0x64 /* 'd */
239
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 0
diff changeset
129 beq .f64
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
130 .i64:
239
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 0
diff changeset
131 lwz r3, SP_RESULT (r1)
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 0
diff changeset
132 lwz r4, SP_RESULT + 4 (r1)
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
133 .end:
239
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 0
diff changeset
134 lwz r1, SP_PREV(r1) /* restore stack pointer */
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 0
diff changeset
135 lwz r0, SP_LR(r1) /* load link register with return address */
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 0
diff changeset
136 mtlr r0
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 0
diff changeset
137 blr /* branch back to link register */
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 0
diff changeset
138 .f32:
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 0
diff changeset
139 lfs f1, SP_RESULT(r1)
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 0
diff changeset
140 b .end
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
141 .f64:
239
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 0
diff changeset
142 lfd f1, SP_RESULT(r1)
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 0
diff changeset
143 b .end
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 0
diff changeset
144