Annotation of xinu/sys/create.c, revision 1.1.1.2

1.1       root        1: /* create.c - create, newpid */
                      2: 
                      3: #include <conf.h>
                      4: #include <kernel.h>
                      5: #include <proc.h>
1.1.1.2 ! root        6: #include <sem.h>
1.1       root        7: #include <mem.h>
                      8: 
                      9: /*------------------------------------------------------------------------
                     10:  *  create  -  create a process to start running a procedure
                     11:  *------------------------------------------------------------------------
                     12:  */
                     13: SYSCALL create(procaddr,ssize,priority,name,nargs,args)
                     14:        int     *procaddr;              /* procedure address            */
1.1.1.2 ! root       15:        int     ssize;                  /* stack size in words          */
        !            16:        int     priority;               /* process priority >= 0        */
1.1       root       17:        char    *name;                  /* name (for debugging)         */
                     18:        int     nargs;                  /* number of args that follow   */
1.1.1.2 ! root       19:        WORD    args;                   /* arguments (treated like an   */
1.1       root       20:                                        /* array in the code)           */
                     21: {
                     22:        int     pid;                    /* stores new process id        */
                     23:        struct  pentry  *pptr;          /* pointer to proc. table entry */
                     24:        int     i;
1.1.1.2 ! root       25:        WORD    *a;                     /* points to list of args       */
        !            26:        WORD    *saddr;                 /* stack address                */
        !            27:        int     INITRET();
1.1       root       28: 
1.1.1.2 ! root       29:        disable();
1.1       root       30:        ssize = (int) roundew(ssize);
1.1.1.2 ! root       31:        if ( ssize < MINSTK || ((saddr = getstk(ssize)) == SYSERR ) ||
1.1       root       32:                (pid=newpid()) == SYSERR || isodd(procaddr) ||
                     33:                priority < 1 ) {
1.1.1.2 ! root       34:                restore();
1.1       root       35:                return(SYSERR);
                     36:        }
                     37:        numproc++;
                     38:        pptr = &proctab[pid];
                     39:        pptr->pstate = PRSUSP;
1.1.1.2 ! root       40:        for (i=0 ; i<PNMLEN && (int)(pptr->pname[i]=name[i])!=0 ; i++)
1.1       root       41:                ;
                     42:        pptr->pprio = priority;
1.1.1.2 ! root       43:        pptr->pbase = (WORD) saddr;
1.1       root       44:        pptr->pstklen = ssize;
1.1.1.2 ! root       45:        pptr->plimit = pptr->pbase - ssize + sizeof (WORD);     
        !            46:                /* Bottom of stack */
1.1       root       47:        pptr->psem = 0;
                     48:        pptr->pargs = nargs;
1.1.1.2 ! root       49:        pptr->phasps = 0;
        !            50:        pptr->phasmsg = 0;
        !            51:        for (i=0 ; i<PNREGS ; i++)
1.1       root       52:                pptr->pregs[i]=INITREG;
1.1.1.2 ! root       53:        pptr->pregs[PC] = pptr->paddr = (WORD)procaddr;
        !            54:        pptr->pregs[PS] = INITPS;
1.1       root       55:        a = (&args) + (nargs-1);        /* point to last argument       */
1.1.1.2 ! root       56:        for ( ; nargs > 0 ; nargs--) {  /* machine dependent; copy args */
        !            57:                *saddr-- = *a--;
        !            58:        }
        !            59:                                        /* onto created process' stack  */
        !            60:        *saddr = (WORD)INITRET; /* push on return address       */
        !            61: #ifdef lsi11
        !            62:        pptr->pregs[SP] = (WORD)saddr;
        !            63: #else
        !            64:        pptr->pregs[USP] = (WORD)saddr;
        !            65:        pptr->pregs[SSP] = (WORD)saddr;
        !            66: #endif
        !            67:        restore();
1.1       root       68:        return(pid);
                     69: }
                     70: 
                     71: /*------------------------------------------------------------------------
                     72:  * newpid  --  obtain a new (free) process id
                     73:  *------------------------------------------------------------------------
                     74:  */
                     75: LOCAL  newpid()
                     76: {
                     77:        int     pid;                    /* process id to return         */
                     78:        int     i;
                     79: 
                     80:        for (i=0 ; i<NPROC ; i++) {     /* check all NPROC slots        */
                     81:                if ( (pid=nextproc--) <= 0)
                     82:                        nextproc = NPROC-1;
                     83:                if (proctab[pid].pstate == PRFREE)
                     84:                        return(pid);
                     85:        }
                     86:        return(SYSERR);
                     87: }

unix.superglobalmegacorp.com

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