Mercurial > pub > dyncall > dyncall
comparison dyncallback/dyncall_callback_sparc32.s @ 198:706fb60a1760
- safety fix for sparc32, protecting from callback handler problems when handler itself needs to spill
author | Tassilo Philipp |
---|---|
date | Sun, 19 Mar 2017 18:44:47 +0100 |
parents | 06ee88ce4962 |
children |
comparison
equal
deleted
inserted
replaced
197:53c42b1d9f8b | 198:706fb60a1760 |
---|---|
4 Library: dyncallback | 4 Library: dyncallback |
5 File: dyncallback/dyncall_callback_sparc32.s | 5 File: dyncallback/dyncall_callback_sparc32.s |
6 Description: Callback - Implementation for Sparc 32-bit | 6 Description: Callback - Implementation for Sparc 32-bit |
7 License: | 7 License: |
8 | 8 |
9 Copyright (c) 2007-2016 Daniel Adler <dadler@uni-goettingen.de>, | 9 Copyright (c) 2007-2017 Daniel Adler <dadler@uni-goettingen.de>, |
10 Tassilo Philipp <tphilipp@potion-studios.com> | 10 Tassilo Philipp <tphilipp@potion-studios.com> |
11 | 11 |
12 Permission to use, copy, modify, and distribute this software for any | 12 Permission to use, copy, modify, and distribute this software for any |
13 purpose with or without fee is hereby granted, provided that the above | 13 purpose with or without fee is hereby granted, provided that the above |
14 copyright notice and this permission notice appear in all copies. | 14 copyright notice and this permission notice appear in all copies. |
35 /* Called by thunk - thunk stores pointer to DCCallback */ | 35 /* Called by thunk - thunk stores pointer to DCCallback */ |
36 /* in %g1, and pointer to called function in %g2 */ | 36 /* in %g1, and pointer to called function in %g2 */ |
37 dcCallbackThunkEntry: | 37 dcCallbackThunkEntry: |
38 | 38 |
39 /* Prolog. */ | 39 /* Prolog. */ |
40 /* Frame size of 80b comes from needing storage space for the following: */ | 40 /* Frame size of 104b comes from needing storage space for the following: */ |
41 /* DCargs(sparc_req_reg_save_area:64 + argptr:4) + pad:4 + retval:8 */ | 41 /* req_reg_save_area:64 + spill:24 + dcargs:4 + retval:8 + pad:4 */ |
42 save %sp, -80, %sp | 42 /* Spill area could theoretically be only 16b, b/c cbHandler function has */ |
43 /* 4 arguments, but let's be conservative. */ /* cbHandler function might decide to spill (6x4b) @@@ testcode, or rely on 8byte return space in parent stack */ | |
44 save %sp, -104, %sp | |
43 | 45 |
44 /* Spill register args. */ | 46 /* Spill register args as dcargs is based on that (in prev frame, after */ |
45 st %i0, [ %fp + 68 ] /* reg arg 0 */ | 47 /* req_reg_save_area and struct_ret_ptr). */ |
46 st %i1, [ %fp + 72 ] /* reg arg 1 */ | |
47 st %i2, [ %fp + 76 ] /* reg arg 2 */ | |
48 st %i3, [ %fp + 80 ] /* reg arg 3 */ | |
49 st %i4, [ %fp + 84 ] /* reg arg 4 */ | |
50 st %i5, [ %fp + 88 ] /* reg arg 5 */ | |
51 add %fp, 68, %l0 | 48 add %fp, 68, %l0 |
52 st %l0, [ %sp + 64 ] /* init arg_ptr */ | 49 st %i0, [ %l0 + 0 ] /* reg arg 0 */ |
50 st %i1, [ %l0 + 4 ] /* reg arg 1 */ | |
51 st %i2, [ %l0 + 8 ] /* reg arg 2 */ | |
52 st %i3, [ %l0 + 12 ] /* reg arg 3 */ | |
53 st %i4, [ %l0 + 16 ] /* reg arg 4 */ | |
54 st %i5, [ %l0 + 20 ] /* reg arg 5 */ | |
55 st %l0, [ %sp + 88 ] /* init arg_ptr */ | |
53 | 56 |
54 /* Zero retval store. */ | 57 /* Zero retval store. */ |
55 st %g0, [ %sp + 72 ] | 58 st %g0, [ %sp + 96 ] |
56 st %g0, [ %sp + 76 ] | 59 st %g0, [ %sp + 100 ] |
57 | 60 |
58 /* Prepare callback handler call. */ | 61 /* Prepare callback handler call. */ |
59 mov %g1, %o0 /* Param 0 = DCCallback*, %g1 holds ptr to thunk */ | 62 mov %g1, %o0 /* Param 0 = DCCallback*, %g1 holds ptr to thunk */ |
60 add %sp, 64, %o1 /* Param 1 = DCArgs* (ptr to struct with args ptr) */ | 63 add %sp, 88, %o1 /* Param 1 = DCArgs* (ptr to struct with args ptr) */ |
61 add %sp, 72, %o2 /* Param 2 = results ptr to 8b of local stack data */ | 64 add %sp, 96, %o2 /* Param 2 = results ptr to 8b of local stack data */ |
62 ld [ %g1 + 28 ], %o3 /* Param 3 = userdata ptr */ | 65 ld [ %g1 + 28 ], %o3 /* Param 3 = userdata ptr */ |
63 | 66 |
64 ld [ %g1 + 24 ], %l0 | 67 ld [ %g1 + 24 ], %l0 |
65 call %l0 | 68 call %l0 |
66 nop | 69 nop |
67 | 70 |
68 /* Put retval in %i0/%i1 (to be in caller's %o0/%o1), and %f0/%f1. */ | 71 /* Put retval in %i0/%i1 (to be in caller's %o0/%o1), and %f0/%f1. */ |
69 ld [ %sp + 72 ], %i0 | 72 ld [ %sp + 96 ], %i0 |
70 ld [ %sp + 76 ], %i1 | 73 ld [ %sp + 100 ], %i1 |
71 ld [ %sp + 72 ], %f0 | 74 ld [ %sp + 96 ], %f0 |
72 ld [ %sp + 76 ], %f1 | 75 ld [ %sp + 100 ], %f1 |
73 | 76 |
74 /* Epilog. */ | 77 /* Epilog. */ |
75 restore /* unshift reg window */ | 78 restore /* unshift reg window */ |
76 retl /* Return from proc. -- jmpl %i7 + 8, %g0 */ | 79 retl /* Return from proc. -- jmpl %i7 + 8, %g0 */ |
77 nop | 80 nop |