Porting Arla to Linux/390

Johan Danielsson joda at pdc.kth.se
Sat Jul 22 00:09:04 CEST 2000


maydin at us.ibm.com writes:

> I have not found any documentation about what the process.S file
> does, so I would appreciate if someone would explain in words, what
> the functions in process.S do.  Thank you very much.

It implements function calling with switched stacks.

void savecontext(void (*f)(void), struct savearea *context, void *new_sp);
void returnto(struct savearea *context);

savecontext saves all necessary processor state (most commonly
register contents) on the stack, saves the stackpointer to the
context, and then switches to the new stack at new_sp, and calls f.

returnto reverses this.

If I where to write a new process.s for an unknown processor, I would
first see what assembler the compiler produces for a simple function
call, and then work from there.

Shortened alpha-version with some more comments below:

NESTED(savecontext,FRAMESIZE,ra)
	ldgp	gp,0(pv)
	lda	sp,-FRAMESIZE(sp)               -- reserve space on stack
/* Save callee-saved registers. */
	stq	s0, (registers+0) (sp)          -- save registers on stack
	stq	s1, (registers+8) (sp)
	stq	s2, (registers+16) (sp)
	stq	s3, (registers+24) (sp)
	stq	s4, (registers+32) (sp)
	stq	s5, (registers+40) (sp)
	stq	s6, (registers+48) (sp)
/* Save return address */
	stq	ra, returnaddr(sp)              -- save return address on stack

	.prologue	1
	stq	sp, topstack(a1)                -- save stackpointer in context
	or	a0,zero,pv		/* call point in pv */
	beq	a2, samestack
	or	a2,zero,sp		/* switch stack */
samestack:
	jsr	ra,(pv),0		/* off we go */
	END(savecontext)


LEAF(returnto)
	ldgp	gp,0(pv)

	.prologue	1
	ldq	sp, topstack(a0)                -- restire 
/* Restore callee-saved regs */
	ldq	s0, (registers+0) (sp)
	ldq	s1, (registers+8) (sp)
	ldq	s2, (registers+16) (sp)
	ldq	s3, (registers+24) (sp)
	ldq	s4, (registers+32) (sp)
	ldq	s5, (registers+40) (sp)
	ldq	s6, (registers+48) (sp)
/* Return address */
	ldq	ra, returnaddr(sp)
	lda	sp, FRAMESIZE(sp)
	stl	zero, PRE_Block
	RET
	END(returnto)


/Johan





More information about the Arla-drinkers mailing list