Mercurial > pub > dyncall > dyncall
annotate dyncallback/dyncall_callback_mips_o32_gas.s @ 102:b7a9b524f0c3
- mips o32 callbacks, first draft (calls into handler correctly, with correct params, but doesn't return)
author | cslag |
---|---|
date | Tue, 07 Jun 2016 09:05:34 +0200 |
parents | ea17e6e6bd3a |
children | b15d814ba274 |
rev | line source |
---|---|
94 | 1 /* |
2 | |
3 Package: dyncall | |
4 Library: dyncallback | |
5 File: dyncallback/dyncall_callback_mips_o32_gas.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 | 7 License: |
8 | |
9 Copyright (c) 2016 Tassilo Philipp <tphilipp@potion-studios.com> | |
10 | |
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 | |
13 copyright notice and this permission notice appear in all copies. | |
14 | |
15 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | |
16 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | |
17 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | |
18 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | |
19 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | |
20 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | |
21 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |
22 | |
23 */ | |
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 | 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 |
b7a9b524f0c3
- mips o32 callbacks, first draft (calls into handler correctly, with correct params, but doesn't return)
cslag
parents:
94
diff
changeset
|
40 /* Called by thunk - thunk stores pointer to DCCallback in $12 ($t4), and pointer to called function in $25 ($t9, required for PIC) */ |
94 | 41 dcCallbackThunkEntry: |
102
b7a9b524f0c3
- mips o32 callbacks, first draft (calls into handler correctly, with correct params, but doesn't return)
cslag
parents:
94
diff
changeset
|
42 .frame $fp,32,$31 /* infos for debugger: reg use, sizes, */ |
b7a9b524f0c3
- mips o32 callbacks, first draft (calls into handler correctly, with correct params, but doesn't return)
cslag
parents:
94
diff
changeset
|
43 /*.mask 0x00000000,0 /* int stack usage, */ |
b7a9b524f0c3
- mips o32 callbacks, first draft (calls into handler correctly, with correct params, but doesn't return)
cslag
parents:
94
diff
changeset
|
44 /*.fmask 0x00000000,0 /* fp stack usage */ |
b7a9b524f0c3
- mips o32 callbacks, first draft (calls into handler correctly, with correct params, but doesn't return)
cslag
parents:
94
diff
changeset
|
45 .set noreorder |
b7a9b524f0c3
- mips o32 callbacks, first draft (calls into handler correctly, with correct params, but doesn't return)
cslag
parents:
94
diff
changeset
|
46 .set nomacro |
94 | 47 |
102
b7a9b524f0c3
- mips o32 callbacks, first draft (calls into handler correctly, with correct params, but doesn't return)
cslag
parents:
94
diff
changeset
|
48 /* Prolog. Just store the minimum, return address, frame pointer, spill area. */ |
b7a9b524f0c3
- mips o32 callbacks, first draft (calls into handler correctly, with correct params, but doesn't return)
cslag
parents:
94
diff
changeset
|
49 addiu $sp, $sp, -32 /* open frame: 32b for 8b aligned frame (retval+ra+fp+spill) */ |
b7a9b524f0c3
- mips o32 callbacks, first draft (calls into handler correctly, with correct params, but doesn't return)
cslag
parents:
94
diff
changeset
|
50 sw $ra, 20($sp) /* save link register */ |
b7a9b524f0c3
- mips o32 callbacks, first draft (calls into handler correctly, with correct params, but doesn't return)
cslag
parents:
94
diff
changeset
|
51 sw $fp, 16($sp) /* save frame pointer */ |
b7a9b524f0c3
- mips o32 callbacks, first draft (calls into handler correctly, with correct params, but doesn't return)
cslag
parents:
94
diff
changeset
|
52 nop |
b7a9b524f0c3
- mips o32 callbacks, first draft (calls into handler correctly, with correct params, but doesn't return)
cslag
parents:
94
diff
changeset
|
53 move $fp, $sp /* frame pointer = sp */ |
b7a9b524f0c3
- mips o32 callbacks, first draft (calls into handler correctly, with correct params, but doesn't return)
cslag
parents:
94
diff
changeset
|
54 |
b7a9b524f0c3
- mips o32 callbacks, first draft (calls into handler correctly, with correct params, but doesn't return)
cslag
parents:
94
diff
changeset
|
55 /* Since all arguments are in one consecutive block, we'll pass the pointer */ |
b7a9b524f0c3
- mips o32 callbacks, first draft (calls into handler correctly, with correct params, but doesn't return)
cslag
parents:
94
diff
changeset
|
56 /* to them as second argument to the callback handler. Caller doesn't spill */ |
b7a9b524f0c3
- mips o32 callbacks, first draft (calls into handler correctly, with correct params, but doesn't return)
cslag
parents:
94
diff
changeset
|
57 /* though, so let's write $4-$7 ($a0-$a3) to the dedicated spill area, first */ |
b7a9b524f0c3
- mips o32 callbacks, first draft (calls into handler correctly, with correct params, but doesn't return)
cslag
parents:
94
diff
changeset
|
58 /* (which is in _caller's_ frame). */ |
b7a9b524f0c3
- mips o32 callbacks, first draft (calls into handler correctly, with correct params, but doesn't return)
cslag
parents:
94
diff
changeset
|
59 sw $7, 44($sp) |
b7a9b524f0c3
- mips o32 callbacks, first draft (calls into handler correctly, with correct params, but doesn't return)
cslag
parents:
94
diff
changeset
|
60 sw $6, 40($sp) |
b7a9b524f0c3
- mips o32 callbacks, first draft (calls into handler correctly, with correct params, but doesn't return)
cslag
parents:
94
diff
changeset
|
61 sw $5, 36($sp) |
b7a9b524f0c3
- mips o32 callbacks, first draft (calls into handler correctly, with correct params, but doesn't return)
cslag
parents:
94
diff
changeset
|
62 sw $4, 32($sp) |
b7a9b524f0c3
- mips o32 callbacks, first draft (calls into handler correctly, with correct params, but doesn't return)
cslag
parents:
94
diff
changeset
|
63 |
b7a9b524f0c3
- mips o32 callbacks, first draft (calls into handler correctly, with correct params, but doesn't return)
cslag
parents:
94
diff
changeset
|
64 /* Prepare callback handler call. */ |
b7a9b524f0c3
- mips o32 callbacks, first draft (calls into handler correctly, with correct params, but doesn't return)
cslag
parents:
94
diff
changeset
|
65 move $4, $12 /* Param 0 = DCCallback*, $12 ($t4) holds pointer to thunk */ |
b7a9b524f0c3
- mips o32 callbacks, first draft (calls into handler correctly, with correct params, but doesn't return)
cslag
parents:
94
diff
changeset
|
66 addiu $5, $sp, 16 /* Param 1 = DCArgs*, basically location of where fp is stored */ |
b7a9b524f0c3
- mips o32 callbacks, first draft (calls into handler correctly, with correct params, but doesn't return)
cslag
parents:
94
diff
changeset
|
67 addiu $6, $sp, 24 /* Param 2 = results pointer to 8b of local data on stack */ |
b7a9b524f0c3
- mips o32 callbacks, first draft (calls into handler correctly, with correct params, but doesn't return)
cslag
parents:
94
diff
changeset
|
68 lw $7, 24($12) /* Param 3 = userdata pointer */ |
b7a9b524f0c3
- mips o32 callbacks, first draft (calls into handler correctly, with correct params, but doesn't return)
cslag
parents:
94
diff
changeset
|
69 |
b7a9b524f0c3
- mips o32 callbacks, first draft (calls into handler correctly, with correct params, but doesn't return)
cslag
parents:
94
diff
changeset
|
70 lw $25, 20($12) /* store handler entry in $25 ($t9) */ |
b7a9b524f0c3
- mips o32 callbacks, first draft (calls into handler correctly, with correct params, but doesn't return)
cslag
parents:
94
diff
changeset
|
71 jalr $25 /* jump */ |
b7a9b524f0c3
- mips o32 callbacks, first draft (calls into handler correctly, with correct params, but doesn't return)
cslag
parents:
94
diff
changeset
|
72 nop |
b7a9b524f0c3
- mips o32 callbacks, first draft (calls into handler correctly, with correct params, but doesn't return)
cslag
parents:
94
diff
changeset
|
73 |
b7a9b524f0c3
- mips o32 callbacks, first draft (calls into handler correctly, with correct params, but doesn't return)
cslag
parents:
94
diff
changeset
|
74 /* 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
|
75 move $sp, $fp /* restore stack pointer */ |
b7a9b524f0c3
- mips o32 callbacks, first draft (calls into handler correctly, with correct params, but doesn't return)
cslag
parents:
94
diff
changeset
|
76 nop |
b7a9b524f0c3
- mips o32 callbacks, first draft (calls into handler correctly, with correct params, but doesn't return)
cslag
parents:
94
diff
changeset
|
77 lw $ra, 20($sp) /* restore return address */ |
b7a9b524f0c3
- mips o32 callbacks, first draft (calls into handler correctly, with correct params, but doesn't return)
cslag
parents:
94
diff
changeset
|
78 lw $fp, 16($sp) /* restore frame pointer */ |
b7a9b524f0c3
- mips o32 callbacks, first draft (calls into handler correctly, with correct params, but doesn't return)
cslag
parents:
94
diff
changeset
|
79 addiu $sp, $sp, 32 /* close frame */ |
b7a9b524f0c3
- mips o32 callbacks, first draft (calls into handler correctly, with correct params, but doesn't return)
cslag
parents:
94
diff
changeset
|
80 j $ra /* return */ |
b7a9b524f0c3
- mips o32 callbacks, first draft (calls into handler correctly, with correct params, but doesn't return)
cslag
parents:
94
diff
changeset
|
81 nop |
b7a9b524f0c3
- mips o32 callbacks, first draft (calls into handler correctly, with correct params, but doesn't return)
cslag
parents:
94
diff
changeset
|
82 |
b7a9b524f0c3
- mips o32 callbacks, first draft (calls into handler correctly, with correct params, but doesn't return)
cslag
parents:
94
diff
changeset
|
83 .set macro |
b7a9b524f0c3
- mips o32 callbacks, first draft (calls into handler correctly, with correct params, but doesn't return)
cslag
parents:
94
diff
changeset
|
84 .set reorder |
b7a9b524f0c3
- mips o32 callbacks, first draft (calls into handler correctly, with correct params, but doesn't return)
cslag
parents:
94
diff
changeset
|
85 .end dcCallbackThunkEntry |
b7a9b524f0c3
- mips o32 callbacks, first draft (calls into handler correctly, with correct params, but doesn't return)
cslag
parents:
94
diff
changeset
|
86 .ident "handwritten" |
b7a9b524f0c3
- mips o32 callbacks, first draft (calls into handler correctly, with correct params, but doesn't return)
cslag
parents:
94
diff
changeset
|
87 |