//------------------------------------------------------------------------ // mkpool -- allocate memory for a buffer pool and link together //------------------------------------------------------------------------ SYSCALL mkpool(int bufsiz, int numbufs) { int ps; int poolid; char *where; if (unmarked(bpmark)) poolinit(); ps = disable(); if (bufsiz < BPMINB || bufsiz > BPMAXB || numbufs < 1 || numbufs > BPMAXN || nbpools >= NBPOOLS || (where = (char *)getmem((bufsiz + sizeof(int)) * numbufs)) == (char *)SYSERR) { restore(ps); return SYSERR; } poolid = nbpools++; bptab[poolid].bpnext = where; bptab[poolid].bpsize = bufsiz; bptab[poolid].bpsem = screate(numbufs); bufsiz += sizeof(int); for (numbufs--; numbufs > 0; numbufs--, where += bufsiz) *((int *)where) = (int) (where + bufsiz); *((int *)where) = (int) NULL; restore(ps); return poolid; }
/*------------------------------------------------------------------------ * 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); }
int input_line(char *string, int length) { char curline[2000]; /* edit buffer */ int noline; unsigned c; int more; int i; if (first) { poolinit(); /* build line pool */ first = 0; } noline = 1; /* no line fetched yet */ for (cl=cp=0; cl<length && cl<(int)sizeof(curline); ) { if (usrbrk()) { clrbrk(); break; } switch (c=input_char()) { case F_RETURN: /* CR */ t_sendl("\r\n", 2); /* yes, print it and */ goto done; /* get out */ case F_CLRSCRN: /* clear screen */ asclrs(); t_sendl(curline, cl); ascurs(0, cp); break; case F_CSRUP: if (noline) { /* no line fetched yet */ getnext(); /* getnext so getprev gets current */ noline = 0; /* we now have line */ } bstrncpy(curline, getprev(), sizeof(curline)); prtcur(curline); break; case F_CSRDWN: noline = 0; /* mark line fetched */ bstrncpy(curline, getnext(), sizeof(curline)); prtcur(curline); break; case F_INSCHR: insert_space(curline, sizeof(curline)); break; case F_DELCHR: delchr(1, curline, sizeof(curline)); /* delete one character */ break; case F_CSRLFT: /* Backspace */ backup(curline); break; case F_CSRRGT: forward(curline, sizeof(curline)); break; case F_ERSCHR: /* Rubout */ backup(curline); delchr(1, curline, sizeof(curline)); if (cp == 0) { t_char(' '); t_char(0x8); } break; case F_DELEOL: t_clrline(0, t_width); if (cl > cp) cl = cp; break; case F_NXTWRD: i = next_word(curline); while (i--) { forward(curline, sizeof(curline)); } break; case F_PRVWRD: i = prev_word(curline); while (i--) { backup(curline); } break; case F_DELWRD: delchr(next_word(curline), curline, sizeof(curline)); /* delete word */ break; case F_NXTMCH: /* Ctl-X */ if (cl==0) { *string = EOS; /* terminate string */ return(c); /* give it to him */ } /* Note fall through */ case F_DELLIN: case F_ERSLIN: while (cp > 0) { backup(curline); /* backup to beginning of line */ } t_clrline(0, t_width); /* erase line */ cp = 0; cl = 0; /* reset cursor counter */ t_char(' '); t_char(0x8); break; case F_SOL: while (cp > 0) { backup(curline); } break; case F_EOL: while (cp < cl) { forward(curline, sizeof(curline)); } while (cp > cl) { backup(curline); } break; case F_TINS: /* toggle insert mode */ mode_insert = !mode_insert; /* flip bit */ break; default: if (c > 255) { /* function key hit */ if (cl==0) { /* if first character then */ *string = EOS; /* terminate string */ return c; /* return it */ } t_honk_horn(); /* complain */ } else { if ((c & 0xC0) == 0xC0) { if ((c & 0xFC) == 0xFC) { more = 5; } else if ((c & 0xF8) == 0xF8) { more = 4; } else if ((c & 0xF0) == 0xF0) { more = 3; } else if ((c & 0xE0) == 0xE0) { more = 2; } else { more = 1; } } else { more = 0; } if (mode_insert) { insert_space(curline, sizeof(curline)); } curline[cp++] = c; /* store character in line being built */ t_char(c); /* echo character to terminal */ while (more--) { c= input_char(); insert_hole(curline, sizeof(curline)); curline[cp++] = c; /* store character in line being built */ t_char(c); /* echo character to terminal */ } if (cp > cl) { cl = cp; /* keep current length */ curline[cp] = 0; } } break; } /* end switch */ } /* If we fall through here rather than goto done, the line is too long simply return what we have now. */ done: curline[cl++] = EOS; /* terminate */ bstrncpy(string,curline,length); /* return line to caller */ /* Save non-blank lines. Note, put line zaps curline */ if (curline[0] != EOS) { putline(curline,cl); /* save line for posterity */ } return 0; /* give it to him/her */ }
// This customized version carves holes defined by the regions. // It'll remove any element which doesn't receive any region. int custom_carveholes(struct mesh *m, struct behavior *b, const int *outside, const int *inside) { struct otri neighbortri; struct otri triangleloop; struct osub subsegloop; triangle **temptri; triangle ptr; /* Temporary variable used by sym(). */ double area; double attribute; double triangle_attribute; int sane_mesh; poolinit(& m->viri, sizeof( triangle * ), VIRUSPERBLOCK, VIRUSPERBLOCK, 0); /* Assigns every triangle a regional attribute of -1 */ traversalinit(& m->triangles); triangleloop.orient = 0; triangleloop.tri = triangletraverse(m); while ( triangleloop.tri != ( triangle * ) NULL ) { setelemattribute(triangleloop, m->eextras, -1.0); triangleloop.tri = triangletraverse(m); } sane_mesh = 1; /* Loop over all segments */ traversalinit(& m->subsegs); subsegloop.ss = subsegtraverse(m); subsegloop.ssorient = 0; while ( subsegloop.ss != ( subseg * ) NULL ) { if ( subsegloop.ss != m->dummysub ) { /* First neighbor. */ ssymself(subsegloop); stpivot(subsegloop, neighbortri); if ( neighbortri.tri != m->dummytri ) { area = 0.0; /// @todo Possible set this as the minimum as well. attribute = outside [ mark(subsegloop) - 1 ]; triangle_attribute = elemattribute(neighbortri, m->eextras); /* The region no number yet. */ if ( triangle_attribute < 0 && attribute >= 0 ) { infect(neighbortri); temptri = ( triangle ** ) poolalloc(& m->viri); * temptri = neighbortri.tri; /* Apply one region's attribute and/or area constraint. */ regionplague(m, b, attribute, area); /* The virus pool should be empty now. */ } else if ( attribute >= 0 && triangle_attribute >= 0 && attribute != triangle_attribute ) { /* Check for problems. */ vertex v1, v2, v3; org(neighbortri, v1); dest(neighbortri, v2); apex(neighbortri, v3); fprintf(stdout, "Error: inconsistent region information (new %d, old %d from %d) (outside) at (%e, %e)\n", ( int ) attribute, ( int ) triangle_attribute, ( int ) mark(subsegloop), ( v1 [ 0 ] + v2 [ 0 ] + v3 [ 0 ] ) / 3, ( v1 [ 1 ] + v2 [ 1 ] + v3 [ 1 ] ) / 3); sane_mesh = 0; } } /* Second neighbor (same procedure). */ ssymself(subsegloop); stpivot(subsegloop, neighbortri); if ( neighbortri.tri != m->dummytri ) { area = 0.0; attribute = inside [ mark(subsegloop) - 1 ]; triangle_attribute = elemattribute(neighbortri, m->eextras); if ( triangle_attribute < 0 && attribute >= 0 ) { infect(neighbortri); temptri = ( triangle ** ) poolalloc(& m->viri); * temptri = neighbortri.tri; regionplague(m, b, attribute, area); } else if ( attribute >= 0 && triangle_attribute >= 0 && attribute != triangle_attribute ) { vertex v1, v2, v3; org(neighbortri, v1); dest(neighbortri, v2); apex(neighbortri, v3); fprintf(stdout, "Error: inconsistent region information (new %d, old %d from %d) (inside) at (%e, %e)\n", ( int ) attribute, ( int ) triangle_attribute, ( int ) mark(subsegloop), ( v1 [ 0 ] + v2 [ 0 ] + v3 [ 0 ] ) / 3, ( v1 [ 1 ] + v2 [ 1 ] + v3 [ 1 ] ) / 3); sane_mesh = 0; } } subsegloop.ss = subsegtraverse(m); } } /* Remove all triangles with marker 0.0 */ traversalinit(& m->triangles); triangleloop.tri = triangletraverse(m); int triangle_number = 0; while ( triangleloop.tri != ( triangle * ) NULL ) { if ( triangleloop.tri != m->dummytri ) { triangle_number++; attribute = elemattribute(triangleloop, m->eextras); if ( attribute == -1.0 ) { fprintf(stderr, "Broken mesh at triangle %d\n", triangle_number); sane_mesh = 0; } else if ( attribute == 0.0 ) { infect(triangleloop); temptri = ( triangle ** ) poolalloc(& m->viri); * temptri = triangleloop.tri; } } triangleloop.tri = triangletraverse(m); } /* Remove the marked elements */ plague(m, b); if ( b->regionattrib && !b->refine ) { /* Note the fact that each triangle has an additional attribute. */ m->eextras++; } /* Free up memory. */ pooldeinit(& m->viri); return sane_mesh; }
void main() { uint j=0,i=0,k=0; uint rev; ulong pc; pc = getpc(); pl011_addr((void *)pc, 1); pl011_puts("Entered main() at "); pl011_addr(&main, 0); pl011_puts(" with SP="); pl011_addr((void *)getsp(), 0); pl011_puts(" with SC="); pl011_addr((void *)getsc(), 0); pl011_puts(" with CPSR="); pl011_addr((void *)getcpsr(), 0); pl011_puts(" with SPSR="); pl011_addr((void *)getspsr(), 1); pl011_puts("Clearing Mach: "); memset(m, 0, sizeof(Mach)); pl011_addr((char *)m, 0); pl011_puts("-"); pl011_addr((char *)(m+1), 1); pl011_puts("Clearing edata: "); memset(edata, 0, end-edata); pl011_addr((char *)&edata, 0); pl011_puts("-"); pl011_addr((char *)&end, 1); conf.nmach = 1; quotefmtinstall(); confinit(); mmuinit1(); xinit(); poolinit(); poolsizeinit(); //uartconsinit(); screeninit(); trapinit(); timersinit(); clockinit(); printinit(); swcursorinit(); rev = getfirmware(); print("\nARM %ld MHz id %8.8lux firmware: rev %d, mem: %ld\n" ,(m->cpuhz+500000)/1000000, getcpuid(), rev, conf.topofmem/MB); print("Inferno OS %s Vita Nuova\n", VERSION); print("Ported to Raspberry Pi (BCM2835) by LynxLine\n\n"); procinit(); links(); chandevreset(); eve = strdup("inferno"); userinit(); schedinit(); pl011_puts("to inifinite loop\n\n"); for (;;); }