/*------------------------------------------------------------------------ * netinit - initialize network data structures *------------------------------------------------------------------------ */ netinit() { struct netq *nqptr; int i; /* Initialize pool of network buffers and rest of Net structure */ if (clkruns == FALSE) panic("net: no clock"); Net.netpool = mkpool(EMAXPAK, NETBUFS); for (i=0 ; i<NETQS ; i++) { nqptr = &Net.netqs[i]; nqptr->valid = FALSE; nqptr->uport = -1; nqptr->xport = pcreate(NETQLEN); } Net.mavalid = FALSE; dtoIP(&Net.gateway, NETGATE); Net.nxtprt = ULPORT; Net.nmutex = screate(1); Net.npacket = Net.ndrop = Net.nover = 0; return(OK); }
/*------------------------------------------------------------------------ * main -- test ethernet by reading packets *------------------------------------------------------------------------ */ main() { char buff[1600]; int i, len; char *p, ch; struct epacket *epkptr; /* call buffer pool stuff so 'freebuf' can be mentioned */ /* without generating a load-time error */ mkpool(10,10); kprintf("Read from Ethernet\n"); epkptr = (struct epacket *)buff; while (1) { if ( (len=read(ETHER, buff, 1500)) == SYSERR) { kprintf("\nError\n"); } else if (epkptr->ep_hdr.e_ptype == EP_ARP) { /* do ARP */ kprintf("ARP...\n"); } else { p = (char *)buff; kprintf("\n LEN: %d\n TO: ",len); for (i=0 ; i<6 ; i++) kprintf("%03o ", 0377& *p++); kprintf("\nFROM: "); for (i=0 ; i<6 ; i++) kprintf("%03o ", 0377& *p++); kprintf("\nTYPE: "); kprintf("%03o ", 0377 & *p++); kprintf("%03o ", 0377 & *p++); kprintf("\nDATA: "); for (i=0 ; i<60 ; i++) if ( printable(ch = *p++) ) kprintf("%c",ch); kprintf("\n"); } } }
//------------------------------------------------------------------------ // sysinit -- initialize all Xinu data structures and devices //------------------------------------------------------------------------ static int sysinit(void) { static int (*nulluserp)() = &nulluser; static uword *nulluserpp = (uword *)&nulluserp; struct pentry *pptr; struct mblock *mptr; // initialize system variables numproc = 0; nextproc = NPROC - 1; nextsem = NSEM - 1; nextqueue = NPROC; // q[0..NPROC-1] are processes // initialize free memory list memlist.mnext = mptr = (struct mblock *)roundew(&end); mptr->mnext = (struct mblock *)NULL; mptr->mlen = (uword)truncew((uintptr_t)maxaddr - NULLSTK - (uintptr_t)&end); // initialize process table for (int k = 0; k < NPROC; k++) proctab[k].pstate = PRFREE; // initialize null process entry pptr = &proctab[NULLPROC]; pptr->pstate = PRCURR; pptr->pprio = 0; strlcpy(pptr->pname, "prnull", PNMLEN); pptr->plimit = ((char *)maxaddr) - NULLSTK - sizeof(uword); pptr->pbase = (char *)maxaddr; *((uword *)pptr->pbase) = MAGIC; pptr->paddr = (char *)(*nulluserpp); pptr->phasmsg = FALSE; pptr->pargs = 0; currpid = NULLPROC; // initialize semaphores for (int k = 0; k < NSEM; k++) { struct sentry *sptr = &semaph[k]; sptr->sstate = SFREE; sptr->sqtail = 1 + (sptr->sqhead = newqueue()); } // initialize ready list rdyhead = newqueue(); rdytail = 1 + rdyhead; // initialize memory marking _mkinit(); // initialize r.t.clock clkinit(); // initialize disk buffers dskdbp = mkpool(DBUFSIZ, NDBUFF); dskrbp = mkpool(DREQSIZ, NDREQ); // initialize devices for (int k = 0; k < NDEVS; k++) init(k); return OK; }
/*------------------------------------------------------------------------ * mon_init - initialize monitor related stuff *------------------------------------------------------------------------ */ int mon_init() { mon_initq(); mon_bufpool = mkpool(1530, 16); return(OK); }