chgstack questions **** THANKS (spoiler) *******

Mike Mc Gaughey mmcg at moncsbruce.oz
Fri Apr 22 03:30:18 AEST 1988


>From article <411 at moncsbruce.oz>, by mmcg at moncsbruce.oz (me):
> 
> 	I am trying to write a coroutine scheduler to run on a
> pyramid 90x under 4.2bsd...  chgstack problems ... can you help me...etc

	Thanks to everyone who replied.  The solution was, of course,
simple (but not obvious - to us, at least!) - For the interested parties, a
short test program, sent by Mark Munkacsy (from here :
uiucdcs!rayssdb.RAY.COM!m2m at munnari.oz) is enclosed.  Special thanks to
Mark, and to Andrew Vignaus, andrew at comp.vuw.ac.nz@vuwcomp.nz, for their help.

					Thanks, everyone.
						Mike.


-------- cut here -----------
#include <stdio.h>
#include <sys/types.h>
#include <sys/context.h>
#include <sys/stacks.h>
#include <sys/psw.h>

#define NUM_PAGES_IN_STACK_INITIAL	12

				/* these are the two context's we will keep */
struct context alternate;
struct context primary;

main()
{
	unsigned	pagesize;	/* system pagesize */
	char		*altstack;	/* points to base of new stack */
	char		*malloc();
	int		testroutine();	/* the entry point for the new task */
	int		result;		/* result of chgstack() calls */

	pagesize = getpagesize();
					/* get current context (will use as
					a model in creating new context) */
	(void) chgstack((struct context *) 0, &primary);

					/* allocate memory for the alternate
					stacks */
	altstack = malloc(NUM_PAGES_IN_STACK_INITIAL * pagesize);
					/* put that pointer on an even CSFRAME
					boundary */
	altstack += (CSFRAME - ((int) altstack & (CSFRAME-1)));
					/* the two halves of a context stack
					grow outward from a center point. Put
					that center point in the middle of the
					area created with the earlier malloc()*/
	alternate.stktop = alternate.stkcfp = alternate.stkbottom =
		altstack + (NUM_PAGES_IN_STACK_INITIAL/2)*pagesize;
	alternate.psw = primary.psw;
					/* set up entry point for alternate
					context */
	alternate.codeaddr = testroutine;

					/* now we are all set up: go make the
					transition to the alternate stack, at
					the alternate entry point */
	result = chgstack(&alternate, &primary);
	if(result < 0) perror("transition to testroutine: chgstack");

	fprintf(stderr, "Normal exit from main\n");
}

int testroutine()
{
	int	result;

	fprintf(stderr, "Wow, got here!\nTrying to return\n");
	result = chgstack(&primary, &alternate);
	if(result < 0) perror("transition to main: chgstack");
}



More information about the Comp.sys.pyramid mailing list