diff dyncallback/dyncall_callback_sparc64.s @ 191:2f7a7f3472cb

- first draft at sparc64 callbacks (floats not working, yet)
author Tassilo Philipp
date Fri, 17 Mar 2017 03:27:36 +0100
parents 03c516772c65
children 95cf20c0d1de
line wrap: on
line diff
--- a/dyncallback/dyncall_callback_sparc64.s	Tue Mar 14 00:07:31 2017 +0100
+++ b/dyncallback/dyncall_callback_sparc64.s	Fri Mar 17 03:27:36 2017 +0100
@@ -3,11 +3,10 @@
  Package: dyncall
  Library: dyncallback
  File: dyncallback/dyncall_callback_sparc64.s
- Description: Callback Thunk - Implementation for Sparc 64-bit
+ Description: Callback - Implementation for Sparc 64-bit
  License:
 
-   Copyright (c) 2007-2011 Daniel Adler <dadler@uni-goettingen.de>,
-                           Tassilo Philipp <tphilipp@potion-studios.com>
+   Copyright (c) 2017 Tassilo Philipp <tphilipp@potion-studios.com>
 
    Permission to use, copy, modify, and distribute this software for any
    purpose with or without fee is hereby granted, provided that the above
@@ -23,8 +22,59 @@
 
 */
 
+/* input:
+	$i0    -> thunk
+	$i0+56 -> cb handler
+	$i0+64 -> userdata
+*/
+
+/* NOTE: %sp/%fp for v9 are offset, using them needs a "BIAS" of 2047 */
+.set BIAS, 2047
+
+.text
 .globl dcCallbackThunkEntry
+
+/* Called by thunk - thunk stores pointer to DCCallback */
+/* in %g1, and pointer to called function in %g2        */
 dcCallbackThunkEntry:
-        jmpl %i7 + 8, %g0			/* Return from proc. */
-	 nop
+
+	/* Prolog. */
+	/* Frame size of 208b comes from needing storage space for the following: */
+	/*   DCargs(sparc_req_reg_save_area:128 + spill:64 + argptr:8) + retval:8 */
+	/* Spill area could theoretically be only 32b, b/c cbHandler function has */
+ 	/* 4 arguments, and retval doesn't need stack, but let's be conservative. */
+	save %sp, -208, %sp
+
+	/* Spill register args. */
+	add  %fp, BIAS + 136, %l0
+	stx  %i0, [ %l0 +  0 ]          /* reg arg 0 */
+	stx  %i1, [ %l0 +  8 ]          /* reg arg 1 */
+	stx  %i2, [ %l0 + 16 ]          /* reg arg 2 */
+	stx  %i3, [ %l0 + 24 ]          /* reg arg 3 */
+	stx  %i4, [ %l0 + 32 ]          /* reg arg 4 */
+	stx  %i5, [ %l0 + 40 ]          /* reg arg 5 */
+	stx  %l0, [ %sp + BIAS + 192 ]  /* init arg_ptr */
+
+	/* Zero retval store. */
+	stx  %g0, [ %sp + BIAS + 200 ]
 
+	/* Prepare callback handler call. */
+	mov  %g1, %o0                   /* Param 0 = DCCallback*, %g1 holds ptr to thunk */
+	add  %sp, BIAS + 192, %o1       /* Param 1 = DCArgs* (ptr to struct with args ptr) */
+	add  %sp, BIAS + 200, %o2       /* Param 2 = results ptr to 8b of local stack data */
+	ldx  [ %g1 + 64 ], %o3          /* Param 3 = userdata ptr */
+
+	/* Fetch callback handler address (after thunk blob) and call. */
+	ldx  [ %g1 + 56 ], %l0
+	call %l0
+	nop
+
+	/* Put retval in %i0 (to be in caller's %o0), and %f0. */
+	ldx  [ %sp + BIAS + 200 ], %i0
+	ldd  [ %sp + BIAS + 200 ], %f0
+
+	/* Epilog. */
+	restore                 /* unshift reg window */
+	retl                    /* Return from proc. -- jmpl %i7 + 8, %g0 */
+	nop
+