comparison dyncallback/dyncall_callback_mips_o32_gas.s @ 103:b15d814ba274

- mostly functional mips o32 callbacks (seems to still have problems with 64bit params)
author cslag
date Wed, 08 Jun 2016 02:27:12 +0200
parents b7a9b524f0c3
children dbca6763f2be
comparison
equal deleted inserted replaced
102:b7a9b524f0c3 103:b15d814ba274
37 .ent dcCallbackThunkEntry 37 .ent dcCallbackThunkEntry
38 .type dcCallbackThunkEntry, @function 38 .type dcCallbackThunkEntry, @function
39 39
40 /* Called by thunk - thunk stores pointer to DCCallback in $12 ($t4), and pointer to called function in $25 ($t9, required for PIC) */ 40 /* Called by thunk - thunk stores pointer to DCCallback in $12 ($t4), and pointer to called function in $25 ($t9, required for PIC) */
41 dcCallbackThunkEntry: 41 dcCallbackThunkEntry:
42 .frame $fp,32,$31 /* infos for debugger: reg use, sizes, */
43 /*.mask 0x00000000,0 /* int stack usage, */
44 /*.fmask 0x00000000,0 /* fp stack usage */
45 .set noreorder 42 .set noreorder
46 .set nomacro 43 .set nomacro
47 44
48 /* Prolog. Just store the minimum, return address, frame pointer, spill area. */ 45 /* Prolog. Just store the minimum, return address, frame pointer, spill area. */
49 addiu $sp, $sp, -32 /* open frame: 32b for 8b aligned frame (retval+ra+fp+spill) */ 46 subu $sp, 32 /* open frame: 32b for 8b aligned frame (retval+ra+fp+spill) */
50 sw $ra, 20($sp) /* save link register */ 47 sw $ra, 20($sp) /* save link register */
51 sw $fp, 16($sp) /* save frame pointer */
52 nop
53 move $fp, $sp /* frame pointer = sp */
54 48
55 /* Since all arguments are in one consecutive block, we'll pass the pointer */ 49 .frame $fp,32,$31 /* specify our frame: fp,size,lr; creates virt $fp */
56 /* to them as second argument to the callback handler. Caller doesn't spill */ 50
57 /* though, so let's write $4-$7 ($a0-$a3) to the dedicated spill area, first */ 51 /* Init return value */
58 /* (which is in _caller's_ frame). */ 52 sw $zero, 24($sp)
59 sw $7, 44($sp) 53 sw $zero, 28($sp)
60 sw $6, 40($sp) 54
61 sw $5, 36($sp) 55 /* If we spill the first four, all arguments will be in one out in consecutive block */
62 sw $4, 32($sp) 56 /* Caller doesn't and it's up to us to spill, so let's write $4-$7 ($a0-$a3) to the */
57 /* dedicated spill area, first (at end of _caller's_ frame, so $fp points right to it). */
58 sw $7, 12($fp)
59 sw $6, 8($fp)
60 sw $5, 4($fp)
61 sw $4, 0($fp)
62
63 /* Init DCArg, which contains stackptr* to the args, which is $fp. Use padding between */
64 /* stored return address and parameter area as place to store it (hacky, but saves 8b) */
65 sw $fp, 16($sp)
63 66
64 /* Prepare callback handler call. */ 67 /* Prepare callback handler call. */
65 move $4, $12 /* Param 0 = DCCallback*, $12 ($t4) holds pointer to thunk */ 68 move $4, $12 /* Param 0 = DCCallback*, $12 ($t4) holds pointer to thunk */
66 addiu $5, $sp, 16 /* Param 1 = DCArgs*, basically location of where fp is stored */ 69 addiu $5, $sp, 16 /* Param 1 = DCArgs*, pointer to where pointer to args is stored */
67 addiu $6, $sp, 24 /* Param 2 = results pointer to 8b of local data on stack */ 70 addiu $6, $sp, 24 /* Param 2 = results pointer to 8b of local data on stack */
68 lw $7, 24($12) /* Param 3 = userdata pointer */ 71 lw $7, 24($12) /* Param 3 = userdata pointer */
69 72
70 lw $25, 20($12) /* store handler entry in $25 ($t9) */ 73 lw $25, 20($12) /* store handler entry in $25 ($t9), required for PIC */
71 jalr $25 /* jump */ 74 jalr $25 /* jump */
72 nop 75 nop
73 76
77 /* Copy result in corresponding registers $2-$3 ($v0-$v1) */
78 lw $2, 24($sp)
79 lw $3, 28($sp)
80
74 /* Epilog. Tear down frame and return. */ 81 /* Epilog. Tear down frame and return. */
75 move $sp, $fp /* restore stack pointer */
76 nop
77 lw $ra, 20($sp) /* restore return address */ 82 lw $ra, 20($sp) /* restore return address */
78 lw $fp, 16($sp) /* restore frame pointer */
79 addiu $sp, $sp, 32 /* close frame */ 83 addiu $sp, $sp, 32 /* close frame */
80 j $ra /* return */ 84 j $ra /* return */
81 nop 85 nop
82 86
83 .set macro 87 .set macro