annotate dyncallback/dyncall_callback_mips_o32.S @ 542:a73a5cd50c19

- fix passing aggregate-by-val on x64/sysv: subaggr classification for aggr *arrays* was wrong (was problematic when there ware exactly 2 8bytes to be classified, potentially be passed via registers)
author Tassilo Philipp
date Mon, 02 May 2022 15:32:41 +0200
parents d55f9d508074
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
94
ea17e6e6bd3a - stubs for mips callback support
cslag
parents:
diff changeset
1 /*
ea17e6e6bd3a - stubs for mips callback support
cslag
parents:
diff changeset
2
ea17e6e6bd3a - stubs for mips callback support
cslag
parents:
diff changeset
3 Package: dyncall
ea17e6e6bd3a - stubs for mips callback support
cslag
parents:
diff changeset
4 Library: dyncallback
302
d55f9d508074 - mips softfloat support for o32 callconv (calls and callbacks, little and big endian)
Tassilo Philipp
parents: 109
diff changeset
5 File: dyncallback/dyncall_callback_mips_o32.S
102
b7a9b524f0c3 - mips o32 callbacks, first draft (calls into handler correctly, with correct params, but doesn't return)
cslag
parents: 94
diff changeset
6 Description: Callback Thunk - Implementation mips32 o32
94
ea17e6e6bd3a - stubs for mips callback support
cslag
parents:
diff changeset
7 License:
ea17e6e6bd3a - stubs for mips callback support
cslag
parents:
diff changeset
8
ea17e6e6bd3a - stubs for mips callback support
cslag
parents:
diff changeset
9 Copyright (c) 2016 Tassilo Philipp <tphilipp@potion-studios.com>
ea17e6e6bd3a - stubs for mips callback support
cslag
parents:
diff changeset
10
ea17e6e6bd3a - stubs for mips callback support
cslag
parents:
diff changeset
11 Permission to use, copy, modify, and distribute this software for any
ea17e6e6bd3a - stubs for mips callback support
cslag
parents:
diff changeset
12 purpose with or without fee is hereby granted, provided that the above
ea17e6e6bd3a - stubs for mips callback support
cslag
parents:
diff changeset
13 copyright notice and this permission notice appear in all copies.
ea17e6e6bd3a - stubs for mips callback support
cslag
parents:
diff changeset
14
ea17e6e6bd3a - stubs for mips callback support
cslag
parents:
diff changeset
15 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
ea17e6e6bd3a - stubs for mips callback support
cslag
parents:
diff changeset
16 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
ea17e6e6bd3a - stubs for mips callback support
cslag
parents:
diff changeset
17 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ea17e6e6bd3a - stubs for mips callback support
cslag
parents:
diff changeset
18 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
ea17e6e6bd3a - stubs for mips callback support
cslag
parents:
diff changeset
19 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ea17e6e6bd3a - stubs for mips callback support
cslag
parents:
diff changeset
20 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
ea17e6e6bd3a - stubs for mips callback support
cslag
parents:
diff changeset
21 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
ea17e6e6bd3a - stubs for mips callback support
cslag
parents:
diff changeset
22
ea17e6e6bd3a - stubs for mips callback support
cslag
parents:
diff changeset
23 */
ea17e6e6bd3a - stubs for mips callback support
cslag
parents:
diff changeset
24
102
b7a9b524f0c3 - mips o32 callbacks, first draft (calls into handler correctly, with correct params, but doesn't return)
cslag
parents: 94
diff changeset
25 /* input:
b7a9b524f0c3 - mips o32 callbacks, first draft (calls into handler correctly, with correct params, but doesn't return)
cslag
parents: 94
diff changeset
26 $t4 -> thunk
b7a9b524f0c3 - mips o32 callbacks, first draft (calls into handler correctly, with correct params, but doesn't return)
cslag
parents: 94
diff changeset
27 $t4+20 -> cb handler
b7a9b524f0c3 - mips o32 callbacks, first draft (calls into handler correctly, with correct params, but doesn't return)
cslag
parents: 94
diff changeset
28 $t4+24 -> userdata
b7a9b524f0c3 - mips o32 callbacks, first draft (calls into handler correctly, with correct params, but doesn't return)
cslag
parents: 94
diff changeset
29 */
b7a9b524f0c3 - mips o32 callbacks, first draft (calls into handler correctly, with correct params, but doesn't return)
cslag
parents: 94
diff changeset
30
b7a9b524f0c3 - mips o32 callbacks, first draft (calls into handler correctly, with correct params, but doesn't return)
cslag
parents: 94
diff changeset
31 .section .mdebug.abi32
b7a9b524f0c3 - mips o32 callbacks, first draft (calls into handler correctly, with correct params, but doesn't return)
cslag
parents: 94
diff changeset
32 .previous
b7a9b524f0c3 - mips o32 callbacks, first draft (calls into handler correctly, with correct params, but doesn't return)
cslag
parents: 94
diff changeset
33 .abicalls
b7a9b524f0c3 - mips o32 callbacks, first draft (calls into handler correctly, with correct params, but doesn't return)
cslag
parents: 94
diff changeset
34 .text
b7a9b524f0c3 - mips o32 callbacks, first draft (calls into handler correctly, with correct params, but doesn't return)
cslag
parents: 94
diff changeset
35 .align 2
94
ea17e6e6bd3a - stubs for mips callback support
cslag
parents:
diff changeset
36 .globl dcCallbackThunkEntry
102
b7a9b524f0c3 - mips o32 callbacks, first draft (calls into handler correctly, with correct params, but doesn't return)
cslag
parents: 94
diff changeset
37 .ent dcCallbackThunkEntry
b7a9b524f0c3 - mips o32 callbacks, first draft (calls into handler correctly, with correct params, but doesn't return)
cslag
parents: 94
diff changeset
38 .type dcCallbackThunkEntry, @function
b7a9b524f0c3 - mips o32 callbacks, first draft (calls into handler correctly, with correct params, but doesn't return)
cslag
parents: 94
diff changeset
39
104
dbca6763f2be - complete, working mips o32 callback (using hardware fp); fixes error from last commit, which ignored first 2 float args
cslag
parents: 103
diff changeset
40 /* Called by thunk - thunk stores pointer to DCCallback in $12 ($t4), and */
dbca6763f2be - complete, working mips o32 callback (using hardware fp); fixes error from last commit, which ignored first 2 float args
cslag
parents: 103
diff changeset
41 /* pointer to called function in $25 ($t9, required for PIC) */
94
ea17e6e6bd3a - stubs for mips callback support
cslag
parents:
diff changeset
42 dcCallbackThunkEntry:
102
b7a9b524f0c3 - mips o32 callbacks, first draft (calls into handler correctly, with correct params, but doesn't return)
cslag
parents: 94
diff changeset
43 .set noreorder
94
ea17e6e6bd3a - stubs for mips callback support
cslag
parents:
diff changeset
44
104
dbca6763f2be - complete, working mips o32 callback (using hardware fp); fixes error from last commit, which ignored first 2 float args
cslag
parents: 103
diff changeset
45 /* Prolog. Just store the minimum, return address, spill area. */
109
9e677d4c0b6b - mips comment cleanups
cslag
parents: 107
diff changeset
46 /* Frame size of 56b comes from following areas (each 8b aligned): */
104
dbca6763f2be - complete, working mips o32 callback (using hardware fp); fixes error from last commit, which ignored first 2 float args
cslag
parents: 103
diff changeset
47 /* local: fpregs:16 + retval:8 + DCArgs:8 */
dbca6763f2be - complete, working mips o32 callback (using hardware fp); fixes error from last commit, which ignored first 2 float args
cslag
parents: 103
diff changeset
48 /* save: ra:4 (+ pad:4) */
dbca6763f2be - complete, working mips o32 callback (using hardware fp); fixes error from last commit, which ignored first 2 float args
cslag
parents: 103
diff changeset
49 /* param: spill:16 */
dbca6763f2be - complete, working mips o32 callback (using hardware fp); fixes error from last commit, which ignored first 2 float args
cslag
parents: 103
diff changeset
50 subu $sp, 56 /* open frame */
103
b15d814ba274 - mostly functional mips o32 callbacks (seems to still have problems with 64bit params)
cslag
parents: 102
diff changeset
51 sw $ra, 20($sp) /* save link register */
b15d814ba274 - mostly functional mips o32 callbacks (seems to still have problems with 64bit params)
cslag
parents: 102
diff changeset
52
104
dbca6763f2be - complete, working mips o32 callback (using hardware fp); fixes error from last commit, which ignored first 2 float args
cslag
parents: 103
diff changeset
53 .frame $fp,56,$31 /* specify our frame: fp,size,lr; creates virt $fp */
106
d595eb90efdd - dyncallback/mips_o32 fixes for when using -O? optimization flags; basically not using $fp directly, anymore
cslag
parents: 104
diff changeset
54 /* code below doesn't use $fp though, as n/a with -O1 */
103
b15d814ba274 - mostly functional mips o32 callbacks (seems to still have problems with 64bit params)
cslag
parents: 102
diff changeset
55 /* Init return value */
104
dbca6763f2be - complete, working mips o32 callback (using hardware fp); fixes error from last commit, which ignored first 2 float args
cslag
parents: 103
diff changeset
56 sw $zero, 32($sp)
dbca6763f2be - complete, working mips o32 callback (using hardware fp); fixes error from last commit, which ignored first 2 float args
cslag
parents: 103
diff changeset
57 sw $zero, 36($sp)
102
b7a9b524f0c3 - mips o32 callbacks, first draft (calls into handler correctly, with correct params, but doesn't return)
cslag
parents: 94
diff changeset
58
104
dbca6763f2be - complete, working mips o32 callback (using hardware fp); fixes error from last commit, which ignored first 2 float args
cslag
parents: 103
diff changeset
59 /* Store the arguments passed via registers somewhere for dcArg* to access. */
dbca6763f2be - complete, working mips o32 callback (using hardware fp); fixes error from last commit, which ignored first 2 float args
cslag
parents: 103
diff changeset
60 /* For $4-$7 ($a0-$a3), use dedicated spill area (caller doesn't spill, but */
dbca6763f2be - complete, working mips o32 callback (using hardware fp); fixes error from last commit, which ignored first 2 float args
cslag
parents: 103
diff changeset
61 /* provides it at end of _caller's_ frame, so $fp points right to it). */
dbca6763f2be - complete, working mips o32 callback (using hardware fp); fixes error from last commit, which ignored first 2 float args
cslag
parents: 103
diff changeset
62 /* For $f12 and $f14 use our space (in local data), which is adjacent. */
302
d55f9d508074 - mips softfloat support for o32 callconv (calls and callbacks, little and big endian)
Tassilo Philipp
parents: 109
diff changeset
63 #if defined(DC__ABI_HARDFLOAT)
d55f9d508074 - mips softfloat support for o32 callconv (calls and callbacks, little and big endian)
Tassilo Philipp
parents: 109
diff changeset
64 s.d $f12, 40($sp) /* -16($fp) */
d55f9d508074 - mips softfloat support for o32 callconv (calls and callbacks, little and big endian)
Tassilo Philipp
parents: 109
diff changeset
65 s.d $f14, 48($sp) /* -8($fp) */
d55f9d508074 - mips softfloat support for o32 callconv (calls and callbacks, little and big endian)
Tassilo Philipp
parents: 109
diff changeset
66 #endif /* DC__ABI_HARDFLOAT */
d55f9d508074 - mips softfloat support for o32 callconv (calls and callbacks, little and big endian)
Tassilo Philipp
parents: 109
diff changeset
67 sw $4, 56($sp) /* 0($fp) */
d55f9d508074 - mips softfloat support for o32 callconv (calls and callbacks, little and big endian)
Tassilo Philipp
parents: 109
diff changeset
68 sw $5, 60($sp) /* 4($fp) */
d55f9d508074 - mips softfloat support for o32 callconv (calls and callbacks, little and big endian)
Tassilo Philipp
parents: 109
diff changeset
69 sw $6, 64($sp) /* 8($fp) */
d55f9d508074 - mips softfloat support for o32 callconv (calls and callbacks, little and big endian)
Tassilo Philipp
parents: 109
diff changeset
70 sw $7, 68($sp) /* 12($fp) */
103
b15d814ba274 - mostly functional mips o32 callbacks (seems to still have problems with 64bit params)
cslag
parents: 102
diff changeset
71
104
dbca6763f2be - complete, working mips o32 callback (using hardware fp); fixes error from last commit, which ignored first 2 float args
cslag
parents: 103
diff changeset
72 /* Init DCArg, which contains reg_count and stackptr* to the args. Point */
dbca6763f2be - complete, working mips o32 callback (using hardware fp); fixes error from last commit, which ignored first 2 float args
cslag
parents: 103
diff changeset
73 /* stackptr to the area where the non-float args start (which is at $fp). */
302
d55f9d508074 - mips softfloat support for o32 callconv (calls and callbacks, little and big endian)
Tassilo Philipp
parents: 109
diff changeset
74 addiu $4, $sp, 56 /* <- non-$fp replacement for: */
d55f9d508074 - mips softfloat support for o32 callconv (calls and callbacks, little and big endian)
Tassilo Philipp
parents: 109
diff changeset
75 sw $4, 28($sp) /* <- sw $fp, 28($sp) */
d55f9d508074 - mips softfloat support for o32 callconv (calls and callbacks, little and big endian)
Tassilo Philipp
parents: 109
diff changeset
76 #if defined(DC__ABI_HARDFLOAT)
d55f9d508074 - mips softfloat support for o32 callconv (calls and callbacks, little and big endian)
Tassilo Philipp
parents: 109
diff changeset
77 sw $zero, 24($sp) /* init num float-regs (unused for soft-float) */
d55f9d508074 - mips softfloat support for o32 callconv (calls and callbacks, little and big endian)
Tassilo Philipp
parents: 109
diff changeset
78 #endif /* DC__ABI_HARDFLOAT */
102
b7a9b524f0c3 - mips o32 callbacks, first draft (calls into handler correctly, with correct params, but doesn't return)
cslag
parents: 94
diff changeset
79
b7a9b524f0c3 - mips o32 callbacks, first draft (calls into handler correctly, with correct params, but doesn't return)
cslag
parents: 94
diff changeset
80 /* Prepare callback handler call. */
103
b15d814ba274 - mostly functional mips o32 callbacks (seems to still have problems with 64bit params)
cslag
parents: 102
diff changeset
81 move $4, $12 /* Param 0 = DCCallback*, $12 ($t4) holds pointer to thunk */
104
dbca6763f2be - complete, working mips o32 callback (using hardware fp); fixes error from last commit, which ignored first 2 float args
cslag
parents: 103
diff changeset
82 addiu $5, $sp, 24 /* Param 1 = DCArgs*, pointer to where pointer to args is stored */
dbca6763f2be - complete, working mips o32 callback (using hardware fp); fixes error from last commit, which ignored first 2 float args
cslag
parents: 103
diff changeset
83 addiu $6, $sp, 32 /* Param 2 = results pointer to 8b of local data on stack */
103
b15d814ba274 - mostly functional mips o32 callbacks (seems to still have problems with 64bit params)
cslag
parents: 102
diff changeset
84 lw $7, 24($12) /* Param 3 = userdata pointer */
102
b7a9b524f0c3 - mips o32 callbacks, first draft (calls into handler correctly, with correct params, but doesn't return)
cslag
parents: 94
diff changeset
85
103
b15d814ba274 - mostly functional mips o32 callbacks (seems to still have problems with 64bit params)
cslag
parents: 102
diff changeset
86 lw $25, 20($12) /* store handler entry in $25 ($t9), required for PIC */
b15d814ba274 - mostly functional mips o32 callbacks (seems to still have problems with 64bit params)
cslag
parents: 102
diff changeset
87 jalr $25 /* jump */
104
dbca6763f2be - complete, working mips o32 callback (using hardware fp); fixes error from last commit, which ignored first 2 float args
cslag
parents: 103
diff changeset
88 nop /* branch delay nop */
102
b7a9b524f0c3 - mips o32 callbacks, first draft (calls into handler correctly, with correct params, but doesn't return)
cslag
parents: 94
diff changeset
89
302
d55f9d508074 - mips softfloat support for o32 callconv (calls and callbacks, little and big endian)
Tassilo Philipp
parents: 109
diff changeset
90 /* Copy result to corresponding registers */
d55f9d508074 - mips softfloat support for o32 callconv (calls and callbacks, little and big endian)
Tassilo Philipp
parents: 109
diff changeset
91 /* Handle single precision soft-float retvals differently on big-endian */
d55f9d508074 - mips softfloat support for o32 callconv (calls and callbacks, little and big endian)
Tassilo Philipp
parents: 109
diff changeset
92 /* targets as they are right-justified in their 8b stack lots */
d55f9d508074 - mips softfloat support for o32 callconv (calls and callbacks, little and big endian)
Tassilo Philipp
parents: 109
diff changeset
93 #if !defined(DC__ABI_HARDFLOAT) && defined(DC__Endian_BIG)
d55f9d508074 - mips softfloat support for o32 callconv (calls and callbacks, little and big endian)
Tassilo Philipp
parents: 109
diff changeset
94 xori $4, $2, 'f' /* $4 = 0 if cb-handler returned 'f' in $2 */
d55f9d508074 - mips softfloat support for o32 callconv (calls and callbacks, little and big endian)
Tassilo Philipp
parents: 109
diff changeset
95 #endif
d55f9d508074 - mips softfloat support for o32 callconv (calls and callbacks, little and big endian)
Tassilo Philipp
parents: 109
diff changeset
96 lw $2, 32($sp)
d55f9d508074 - mips softfloat support for o32 callconv (calls and callbacks, little and big endian)
Tassilo Philipp
parents: 109
diff changeset
97 lw $3, 36($sp)
d55f9d508074 - mips softfloat support for o32 callconv (calls and callbacks, little and big endian)
Tassilo Philipp
parents: 109
diff changeset
98 #if defined(DC__ABI_HARDFLOAT)
104
dbca6763f2be - complete, working mips o32 callback (using hardware fp); fixes error from last commit, which ignored first 2 float args
cslag
parents: 103
diff changeset
99 l.d $f0, 32($sp)
302
d55f9d508074 - mips softfloat support for o32 callconv (calls and callbacks, little and big endian)
Tassilo Philipp
parents: 109
diff changeset
100 #elif defined(DC__Endian_BIG)
d55f9d508074 - mips softfloat support for o32 callconv (calls and callbacks, little and big endian)
Tassilo Philipp
parents: 109
diff changeset
101 bgtz $4, .nonf32r /* if no 'f' returned, $2 and $3 are good */
d55f9d508074 - mips softfloat support for o32 callconv (calls and callbacks, little and big endian)
Tassilo Philipp
parents: 109
diff changeset
102 nop /* branch delay nop */
d55f9d508074 - mips softfloat support for o32 callconv (calls and callbacks, little and big endian)
Tassilo Philipp
parents: 109
diff changeset
103 move $2, $3
d55f9d508074 - mips softfloat support for o32 callconv (calls and callbacks, little and big endian)
Tassilo Philipp
parents: 109
diff changeset
104 .nonf32r:
d55f9d508074 - mips softfloat support for o32 callconv (calls and callbacks, little and big endian)
Tassilo Philipp
parents: 109
diff changeset
105 #endif /* DC__ABI_HARDFLOAT */
103
b15d814ba274 - mostly functional mips o32 callbacks (seems to still have problems with 64bit params)
cslag
parents: 102
diff changeset
106
102
b7a9b524f0c3 - mips o32 callbacks, first draft (calls into handler correctly, with correct params, but doesn't return)
cslag
parents: 94
diff changeset
107 /* Epilog. Tear down frame and return. */
b7a9b524f0c3 - mips o32 callbacks, first draft (calls into handler correctly, with correct params, but doesn't return)
cslag
parents: 94
diff changeset
108 lw $ra, 20($sp) /* restore return address */
104
dbca6763f2be - complete, working mips o32 callback (using hardware fp); fixes error from last commit, which ignored first 2 float args
cslag
parents: 103
diff changeset
109 addiu $sp, $sp, 56 /* close frame */
102
b7a9b524f0c3 - mips o32 callbacks, first draft (calls into handler correctly, with correct params, but doesn't return)
cslag
parents: 94
diff changeset
110 j $ra /* return */
104
dbca6763f2be - complete, working mips o32 callback (using hardware fp); fixes error from last commit, which ignored first 2 float args
cslag
parents: 103
diff changeset
111 nop /* branch delay nop */
102
b7a9b524f0c3 - mips o32 callbacks, first draft (calls into handler correctly, with correct params, but doesn't return)
cslag
parents: 94
diff changeset
112
b7a9b524f0c3 - mips o32 callbacks, first draft (calls into handler correctly, with correct params, but doesn't return)
cslag
parents: 94
diff changeset
113 .set reorder
b7a9b524f0c3 - mips o32 callbacks, first draft (calls into handler correctly, with correct params, but doesn't return)
cslag
parents: 94
diff changeset
114 .end dcCallbackThunkEntry
b7a9b524f0c3 - mips o32 callbacks, first draft (calls into handler correctly, with correct params, but doesn't return)
cslag
parents: 94
diff changeset
115 .ident "handwritten"
b7a9b524f0c3 - mips o32 callbacks, first draft (calls into handler correctly, with correct params, but doesn't return)
cslag
parents: 94
diff changeset
116