[Stackless] Stackless Python for Python 2.5.1

Richard Tew richard.m.tew at gmail.com
Wed May 9 15:09:37 CEST 2007

On 5/9/07, Hieu Hoang <hieu.d.hoang at gmail.com> wrote:
> On 5/9/07, Kristján Valur Jónsson <kristjan at ccpgames.com> wrote:
> > From this it seems that we must save rbp, rbx and r12-r15, plus the mxcsr
> > register.
> >
> With #define REGS_TO_SAVE "rdx", "rbp", "rbx", "r12", "r13", "r14",
> "r15", "mxcsr":
> ./Stackless/platf/switch_amd64_unix.h: In function 'slp_transfer':
> ./Stackless/platf/switch_amd64_unix.h:39: error: unknown register name
> 'mxcsr' in 'asm'
> make: *** [Stackless/core/slp_transfer.o] Error 1

As far as I can tell, it cannot be addressed directly and you need to
load values to it and store values from it manually with specific
assembler instructions (ldmxcsr and stmxcsr).

rbp is already preserved because of the assembler gcc generates, as
shown by the assembler files you have previously provided, where it
was used for

I think that a custom assembler stack switch function is needed here.
Perhaps something like this (not guaranteed to work without tweaking):

@ (int) slp_switch (void);

	.type	slp_switch, @function
	pushq	%rbp
	pushq	%r15
	pushq	%r14
	pushq	%r13
	pushq	%r12
	pushq	%rbx

	subq	4, %rsp
	stmxcsr	[%rsp-4]

	call slp_save_state		@  diff = slp_save_state([?]stackref)
	cmp	-1, %rax		@ if (diff == -1)
	beq	.exit			@     return -1;

	cmp	-1, %rax		@ if (diff ==  1)
	beq	.no_restore		@     return 0;

	addq	%rax, %rsp		@ Adjust the stack pointer for the state we are restoring.

	call slp_restore_state		@ slp_restore_state()

	xor	%rax, %rax		@ Switch successful (whether we restored or not).

	ldmxcsr	[%rsp-4]
	addq	4, %rsp

	popq	%rbx
	popq	%r12
	popq	%r13
	popq	%r14
	popq	%r15

	.size	slp_switch, .-slp_switch

The only thing I am not really really sure about is what register to
pass the stack address into slp_save_state in.  But that could be
determined from the assembler version of slp_switch after it was
compiled with EXTERNAL_ASM defined.

Stackless mailing list
Stackless at stackless.com

More information about the Stackless mailing list