|
|
1.1 root 1: /* getstk.c - getstk */
2:
3: #include <conf.h>
4: #include <kernel.h>
5: #include <mem.h>
6:
7: /*------------------------------------------------------------------------
1.1.1.2 ! root 8: * getstk -- allocate stack memory, returning address of topmost WORD
1.1 root 9: *------------------------------------------------------------------------
10: */
1.1.1.2 ! root 11: WORD *getstk(nbytes)
1.1 root 12: unsigned int nbytes;
13: {
14: struct mblock *p, *q; /* q follows p along memlist */
15: struct mblock *fits, *fitsq;
1.1.1.2 ! root 16: WORD address;
1.1 root 17:
1.1.1.2 ! root 18: disable();
1.1 root 19: if (nbytes == 0) {
1.1.1.2 ! root 20: restore();
! 21: return( (WORD *)SYSERR );
1.1 root 22: }
1.1.1.2 ! root 23: nbytes = (unsigned int) roundew(nbytes);
! 24: fits = (struct mblock *) NULL;
1.1 root 25: q = &memlist;
1.1.1.2 ! root 26: for (p = q->mnext ; p !=(struct mblock *) NULL ; q = p,p = p->mnext)
1.1 root 27: if ( p->mlen >= nbytes) {
28: fitsq = q;
29: fits = p;
30: }
1.1.1.2 ! root 31: if (fits == (struct mblock *) NULL) {
! 32: restore();
! 33: return( (WORD *)SYSERR );
1.1 root 34: }
1.1.1.2 ! root 35: /* eoneil 2/29/88--moved address calc up above if */
! 36: /* so pointing to last word in area returned */
! 37: address = (WORD) fits + fits->mlen - sizeof(WORD);
! 38: if (nbytes == fits->mlen) {
1.1 root 39: fitsq->mnext = fits->mnext;
40: } else {
41: fits->mlen -= nbytes;
42: }
1.1.1.2 ! root 43: /* address = (WORD) fits;
! 44: address += fits->mlen - sizeof(WORD); */
! 45: restore();
! 46: return( (WORD *) address);
1.1 root 47: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.