annotate dyncallback/dyncall_callback_ppc32_apple.s @ 369:26aa936d4841

- removed all .machine ppc pseudo-ops (see prev commit) - format fix
author Tassilo Philipp
date Sat, 08 Aug 2020 20:39:54 +0200
parents d982a00c2177
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_callback_ppc32_apple.s
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
6 Description: Callback Thunk - PowerPC 32-bit System V 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
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
9 Copyright (c) 2007-2015 Daniel Adler <dadler@uni-goettingen.de>,
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
369
26aa936d4841 - removed all .machine ppc pseudo-ops (see prev commit)
Tassilo Philipp
parents: 357
diff changeset
26 /* .machine ppc /* clang's integrated as doesn't handle this on anything but Darwin (at least for clang <= 9) */
239
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 235
diff changeset
27 .text
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 235
diff changeset
28 .align 2
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
29
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
30 /* Callback Thunk Entry code for PowerPC 32-bit Darwin/Apple Mac OS X. */
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
31
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
32
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
33 /* Stack Frame Layout:
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
34
239
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 235
diff changeset
35 204 DCValue ()
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 235
diff changeset
36 56 DCArgs (32+104+4+8 = 148)
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 235
diff changeset
37 24 Parameter area (4*8 = 32)
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 235
diff changeset
38 0 Linkage area (24)
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
39
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
40 */
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
41
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
42 /* Constants. */
239
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 235
diff changeset
43 INT_REGS = 8
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 235
diff changeset
44 FLOAT_REGS = 13
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 235
diff changeset
45 SIZEOF_INT = 4
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 235
diff changeset
46 SIZEOF_DOUBLE = 8
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 235
diff changeset
47
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
48
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
49 /* Linkage area. */
239
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 235
diff changeset
50 LINK_SP = 0
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 235
diff changeset
51 LINK_CR = 4
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 235
diff changeset
52 LINK_LR = 8
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 235
diff changeset
53 LINK_OFFSET = 0
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 235
diff changeset
54 LINK_SIZE = 24
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
55 /* Parameter area. */
239
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 235
diff changeset
56 PAR_OFFSET = LINK_SIZE
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 235
diff changeset
57 PAR_SIZE = 32
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
58 /* local struct DCArgs */
239
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 235
diff changeset
59 ARGS_OFFSET = (PAR_OFFSET+PAR_SIZE)
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 235
diff changeset
60 ARGS_SIZE = (SIZEOF_INT*INT_REGS)+(SIZEOF_DOUBLE*FLOAT_REGS) /* = 136 */
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
61 /* local struct DCValue */
239
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 235
diff changeset
62 RESULT_OFFSET = (ARGS_OFFSET+ARGS_SIZE)
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 235
diff changeset
63 RESULT_SIZE = 16
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
64 /* additional locals (reg 30/31) */
239
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 235
diff changeset
65 LOCALS_OFFSET = (RESULT_OFFSET+RESULT_SIZE)
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 235
diff changeset
66 LOCALS_SIZE = 2*SIZEOF_INT
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
67 /* total */
239
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 235
diff changeset
68 FRAME_SIZE = ((LOCALS_OFFSET+LOCALS_SIZE)+15 & (-16))
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
69
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
70 /* struct DCCallback */
239
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 235
diff changeset
71 DCB_THUNK = 0
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 235
diff changeset
72 DCB_HANDLER = 24
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 235
diff changeset
73 DCB_STACKCLEAN = 28
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 235
diff changeset
74 DCB_USERDATA = 32
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 /* struct DCArgs */
239
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 235
diff changeset
77 DCA_IARRAY = 0
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 235
diff changeset
78 DCA_FARRAY = SIZEOF_INT*INT_REGS
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 235
diff changeset
79 DCA_SP = DCA_FARRAY + SIZEOF_DOUBLE*FLOAT_REGS
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 235
diff changeset
80 DCA_ICOUNT = DCA_SP + 4
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 235
diff changeset
81 DCA_FCOUNT = DCA_ICOUNT + 4
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
82
239
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 235
diff changeset
83 iregfile = ARGS_OFFSET+DCA_IARRAY
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 235
diff changeset
84 fregfile = ARGS_OFFSET+DCA_FARRAY
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 235
diff changeset
85 save_sp = ARGS_OFFSET+DCA_SP
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 235
diff changeset
86 icount = ARGS_OFFSET+DCA_ICOUNT
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 235
diff changeset
87 fcount = ARGS_OFFSET+DCA_FCOUNT
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
88
239
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 235
diff changeset
89 .globl _dcCallbackThunkEntry
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 235
diff changeset
90
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 235
diff changeset
91 /*
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 235
diff changeset
92 Thunk entry:
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 235
diff changeset
93 r2 = DCCallback*
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 235
diff changeset
94 */
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
95 _dcCallbackThunkEntry:
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
96
235
df556fd8ea37 Darwin/PPC:
Tassilo Philipp
parents: 0
diff changeset
97 mflr r0
239
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 235
diff changeset
98 stw r0, 8(r1) /* store return address */
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 235
diff changeset
99 addi r12,r1, PAR_OFFSET /* temporary r12 = parameter area on callers stack frame */
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 235
diff changeset
100 stwu r1, -FRAME_SIZE(r1) /* save callers stack pointer and make new stack frame. */
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 235
diff changeset
101 stw r3, iregfile+ 0*4(r1) /* spill 8 integer parameter registers */
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 235
diff changeset
102 stw r4, iregfile+ 1*4(r1)
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 235
diff changeset
103 stw r5, iregfile+ 2*4(r1)
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 235
diff changeset
104 stw r6, iregfile+ 3*4(r1)
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 235
diff changeset
105 stw r7, iregfile+ 4*4(r1)
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 235
diff changeset
106 stw r8, iregfile+ 5*4(r1)
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 235
diff changeset
107 stw r9, iregfile+ 6*4(r1)
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 235
diff changeset
108 stw r10,iregfile+ 7*4(r1)
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 235
diff changeset
109 stfd f1, fregfile+ 0*8(r1) /* spill 13 float parameter registers */
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
110 stfd f2, fregfile+ 1*8(r1)
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
111 stfd f3, fregfile+ 2*8(r1)
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
112 stfd f4, fregfile+ 3*8(r1)
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
113 stfd f5, fregfile+ 4*8(r1)
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
114 stfd f6, fregfile+ 5*8(r1)
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
115 stfd f7, fregfile+ 6*8(r1)
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
116 stfd f8, fregfile+ 7*8(r1)
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
117 stfd f9, fregfile+ 8*8(r1)
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
118 stfd f10,fregfile+ 9*8(r1)
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
119 stfd f11,fregfile+10*8(r1)
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
120 stfd f12,fregfile+11*8(r1)
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
121 stfd f13,fregfile+12*8(r1)
239
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 235
diff changeset
122 /* initialize struct DCCallback */
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 235
diff changeset
123 stw r12,save_sp(r1) /* init stack pointer */
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 235
diff changeset
124 xor r0, r0, r0 /* init register counters */
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 235
diff changeset
125 stw r0, icount(r1)
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 235
diff changeset
126 stw r0, fcount(r1)
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 235
diff changeset
127 /* invoke callback handler */
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 235
diff changeset
128 mr r3, r2 /* arg 1: DCCallback* pcb */
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 235
diff changeset
129 addi r4, r1, ARGS_OFFSET /* arg 2: DCArgs* args */
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 235
diff changeset
130 addi r5, r1, RESULT_OFFSET /* arg 3: DCValue* result */
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 235
diff changeset
131 lwz r6, DCB_USERDATA(r2) /* arg 4: void* userdata */
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
132
239
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 235
diff changeset
133 /* branch-and-link to DCCallback.handler */
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 235
diff changeset
134 lwz r12,DCB_HANDLER(r2)
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 235
diff changeset
135 mtctr r12
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
136 bctrl
239
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 235
diff changeset
137 /* switch on base 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: 240
diff changeset
138 cmpi cr0, 0, r3, 0x66 /* 'f */
239
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 235
diff changeset
139 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: 240
diff changeset
140 cmpi cr0, 0, r3, 0x64 /* 'd */
239
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 235
diff changeset
141 beq .f64
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 235
diff changeset
142 .i64:
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 235
diff changeset
143 lwz r3, RESULT_OFFSET (r1)
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 235
diff changeset
144 lwz r4, RESULT_OFFSET + 4 (r1)
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
145 .end:
239
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 235
diff changeset
146 lwz r1, 0(r1) /* restore stack pointer */
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 235
diff changeset
147 lwz r0, 8(r1) /* load link register with return address */
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 235
diff changeset
148 mtlr r0
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 235
diff changeset
149 blr /* branch back to link register */
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 235
diff changeset
150 .f32:
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 235
diff changeset
151 lfs f1, RESULT_OFFSET(r1)
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 235
diff changeset
152 b .end
235
df556fd8ea37 Darwin/PPC:
Tassilo Philipp
parents: 0
diff changeset
153 .f64:
239
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 235
diff changeset
154 lfd f1, RESULT_OFFSET(r1)
c04be81f4874 - whitespace cleanup in ppc32 asm files
Tassilo Philipp
parents: 235
diff changeset
155 b .end
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
156