comparison dyncallback/dyncall_callback_mips_n64.S @ 305:b104c5beec8b

- softfloat support for mips64/n64 abi
author Tassilo Philipp
date Wed, 23 May 2018 11:41:34 +0200
parents d55f9d508074
children
comparison
equal deleted inserted replaced
304:6869d834a847 305:b104c5beec8b
4 Library: dyncallback 4 Library: dyncallback
5 File: dyncallback/dyncall_callback_mips_n64.S 5 File: dyncallback/dyncall_callback_mips_n64.S
6 Description: Callback Thunk - Implementation for mips64 n64 6 Description: Callback Thunk - Implementation for mips64 n64
7 License: 7 License:
8 8
9 Copyright (c) 2016 Tassilo Philipp <tphilipp@potion-studios.com> 9 Copyright (c) 2016-2018 Tassilo Philipp <tphilipp@potion-studios.com>
10 10
11 Permission to use, copy, modify, and distribute this software for any 11 Permission to use, copy, modify, and distribute this software for any
12 purpose with or without fee is hereby granted, provided that the above 12 purpose with or without fee is hereby granted, provided that the above
13 copyright notice and this permission notice appear in all copies. 13 copyright notice and this permission notice appear in all copies.
14 14
26 $t8 -> thunk 26 $t8 -> thunk
27 $t8+56 -> cb handler 27 $t8+56 -> cb handler
28 $t8+64 -> userdata 28 $t8+64 -> userdata
29 */ 29 */
30 30
31 /* Frame size is 160b for hard- and 128b for soft-float, as follows: */
32 /* DCargs(fregs:64? + iregs:64 + regcnts:8 + sp:8) + rval:8 + ra:8 */
33 #if defined(DC__ABI_HARDFLOAT)
34 SP_SP = 160
35 #else
36 SP_SP = 96
37 #endif
38 SP_LR = SP_SP-8
39 SP_RVAL = SP_SP-16
40 SP_ARG_SP = SP_SP-24
41 SP_ARG_RC = SP_SP-32
42
31 .section .mdebug.abi64 43 .section .mdebug.abi64
32 .previous 44 .previous
33 .abicalls 45 .abicalls
34 .text 46 .text
35 .align 2 47 .align 2
37 .ent dcCallbackThunkEntry 49 .ent dcCallbackThunkEntry
38 dcCallbackThunkEntry: 50 dcCallbackThunkEntry:
39 .set noreorder 51 .set noreorder
40 52
41 /* Prolog. */ 53 /* Prolog. */
42 /* Frame size of 160b comes from following: */ 54 daddiu $sp, $sp, -SP_SP /* open frame */
43 /* DCargs(fregs:64 + iregs:64 + regcounts:8 + stackptr:8) + retval:8 + ra:8 */ 55 sd $ra, SP_LR($sp) /* save link register */
44 daddiu $sp, $sp, -160 /* open frame */
45 sd $ra, 152($sp) /* save link register */
46 56
47 .frame $fp,160,$31 /* specify our frame: fp,size,lr; creates virt $fp */ 57 .frame $fp,SP_SP,$31 /* specify our frame: fp,size,lr; creates virt $fp */
48 /* code below doesn't use $fp though, as n/a with -O1 */ 58 /* code below doesn't use $fp though, as n/a with -O1 */
49 /* Init return value */ 59 /* Init return value */
50 sd $zero, 144($sp) 60 sd $zero, SP_RVAL($sp)
51 61
52 /* Store float and int args where our DCargs member arrays are, in local area. */ 62 /* Store reg args where our DCargs member arrays are, in local stack area */
53 sd $4, 0($sp) 63 sd $4, 0($sp)
54 sd $5, 8($sp) 64 sd $5, 8($sp)
55 sd $6, 16($sp) 65 sd $6, 16($sp)
56 sd $7, 24($sp) 66 sd $7, 24($sp)
57 sd $8, 32($sp) 67 sd $8, 32($sp)
58 sd $9, 40($sp) 68 sd $9, 40($sp)
59 sd $10, 48($sp) 69 sd $10, 48($sp)
60 sd $11, 56($sp) 70 sd $11, 56($sp)
71 #if defined(DC__ABI_HARDFLOAT)
61 s.d $f12, 64($sp) 72 s.d $f12, 64($sp)
62 s.d $f13, 72($sp) 73 s.d $f13, 72($sp)
63 s.d $f14, 80($sp) 74 s.d $f14, 80($sp)
64 s.d $f15, 88($sp) 75 s.d $f15, 88($sp)
65 s.d $f16, 96($sp) 76 s.d $f16, 96($sp)
66 s.d $f17, 104($sp) 77 s.d $f17, 104($sp)
67 s.d $f18, 112($sp) 78 s.d $f18, 112($sp)
68 s.d $f19, 120($sp) 79 s.d $f19, 120($sp)
80 #endif
69 81
70 /* Init DCarg's reg_counts and stackptr. */ 82 /* Init DCarg's reg_counts and stackptr. */
71 sd $zero, 128($sp) /* reg_count */ 83 sd $zero, SP_ARG_RC($sp) /* reg_count */
72 daddiu $4, $sp, 160 84 daddiu $4, $sp, SP_SP
73 sd $4, 136($sp) /* stackptr */ 85 sd $4, SP_ARG_SP($sp) /* stackptr */
74 86
75 /* Prepare callback handler call. */ 87 /* Prepare callback handler call. */
76 move $4, $24 /* Param 0 = DCCallback*, $24 ($t8) holds pointer to thunk */ 88 move $4, $24 /* Param 0 = DCCallback*, $24/$t8 holds DCThunk* */
77 move $5, $sp /* Param 1 = DCArgs*, pointer to where pointer to args is stored */ 89 move $5, $sp /* Param 1 = ptr to where DCArgs* is stored */
78 daddiu $6, $sp, 144 /* Param 2 = results pointer to 8b of local data on stack */ 90 daddiu $6, $sp, SP_RVAL /* Param 2 = results ptr to 8b of local stack data */
79 ld $7, 64($24) /* Param 3 = userdata pointer */ 91 ld $7, 64($24) /* Param 3 = userdata pointer */
80 92
81 ld $25, 56($24) /* store handler entry in $25 ($t9), required for PIC */ 93 ld $25, 56($24) /* store handler entry in $25/$t9, required for PIC */
82 jalr $25 /* jump */ 94 jalr $25 /* jump */
83 nop /* branch delay nop */ 95 nop /* branch delay nop */
84 96
85 /* Copy result in corresponding registers $2-$3 ($v0-$v1) and $f0 */ 97 /* Copy result in corresponding registers $2-$3 ($v0-$v1) and $f0 */
86 ld $2, 144($sp) /* note: ignoring second possible retval in $3, here */ 98 ld $2, SP_RVAL($sp) /* note: ignoring 2nd possible retval in $3, here */
87 l.d $f0, 144($sp) 99 #if defined(DC__ABI_HARDFLOAT)
100 l.d $f0, SP_RVAL($sp)
101 #endif
88 102
89 /* Epilog. Tear down frame and return. */ 103 /* Epilog. Tear down frame and return. */
90 ld $ra, 152($sp) /* restore return address */ 104 ld $ra, SP_LR($sp) /* restore return address */
91 daddiu $sp, $sp, 160 /* close frame */ 105 daddiu $sp, $sp, SP_SP /* close frame */
92 j $ra /* return */ 106 j $ra /* return */
93 nop /* branch delay nop */ 107 nop /* branch delay nop */
94 108
95 .set reorder 109 .set reorder
96 .end dcCallbackThunkEntry 110 .end dcCallbackThunkEntry
97 .ident "handwritten" 111 .ident "handwritten"
98 112