--- xinu/sys/initialize.c 2018/04/24 17:39:02 1.1 +++ xinu/sys/initialize.c 2018/04/24 17:39:22 1.1.1.2 @@ -9,11 +9,6 @@ #include #include #include -#include -#include -#include -#include -#include extern int main(); /* address of user's main prog */ @@ -22,11 +17,10 @@ extern int main(); /* address of user' struct pentry proctab[NPROC]; /* process table */ int nextproc; /* next process slot to use in create */ struct sentry semaph[NSEM]; /* semaphore table */ -int nextsem; /* next semaphore slot to use in screate*/ +int nextsem; /* next sempahore slot to use in screate*/ struct qent q[NQENT]; /* q table (see queue.c) */ int nextqueue; /* next slot in q structure to use */ -int *maxaddr; /* max memory address (set by sizmem) */ -int machinesid; /* machine system identification */ +WORD *maxaddr; /* max memory address (set by sizmem) */ #ifdef NDEVS struct intmap intmap[NDEVS]; /* interrupt dispatch table */ #endif @@ -41,10 +35,24 @@ int numproc; /* number of live user pro int currpid; /* id of currently running process */ int reboot = 0; /* non-zero after first boot */ -int rdyhead,rdytail; /* head/tail of ready list (q indexes) */ -char *sysid; -char vers[] = VERSION; /* Xinu version printed at startup */ -long iospace; /* Address of I/O space on this VAX */ +/* real-time clock variables and sleeping process queue pointers */ +#ifdef RTCLOCK +int count6; /* counts in 60ths of a second 6-0 */ +int defclk; /* non-zero, then deferring clock count */ +int clkdiff; /* deferred clock ticks */ +int slnempty; /* FALSE if the sleep queue is empty */ +int *sltop; /* address of key part of top entry in */ + /* the sleep queue if slnonempty==TRUE */ +int clockq; /* head of queue of sleeping processes */ +int preempt; /* preemption counter. Current process */ + /* is preempted when it reaches zero; */ + /* set in resched; counts in ticks */ +int clkruns = 1; /* set TRUE iff clock exists by setclkr */ +#else +int clkruns = FALSE; /* no clock configured; be sure sleep */ +#endif /* doesn't wait forever */ +int rdyhead,rdytail; /* head/tail of ready list (q indicies) */ + /************************************************************************/ /*** NOTE: ***/ @@ -66,109 +74,95 @@ long iospace; /* Address of I/O space o */ nulluser() /* babysit CPU when no one home */ { - int userpid; +int pid,retval; - if (isUVAXI) { - sysid = UISYSTEM; - iospace = IOUVAXI; - } else if (isUVAXII) { - sysid = UIISYSTEM; - iospace = IOUVAXII; - } else { - sysid = SYSTEM; - iospace = IOVAX; - } - kprintf("\n\n%s Xinu Version %s", sysid, vers); - if (reboot++ < 1) - kprintf("\n"); - else - kprintf(" (reboot %d)\n", reboot); - sysinit(); /* initialize all of Xinu */ - kprintf("%u real mem\n",(unsigned)maxaddr+(unsigned)sizeof(int)); - kprintf("%u avail mem\n", - (unsigned)maxaddr-(unsigned)(&end)+(unsigned)sizeof(int)); - kprintf("clock %sabled\n\n", clkruns==1?"en":"dis"); - enable(); /* enable interrupts */ - - /* create a process to execute the user's main program */ - - userpid = create(main,INITSTK,INITPRIO,INITNAME,INITARGS); - -#ifdef NETDAEMON - /* start the network input daemon process */ - resume( - create(NETIN, NETISTK, NETIPRI, NETINAM, NETIARGC, userpid) - ); -#else - resume( userpid ); +#ifdef DEBUG + dotrace("nulluser", NULL, 0); #endif + kprintf("\n\nXinu Version %s%s\n", VERSION, + reboot++==0 ? "" : " (rebooted)"); + sysinit(); /* initialize all of Xinu */ + kprintf("%u real mem\n", (WORD) (maxaddr + 1)); + kprintf("%u avail mem\n",(unsigned)maxaddr-(unsigned)(&end)+(unsigned)sizeof(WORD)); + kprintf("%u end mem\n",(unsigned)(&end)); + setlowpri(); + + /* start a process executing the user's main program */ - while (TRUE) { /* run forever without actually */ - pause(); /* executing instructions */ + if ((pid = create(main,INITSTK,INITPRIO,INITNAME,1,0)) == SYSERR) { + kprintf("Error in initial create call\n"); + } + if ((retval = resume(pid)) == SYSERR) { + kprintf("Error in resume of initial user process!\n"); + } + while (TRUE) { /* run forever */ + pause(); /* release bus if possible, else loop */ } } /*------------------------------------------------------------------------ - * sysinit -- initialize all Xinu data structures and devices + * sysinit -- initialize all Xinu data structeres and devices *------------------------------------------------------------------------ */ LOCAL sysinit() { - int i; + int i,j; struct pentry *pptr; struct sentry *sptr; struct mblock *mptr; - numproc = 0; /* initialize system variables */ +#ifdef DEBUG + dotrace("sysinit", NULL, 0); +#endif + numproc = 0; /* initialize system variables */ nextproc = NPROC-1; - nextsem = NSEM-1; - nextqueue= NPROC; /* q[0..NPROC-1] are processes */ + nextsem = NSEM-1; + nextqueue = NPROC; /* q[0..NPROC-1] are processes */ memlist.mnext = mptr = /* initialize free memory list */ (struct mblock *) roundew(&end); mptr->mnext = (struct mblock *)NULL; - mptr->mlen = (unsigned) truncew ( (unsigned)maxaddr - - (int)roundew(NULLSTK) - (unsigned)&end + sizeof(int) ); + mptr->mlen = (int) truncew((unsigned)maxaddr-NULLSTK-(unsigned)&end); for (i=0 ; ipstate = PRCURR; - strcpy(pptr->pname, "prnull"); - pptr->plimit = (int)maxaddr - (int)roundew(NULLSTK) + sizeof(int); - pptr->pbase = (int)maxaddr; - pptr->pstklen = (int)roundew(NULLSTK); - *( (int *)pptr->pbase ) = MAGIC; - pptr->paddr = (int)nulluser; + for (j=0; j<7; j++) + pptr->pname[j] = "prnull"[j]; + pptr->plimit = (WORD)(maxaddr + 1) - NULLSTK; + pptr->pbase = (WORD) maxaddr; + pptr->paddr = (WORD) nulluser; pptr->pargs = 0; + pptr->phasps = 0; pptr->pprio = 0; currpid = NULLPROC; - /* pptr->pregs was previously initialized (by startup) */ + for (i=0 ; isstate = SFREE; - sptr->sqtail = 1 + (sptr->sqhead = newqueue()); + newqueue(&(sptr->sqhead), &(sptr->sqtail)); } - rdytail = 1 + (rdyhead=newqueue());/* initialize ready list */ + newqueue(&rdyhead,&rdytail); /* initialize ready list */ #ifdef MEMMARK _mkinit(); /* initialize memory marking */ #endif #ifdef RTCLOCK - clkinit(); /* initialize r.t.clock */ + clkinit(); /* init r.t.clock */ #endif #ifdef Ndsk dskdbp= mkpool(DBUFSIZ,NDBUFF); /* initialize disk buffers */ dskrbp= mkpool(DREQSIZ,NDREQ); #endif - if (isUVAXII) { - qmapinit(); /* init. qbus map regs. */ - *(short *)QMCPMBX = QMHALT; /* on halt, really halt */ - } - for ( i=0 ; i