File:  [XINU] / xinu / sys / getstk.c
Revision 1.1.1.2 (vendor branch): download - view: text, annotated - select for diffs
Tue Apr 24 17:40:05 2018 UTC (8 years, 2 months ago) by root
Branches: xinu, MAIN
CVS tags: xinu-19910600, HEAD
Xinu for 68000/68010

/* getstk.c - getstk */

#include <conf.h>
#include <kernel.h>
#include <mem.h>

/*------------------------------------------------------------------------
 * getstk  --  allocate stack memory, returning address of topmost WORD
 *------------------------------------------------------------------------
 */
WORD	*getstk(nbytes)
	unsigned  int nbytes;
{
	struct	mblock	*p, *q;	/* q follows p along memlist		*/
	struct	mblock	*fits, *fitsq;
	WORD	address;

	disable();
	if (nbytes == 0) {
		restore();
		return( (WORD *)SYSERR );
	}
	nbytes = (unsigned int) roundew(nbytes);
	fits = (struct mblock *) NULL;
	q = &memlist;
	for (p = q->mnext ; p !=(struct mblock *) NULL ; q = p,p = p->mnext)
		if ( p->mlen >= nbytes) {
			fitsq = q;
			fits = p;
		}
	if (fits == (struct mblock *) NULL) {
		restore();
		return( (WORD *)SYSERR );
	}
	/* eoneil 2/29/88--moved address calc up above if */
	/* so pointing to last word in area returned */
	address = (WORD) fits + fits->mlen - sizeof(WORD);
	if (nbytes == fits->mlen) {
		fitsq->mnext = fits->mnext;
	} else {
		fits->mlen -= nbytes;
	}
/*	address = (WORD) fits;
	address += fits->mlen - sizeof(WORD); */
	restore();
	return( (WORD *) address);
}

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.