[Python-checkins] r45885 - in stackless/Python-2.4.3/dev/Stackless: core/slp_transfer.c platf/slp_platformselect.h platf/switch_arm_thumb_gas.s platf/switch_arm_thumb_gcc.h platf/switch_x64_msvc.h

richard.tew python-checkins at python.org
Wed May 3 13:55:31 CEST 2006


Author: richard.tew
Date: Wed May  3 13:55:27 2006
New Revision: 45885

Added:
   stackless/Python-2.4.3/dev/Stackless/platf/switch_arm_thumb_gas.s   (contents, props changed)
   stackless/Python-2.4.3/dev/Stackless/platf/switch_arm_thumb_gcc.h   (contents, props changed)
Modified:
   stackless/Python-2.4.3/dev/Stackless/core/slp_transfer.c
   stackless/Python-2.4.3/dev/Stackless/platf/slp_platformselect.h
   stackless/Python-2.4.3/dev/Stackless/platf/switch_x64_msvc.h
Log:
There were CCP x64/masm specific changes to slp_transfer.c which exposed wrapped versions of the SLP_SAVE_STATE and SLP_RESTORE_STATE macros for the masm assembler version of slp_switch to call.  They are now no longer masm specific, and should work for other platform's which have assembler versions of slp_switch (like the arm thumb version which is also added in this change).

Modified: stackless/Python-2.4.3/dev/Stackless/core/slp_transfer.c
==============================================================================
--- stackless/Python-2.4.3/dev/Stackless/core/slp_transfer.c	(original)
+++ stackless/Python-2.4.3/dev/Stackless/core/slp_transfer.c	Wed May  3 13:55:27 2006
@@ -41,11 +41,24 @@
 		slp_cstack_restore(_cst); \
 	}
 
-// #define USE_MASM	  // CCP addition, define to use masm code
-#ifdef USE_MASM
-//ccp addition: make these functions, to be called from assembler
-#define STACK_MAGIC 0
+/* This define is no longer needed now? */
+#define SLP_EVAL
+#include "platf/slp_platformselect.h"
 
+#ifdef EXTERNAL_ASM
+/* CCP addition: Make these functions, to be called from assembler.
+ * The token include file for the given platform should enable the
+ * EXTERNAL_ASM define so that this is included.
+ */
+
+/* There are two cases where slp_save_state would return 0, the
+ * first where there is no difference in where the stack pointer
+ * should be from where it is now.  And the second where
+ * SLP_SAVE_STATE returns without restoring because we are only
+ * here to save.  The assembler routine needs to differentiate
+ * between these, which is why we override the returns and flag
+ * the low bit of the return value on early exit.
+ */
 #undef __return
 #define __return(x) { exitcode = x; goto exit; }
 
@@ -65,11 +78,6 @@
 
 extern int slp_switch(void);
 
-#else
-
-#define SLP_EVAL
-#include "platf/slp_platformselect.h"
-
 #endif
 
 static int

Modified: stackless/Python-2.4.3/dev/Stackless/platf/slp_platformselect.h
==============================================================================
--- stackless/Python-2.4.3/dev/Stackless/platf/slp_platformselect.h	(original)
+++ stackless/Python-2.4.3/dev/Stackless/platf/slp_platformselect.h	Wed May  3 13:55:27 2006
@@ -20,6 +20,8 @@
 #include "switch_s390_unix.h"	/* Linux/S390 */
 #elif defined(__GNUC__) && defined(__s390x__) && defined(__linux__)
 #include "switch_s390_unix.h"	/* Linux/S390 zSeries (identical) */
+#elif defined(__GNUC__) && defined(__arm__) && defined(__thumb__)
+#include "switch_arm_thumb_gcc.h" /* gcc using arm thumb */
 #endif
 
 /* default definitions if not defined in above files */

Added: stackless/Python-2.4.3/dev/Stackless/platf/switch_arm_thumb_gas.s
==============================================================================
--- (empty file)
+++ stackless/Python-2.4.3/dev/Stackless/platf/switch_arm_thumb_gas.s	Wed May  3 13:55:27 2006
@@ -0,0 +1,70 @@
+@ The stack switching logic for the arm thumb instruction set.
+@ Written by Richard Tew, 2nd May 2006.
+@
+@ It is not possible to do this as inline assembler as gcc generates functions
+@ where the stack register is preserved, so any changes we make to it will be
+@ discarded.  However, any stack copying we have done is left in place, which
+@ results in corrupt state.
+@
+@ This adapts the MASM approach written by Kristjan Jonsson, where early
+@ returns from SLP_SAVE_STATE (within slp_save_state) are flagged by setting
+@ the low bit of the return value.  This either indicates that there was an
+@ error (-1) or that we do not need to restore the stack (1) as we are only
+@ here to save the current one.
+@
+@ I know little arm thumb assembly, so in case anyone else wants to know the
+@ approach I took, I will document it here.  The first uncertainty was which
+@ registers should be saved.  I took this section of code from the assembler
+@ generated by gcc with a command line of:
+@     gcc -mthumb -S slp_transfer.c
+@ where slp_transfer included the inline version of slp_switch for the arm
+@ thumb.  Another initial uncertainty were the instructions needed to:
+@     a) obtain the stack pointer.    (mov r0, sp)
+@     b) restore the stack pointer.   (add sp, sp, r0)
+@ which were used in the original inlined assembly.  The rest of the code was
+@ just patched together based on Kristjan's existing masm source code.
+
+@ (int) slp_switch (void);
+	.thumb
+	.align	2
+	.global	slp_switch
+	.type	slp_switch, %function		@ Apparently useful for .map files.
+	.thumb_func
+
+slp_switch:
+	push	{r4, r5, r6, r7, lr}
+	mov	r7, fp
+	mov	r6, sl
+	mov	r5, r9
+	mov	r4, r8
+	push	{r4, r5, r6, r7}
+ 
+	mov	r0, sp
+	bl	slp_save_state			@ diff = slp_save_state([r0]stackref)
+
+	mov	r1, #0				@ r1 = -1
+	mvn	r1, r1
+	
+	cmp	r0, r1				@ if (diff == -1)
+	beq	.exit				@     return -1;
+
+	cmp	r0, #1				@ if (diff ==  1)
+	beq	.no_restore			@     return  0;
+
+.restore:
+	add	sp, sp, r0			@ Adjust the stack pointer for the state we are restoring.
+
+	bl	slp_restore_state		@ slp_restore_state()
+
+.no_restore:
+	mov	r0, #0				@ Switch successful (whether we restored or not).
+
+.exit:
+	pop	{r2, r3, r4, r5}
+	mov	r8, r2
+	mov	r9, r3
+	mov	sl, r4
+	mov	fp, r5
+	pop	{r4, r5, r6, r7, pc}
+
+	.size	slp_switch, .-slp_switch	@ Apparently useful for .map files.

Added: stackless/Python-2.4.3/dev/Stackless/platf/switch_arm_thumb_gcc.h
==============================================================================
--- (empty file)
+++ stackless/Python-2.4.3/dev/Stackless/platf/switch_arm_thumb_gcc.h	Wed May  3 13:55:27 2006
@@ -0,0 +1,10 @@
+
+#define STACK_REFPLUS 1
+#define STACK_MAGIC 0
+
+/* Use the generic support for an external assembly language slp_switch function. */
+#define EXTERNAL_ASM
+
+#ifdef SLP_EVAL
+/* This always uses the external masm assembly file. */
+#endif

Modified: stackless/Python-2.4.3/dev/Stackless/platf/switch_x64_msvc.h
==============================================================================
--- stackless/Python-2.4.3/dev/Stackless/platf/switch_x64_msvc.h	(original)
+++ stackless/Python-2.4.3/dev/Stackless/platf/switch_x64_msvc.h	Wed May  3 13:55:27 2006
@@ -25,25 +25,13 @@
 #define alloca _alloca
 
 #define STACK_REFPLUS 1
-
-#ifdef SLP_EVAL
-
 #define STACK_MAGIC 0
 
-extern int slp_switch(void); /* defined in masm assembler */
-
-/* These two are called from the assembler module */
-SSIZE_T slp_save_state(intptr_t *ref) {
-	SSIZE_T diff;
-	SLP_SAVE_STATE(ref, diff);
-	return diff;
-}
-
-void slp_restore_state(void)
-{
-	SLP_RESTORE_STATE();
-}
+/* Use the generic support for an external assembly language slp_switch function. */
+#define EXTERNAL_ASM
 
+#ifdef SLP_EVAL
+/* This always uses the external masm assembly file. */
 #endif
 
 /*
@@ -62,6 +50,6 @@
     int stackref;
     intptr_t stackbase = ((intptr_t)&stackref) & 0xfffff000;
     return (intptr_t)p >= stackbase && (intptr_t)p < stackbase + 0x00100000;
-} 
+}
 
 #endif


More information about the Python-checkins mailing list