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

1.1       root        1: /* initialize.c - nulluser, sysinit */
                      2: 
                      3: #include <conf.h>
                      4: #include <kernel.h>
                      5: #include <proc.h>
                      6: #include <sem.h>
                      7: #include <mem.h>
                      8: #include <tty.h>
                      9: #include <q.h>
                     10: #include <io.h>
                     11: #include <disk.h>
                     12: 
                     13: extern int     main();                 /* address of user's main prog  */
                     14: 
                     15: /* Declarations of major kernel variables */
                     16: 
                     17: struct pentry  proctab[NPROC]; /* process table                        */
                     18: int    nextproc;               /* next process slot to use in create   */
                     19: struct sentry  semaph[NSEM];   /* semaphore table                      */
1.1.1.2 ! root       20: int    nextsem;                /* next sempahore slot to use in screate*/
1.1       root       21: struct qent    q[NQENT];       /* q table (see queue.c)                */
                     22: int    nextqueue;              /* next slot in q structure to use      */
1.1.1.2 ! root       23: WORD   *maxaddr;               /* max memory address (set by sizmem)   */
1.1       root       24: #ifdef NDEVS
                     25: struct intmap  intmap[NDEVS];  /* interrupt dispatch table             */
                     26: #endif
                     27: struct mblock  memlist;        /* list of free memory blocks           */
                     28: #ifdef Ntty
                     29: struct  tty     tty[Ntty];     /* SLU buffers and mode control         */
                     30: #endif
                     31: 
                     32: /* active system status */
                     33: 
                     34: int    numproc;                /* number of live user processes        */
                     35: int    currpid;                /* id of currently running process      */
                     36: int    reboot = 0;             /* non-zero after first boot            */
                     37: 
1.1.1.2 ! root       38: /* real-time clock variables and sleeping process queue pointers               */
        !            39: #ifdef RTCLOCK
        !            40: int    count6;                 /* counts in 60ths of a second 6-0      */
        !            41: int     defclk;                        /* non-zero, then deferring clock count */
        !            42: int     clkdiff;               /* deferred clock ticks                 */
        !            43: int     slnempty;              /* FALSE if the sleep queue is empty    */
        !            44: int     *sltop;                        /* address of key part of top entry in  */
        !            45:                                /* the sleep queue if slnonempty==TRUE  */
        !            46: int     clockq;                        /* head of queue of sleeping processes  */
        !            47: int    preempt;                /* preemption counter.  Current process */
        !            48:                                /* is preempted when it reaches zero;   */
        !            49:                                /* set in resched; counts in ticks      */
        !            50: int    clkruns = 1;            /* set TRUE iff clock exists by setclkr */
        !            51: #else
        !            52: int    clkruns = FALSE;        /* no clock configured; be sure sleep   */
        !            53: #endif                         /*   doesn't wait forever               */
        !            54: int    rdyhead,rdytail;        /* head/tail of ready list (q indicies) */
        !            55: 
1.1       root       56: 
                     57: /************************************************************************/
                     58: /***                           NOTE:                                 ***/
                     59: /***                                                                 ***/
                     60: /***   This is where the system begins after the C environment has    ***/
                     61: /***   been established.  Interrupts are initially DISABLED, and      ***/
                     62: /***   must eventually be enabled explicitly.  This routine turns     ***/
                     63: /***   itself into the null process after initialization.  Because    ***/
                     64: /***   the null process must always remain ready to run, it cannot    ***/
                     65: /***   execute code that might cause it to be suspended, wait for a   ***/
                     66: /***   semaphore, or put to sleep, or exit.  In particular, it must   ***/
                     67: /***   not do I/O unless it uses kprintf for polled output.           ***/
                     68: /***                                                                 ***/
                     69: /************************************************************************/
                     70: 
                     71: /*------------------------------------------------------------------------
                     72:  *  nulluser  -- initialize system and become the null process (id==0)
                     73:  *------------------------------------------------------------------------
                     74:  */
                     75: nulluser()                             /* babysit CPU when no one home */
                     76: {
1.1.1.2 ! root       77: int pid,retval;
1.1       root       78: 
1.1.1.2 ! root       79: #ifdef DEBUG
        !            80:        dotrace("nulluser", NULL, 0);
1.1       root       81: #endif
1.1.1.2 ! root       82:        kprintf("\n\nXinu Version %s%s\n", VERSION,
        !            83:                reboot++==0 ? "" : "   (rebooted)");
        !            84:        sysinit();                      /* initialize all of Xinu */
        !            85:        kprintf("%u real mem\n", (WORD) (maxaddr + 1));
        !            86:        kprintf("%u avail mem\n",(unsigned)maxaddr-(unsigned)(&end)+(unsigned)sizeof(WORD));
        !            87:        kprintf("%u end mem\n",(unsigned)(&end));
        !            88:        setlowpri();
        !            89: 
        !            90:        /* start a process executing the user's main program */
1.1       root       91: 
1.1.1.2 ! root       92:        if ((pid = create(main,INITSTK,INITPRIO,INITNAME,1,0)) == SYSERR) {
        !            93:                kprintf("Error in initial create call\n");
        !            94:        }
        !            95:        if ((retval = resume(pid)) == SYSERR) {
        !            96:                kprintf("Error in resume of initial user process!\n");
        !            97:        }
        !            98:        while (TRUE) {                  /* run forever */
        !            99:                pause();        /* release bus if possible, else loop */
1.1       root      100:        }
                    101: }
                    102: 
                    103: /*------------------------------------------------------------------------
1.1.1.2 ! root      104:  *  sysinit  --  initialize all Xinu data structeres and devices
1.1       root      105:  *------------------------------------------------------------------------
                    106:  */
                    107: LOCAL  sysinit()
                    108: {
1.1.1.2 ! root      109:        int     i,j;
1.1       root      110:        struct  pentry  *pptr;
                    111:        struct  sentry  *sptr;
                    112:        struct  mblock  *mptr;
                    113: 
1.1.1.2 ! root      114: #ifdef DEBUG
        !           115:        dotrace("sysinit", NULL, 0);
        !           116: #endif
        !           117:        numproc = 0;                    /* initialize system variables */
1.1       root      118:        nextproc = NPROC-1;
1.1.1.2 ! root      119:        nextsem = NSEM-1;
        !           120:        nextqueue = NPROC;              /* q[0..NPROC-1] are processes */
1.1       root      121: 
                    122:        memlist.mnext = mptr =          /* initialize free memory list */
                    123:          (struct mblock *) roundew(&end);
                    124:        mptr->mnext = (struct mblock *)NULL;
1.1.1.2 ! root      125:        mptr->mlen = (int) truncew((unsigned)maxaddr-NULLSTK-(unsigned)&end);
1.1       root      126: 
                    127:        for (i=0 ; i<NPROC ; i++)       /* initialize process table */
                    128:                proctab[i].pstate = PRFREE;
                    129: 
                    130:        pptr = &proctab[NULLPROC];      /* initialize null process entry */
                    131:        pptr->pstate = PRCURR;
1.1.1.2 ! root      132:        for (j=0; j<7; j++)
        !           133:                pptr->pname[j] = "prnull"[j];
        !           134:        pptr->plimit = (WORD)(maxaddr + 1) - NULLSTK;
        !           135:        pptr->pbase = (WORD) maxaddr;
        !           136:        pptr->paddr = (WORD) nulluser;
1.1       root      137:        pptr->pargs = 0;
1.1.1.2 ! root      138:        pptr->phasps = 0;
1.1       root      139:        pptr->pprio = 0;
                    140:        currpid = NULLPROC;
1.1.1.2 ! root      141: 
1.1       root      142:        for (i=0 ; i<NSEM ; i++) {      /* initialize semaphores */
                    143:                (sptr = &semaph[i])->sstate = SFREE;
1.1.1.2 ! root      144:                newqueue(&(sptr->sqhead), &(sptr->sqtail));
1.1       root      145:        }
                    146: 
1.1.1.2 ! root      147:        newqueue(&rdyhead,&rdytail);    /* initialize ready list */
1.1       root      148: 
                    149: #ifdef MEMMARK
                    150:        _mkinit();                      /* initialize memory marking */
                    151: #endif
                    152: #ifdef RTCLOCK
1.1.1.2 ! root      153:        clkinit();              /* init r.t.clock       */
1.1       root      154: #endif
                    155: #ifdef Ndsk
                    156:        dskdbp= mkpool(DBUFSIZ,NDBUFF); /* initialize disk buffers */
                    157:        dskrbp= mkpool(DREQSIZ,NDREQ);
                    158: #endif
1.1.1.2 ! root      159: #ifdef NDEVS
        !           160:        for ( i=0 ; i<NDEVS ; i++ ){    /* initialize devices */
1.1       root      161:                init(i);
                    162:        }
1.1.1.2 ! root      163: #endif
        !           164: #ifdef NNETS
        !           165:        netinit();                      /* initialize networks */
        !           166: #endif
1.1       root      167:        return(OK);
                    168: }

unix.superglobalmegacorp.com

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