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

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: #include <network.h>
                     13: #include <sleep.h>
                     14: #include <iospace.h>
                     15: #include <qbus.h>
                     16: #include <mach.h>
                     17: 
                     18: extern int     main();                 /* address of user's main prog  */
                     19: 
                     20: /* Declarations of major kernel variables */
                     21: 
                     22: struct pentry  proctab[NPROC]; /* process table                        */
                     23: int    nextproc;               /* next process slot to use in create   */
                     24: struct sentry  semaph[NSEM];   /* semaphore table                      */
                     25: int    nextsem;                /* next semaphore slot to use in screate*/
                     26: struct qent    q[NQENT];       /* q table (see queue.c)                */
                     27: int    nextqueue;              /* next slot in q structure to use      */
                     28: int    *maxaddr;               /* max memory address (set by sizmem)   */
                     29: int    machinesid;             /* machine system identification        */
                     30: #ifdef NDEVS
                     31: struct intmap  intmap[NDEVS];  /* interrupt dispatch table             */
                     32: #endif
                     33: struct mblock  memlist;        /* list of free memory blocks           */
                     34: #ifdef Ntty
                     35: struct  tty     tty[Ntty];     /* SLU buffers and mode control         */
                     36: #endif
                     37: 
                     38: /* active system status */
                     39: 
                     40: int    numproc;                /* number of live user processes        */
                     41: int    currpid;                /* id of currently running process      */
                     42: int    reboot = 0;             /* non-zero after first boot            */
                     43: 
                     44: int    rdyhead,rdytail;        /* head/tail of ready list (q indexes)  */
                     45: char   *sysid;
                     46: char   vers[] = VERSION;       /* Xinu version printed at startup      */
                     47: long   iospace;                /* Address of I/O space on this VAX     */
                     48: 
                     49: /************************************************************************/
                     50: /***                           NOTE:                                 ***/
                     51: /***                                                                 ***/
                     52: /***   This is where the system begins after the C environment has    ***/
                     53: /***   been established.  Interrupts are initially DISABLED, and      ***/
                     54: /***   must eventually be enabled explicitly.  This routine turns     ***/
                     55: /***   itself into the null process after initialization.  Because    ***/
                     56: /***   the null process must always remain ready to run, it cannot    ***/
                     57: /***   execute code that might cause it to be suspended, wait for a   ***/
                     58: /***   semaphore, or put to sleep, or exit.  In particular, it must   ***/
                     59: /***   not do I/O unless it uses kprintf for polled output.           ***/
                     60: /***                                                                 ***/
                     61: /************************************************************************/
                     62: 
                     63: /*------------------------------------------------------------------------
                     64:  *  nulluser  -- initialize system and become the null process (id==0)
                     65:  *------------------------------------------------------------------------
                     66:  */
                     67: nulluser()                             /* babysit CPU when no one home */
                     68: {
                     69:        int     userpid;
                     70: 
                     71:        if (isUVAXI) {
                     72:                sysid = UISYSTEM;
                     73:                iospace = IOUVAXI;
                     74:        } else if (isUVAXII) {
                     75:                sysid = UIISYSTEM;
                     76:                iospace = IOUVAXII;
                     77:        } else {
                     78:                sysid = SYSTEM;
                     79:                iospace = IOVAX;
                     80:        }
                     81:        kprintf("\n\n%s Xinu Version %s", sysid, vers);
                     82:        if (reboot++ < 1)
                     83:                kprintf("\n");
                     84:        else
                     85:                kprintf("   (reboot %d)\n", reboot);
                     86:        sysinit();                      /* initialize all of Xinu */
                     87:        kprintf("%u real mem\n",(unsigned)maxaddr+(unsigned)sizeof(int));
                     88:        kprintf("%u avail mem\n",
                     89:                (unsigned)maxaddr-(unsigned)(&end)+(unsigned)sizeof(int));
                     90:        kprintf("clock %sabled\n\n", clkruns==1?"en":"dis");
                     91:        enable();                       /* enable interrupts */
                     92: 
                     93:        /* create a process to execute the user's main program */
                     94: 
                     95:        userpid = create(main,INITSTK,INITPRIO,INITNAME,INITARGS);
                     96: 
                     97: #ifdef NETDAEMON
                     98:        /* start the network input daemon process */
                     99:        resume(
                    100:          create(NETIN, NETISTK, NETIPRI, NETINAM, NETIARGC, userpid)
                    101:        );
                    102: #else
                    103:        resume( userpid );
                    104: #endif
                    105: 
                    106:        while (TRUE) {                  /* run forever without actually */
                    107:                pause();                /*  executing instructions      */
                    108:        }
                    109: }
                    110: 
                    111: /*------------------------------------------------------------------------
                    112:  *  sysinit  --  initialize all Xinu data structures and devices
                    113:  *------------------------------------------------------------------------
                    114:  */
                    115: LOCAL  sysinit()
                    116: {
                    117:        int     i;
                    118:        struct  pentry  *pptr;
                    119:        struct  sentry  *sptr;
                    120:        struct  mblock  *mptr;
                    121: 
                    122:        numproc  = 0;                   /* initialize system variables */
                    123:        nextproc = NPROC-1;
                    124:        nextsem  = NSEM-1;
                    125:        nextqueue= NPROC;               /* q[0..NPROC-1] are processes */
                    126: 
                    127:        memlist.mnext = mptr =          /* initialize free memory list */
                    128:          (struct mblock *) roundew(&end);
                    129:        mptr->mnext = (struct mblock *)NULL;
                    130:        mptr->mlen = (unsigned) truncew ( (unsigned)maxaddr -
                    131:           (int)roundew(NULLSTK) - (unsigned)&end + sizeof(int) );
                    132: 
                    133:        for (i=0 ; i<NPROC ; i++)       /* initialize process table */
                    134:                proctab[i].pstate = PRFREE;
                    135: 
                    136:        pptr = &proctab[NULLPROC];      /* initialize null process entry */
                    137:        pptr->pstate = PRCURR;
                    138:        strcpy(pptr->pname, "prnull");
                    139:        pptr->plimit = (int)maxaddr - (int)roundew(NULLSTK) + sizeof(int);
                    140:        pptr->pbase = (int)maxaddr;
                    141:        pptr->pstklen = (int)roundew(NULLSTK);
                    142:        *( (int *)pptr->pbase ) = MAGIC;
                    143:        pptr->paddr = (int)nulluser;
                    144:        pptr->pargs = 0;
                    145:        pptr->pprio = 0;
                    146:        currpid = NULLPROC;
                    147:        /* pptr->pregs was previously initialized (by startup) */
                    148:        for (i=0 ; i<NSEM ; i++) {      /* initialize semaphores */
                    149:                (sptr = &semaph[i])->sstate = SFREE;
                    150:                sptr->sqtail = 1 + (sptr->sqhead = newqueue());
                    151:        }
                    152: 
                    153:        rdytail = 1 + (rdyhead=newqueue());/* initialize ready list */
                    154: 
                    155: #ifdef MEMMARK
                    156:        _mkinit();                      /* initialize memory marking */
                    157: #endif
                    158: #ifdef RTCLOCK
                    159:        clkinit();                      /* initialize r.t.clock */
                    160: #endif
                    161: #ifdef Ndsk
                    162:        dskdbp= mkpool(DBUFSIZ,NDBUFF); /* initialize disk buffers */
                    163:        dskrbp= mkpool(DREQSIZ,NDREQ);
                    164: #endif
                    165:        if (isUVAXII) {
                    166:                qmapinit();                     /* init. qbus map regs. */
                    167:                *(short *)QMCPMBX = QMHALT;     /* on halt, really halt */
                    168:        }
                    169:        for ( i=0 ; i<NDEVS ; i++ ) {   /* initialize devices */
                    170:                devtab[i].dvcsr = iospace | (IOADDRM&devtab[i].dvcsr);
                    171:                init(i);
                    172:        }
                    173:        return(OK);
                    174: }

unix.superglobalmegacorp.com

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