int main(int argc, char **argv) { if(argc != 3) { printf("Usage: zmq_bridge <port 1> <port 2>\n"); exit(EXIT_FAILURE); } int ret; int port1, port2; char portBuf[128]; void *context = zmq_init(1); void *pubber = zmq_socket(context, ZMQ_PUB); void *subber = zmq_socket(context, ZMQ_SUB); port1 = atoi(argv[1]); port2 = atoi(argv[2]); printf("%d-->%d\n", port1, port2); bzero(portBuf, 128); sprintf(portBuf, "tcp://*:%d", port1); printf("Subber: %s\n", portBuf); ret = zmq_bind(subber, portBuf); if(ret < 0) { printf("Error no= %s\n", strerror(errno)); } zmq_setsockopt(subber, ZMQ_SUBSCRIBE, "", 0); bzero(portBuf, 128); sprintf(portBuf, "tcp://*:%d", port2); printf("Pubber: %s\n", portBuf); ret = zmq_bind(pubber, portBuf); if(ret < 0) { printf("Error no= %s\n", strerror(errno)); } subq = newqueue(); pubq = newqueue(); /*Init sockaddr for UDP*/ memset((char *)&client, 0, sizeof(client)); client.sin_family = AF_INET; client.sin_port = htons(INT_PORT2); inet_aton("127.0.0.1", &client.sin_addr); memset((char *)&server, 0, sizeof(server)); server.sin_family = AF_INET; server.sin_port = htons(INT_PORT1); inet_aton("127.0.0.1", &server.sin_addr); startBridge(subber, pubber); //Clean up; clearQueue(subq); clearQueue(pubq); //Clean zmq return EXIT_SUCCESS; }
/** * Intializes all XINU data structures and devices. * @return OK if everything is initialized successfully */ local sysinit(void) { int i = 0; pcb *ppcb = NULL; /* process control block pointer */ semblk *psem = NULL; /* semaphore block pointer */ memblk *pmem = NULL; /* memory block pointer */ /* Initialize system variables */ /* Count this NULLPROC as the first process in the system. */ numproc = 1; /* Initialize free memory list */ freelist.next = pmem = (memblk *) roundmb(minheap); freelist.length = (ulong)truncew((ulong)platform.maxaddr - (ulong)minheap); pmem->next = NULL; pmem->length = freelist.length; /* Initialize process table */ for (i = 0; i < NPROC; i++) { proctab[i].state = PRFREE; } /* initialize null process entry */ ppcb = &proctab[NULLPROC]; ppcb->state = PRCURR; strncpy(ppcb->name, "prnull", 7); ppcb->stkbase = (void *)&end; ppcb->stkptr = NULL; ppcb->stklen = (ulong)minheap - (ulong)&end; ppcb->priority = 0; currpid = NULLPROC; /* Initialize semaphores */ for (i = 0; i < NSEM; i++) { psem = &semtab[i]; psem->state = SFREE; psem->count = 0; psem->queue = newqueue(); } /* initialize bounded-waiting mutex subsystems */ mutexInit(); /* initialize process ready list */ readylist = newqueue(); #if RTCLOCK /* initialize real time clock */ clockinit(); #endif return OK; }
/*------------------------------------------------------------------------ * linit -- initialize all Xinu locks *------------------------------------------------------------------------ */ int linit() { int i; struct lentry *lptr; for (i=0; i<NLOCKS; i++) { /* for each lock */ (lptr = &locks[i])->lstate = LFREE; lptr->lwqtail = 1 + (lptr->lwqhead = newqueue()); lptr->lrqtail = 1 + (lptr->lrqhead = newqueue()); } return OK; }
int main() { pthread_t threads[2]; int i; int ret; queuetype *q; void *thread_ret; fprintf(stderr, "creating new queue...\n"); q = newqueue(); fprintf(stderr, "have new queue. \n"); if (q == NULL) die ("bad queue\n"); i = 0; ret = pthread_create(&threads[i], NULL, (void *)(void *)slam_stuff_in_queue, (void *)q); fprintf(stderr, "back from pthread_create 1; ret is %d, errno is %d\n", ret, errno); errno = 0; i = 1; ret = pthread_create(&threads[i], NULL, (void *)(void *)read_stuff_from_queue, (void *)q); fprintf(stderr, "back from pthread_create 2; ret is %d, errno is %d\n", ret, errno); fprintf(stderr, "waiting on thread 1 \n"); pthread_join(threads[0], &thread_ret); fprintf(stderr, "waiting on thread 2 \n"); pthread_join(threads[1], &thread_ret); fprintf(stderr, "freeing queue...\n"); freequeue(q); fprintf(stderr, "done. \n"); return 0; }
/* *------------------------------------------------------------------------ * clkinit - initialize the clock and sleep queue (called at startup) *------------------------------------------------------------------------ */ int clkinit() { //TODO set up interrupt vector //int *vector; //vector = (int *) CVECTOR; /* set up interrupt vector */ //*vector++ = clkint; //*vector = DISABLE; // setclkr(); struct sigaction sa; struct itimerval timer; sigemptyset(&sa.sa_mask); sa.sa_handler = &clkint; if (sigaction(SIGVTALRM,&sa,NULL) == -1) { perror("unable to set alarm "); exit(4); } //100msec timer.it_value.tv_sec = 0; timer.it_value.tv_usec = 100000; timer.it_interval.tv_sec = 0; timer.it_interval.tv_usec = 100000; preempt = QUANTUM; /* initial time quantum */ //count6 = 6; /* 60ths of a sec. counter */ slnempty = FALSE; /* initially, no process asleep */ clkdiff = 0; /* zero deferred ticks */ defclk = 0; /* clock is not deferred */ clockq = newqueue(); /* allocate clock queue in q */ setitimer(ITIMER_VIRTUAL,&timer,NULL); return; }
/*------------------------------------------------------------------------ * clkinit - initialize the clock and sleep queue at startup *------------------------------------------------------------------------ */ void clkinit(void) { uint16 intv; /* clock rate in KHz */ /* Set interrupt vector for clock to invoke clkint */ set_evec(IRQBASE, (uint32)clkint); /* clock rate is 1.190 Mhz; this is 10ms interrupt rate */ intv = 1190; sleepq = newqueue(); /* allocate a queue to hold the delta */ /* list of sleeping processes */ preempt = QUANTUM; /* initial time quantum */ /* Specify that seepq is initially empty */ slnonempty = FALSE; clktime = 0; /* start counting seconds */ /* set to: timer 0, 16-bit counter, rate generator mode, counter is binary */ outb(CLKCNTL, 0x34); /* must write LSB first, then MSB */ outb(CLOCK0, (char)intv); outb(CLOCK0, intv>>8); return; }
void handleServerData(int sock) { if(outDC == NULL) { dataChunk *dc = (dataChunk *)dequeue(subq); if(dc == NULL) { printf("nothing to send to UDP\n"); return; } outDC = newqueue(); chunkifyDC(outDC, dc); freeDataChunk(dc); } if(waitACK == NULL) { dataPacket *pkt = (dataPacket *)dequeue(outDC); if(pkt == NULL) { printf("No more pkt to send to UPD\n"); free(outDC); outDC = NULL; } else { char buf[1500]; bzero(buf, 1500); memcpy(buf, &pkt->id, 4); memcpy(buf + 4, &pkt->size, 4); memcpy(buf + 8, &pkt->allSize, 4); memcpy(buf + 12, &pkt->ack, 4); memcpy(buf + 16, &pkt->data, pkt->size); sendto(sock, buf, 1500, 0, (struct sockaddr *)&client, sizeof(client)); waitACK = pkt; } } }
void nulluser() { struct memblk *memptr; /* Ptr to memory block */ uint32 free_mem; /* Total amount of free memory */ /* Initialize the system */ sysinit(); kprintf("\n\r%s\n\n\r", VERSION); /* Output Xinu memory layout */ free_mem = 0; for (memptr = memlist.mnext; memptr != NULL; memptr = memptr->mnext) { free_mem += memptr->mlength; } kprintf("%10d bytes of free memory. Free list:\n", free_mem); for (memptr=memlist.mnext; memptr!=NULL;memptr = memptr->mnext) { kprintf(" [0x%08X to 0x%08X]\r\n", (uint32)memptr, ((uint32)memptr) + memptr->mlength - 1); } kprintf("%10d bytes of Xinu code.\n", (uint32)&etext - (uint32)&text); kprintf(" [0x%08X to 0x%08X]\n", (uint32)&text, (uint32)&etext - 1); kprintf("%10d bytes of data.\n", (uint32)&ebss - (uint32)&data); kprintf(" [0x%08X to 0x%08X]\n\n", (uint32)&data, (uint32)&ebss - 1); /* Enable interrupts */ enable(); /* Create a ready list for processes */ int32 i; for (i=0; i < 10; ++i) { readylist[i] = newqueue(); } /* Create a process to execute function main() */ resume ( create((void *)main, INITSTK, INITPRIO, "Main process", 0, NULL)); /* Become the Null process (i.e., guarantee that the CPU has */ /* something to run when no other process is ready to execute) */ while (TRUE) { ; /* Do nothing */ } }
void init(bt_config_t *config) { int i; fillChunkList(&masterChunk, MASTER, config->chunk_file); fillChunkList(&hasChunk, HAS, config->has_chunk_file); fillPeerList(config); if((log_file = fopen("lab2-errors.txt", "w")) == NULL) { fprintf(stderr, "Failed to open logging file.\n"); }; maxConn = config->max_conn; nonCongestQueue = newqueue(); for(i = 0; i < peerInfo.numPeer; i++) { int peerID = peerInfo.peerList[i].peerID; uploadPool[peerID].dataQueue = newqueue(); uploadPool[peerID].ackWaitQueue = newqueue(); uploadPool[peerID].connID = 0; downloadPool[peerID].getQueue = newqueue(); downloadPool[peerID].timeoutQueue = newqueue(); downloadPool[peerID].ackSendQueue = newqueue(); downloadPool[peerID].connected = 0; downloadPool[peerID].cache = NULL; initWindows(&(downloadPool[peerID].rw), &(uploadPool[peerID].sw)); } printInit(); }
/* *------------------------------------------------------------------------ * clkinit - initialize the clock and sleep queue (called at startup) *------------------------------------------------------------------------ */ void clkinit() { preempt = QUANTUM; /* initial time quantum */ countTick = TICK; /* TICKs of a sec. counter */ clmutex = screate(1); /* semaphore for tod clock */ clktime = 0L; /* initially a low number */ ctr100 = 0L; /* timer (relative) */ slnempty = FALSE; /* initially, no process asleep */ clkdiff = 0; /* zero deferred ticks */ defclk = FALSE; /* clock is not deferred */ clkruns = 1; clockq = newqueue(); /* Initialize timer 3 (System Clock) */ /* 100 Hz clock 16000000/256/(1+624) */ /* OCR3A set to 624 for CTC mode */ OCR3AH = hibyte(624); /* 0-624 => divide by 625 */ OCR3AL = lobyte(624); /* write high byte first! */ TCNT3L = 0x00; TCNT3H = 0x00; TCCR3A = 0x00; /* normal port operation, WGM31=0 WGM30=0 */ TCCR3B = (1<<CS32) | (0<<CS31) | (0<<CS30); /* (clock source/256) for 62500Hz */ TCCR3B |= (1 << WGM32); /* normal mode 4: CTC w/OCR3A */ TCCR3C = 0x00; TIMSK3 |= (1<<OCF3A); /* Clear overflow flag bit */ TIMSK3 |= (1<<OCIE3A); /* Output Compare A Match Interrupt Enable */ /* Initialize timer 2 (RTC) */ TIMSK2 &= ~((1<<TOIE2)|(1<<OCIE2A)|(1<<OCIE2B)); //Disable TC2 interrupt ASSR |= (1<<AS2); //set Timer/Counter2 to be asynchronous from the CPU clock //with a second external clock(32.768kHz)driving it. TCNT2 = 0x00; TCCR2A = 0x00; //normal mode 0 TCCR2B = 0x05; //prescale the timer to be clock source / 128 // //TIMER2 quit working on me 12/21/2013 -- change rtc & MAC Symbol counter!!!!!!!!!!!!!!!!!! // // while(ASSR&0x1F) // while(ASSR&( (1<<TCR2BUB)|(1<<OCR2BUB)|(1<<TCN2UB) )) // ; //Wait until TC0 is updated // TIFR2 |= (1<<TOV2); //Clear overflow flag bit // TIMSK2 |= (1<<TOIE2); //set 8-bit Timer/Counter0 Overflow Interrupt Enable }
/*------------------------------------------------------------------------ * clkinit - initialize the clock and sleep queue at startup *------------------------------------------------------------------------ */ void clkinit(void) { sleepq = newqueue(); /* allocate a queue to hold the delta */ /* list of sleeping processes */ clkticks = 0; /* start counting one second */ /* Add clock interrupt handler to interrupt vector array */ interruptVector[IRQ_TIMER] = &clkhandler; /* Enable clock interrupts */ enable_irq(IRQ_TIMER); /* Start interval timer */ clkupdate(CLKCYCS_PER_TICK); }
void linit() { struct lentry *lptr; int i, j; nextlock = NLOCKS-1; for(i = 0; i < NLOCKS; i++) { (lptr = &locks[i])->lstate = LFREE; lptr -> locknum = i; lptr -> lqtail = 1 + (lptr -> lqhead = newqueue()); lptr -> nreaders = 0; lptr -> nwriters = 0; lptr -> version = 0; } for(i = 0; i < NPROC; i ++) for(j = 0; j < NLOCKS; j ++) lockholdtab[i][j] = 0; }
void linit(void) { struct lentry *lptr; int i, j; nextlock = NLOCKS - 1; lockiter = 0; for (i = 0; i < NLOCKS; i++) { (lptr = &locks[i])->lstate = LFREE; lptr->lqtail = 1 + (lptr->lqhead = newqueue()); lptr->liter = 0; lptr->lprio = -1; for (j=0 ; j<NPROC ; j++) { lptr->pidheld[j] = 0; } } }
/* *------------------------------------------------------------------------ * clkinit - initialize the clock and sleep queue (called at startup) *------------------------------------------------------------------------ */ int clkinit(void) { int clkint(); set_evec(IRQBASE, clkint); clkruns = 1; clockq = newqueue(); preempt = QUANTUM; /* initial time quantum */ compute_delay(); /* set to: timer 0, 16-bit counter, rate generator mode, counter is binary */ outb(CLKCNTL, 0x34); /* must write LSB first, then MSB */ outb(CLOCK0, (char)DIVIDER); outb(CLOCK0, DIVIDER>>8); return OK; }
/* *------------------------------------------------------------------------ * clkinit - initialize the clock and sleep queue (called at startup) *------------------------------------------------------------------------ */ void clkinit() { unsigned short intv; int clkint(); set_evec(IRQBASE, (u_long)clkint); /* clock rate is 1.190 Mhz; this is 10ms interrupt rate */ intv = 1190; clkruns = 1; clockq = newqueue(); preempt = QUANTUM; /* initial time quantum */ clmutex = screate(1); /* set to: timer 0, 16-bit counter, rate generator mode, counter is binary */ outb(CLKCNTL, 0x34); /* must write LSB first, then MSB */ outb(CLOCK0, (char)intv); outb(CLOCK0, intv>>8); outb(CLOCK0, intv>>8); }
/** * Intializes all XINU data structures and devices. * @return OK if everything is initialized successfully */ local sysinit(void) { int i = 0; pcb *ppcb = NULL; /* process control block pointer */ /* Initialize system variables */ /* Count this NULLPROC as the first process in the system. */ numproc = 1; /* Initialize process table */ for (i = 0; i < NPROC; i++) { proctab[i].state = PRFREE; } /* initialize null process entry */ ppcb = &proctab[NULLPROC]; ppcb->state = PRCURR; strncpy(ppcb->name, "prnull", 7); ppcb->stkbase = (void *)&end; ppcb->stkptr = NULL; ppcb->stklen = (ulong)minheap - (ulong)&end; /* TODO: This line won't compile properly until you have added * a priority field to the process control block. */ ppcb->priority = 0; currpid = NULLPROC; /* initialize process ready list */ readylist = newqueue(); #if RTCLOCK /* initialize real time clock */ clockinit(); #endif return OK; }
/*------------------------------------------------------------------------ * sysinit -- initialize all Xinu data structeres and devices *------------------------------------------------------------------------ */ LOCAL int sysinit() { int i,j; struct pentry *pptr; struct sentry *sptr; struct mblock *mptr; numproc = 0; /* initialize system variables */ nextproc = NPROC-1; nextsem = NSEM-1; nextqueue = NPROC; /* q[0..NPROC-1] are processes */ /* initialize free memory list */ /* PC version has to pre-allocate 640K-1024K "hole" */ if (maxaddr+1 > (char *)HOLESTART) { memlist.mnext = mptr = (struct mblock *) roundmb(&end); mptr->mnext = (struct mblock *)HOLEEND; mptr->mlen = (int) truncew(((unsigned) HOLESTART - (unsigned)&end)); mptr->mlen -= 4; mptr = (struct mblock *) HOLEEND; mptr->mnext = 0; mptr->mlen = (int) truncew((unsigned)maxaddr - HOLEEND - NULLSTK); } else { /* initialize free memory list */ memlist.mnext = mptr = (struct mblock *) roundmb(&end); mptr->mnext = 0; mptr->mlen = (int) truncew((unsigned)maxaddr - (int)&end - NULLSTK); } for (i=0 ; i<NPROC ; i++) /* initialize process table */ proctab[i].pstate = PRFREE; pptr = &proctab[NULLPROC]; /* initialize null process entry */ pptr->pstate = PRCURR; for (j=0; j<7; j++) pptr->pname[j] = "prnull"[j]; pptr->plimit = (WORD)(maxaddr + 1) - NULLSTK; pptr->pbase = (WORD) maxaddr - 3; pptr->pesp = pptr->pbase-4; /* for stkchk; rewritten before used */ *( (int *)pptr->pbase ) = MAGIC; pptr->paddr = (WORD) nulluser; pptr->pargs = 0; pptr->pprio = 0; currpid = NULLPROC; for (i=0 ; i<NSEM ; i++) { /* initialize semaphores */ (sptr = &semaph[i])->sstate = SFREE; sptr->sqtail = 1 + (sptr->sqhead = newqueue()); } rdytail = 1 + (rdyhead=newqueue());/* initialize ready list */ #ifdef MEMMARK _mkinit(); /* initialize memory marking */ #endif #ifdef RTCLOCK clkinit(); /* initialize r.t.clock */ #endif pci_init(); /* PCI */ mon_init(); /* init monitor */ // ripinit(); #ifdef NDEVS for (i=0 ; i<NDEVS ; i++ ) { init_dev(i); } #endif buf_init(); return(OK); }
static void sysinit(void) { int32 i; struct procent *prptr; /* ptr to process table entry */ struct sentry *semptr; /* prr to semaphore table entry */ struct memblk *memptr; /* ptr to memory block */ /* Initialize system variables */ /* Count the Null process as the first process in the system */ prcount = 1; /* Scheduling is not currently blocked */ Defer.ndefers = 0; /* Initialize the free memory list */ maxheap = (void *)addressp2k(MAXADDR); memlist.mnext = (struct memblk *)minheap; /* Overlay memblk structure on free memory and set fields */ memptr = (struct memblk *)minheap; memptr->mnext = NULL; memptr->mlength = memlist.mlength = (uint32)(maxheap - minheap); /* Initialize process table entries free */ for (i = 0; i < NPROC; i++) { prptr = &proctab[i]; prptr->prstate = PR_FREE; prptr->prname[0] = NULLCH; prptr->prstkbase = NULL; prptr->prprio = 0; } /* Initialize the Null process entry */ prptr = &proctab[NULLPROC]; prptr->prstate = PR_CURR; prptr->prprio = 0; strncpy(prptr->prname, "prnull", 7); prptr->prstkbase = minheap; prptr->prstklen = NULLSTK; prptr->prstkptr = 0; currpid = NULLPROC; /* Initialize semaphores */ for (i = 0; i < NSEM; i++) { semptr = &semtab[i]; semptr->sstate = S_FREE; semptr->scount = 0; semptr->squeue = newqueue(); } /* Initialize buffer pools */ bufinit(); /* Create a ready list for processes */ readylist = newqueue(); /* Initialize real time clock */ clkinit(); /* Initialize non-volative RAM storage */ #if 0 nvramInit(); #endif /* Initialize devices */ for (i = 0; i < NDEVS; i++) { init(i); } return; }
/*------------------------------------------------------------------------ * * sysinit - Initialize all Xinu data structures and devices * *------------------------------------------------------------------------ */ static void sysinit() { int32 i; struct procent *prptr; /* Ptr to process table entry */ struct sentry *semptr; /* Ptr to semaphore table entry */ /* Platform Specific Initialization */ platinit(); /* kprintf("\033[39;49m\n\r%s\n\n\r", VERSION);*/ /* Initialize the interrupt vectors */ initevec(); /* Initialize free memory list */ meminit(); /* Initialize system variables */ /* Count the Null process as the first process in the system */ prcount = 1; /* Scheduling is not currently blocked */ Defer.ndefers = 0; /* Initialize process table entries free */ for (i = 0; i < NPROC; i++) { prptr = &proctab[i]; prptr->prstate = PR_FREE; prptr->prname[0] = NULLCH; prptr->prstkbase = NULL; prptr->prprio = 0; } /* Initialize the Null process entry */ prptr = &proctab[NULLPROC]; prptr->prstate = PR_CURR; prptr->prprio = 0; strncpy(prptr->prname, "prnull", 7); prptr->prstkbase = getstk(NULLSTK); prptr->prstklen = NULLSTK; prptr->prstkptr = 0; currpid = NULLPROC; /* Initialize semaphores */ for (i = 0; i < NSEM; i++) { semptr = &semtab[i]; semptr->sstate = S_FREE; semptr->scount = 0; semptr->squeue = newqueue(); } /* Initialize buffer pools */ bufinit(); /* Create a ready list for processes */ readylist = newqueue(); /* Initialize the real time clock */ clkinit(); for (i = 0; i < NDEVS; i++) { init(i); } return; }
/*------------------------------------------------------------------------ * sysinit -- initialize all Xinu data structeres and devices *------------------------------------------------------------------------ */ LOCAL sysinit() { int i,j,len; struct pentry *pptr; /* null process entry */ struct sentry *sptr; struct mblock *volatile mptr; numproc = 0; /* initialize system variables */ nextproc = NPROC-1; nextsem = NSEM-1; nextqueue = NPROC; /* q[0..NPROC-1] are processes */ memlist.mnext = mptr = /* initialize free memory list */ (struct mblock *volatile) roundmb(__malloc_heap_start); mptr->mnext = (struct mblock *)NULL; mptr->mlen = len = (int) truncmb(RAMEND - NULLSTK - (unsigned)&__bss_end); __malloc_heap_start = (char *)mptr; __malloc_heap_end = __malloc_heap_start + len; kprintf_P(PSTR("Heap: %p of length %d\n"), mptr, len); for (i=0 ; i<NPROC ; i++) /* initialize process table */ proctab[i].pstate = PRFREE; /* initialize null process entry */ pptr = &proctab[NULLPROC]; pptr->pstate = PRCURR; for (j=0; j<6; j++) pptr->pname[j] = "nullp"[j]; pptr->plimit = (unsigned char *)(RAMEND + 1) - NULLSTK; pptr->pbase = (unsigned char *) RAMEND; *pptr->pbase = (unsigned char)MAGIC; /* clobbers return, but proc 0 doesn't return */ pptr->paddr = (int *) main; pptr->pargs = 0; pptr->pprio = 0; pptr->pregs[SSP_L] = lobyte((unsigned int)pptr->plimit); /* for error checking */ pptr->pregs[SSP_H] = hibyte((unsigned int)pptr->plimit); /* for error checking */ currpid = NULLPROC; for (i=0 ; i<NSEM ; i++) { /* initialize semaphores */ (sptr = &semaph[i])->sstate = SFREE; sptr->sqtail = 1 + (sptr->sqhead = newqueue()); } rdytail = 1 + (rdyhead=newqueue()); /* initialize ready list */ #ifdef MEMMARK kprintf("Memory marking\n"); _mkinit(); /* initialize memory marking */ #else kprintf("Pool init\n"); poolinit(); /* explicitly */ pinit(MAXMSGS); #endif #ifdef RTCLOCK kprintf("init RTC\n"); clkinit(); /* initialize r.t.clock */ #endif #ifdef NDEVS for ( i=0 ; i<NDEVS ; i++ ) { if (i>0) kprintf("init dev %d\n", i); init(i); } #endif #ifdef NNETS // kprintf("net init\n"); netinit(); #endif return (OK); }
static void sysinit(void) { int32 i; struct pipentry *pipptr; /* ptr to pipe tabe entry */ struct procent *prptr; /* ptr to process table entry */ struct dentry *devptr; /* ptr to device table entry */ struct sentry *semptr; /* prr to semaphore table entry */ struct memblk *memptr; /* ptr to memory block */ /* Initialize system variables */ /* Count the Null process as the first process in the system */ prcount = 1; /* Scheduling is not currently blocked */ Defer.ndefers = 0; /* Initialize the free memory list */ maxheap = (void *)addressp2k(MAXADDR); memlist.mnext = (struct memblk *)minheap; /* Overlay memblk structure on free memory and set fields */ memptr = (struct memblk *)minheap; memptr->mnext = NULL; memptr->mlength = memlist.mlength = (uint32)(maxheap - minheap); /* Initialize pipe table entries free */ for (i = 0; i < NPIPE; i++) { pipptr = &piptab[i]; pipptr->pipstate = PR_FREE; pipptr->owner = NPROC + 1; pipptr->rdend = NPROC + 1; pipptr->wrtend = NPROC + 1; pipptr->nextpos = -1; pipptr->buffer[0] = NULL; } /* Initialize process table entries free */ for (i = 0; i < NPROC; i++) { prptr = &proctab[i]; prptr->prstate = PR_FREE; prptr->prname[0] = NULLCH; prptr->prstkbase = NULL; prptr->prprio = 0; } /* Initialize the Null process entry */ prptr = &proctab[NULLPROC]; prptr->prstate = PR_CURR; prptr->prprio = 0; strncpy(prptr->prname, "prnull", 7); prptr->prstkbase = minheap; prptr->prstklen = NULLSTK; prptr->prstkptr = 0; currpid = NULLPROC; /* Initialize semaphores */ for (i = 0; i < NSEM; i++) { semptr = &semtab[i]; semptr->sstate = S_FREE; semptr->scount = 0; semptr->squeue = newqueue(); } /* Initialize buffer pools */ bufinit(); /* Create a ready list for processes */ readylist = newqueue(); /* Initialize real time clock */ clkinit(); for (i = 0; i < NDEVS; i++) { if (! isbaddev(i)) { devptr = (struct dentry *) &devtab[i]; (devptr->dvinit) (devptr); } } return; }
/*------------------------------------------------------------------------ * create, newpid - Create a process to start running a procedure *------------------------------------------------------------------------ */ pid32 create( void *funcaddr, /* address of function to run */ uint32 ssize, /* stack size in bytes */ pri16 priority, /* process priority */ char *name, /* process name (for debugging) */ uint32 nargs, /* number of args that follow */ ... ) { intmask mask; /* saved interrupt mask */ struct procent *prptr; /* ptr to process' table entry */ uint32 *saddr; /* stack address */ uint32 *savargs; /* pointer to arg save area */ pid32 pid; /* ID of newly created process */ uint32 *ap; /* points to list of var args */ int32 pad; /* padding needed for arg area */ uint32 i; void INITRET(void); mask = disable(); if ( (ssize < MINSTK) || (priority <= 0) || (((int32)(pid = newpid())) == (int32) SYSERR) || ((saddr = (uint32 *)getstk(ssize)) == (uint32 *)SYSERR)) { restore(mask); return SYSERR; } prcount++; prptr = &proctab[pid]; /* Initialize process table entry for new process */ prptr->prstate = PR_SUSP; /* initial state is suspended */ prptr->prprio = priority; prptr->prstkptr = (char *)saddr; prptr->prstkbase = (char *)saddr; prptr->prstklen = ssize; prptr->prname[PNMLEN-1] = NULLCH; for (i=0 ; i<PNMLEN-1 && (prptr->prname[i]=name[i])!=NULLCH; i++) ; prptr->prparent = (pid32)getpid(); prptr->prhasmsg = FALSE; /* Set up initial device descriptors for the shell */ prptr->prdesc[0] = CONSOLE; /* stdin is CONSOLE device */ prptr->prdesc[1] = CONSOLE; /* stdout is CONSOLE device */ prptr->prdesc[2] = CONSOLE; /* stderr is CONSOLE device */ /* Continue initialize process table entry for new process */ prptr->sndflag = FALSE; prptr->sndqueue = newqueue(); /* Initialize stack as if the process was called */ *saddr = STACKMAGIC; *--saddr = pid; *--saddr = (uint32)prptr->prstklen; *--saddr = (uint32)prptr->prstkbase - prptr->prstklen + sizeof(int); if (nargs == 0) { /* compute padding */ pad = 4; } else if ((nargs%4) == 0) { /* pad for A0 - A3 */ pad = 0; } else { pad = 4 - (nargs % 4); } for (i = 0; i < pad; i++) { /* pad stack by inserting zeroes*/ *--saddr = 0; } for (i = nargs; i > 0; i--) { /* reserve space for arguments */ *--saddr = 0; } savargs = saddr; /* loc. of args on the stack */ /* Build the context record that ctxsw expects */ for (i = (CONTEXT_WORDS); i > 0; i--) { *--saddr = 0; } prptr->prstkptr = (char *)saddr; /* Address of process entry point */ saddr[(CONTEXT_WORDS) - 1] = (uint32) funcaddr; /* Return address value */ saddr[(CONTEXT_WORDS) - 2] = (uint32) INITRET; /* Copy arguments into activation record */ ap = (uint32 *)(&nargs + 1); /* machine dependent code to */ for (i = 0; i < nargs; i++) { /* copy args onto process stack */ *savargs++ = *ap++; } restore(mask); return pid; }
/*------------------------------------------------------------------------ * sysinit -- initialize all Xinu data structeres and devices *------------------------------------------------------------------------ */ LOCAL sysinit() { static long currsp; int i,j; struct pentry *pptr; struct sentry *sptr; struct mblock *mptr; numproc = 0; /* initialize system variables */ nextproc = NPROC-1; nextsem = NSEM-1; nextqueue = NPROC; /* q[0..NPROC-1] are processes */ #ifdef X__COM32__ puts_com32("sysinit()\n"); #endif #ifdef __COM32__ /* initialize free memory list */ kprintf("com32topmem %d\n", (unsigned long) com32topmem); com32topmem = com32topmem - 1024*64; /* !!! we need some space fort this code */ maxaddr = (char*) com32topmem; kprintf("maxaddr %d\n", (unsigned long) maxaddr); memlist.mnext = mptr = (struct mblock *) roundmb(&end); mptr->mnext = 0; mptr->mlen = (int) truncew((unsigned)maxaddr - (int)&end - NULLSTK); #else /* initialize free memory list */ /* PC version has to pre-allocate 640K-1024K "hole" */ if (maxaddr+1 > HOLESTART) { memlist.mnext = mptr = (struct mblock *) roundmb(&end); mptr->mnext = (struct mblock *)HOLEEND; mptr->mlen = (int) truncew((unsigned) HOLESTART - (unsigned)&end - 4); mptr = (struct mblock *) HOLEEND; mptr->mnext = 0; mptr->mlen = (int) truncew(maxaddr - HOLEEND - NULLSTK); } else { /* initialize free memory list */ memlist.mnext = mptr = (struct mblock *) roundmb(&end); mptr->mnext = 0; mptr->mlen = (int) truncew((unsigned)maxaddr - (int)&end - NULLSTK); } #endif #ifdef X__COM32__ puts_com32("sysinit() free memory list done\n"); #endif for (i=0 ; i<NPROC ; i++) /* initialize process table */ proctab[i].pstate = PRFREE; #ifdef X__COM32__ puts_com32("sysinit() proctab done\n"); #endif pptr = &proctab[NULLPROC]; /* initialize null process entry */ pptr->pstate = PRCURR; for (j=0; j<7; j++) pptr->pname[j] = "prnull"[j]; pptr->plimit = (WORD)(maxaddr + 1) - NULLSTK; pptr->pbase = (WORD) maxaddr - 3; pptr->pesp = pptr->pbase-4; /* for stkchk; rewritten before used */ *( (int *)pptr->pbase ) = MAGIC; pptr->paddr = (WORD) nulluser; pptr->pargs = 0; pptr->pprio = 0; currpid = NULLPROC; for (i=0 ; i<NSEM ; i++) { /* initialize semaphores */ (sptr = &semaph[i])->sstate = SFREE; sptr->sqtail = 1 + (sptr->sqhead = newqueue()); } rdytail = 1 + (rdyhead=newqueue());/* initialize ready list */ #ifdef X__COM32__ puts_com32("sysinit() semaphores done\n"); #endif #ifdef MEMMARK _mkinit(); /* initialize memory marking */ #ifdef __COM32__ puts_com32("sysinit() memory marking done\n"); #endif #endif #ifdef RTCLOCK clkinit(); /* initialize r.t.clock */ #ifdef __COM32__ puts_com32("sysinit() rtc done\n"); #endif #endif #ifdef NDEVS for ( i=0 ; i<NDEVS ; i++ ) { init(i); } #ifdef __COM32__ puts_com32("sysinit() devs done\n"); #endif #endif #ifdef NNETS netinit(); #ifdef __COM32__ puts_com32("sysinit() netinit() done\n"); #endif #endif return(OK); }
/*------------------------------------------------------------------------ * * sysinit - Initialize all Xinu data structures and devices * *------------------------------------------------------------------------ */ static void sysinit() { int32 i; struct procent *prptr; /* Ptr to process table entry */ struct sentry *semptr; /* Ptr to semaphore table entry */ /* Platform Specific Initialization */ platinit(); /* Initialize the interrupt vectors */ initevec(); /* Initialize free memory list */ meminit(); /* Initialize system variables */ /* Count the Null process as the first process in the system */ prcount = 1; /* Scheduling is not currently blocked */ Defer.ndefers = 0; /* Initialize process table entries free */ for (i = 0; i < NPROC; i++) { prptr = &proctab[i]; prptr->prstate = PR_FREE; prptr->prname[0] = NULLCH; prptr->prstkbase = NULL; prptr->prprio = 0; prptr->prcpu_wait_ratio = 0; // Initializing waits at creation for each process to 0 } /* Initialize the Null process entry */ prptr = &proctab[NULLPROC]; prptr->prstate = PR_CURR; /* Setting the null process initial priority as the highest so that all other processes can run before it*/ prptr->initprio = MAXKEY; prptr->prcpumsec = 0; prptr->prctxswintime = 0; /* Reversing the priority order in case of Dynamic Process Scheduling (Q4 and Q5.) */ if (LAB2COND) { prptr->prprio = MAXKEY;// prptr->initprio + prptr->prcpumsec; //Highest int16 value. The Null process must take the lowest priority. } else { prptr->prprio = MINPRIO; } strncpy(prptr->prname, "prnull", 7); prptr->prstkbase = getstk(NULLSTK); prptr->prstklen = NULLSTK; prptr->prstkptr = 0; currpid = NULLPROC; /* Initialize semaphores */ for (i = 0; i < NSEM; i++) { semptr = &semtab[i]; semptr->sstate = S_FREE; semptr->scount = 0; semptr->squeue = newqueue(); } /* Initialize buffer pools */ bufinit(); /* Create a ready list for processes */ readylist = newqueue(); initialize_mltfbq(); init_recieverq(); /* Initialize the real time clock */ clkinit(); for (i = 0; i < NDEVS; i++) { init(i); } return; }
//------------------------------------------------------------------------ // 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; }
void main(int argc, char **argv) { int i, nets = 0; char *ann; rfork(RFNOTEG); formatinit(); machinit(); conf.confdev = "n"; /* Devnone */ ARGBEGIN{ case 'a': /* announce on this net */ ann = EARGF(usage()); if (nets >= Maxnets) { fprint(2, "%s: too many networks to announce: %s\n", argv0, ann); exits("too many nets"); } annstrs[nets++] = ann; break; case 'c': /* use new, faster cache layout */ oldcachefmt = 0; break; case 'f': /* enter configuration mode first */ conf.configfirst++; break; case 'm': /* name device-map file */ conf.devmap = EARGF(usage()); break; default: usage(); break; }ARGEND if (argc != 1) usage(); conf.confdev = argv[0]; /* config string for dev holding full config */ Binit(&bin, 0, OREAD); confinit(); print("\nPlan 9 %d-bit cached-worm file server with %d-deep indir blks\n", sizeof(Off)*8 - 1, NIBLOCK); printsizes(); qlock(&reflock); qunlock(&reflock); serveq = newqueue(1000, "9P service"); /* tunable */ raheadq = newqueue(1000, "readahead"); /* tunable */ mbinit(); netinit(); scsiinit(); files = malloc(conf.nfile * sizeof *files); for(i=0; i < conf.nfile; i++) { qlock(&files[i]); qunlock(&files[i]); } wpaths = malloc(conf.nwpath * sizeof(*wpaths)); uid = malloc(conf.nuid * sizeof(*uid)); gidspace = malloc(conf.gidspace * sizeof(*gidspace)); authinit(); print("iobufinit\n"); iobufinit(); arginit(); boottime = time(nil); print("sysinit\n"); sysinit(); /* * Ethernet i/o processes */ netstart(); /* * read ahead processes */ newproc(rahead, 0, "rah"); /* * server processes */ for(i=0; i < conf.nserve; i++) newproc(serve, 0, "srv"); /* * worm "dump" copy process */ newproc(wormcopy, 0, "wcp"); /* * processes to read the console */ consserve(); /* * "sync" copy process * this doesn't return. */ procsetname("scp"); synccopy(); }
static void sysinit(void) { int32 i; struct procent *prptr; /* ptr to process table entry */ struct dentry *devptr; /* ptr to device table entry */ struct sentry *semptr; /* prr to semaphore table entry */ struct memblk *memptr; /* ptr to memory block */ /* Initialize system variables */ /* Count the Null process as the first process in the system */ prcount = 1; /* Scheduling is not currently blocked */ Defer.ndefers = 0; /* Initialize the free memory list */ maxheap = (void *)addressp2k(MAXADDR); memlist.mnext = (struct memblk *)minheap; /* Overlay memblk structure on free memory and set fields */ memptr = (struct memblk *)minheap; memptr->mnext = NULL; memptr->mlength = memlist.mlength = (uint32)(maxheap - minheap); /* Initialize process table entries free */ for (i = 0; i < NPROC; i++) { prptr = &proctab[i]; prptr->prstate = PR_FREE; prptr->prname[0] = NULLCH; prptr->prstkbase = NULL; prptr->prprio = 0; } /* Initialize the Null process entry */ prptr = &proctab[NULLPROC]; prptr->prstate = PR_CURR; prptr->prprio = 0; strncpy(prptr->prname, "prnull", 7); prptr->prstkbase = minheap; prptr->prstklen = NULLSTK; prptr->prstkptr = 0; currpid = NULLPROC; /* Initialize semaphores */ for (i = 0; i < NSEM; i++) { semptr = &semtab[i]; semptr->sstate = S_FREE; semptr->scount = 0; semptr->squeue = newqueue(); } /* Initialize buffer pools */ bufinit(); /* Create a ready list for processes */ readylist = newqueue(); /* Initialize real time clock */ clkinit(); /* Initialize non-volative RAM storage */ nvramInit(); for (i = 0; i < NDEVS; i++) { if (! isbaddev(i)) { devptr = (struct dentry *) &devtab[i]; (devptr->dvinit) (devptr); } } /** * Initialize the last two entries in lflcblk used for * directory manipulation. */ struct dentry dircblk; dircblk.dvminor = Nlfl; lflInit(&dircblk); dircblk.dvminor = Nlfl+1; lflInit(&dircblk); lfDirCblkMutex = semcreate(1); open(ETHER0,NULL, NULL); /* Create a process to handle network packets */ resume((create(netin, 8192, 500, "netin", 0)) ); return; }
static void sysinit(void) { int32 i; struct procent *prptr; /* ptr to process table entry */ struct dentry *devptr; /* ptr to device table entry */ struct sentry *semptr; /* prr to semaphore table entry */ struct memblk *memptr; /* ptr to memory block */ /* Initialize the interrupt vectors */ initevec(); /* Initialize system variables */ /* Count the Null process as the first process in the system */ prcount = 1; /* Scheduling is not currently blocked */ Defer.ndefers = 0; /* Initialize the free memory list */ /* Note: PC version has to pre-allocate 640K-1024K "hole" */ maxheap = (void *)MAXADDR; minheap = &end; memptr = memlist.mnext = (struct memblk *)roundmb(minheap); if ((char *)(maxheap+1) > HOLESTART) { /* create two blocks that straddle the hole */ memptr->mnext = (struct memblk *)HOLEEND; memptr->mlength = (int) truncmb((unsigned) HOLESTART - (unsigned)&end - 4); memptr = (struct memblk *) HOLEEND; memptr->mnext = (struct memblk *) NULL; memptr->mlength = (int) truncmb( (uint32)maxheap - (uint32)HOLEEND - NULLSTK); } else { /* initialize free memory list to one block */ memlist.mnext = memptr = (struct memblk *) roundmb(&end); memptr->mnext = (struct memblk *) NULL; memptr->mlength = (uint32) truncmb((uint32)maxheap - (uint32)&end - NULLSTK); } /* Initialize process table entries free */ for (i = 0; i < NPROC; i++) { prptr = &proctab[i]; prptr->prstate = PR_FREE; prptr->prname[0] = NULLCH; prptr->prstkbase = NULL; prptr->prprio = 0; } /* Initialize the Null process entry */ prptr = &proctab[NULLPROC]; prptr->prstate = PR_CURR; prptr->prprio = 0; strncpy(prptr->prname, "prnull", 7); prptr->prstkbase = getstk(NULLSTK); prptr->prstklen = NULLSTK; prptr->prstkptr = 0; currpid = NULLPROC; /* Initialize semaphores */ for (i = 0; i < NSEM; i++) { semptr = &semtab[i]; semptr->sstate = S_FREE; semptr->scount = 0; semptr->squeue = newqueue(); } /* Initialize buffer pools */ bufinit(); /* Create a ready list for processes */ readylist = newqueue(); /* Initialize the PCI bus */ pci_init(); /* Initialize the real time clock */ clkinit(); for (i = 0; i < NDEVS; i++) { if (! isbaddev(i)) { devptr = (struct dentry *) &devtab[i]; (devptr->dvinit) (devptr); } } return; }
/*------------------------------------------------------------------------ * sysinit -- initialize all Xinu data structeres and devices *------------------------------------------------------------------------ */ LOCAL sysinit() { static long currsp; int i,j, avail; struct pentry *pptr; struct sentry *sptr; struct mblock *mptr; SYSCALL pfintr(); /*********************/ set_evec(14, pfintr); pptr = &proctab[NULLPROC]; /* initialize null process entry */ /*********************/ numproc = 0; /* initialize system variables */ nextproc = NPROC-1; nextsem = NSEM-1; nextqueue = NPROC; /* q[0..NPROC-1] are processes */ /* initialize free memory list */ /* PC version has to pre-allocate 640K-1024K "hole" */ if (maxaddr+1 > HOLESTART) { memlist.mnext = mptr = (struct mblock *) roundmb(&end); mptr->mnext = (struct mblock *)HOLEEND; mptr->mlen = (int) truncew(((unsigned) HOLESTART - (unsigned)&end)); mptr->mlen -= 4; mptr = (struct mblock *) HOLEEND; mptr->mnext = 0; mptr->mlen = (int) truncew((unsigned)maxaddr - HOLEEND - NULLSTK); /* mptr->mlen = (int) truncew((unsigned)maxaddr - (4096 - 1024 ) * 4096 - HOLEEND - NULLSTK); */ } else { /* initialize free memory list */ memlist.mnext = mptr = (struct mblock *) roundmb(&end); mptr->mnext = 0; mptr->mlen = (int) truncew((unsigned)maxaddr - (int)&end - NULLSTK); } for (i=0 ; i<NPROC ; i++) /* initialize process table */ proctab[i].pstate = PRFREE; #ifdef MEMMARK _mkinit(); /* initialize memory marking */ #endif #ifdef RTCLOCK clkinit(); /* initialize r.t.clock */ #endif mon_init(); /* init monitor */ #ifdef NDEVS for (i=0 ; i<NDEVS ; i++ ) { init_dev(i); } #endif pptr = &proctab[NULLPROC]; /* initialize null process entry */ pptr->pstate = PRCURR; for (j=0; j<7; j++) pptr->pname[j] = "prnull"[j]; pptr->plimit = (WORD)(maxaddr + 1) - NULLSTK; pptr->pbase = (WORD) maxaddr - 3; /* pptr->plimit = (WORD)(maxaddr + 1) - NULLSTK - (4096 - 1024 )*4096; pptr->pbase = (WORD) maxaddr - 3 - (4096-1024)*4096; */ pptr->pesp = pptr->pbase-4; /* for stkchk; rewritten before used */ *( (int *)pptr->pbase ) = MAGIC; pptr->paddr = (WORD) nulluser; pptr->pargs = 0; pptr->pprio = 0; currpid = NULLPROC; for (i=0 ; i<NSEM ; i++) { /* initialize semaphores */ (sptr = &semaph[i])->sstate = SFREE; sptr->sqtail = 1 + (sptr->sqhead = newqueue()); } rdytail = 1 + (rdyhead=newqueue());/* initialize ready list */ init_bsm(); init_frm(); kprintf("initialize page tables for null process\n"); init_glb_pgs(glb_pg_tbl_frm_mapping); // init pg dir for proc 0 frame_t *pg_dir = get_free_frame(); init_pg_dir(pg_dir, NULLPROC); pptr->pdbr = pg_dir->frm_num; pptr->pd = pg_dir; return(OK); }