Esempio n. 1
0
void
main(void)
{
	cgapost(0);
	mach0init();
	options();
	ioinit();
	i8250console();
	quotefmtinstall();
	screeninit();

	print("\nPlan 9\n");

	trapinit0();
	mmuinit0();

	kbdinit();
	i8253init();
	cpuidentify();
	meminit();
	confinit();
	archinit();
	if(!isa20on())
		panic("bootstrap didn't leave a20 address line enabled");
	xinit();
	if(i8237alloc != nil)
		i8237alloc();
	trapinit();
	printinit();
	cpuidprint();
	mmuinit();
	fpsavealloc();
	if(arch->intrinit)	/* launches other processors on an mp */
		arch->intrinit();
	timersinit();
	mathinit();
	kbdenable();
	if(arch->clockenable)
		arch->clockenable();
	procinit0();
	initseg();
	if(delaylink){
		bootlinks();
		pcimatch(0, 0, 0);
	}else
		links();
	conf.monitor = 1;
	chandevreset();
	cgapost(0xcd);

	pageinit();
	i8253link();
	swapinit();
	userinit();
	active.thunderbirdsarego = 1;

	cgapost(0x99);
	schedinit();
}
Esempio n. 2
0
File: i.c Progetto: mbrukman/jsource
B jtglobinit(J jt){A x,y;C*s;D*d;I j;UC c,k;
 liln=1&&C_LE;
 jt->adbreak=&breakdata; /* required for ma to work */
 meminit();  /* required for ma to work */
 jt->parsercalls=0;
 jt->parserstkbgn=jt->parserstkend1=0;
 s=bitdisp; 
 DO(256, c=(UC)i;      DO(BB, *s++=c&(UC)128?'1':'0'; *s++=' '; c<<=1;);           );
Esempio n. 3
0
int main(){ 
   printf("Test application\n");
   printf("sizeof int %d\n", sizeof(char *));
   printf("int shift %d\n", (1<<1));
   int array[5] = {2, 4, 8, 16, 0};
   int i;
   int *alloc;
   //meminit(4096,2,1,array);
   //int handler1=meminit(4096,2,1,array);
   
   int handler2=meminit(4096*2,2, 1, array);
   
   
	for(i=0; i<2048+16; i++) {
		printf("%d ", ((int*)alloc_array[handler2-100])[i]);
	}
	puts("");
    //memalloc(handler2, 16);
   alloc=memalloc(handler2, 8);
   memalloc(handler2, 16);
   
   //alloc=memalloc(handler2, 16);
   *alloc=124;
   for (i=0; i<511; i++){
      printf("i:%d\n", i);
      alloc=memalloc(handler2, 8);
      *alloc = 124;
   }
   int *test;
   test=memalloc(handler2,8);
   printf("test: %d\n", test);
   if(!test){
      printf("EXIT!\n");
      return 0;
   }
   
  // memalloc(handler2, 8);
   for(i=0; i<2048+16; i++) {
		printf("%d ", ((int*)alloc_array[handler2-100])[i]);
	}
	puts("");
    printf("alloc is %d\n", alloc);
    for (i=0; i<512; i++){
       memfree(alloc-((i)*2));
    }
    /*
    //memalloc(handler2, 8);
    memalloc(handler2, 16);
    memalloc(handler2, 8);
    */
    for(i=0; i<2048+16; i++) {
		printf("%d ", ((int*)alloc_array[handler2-100])[i]);
	}
	puts("");

   return 0;
}
Esempio n. 4
0
main ()
{
	meminit ();
	printf (MSG ("\nBOOT %s    %s\n", "\nГРУЗИЛО %s    %s\n"),
		BOOTVERSION, MSG (LCOPYRIGHT, RCOPYRIGHT));

	scinit ();      /* инициализация селекторных каналов */

	printf (": run %s\n", bootcmd);
	run (bootcmd);
}
Esempio n. 5
0
int main(int argc, char**argv){
	int parm2 = 1;
	
	int h1 = meminit(65536,0x1,12,&parm2);

        info *h = MemAllocs[h1];
		printf("memptr: %p, n_bytes: %lu, flags: %d, parm1: %d, parm2: %p\n",
			h->memptr, h->n_bytes, h->flags, h->parm1, h->parm2);
	

	free(MemAllocs[h1]->memptr);
	return 0;
}
Esempio n. 6
0
File: main.c Progetto: abbrev/punix
/*
 * initialisation function
 * We start here as soon as we have a stack.
 * Here we initialize the various systems
 * and devices that need to be initialized.
 */
STARTUP(void kmain())
{
	// TODO: move these to the appropriate headers
	void vtinit();
	void grayinit();
	void loadavinit();
	void battinit();
	void usageinit();
	void bogomips();

	calloutinit();
	lcdinit();
	meminit();
	grayinit();
	vtinit();
	linkinit();
	audioinit();
	sched_init();
	procinit();
	bufinit();
	flashinit();
	inodeinit();
	loadavinit();
	battinit();
	usageinit();
	
#if 1
	kprintf("%s build %s\n", uname_sysname, uname_version);
#else
	kprintf("%s v%s\n", uname_sysname, uname_release);
	kputs(
	 "Copyright 2005-2011 Christopher Williams <*****@*****.**>\n"
	 "Some portions copyright 2003, 2005 PpHd\n"
	 "\n"
	 "This program comes with ABSOLUTELY NO WARRANTY.\n"
	 "You may redistribute copies of this program\n"
	 "under the terms of the GNU General Public License.\n"
	 "\n");
#endif
	if (realtime.tv_sec < 1000000000L) { /* before ~2001 */
		extern const unsigned long build_date;
		realtime.tv_sec = build_date;
		realtime.tv_nsec = 0;
	}
	G.seconds = realtime.tv_sec;
	uptime.tv_sec = uptime.tv_nsec = 0;
	spl0();
	bogomips();
}
Esempio n. 7
0
int main(int argc, char * const * argv)
{
	int size = getBufferSize(argc, argv);
	short c = 0;

	meminit(size);
	memattach();

	do {
		errno = 0;
		if ((c = fgetc(stdin)) == (short) EOF && ferror(stdin) != 0)
		{
			fprintf(stderr, "%s: %s\n", appname, strerror(errno));
			memdetach();
			memrmv();
			return EXIT_FAILURE;
		}
		memwrite(c);
	} while (c != EOF);

	memdetach();

	return EXIT_SUCCESS;
}
Esempio n. 8
0
static void
confinit(void)
{
	conf.nmach = 1;

	conf.mem = meminit();

	conf.nuid = 1000;
	conf.nserve = 15;		/* tunable */
	conf.nfile = 30000;
	conf.nlgmsg = 100;
	conf.nsmmsg = 500;

	localconfinit();

	conf.nwpath = conf.nfile*8;
	conf.nauth =  conf.nfile/10;
	conf.gidspace = conf.nuid*3;

	cons.flags = 0;

	if (conf.devmap)
		mapinit(conf.devmap);
}
Esempio n. 9
0
/*------------------------------------------------------------------------
 *
 * 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;
}
Esempio n. 10
0
void lcd_init (void)
{
    // Reset the SDRAM.
    meminit (cpu_frequency (1));

    puts ("LCD setup:");
    static const unsigned pins[] = {
        // Setup the PLL0AUDIO to give 74.75MHz off 50MHz ethernet clock.
        // ndec=122, mdec=13107, pdec=66
        // selr=0, seli=48, selp=24
        // pllfract = 47.839996,0x17eb85
        // pre-divider=16, feedback div=47, post-div=2
        // fcco=299MHz, fout=74.749994MHz.
        WORD_WRITE32n(PLL0AUDIO->ctrl, 4,
                      0x03001811,       // CTRL
                      13107,            // MDIV
                      66 + (122 << 12), // NP_DIV
                      0x17eb85),        // FRAC

        BIT_RESET(PLL0AUDIO->ctrl, 0),

        // Wait for lock.
        BIT_WAIT_ZERO(PLL0AUDIO->stat, 0),

        // The lcd clock is outclk11.  PLL0AUDIO is clock source 8.
        WORD_WRITE32(*BASE_LCD_CLK, 0x08000800),

        // Reset the lcd.
        WORD_WRITE32(RESET_CTRL[0], 1<<16),
        BIT_WAIT_SET(RESET_ACTIVE_STATUS[0], 16),

        // 1024x1024 59.90 Hz (CVT) hsync: 63.13 kHz; pclk: 74.75 MHz
        // Modeline "1024x1024R" 74.75  1024 1072 1104 1184  1024 1027 1037 1054
        // +hsync -vsync
        // horizontal 1024 48 32 80
        // vertical 1024 3 10 17

        WORD_WRITE32n(LCD->timh, 7,
                      (79 << 24) + (47 << 8) + (31 << 16) + 0xfc, // TIMH
                      (16 << 24) + (2 << 16) + (9 << 10) + 1023,  // TIMV
                      // PCD_LO = 0, Clock divisor = 0.
                      // CLK_SEL = 1, LCDCLKIN.
                      // ACB = 0, N/A.
                      // IVS=0, IHS=1, positive vsync, negative hsync (!?)
                      // IPC=1, falling clock edge.
                      // IOE=0, out enable positive.
                      // CPL=1023.
                      // BCD=1, no clock divider.
                      // PCD_HI=0.
                      0x07ff3020,                                 // POL
                      0,                                          // LE
                      (unsigned) FRAME_BUFFER,                    // UPBASE
                      (unsigned) FRAME_BUFFER,                    // LPBASE
                      LCD_CONTROL),

        // PIN_OUT_FAST(4,1,2),            // A1  LCD_VD0
        // PIN_OUT_FAST(4,3,2),            // C2  LCD_VD2
        // PIN_OUT_FAST(4,4,2),            // B1  LCD_VD1
        // PIN_OUT_FAST(4,8,2),            // E2  LCD_VD9
        // PIN_OUT_FAST(7,2,3),            // A16 LCD_VD18
        // PIN_OUT_FAST(7,3,3),            // C13 LCD_VD17
        // PIN_OUT_FAST(7,4,3),            // C8  LCD_VD16
        // PIN_OUT_FAST(7,5,3),            // A7  LCD_VD8
        //PIN_OUT_FAST(,,), // B16 LCD_LE
        //PIN_OUT_FAST(,,), // B6  LCD_PWR
        PIN_OUT_FAST(3,4,7)             // A15 LCD_VD13
        + PIN_EXTRA(1),                 // C12 LCD_VD12
        PIN_OUT_FAST(4,2,2),            // D3  LCD_VD3
        PIN_OUT_FAST(4,5,2)             // D2  LCD_FP
        + PIN_EXTRA(1),                 // C1  LCD_ENAB/LCDM
        PIN_OUT_FAST(4,9,2)             // L2  LCD_VD11
        + PIN_EXTRA(1),                 // M3  LCD_VD10
        PIN_OUT_FAST(7,1,4),            // C14 LCD_VD7
        PIN_OUT_FAST(7,6,3),            // C7  LCD_LP
        PIN_OUT_FAST(8,5,3)             // J1  LCD_VD6
        + PIN_EXTRA(2),                 // K3  LCD_VD5, K1  LCD_VD4
        PIN_OUT_FAST(11,0,2)            // B15 LCD_VD23
        + PIN_EXTRA(6),         // ... A13 VD20, B11 VD15, A12 VD14, A6 VD19
        PIN_OUT_FAST(12,0,4),           // D4  LCD_DCLK

        // Enable the lcd.
        BIT_SET(LCD->ctrl, 0), // TFT, 16bpp, 565, watermark=8.

        // Enable the frame interrupt.
        WORD_WRITE(LCD->intmsk, 4),
    };

    configure(pins, sizeof pins / sizeof pins[0]);

    NVIC_ISER[0] = 1 << m4_lcd;

    puts (" done\n");
}
Esempio n. 11
0
File: main.c Progetto: Ntools/n
int main(int argc,char *argv[])
{
	register int i;
	int st, read_only;
	char *sp;
	extern char *ininame;
	int batch(char *,char *);
	void help(int);

	st= 0;
#ifdef __386__
	fprintf(stderr, "Nobby's Editor Version %s\n"
	"Copyright (c) Nobby N. Hirano 1990-94\n", VERSION);
#endif
#ifdef TEXT98
	lastdisplay= 24;
	displaylen = 80;
#endif
#ifdef DOSV
	lastdisplay= 0;
	displaylen = 0;
#endif
	read_only = beut_flg = OFF;
	meminit();
	keycount();
	tool();
	initdefkey();
	for(i=1;i < argc;++i) {
		sp= argv[i];
		if(*sp == '-') {
			sp= argv[i]+1;
			while(*sp != '\0') {
				switch(toupper(*sp)) {          /* to lower case */
					case 'B' : back_flg= ON; ++sp; break;
					case 'E' : bat_flg= OFF; ++sp; break;
#if (defined TEXT98)
					case 'H' : beut_flg= ON; ++sp; break;
					case 'N' : beut_flg= OFF; ++sp; break;
#endif
					case 'L' :
					++sp;
					if(*sp == '=') ++sp;
					if((lastdisplay= atoi(sp)) != 0) {
						while(isdigit(*sp)) ++sp;
						break;
					}
					fprintf(stderr,"Unknow option '%s' !\n",sp);
					help(1);
					case 'V' :
					fprintf(stderr,"Copyright (c) Nobby N. Hirano 1990 - 94 All rights reserved.\r\n"
#if (defined TEXT98)
					"Version 5.0  %s  for PC9801 & PC-286,386 i80286,386,486.\n"
#elif (defined ATVRAM)
# ifdef __386__
					"Version %s %s  for PC-DOS MS-DOS J5.0/V, J6.x/V DPMI Version.\n", VERSION
# else
					"Version 6.0  %s  for PC-DOS MS-DOS J5.0/V, J6.x/V.\n"
# endif
#elif (defined DOSV)
					"Version 5.0  %s  for PC-AT, its Compatible and J3100.\n"
#elif (defined UNIX)
					"Version 1.1.0  %s  for UNIX.\r\n"
#endif
					,__DATE__);
					exit(1);
					case 'M' :
					++sp;
					execinitbl= ON;
					break;
					case 'R' :
					++sp;
					read_only = ON;
					break;
					case '?':
					help(0);
					case 'S' :
					++sp;
					if(*sp == '=') ++sp;
					if((tabs= atoi(sp)) != 0) {
						tabset= ON;
						while(isdigit(*sp)) ++sp;
						break;
					}
					default :
					fprintf(stderr,"Unknow option '%s' !\n",sp);
					help(1);
				}
			}
		}
		else {
			++st;
			arg_flg = ON;
		}
	}
	if(execinitbl) {
		printf("Write Key command tablefile to [keys.ini].\n");
		toolwrite("keys.ini");
		exit(0);
	}
#ifdef UNIX
	system("stty -icanon -echo intr ^T");
	ttopen();
#endif
#if defined(TEXT98)
	pushscrn();
#elif !defined(ATVRAM) && !defined(UNIX)
	batch(NULL,"///");
#endif
#if defined(ATVRAM)
	vtopen();
#elif defined(DOSV)
	if(!lastdisplay) {
	lastdisplay= *((unsigned char __far *)
# ifdef __386__
	MK_FP(0x40, 0x84));
# else
	0x400084);
#endif
	if(lastdisplay < 24) lastdisplay = 24;
}
Esempio n. 12
0
void
kinitlong(unsigned long pmemsz)
{
#if (NEWTMR)
    uint32_t tmrcnt = 0;
#endif

/* initialise interrupt management */
#if (VBE)
    trapinitprot();
#endif
    /* initialise virtual memory */
    vminitlong((uint64_t *)kernpagemapl4tab);
#if 0
    /* FIXME: map possible device memory */
    vmmapseg((uint32_t *)&_pagetab, DEVMEMBASE, DEVMEMBASE, 0xffffffffU,
             PAGEPRES | PAGEWRITE | PAGENOCACHE);
#endif
//    schedinit();
    /* zero kernel BSS segment */
    kbzero(&_bssvirt, (uint32_t)&_ebssvirt - (uint32_t)&_bssvirt);
    /* set kernel I/O permission bitmap to all 1-bits */
    kmemset(&kerniomap, 0xff, sizeof(kerniomap));
    /* INITIALIZE CONSOLES AND SCREEN */
#if (VBE)
    vbeinitscr();
#endif
#if (VBE) && (NEWFONT)
    consinit(768 / vbefontw, 1024 / vbefonth);
#elif (VBE)
    consinit(768 >> 3, 1024 >> 3);
#endif
    /* TODO: use memory map from GRUB? */
//    vminitphys((uintptr_t)&_epagetab, pmemsz);
    vminitphys((uintptr_t)&_epagetab, pmemsz);
    meminit(pmemsz);
    tssinit(0);
#if (VBE) && (NEWFONT)
//    consinit(768 / vbefontw, 1024 / vbefonth);
#elif (VBE)
    consinit(768 >> 3, 1024 >> 3);
#endif
#if (SMBIOS)
    smbiosinit();
#endif
#if (PS2DRV)
    ps2init();
#endif
#if (VBE) && (PLASMA)
    plasmaloop();
#endif
#if (VBE)
    vbeprintinfo();
#endif
    logoprint();
//    vminitphys((uintptr_t)&_ebss, pmemsz - (unsigned long)&_ebss);
    /* HID devices */
#if (PCI)
    /* initialise PCI bus driver */
    pciinit();
#endif
#if (ATA)
    /* initialise ATA driver */
    atainit();
#endif
#if (SB16)
    /* initialise Soundblaster 16 driver */
    sb16init();
#endif
#if (ACPI)
    /* initialise ACPI subsystem */
    acpiinit();
#endif
    /* initialise block I/O buffer cache */
    if (!bufinit()) {
        kprintf("failed to allocate buffer cache\n");

        while (1) {
            ;
        }
    }
    /* allocate unused device regions (in 3.5G..4G) */
//    pageaddzone(DEVMEMBASE, &vmshmq, 0xffffffffU - DEVMEMBASE + 1);
#if (SMP) || (APIC)
//#if (SMP)
    /* multiprocessor initialisation */
//    mpinit();
//#endif
    if (mpncpu == 1) {
        kprintf("found %ld processor\n", mpncpu);
    } else {
        kprintf("found %ld processors\n", mpncpu);
    }
#if (HPET)
    /* initialise high precision event timers */
    hpetinit();
#endif
#if (NEWTMR)
    tmrcnt = apicinitcpu(0);
#else
    apicinitcpu(0);
#endif
#if (IOAPIC)
    ioapicinit(0);
#endif
#endif /* SMP || APIC */
#if (SMP)
    if (mpmultiproc) {
        mpstart();
    }
#endif
    /* CPU interface */
    taskinit();
//    tssinit(0);
//    machinit();
    /* execution environment */
    procinit(PROCKERN);
//    k_curtask = &k_curproc->task;
//    sysinit();
    kprintf("DMA buffers (%ul x %ul kilobytes) @ 0x%p\n",
            DMANCHAN, DMACHANBUFSIZE >> 10, DMABUFBASE);
    kprintf("VM page tables @ 0x%p\n", (unsigned long)&_pagetab);
//    kprintf("%ld kilobytes physical memory\n", pmemsz >> 10);
    kprintf("%ld kilobytes kernel memory\n", (uint32_t)&_ebss >> 10);
    kprintf("%ld kilobytes allocated physical memory (%ld wired, %ld total)\n",
            (vmpagestat.nwired + vmpagestat.nmapped + vmpagestat.nbuf) << (PAGESIZELOG2 - 10),
            vmpagestat.nwired << (PAGESIZELOG2 - 10),
            vmpagestat.nphys << (PAGESIZELOG2 - 10));
    k_curcpu = &cputab[0];
    cpuinit(k_curcpu);
    schedinit();
#if (APIC)
    apicstarttmr(tmrcnt);
#else
    pitinit();
#endif
    schedloop();

    /* NOTREACHED */
}
Esempio n. 13
0
int main (int argc, char **argv) {
	char c;
	int mismatch = 0;
	char *in[3] = {0,0,0};
	char *out[5];
	char *orep=NULL;
	int out_n = 0;
	int in_n = 0;
	int threads = 1;				// not really necessary
	char verify='\0';

	int i;
	int mino = 6;
	int pctdiff = 8;				// this number tested well on exome data... tweak for best results
	bool omode = false;	
	char *bfil = NULL;
    bool norevcomp = false;
    bool allow_ex = false;

	while (	(c = getopt (argc, argv, "-dRnbeo:t:v:m:p:r:xV")) != -1) {
		switch (c) {
		case '\1':
			if (!in[0]) 
				in[0]=optarg;
			else if (!in[1])		
				in[1]=optarg;
			else if (!in[2])		
				in[2]=optarg;
			else {
				usage(stderr); return 1;
			}
			++in_n;
			break;
                case 'o': if (out_n == 3) {
				usage(stderr); return 1;
			  }
			  out[out_n++] = optarg; 
			  break;
		case 'r': orep = optarg; break;
		case 't': threads = atoi(optarg); break;
        case 'V': printf("Version: %s.%d\n", VERSION, SVNREV); return 0; break;
		case 'm': mino = atoi(optarg); break;
		case 'x': allow_ex = true; break;
		case 'p': pctdiff = atoi(optarg); break;
		case 'R': norevcomp = true; break;
		case 'd': ++debug; break;
                case 'v':
                        if (strlen(optarg)>1) {
                                fprintf(stderr, "Option -v requires a single character argument");
                                exit(1);
                        }
                        verify = *optarg; break;
		case '?': 
		     if (strchr("otvmpr", optopt))
		       fprintf (stderr, "Option -%c requires an argument.\n", optopt);
		     else if (isprint(optopt))
		       fprintf (stderr, "Unknown option `-%c'.\n", optopt);
		     else
		       fprintf (stderr,
				"Unknown option character `\\x%x'.\n",
				optopt);
		     usage(stderr);
             	     return 1;
		}
	}

	if (argc < 3 || !in[1] || (!in[2] && out_n != 1 && out_n != 3) || (in[2] && out_n != 1 && out_n != 5)) {
		usage(stderr);
		return 1;
	}

	FILE *fin[2];
	bool gzin[2]; meminit(gzin);
	for (i = 0; i < in_n; ++i) {
		fin[i] = gzopen(in[i], "r",&gzin[i]); 
		if (!fin[i]) {
			fprintf(stderr, "Error opening file '%s': %s\n",in[i], strerror(errno));
			return 1;
		}
	}

	const char *suffix[5]={"un1", "un2", "join", "un3", "join2"};
	FILE *fout[5]; meminit(fout);
	bool gzout[5]; meminit(gzout);
	char *pre = out[0];
	for (i = 0; i < (in[2] ? 5 : 3); ++i) {
		// prefix out
		if (out_n == 1) {
			out[i]=(char *)malloc(strlen(pre)+10);
			strcpy(out[i], pre);
			char *p;
			if (p=strchr(out[i], '%')) {
				// substiture instead of append
				strcpy(p, suffix[i]);
				strcpy(p+strlen(suffix[i]), pre+(p-out[i])+1);
			} else {
				strcat(out[i], suffix[i]);
			}
		} // else explicit
		fout[i] = gzopen(out[i], "w",&gzout[i]);
		if (!fout[i]) {
				fprintf(stderr, "Error opening output file '%s': %s\n",out[i], strerror(errno));
				return 1;
		}
	}

//printf("in_n:%d in:%x fo:%x", in_n, in[3], fout[4]);
//return 1;

	FILE *frep = NULL;
	if (orep) {
                frep = fopen(orep, "w");
                if (!orep) {
                        fprintf(stderr, "Error opening report file '%s': %s\n",out[i], strerror(errno));
                        return 1;
                }
	}


	// some basic validation of the file formats
	{
		for (i=0;i<in_n;++i) {
			char c=getc(fin[i]);
			if (c != '@')  {
				fprintf(stderr, "%s doesn't appear to be a fastq file (%c)\n", in[i], c);
				return 1;
			}
			ungetc(c, fin[i]);
		}
	}

	struct fq fq[3];	
        meminit(fq);

	int nrec=0;
	int nerr=0;
	int nok=0;
	int joincnt=0;
	double tlen=0;
	double tlensq=0;
	int read_ok;

	struct fq rc;
	meminit(rc);

	// read in 1 record from each file
	while (read_ok=read_fq(fin[0], nrec, &fq[0])) {
		for (i=1;i<in_n;++i) {
		int mate_ok=read_fq(fin[i], nrec, &fq[i]);
		if (read_ok != mate_ok) {
			fprintf(stderr, "# of rows in mate file '%s' doesn't match primary file, quitting!\n", in[i]);
			return 1;
		}
		if (verify) {
			// verify 1 in 100
			if (0 == (nrec % 100)) {
				char *p=strchr(fq[i].id.s,verify);
				if (!p) {
					fprintf(stderr, "File %s is missing id verification char %c at line %d", in[i], verify, nrec*4+1);
					return 1;
				}
				int l = p-fq[i].id.s;
				if (strncmp(fq[0].id.s, fq[i].id.s, l)) {
					fprintf(stderr, "File %s, id doesn't match file %s at line %d", in[0], in[i], nrec*4+1);
					return 1;
				}
			}
		}
		}

		++nrec;
		if (read_ok < 0) continue;

		if (debug) fprintf(stderr, "seq: %s %d\n", fq[0].seq.s, fq[0].seq.n);

        if (!norevcomp) {
    		revcomp(&rc, &fq[1]);
        } else {
            rc=fq[1];
        }

		if (debug) fprintf(stderr, "comp: %s %d\n", rc.seq.s, rc.seq.n);

		int maxo = min(fq[0].seq.n, rc.seq.n);
		int bestscore=INT_MAX;
		int besto=-1;
		for (i=mino; i <= maxo; ++i) {
			int mind = (pctdiff * i) / 100;
            int d;
            d=hd(fq[0].seq.s+fq[0].seq.n-i, rc.seq.s, i);
			if (debug) fprintf(stderr, "hd: %d, %d\n", i, d);
			if (d <= mind) {
				// squared-distance over length, probably can be proven better (like pearson's)
				int score = (1000*(d*d+1))/i;	
				if (score < bestscore) {
					bestscore=score;
					besto=i;
				}
			}
		}

        int hasex=0;
        if (allow_ex && besto<maxo) {
            if (fq[0].seq.n > rc.seq.n) {
                int mind = (pctdiff * maxo) / 100;
                for (i=0; i < fq[0].seq.n-maxo; ++i ) {
                    int d;
                    d=hd(fq[0].seq.s+fq[0].seq.n-rc.seq.n-i-1, rc.seq.s, maxo);
                    if (debug) fprintf(stderr, "hd: %d, %d\n", -i, d);
                    if (d <= mind) {
                        // squared-distance over length, probably can be proven better (like pearson's)
                        int score = (1000*(d*d+1))/maxo;
                        if (score < bestscore) {
                            bestscore=score;
                            // negative overlap!
                            hasex=-i;
                            besto=maxo;
                        }
                    }
                }
            } else if (fq[0].seq.n < rc.seq.n) {
                int mind = (pctdiff * maxo) / 100;
                for (i=0; i < rc.seq.n-maxo; ++i ) {
                    int d;
                    d=hd(fq[0].seq.s, rc.seq.s+i, maxo);
                    if (debug) fprintf(stderr, "hd: %d, %d\n", -i, d);
                    if (d <= mind) {
                        // squared-distance over length, probably can be proven better (like pearson's)
                        int score = (1000*(d*d+1))/maxo;
                        if (score < bestscore) {
                            bestscore=score;
                            // negative overlap!
                            hasex=-i;
                            besto=maxo;
                        }
                    }
                }
            }
        }

		if (debug) {
			fprintf(stderr, "best: %d %d\n", besto-hasex, bestscore);
		}

		FILE *fmate = NULL;
        int olen = besto-hasex;

		if (besto > 0) {
			++joincnt;

			tlen+=olen;
			tlensq+=olen*olen;

            char *sav_fqs=NULL, *sav_rcs;
            char *sav_fqq, *sav_rcq;

            if (hasex) {
                sav_fqs=fq[0].seq.s;
                sav_fqq=fq[0].qual.s;
                sav_rcs=rc.seq.s;
                sav_rcq=rc.qual.s;
                if (fq[0].seq.n < rc.seq.n) {
                    rc.seq.s=rc.seq.s-hasex;
                    rc.qual.s=rc.qual.s-hasex;
                    rc.seq.n=maxo;
                    rc.qual.n=maxo;
                } else {
                    // fprintf(stderr, "rc negative overlap: %s %d\n", rc.seq.s, hasex);
                    fq[0].seq.s=fq[0].seq.s+fq[0].seq.n-maxo+hasex-1;
                    fq[0].qual.s=fq[0].qual.s+fq[0].seq.n-maxo+hasex-1;
                    fq[0].seq.n=maxo;
                    fq[0].qual.n=maxo;
                    // fprintf(stderr, "negative overlap: %s -> %s, %d\n", fq[0].seq.s, rc.seq.s, maxo);
                }
                // ok now pretend everythings normal, 100% overlap
		        //if (debug) 
            }

			FILE *f=fout[2];

			if (verify) {
				char *p=strchr(fq[0].id.s,verify);
				if (p) {
					*p++ = '\n';
					*p = '\0';
				}
			}
			fputs(fq[0].id.s,f);
			for (i = 0; i < besto; ++i ) {
				int li = fq[0].seq.n-besto+i;
				int ri = i;
                if (debug>=2) printf("%c %c / %c %c / ", fq[0].seq.s[li], rc.seq.s[ri], fq[0].qual.s[li], rc.qual.s[ri]);
				if (fq[0].seq.s[li] == rc.seq.s[ri]) {
					fq[0].qual.s[li] = max(fq[0].qual.s[li], rc.qual.s[ri]);
                    // bounded improvement in quality, since there's no independence
					// fq[0].qual.s[ri] = max(fq[0].qual.s[li], rc.qual.s[ri])+min(3,min(fq[0].qual.s[li],rc.qual.s[ri])-33);
				} else {
					// use the better-quality read
                    // this approximates the formula: E = min(0.5,[(1-e2/2) * e1] / [(1-e1) * e2/2 + (1-e2/2) * e1])
					if (fq[0].qual.s[li] > rc.qual.s[ri]) {
                        // reduction in quality, based on phred-difference
					    fq[0].qual.s[li] = 33+min(fq[0].qual.s[li],max(fq[0].qual.s[li]-rc.qual.s[ri],3));
					} else {
						fq[0].seq.s[li] = rc.seq.s[ri];
                        // reduction in quality, based on phred-difference
					    fq[0].qual.s[li] = 33+min(rc.qual.s[ri],max(rc.qual.s[ri]-fq[0].qual.s[li],3));
					}
				}
                if (debug>=2) printf("%c %c\n", fq[0].seq.s[li], fq[0].qual.s[li]);
			}

			fwrite(fq[0].seq.s,1,fq[0].seq.n,f);
			fputs(rc.seq.s+besto,f);
			fputc('\n',f);
			fputs(fq[0].com.s,f);
			fwrite(fq[0].qual.s,1,fq[0].qual.n,f);
			fputs(rc.qual.s+besto,f);
			fputc('\n',f);
			fmate=fout[4];

            if (sav_fqs) {
                fq[0].seq.s=sav_fqs;
                fq[0].qual.s=sav_fqq;
                rc.seq.s=sav_rcs;
                rc.qual.s=sav_rcq;
            }

			if (frep) {
				fprintf(frep, "%d\n", besto);
			}
		} else {
			for (i=0;i<2;++i) {
				FILE *f=fout[i];
				fputs(fq[i].id.s,f);
				fputs(fq[i].seq.s,f);
				fputc('\n',f);
				fputs(fq[i].com.s,f);
				fputs(fq[i].qual.s,f);
				fputc('\n',f);
			}
			fmate=fout[3];
		}

		if (fmate) {
			fputs(fq[2].id.s,fmate);
			fputs(fq[2].seq.s,fmate);
			fputc('\n',fmate);
			fputs(fq[2].com.s,fmate);
			fputs(fq[2].qual.s,fmate);
			fputc('\n',fmate);
		}
	}


	double dev = sqrt((((double)joincnt)*tlensq-pow((double)tlen,2)) / ((double)joincnt*((double)joincnt-1)) );
	printf("Total reads: %d\n", nrec);
	printf("Total joined: %d\n", joincnt);
	printf("Average join len: %.2f\n", (double) tlen / (double) joincnt);
	printf("Stdev join len: %.2f\n", dev);
    printf("Version: %s.%d\n", VERSION, SVNREV);

	return 0;
}
Esempio n. 14
0
void
main(void)
{
	Proc *savup;
	static ulong vfy = Datamagic;
	static char novga[] = "\nno vga; serial console only\n";

	savup = up;
	up = nil;
	/* m has been set by l32v.s */

	/*
	 * disable address wraps at 1MB boundaries.
	 * if we're 9boot, ldecomp.s already did this.
	 */
	a20init();

	mach0init();
//	options();		/* we don't get options passed to us */
	ioinit();
	/* we later call i8250console after plan9.ini has been read */
	i8250config("0");	/* configure serial port 0 with defaults */
	quotefmtinstall();
 	fmtinstall('i', eipfmt);
 	fmtinstall('I', eipfmt);
 	fmtinstall('E', eipfmt);
 	fmtinstall('V', eipfmt);
 	fmtinstall('M', eipfmt);
	screeninit();			/* cga setup */
	cgapost(0xc);

	trapinit0();
	mmuinit0();

	kbdinit();
	i8253init();
	cpuidentify();
	readlsconf();
	meminit();
	confinit();
	archinit();
	xinit();
	if(i8237alloc != nil)
		i8237alloc();		/* dma (for floppy) init */
	trapinit();
	printinit();
	sanity();
	cgapost(1);

	/*
	 * soekris servers have no built-in video but each has a serial port.
	 * they must see serial output, if any, before cga output because
	 * otherwise the soekris bios will translate cga output to serial
	 * output, which will garble serial console output.
	 */
	pcimatch(nil, 0, 0);		/* force scan of pci table */
	if (!pcivga) {
		screenputs = nil;
		uartputs(novga, sizeof novga - 1);
	}
	print(" %s\n\n", hellomsg);

	if (vfy != Datamagic)
		panic("data segment incorrectly aligned or loaded");
	if (savup)
		print("up was non-nil (%#p) upon entry to main; bss wasn't zeroed!\n",
			savup);

//	xsummary();
	cpuidprint();
	mmuinit();
	if(arch->intrinit)	/* launches other processors on an mp */
		arch->intrinit();
	timersinit();
	mathinit();
	kbdenable();
	/*
	 * 9loadusb runs much faster if we don't use the clock.
	 * perhaps we're competing with the bios for the use of it?
	 */
	if(!noclock && arch->clockenable)
		arch->clockenable();
	procinit0();
	initseg();
	if(delaylink){
		bootlinks();
		pcimatch(0, 0, 0);
	}else
		links();
	conf.monitor = 1;
	cgapost(0xcd);
	chandevreset();
	cgapost(2);
	pageinit();	/* must follow xinit, and conf.mem must be populated */
	i8253link();
	userinit();

	active.thunderbirdsarego = 1;
	cgapost(0xb0);
	schedinit();
}
Esempio n. 15
0
void
main(void)
{
	int machno;

	/* entry to main pushed stuff onto the stack. */

//	memset(edata, 0, (ulong)end-(ulong)edata);

	machno = getpir();
	if (machno > 0)
		startcpu(machno);

//	dcrcompile();
	if (dverify != 0x01020304) {
		uartlputs("data segment not initialised\n");
		panic("data segment not initialised");
	}
	if (bverify != 0) {
		uartlputs("bss segment not zeroed\n");
		panic("bss segment not zeroed");
	}
	mach0init();
	archreset();
	quotefmtinstall();
	optionsinit("/boot/boot boot");
//	archconsole();

	meminit();
	confinit();
	mmuinit();
	xinit();			/* xinit would print if it could */
	trapinit();
	qtminit();
	ioinit();
	uncinit();
	printinit();
	uartliteconsole();

	mainmem->flags |= POOL_ANTAGONISM;
	mainmem->panic = mypanic;
	ethermedium.maxtu = 1512;   /* must be multiple of 4 for temac's dma */

//	print("\n\nPlan 9k H\n");	/* already printed by l.s */
	plan9iniinit();
	timersinit();
	clockinit();

	dma0init();			/* does not start kprocs; see init0 */
	fpuinit();
	procinit0();
	initseg();
	links();

	chandevreset();
	okprint = 1;			/* only now can we print */
	barriers();
	dcflush((uintptr)&okprint, sizeof okprint);

	cpuidprint();

	print("%d Hz clock", HZ);
	print("; memory size %,ud (%#ux)\n", (uint)memsz, (uint)memsz);

	pageinit();
	swapinit();
	userinit();
	active.thunderbirdsarego = 1;
	dcflush((uintptr)&active.thunderbirdsarego,
		sizeof active.thunderbirdsarego);
	schedinit();
	/* no return */
	panic("schedinit returned");
}
Esempio n. 16
0
int main () {

   srand(time(NULL));

   int handle[3];
   int *myInts[30];
   int bytesRequested[30];
   int totalBytesRequested;
   
   long n_bytes = 1048576; // 1 MB
   
   int parm2[10];
   parm2[0] = 16;
   parm2[1] = 32;
   parm2[2] = 64;
   parm2[3] = 128;
   parm2[4] = 12432;
   parm2[5] = 1223;
   parm2[6] = 0;
   
   handle[0] = meminit (n_bytes, BUDDY_FLAG, 4, parm2);  
   handle[1] = meminit (n_bytes, SLAB_FLAG, 8, parm2);
   handle[2] = meminit (n_bytes, FREELIST_FLAG, 0, parm2);
   
   int handleCount;
   for (handleCount = 0; handleCount < 3; handleCount++) {
      totalBytesRequested = 0;
      if (handle[handleCount] < 0)
         printf ("%s: %s %d %s\n", "ERROR", "handle", handleCount, "did not initialize");
      int counter;
      for (counter = 0; counter < 30; counter++) {
         int randBytes = sizeof(char)*((rand()%99)+1); //1 - 100 bytes
         myInts[counter] = (int*)memalloc (handle[handleCount], randBytes);
         bytesRequested[counter] = randBytes;
         totalBytesRequested += randBytes;
      }
      // Free half
      for (counter = 0; counter < 30; counter+=2) {
         memfree(myInts[counter]);
         totalBytesRequested -= bytesRequested[counter];
         bytesRequested[counter] = 0;
      }
      // Reallocate
      for (counter = 0; counter < 30; counter+=2) {
         int randBytes = sizeof(char)*((rand()%99)+1); //1 - 100 bytes
         myInts[counter] = (int*)memalloc (handle[handleCount], randBytes);
         bytesRequested[counter] = randBytes;
         totalBytesRequested += randBytes;
      }
      int memoryUsed = memUsed(handle[handleCount]);
      printf("Allocator %d:\n", handleCount);
      printf("Total bytes: %d\n", memSize(handle[handleCount]));
      printf("Total bytes requested: %d\n", totalBytesRequested);
      printf("Total bytes used: %d\n", memoryUsed);
      printf("Total waste: %f%%\n", (1- (float)totalBytesRequested/memoryUsed)*100);
      if (handleCount == 0) handle[0] = handle[1];
      else if (handleCount == 1) handle[0] = handle[2];
   }
   
   printf("Tester complete.\n");
}
Esempio n. 17
0
int main (){
    int *nullARR;
    int retINIT = meminit(64000,0x1,4000,nullARR);
    memalloc(retINIT,8000);
}
Esempio n. 18
0
/*------------------------------------------------------------------------
 *
 * 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;
}
Esempio n. 19
0
void
main(uint32_t mbmagic, uint32_t mbaddress)
{
	Mach *m = entrym;
	/* when we get here, entrym is set to core0 mach. */
	sys->machptr[m->machno] = m;
	// Very special case for BSP only. Too many things
	// assume this is set.
	wrmsr(GSbase, PTR2UINT(&sys->machptr[m->machno]));
	if (machp() != m)
		panic("m and machp() are different!!\n");
	assert(sizeof(Mach) <= PGSZ);

	/*
	 * Check that our data is on the right boundaries.
	 * This works because the immediate value is in code.
	 */
	if (x != 0x123456) 
		panic("Data is not set up correctly\n");
	memset(edata, 0, end - edata);

	m = (void *) (KZERO + 1048576 + 11*4096);
	sys = (void *) (KZERO + 1048576);

	/*
	 * ilock via i8250enable via i8250console
	 * needs m->machno, sys->machptr[] set, and
	 * also 'up' set to nil.
	 */
	cgapost(sizeof(uintptr_t)*8);
	memset(m, 0, sizeof(Mach));

	m->machno = 0;
	m->online = 1;
	m->nixtype = NIXTC;
	sys->machptr[m->machno] = &sys->mach;
	m->stack = PTR2UINT(sys->machstk);
	*(uintptr_t*)m->stack = STACKGUARD;
	m->vsvm = sys->vsvmpage;
	m->externup = (void *)0;
	active.nonline = 1;
	active.exiting = 0;
	active.nbooting = 0;

	asminit();
	multiboot(mbmagic, mbaddress, 0);
	options(oargc, oargv);

	/*
	 * Need something for initial delays
	 * until a timebase is worked out.
	 */
	m->cpuhz = 2000000000ll;
	m->cpumhz = 2000;

	cgainit();
	i8250console("0");
	
	consputs = cgaconsputs;

	/* It all ends here. */
	vsvminit(MACHSTKSZ, NIXTC, m);
	if (machp() != m)
		panic("After vsvminit, m and machp() are different");

	sys->nmach = 1;	
	
	fmtinit();
	print("\nHarvey\n");

	if(vflag){
		multiboot(mbmagic, mbaddress, vflag);
	}

	m->perf.period = 1;
	if((hz = archhz()) != 0ll){
		m->cpuhz = hz;
		m->cyclefreq = hz;
		m->cpumhz = hz/1000000ll;
	}
	//iprint("archhz returns 0x%lld\n", hz);
	//iprint("NOTE: if cpuidhz runs too fast, we get die early with a NULL pointer\n");
	//iprint("So, until that's fixed, we bring up AP cores slowly. Sorry!\n");

	/*
	 * Mmuinit before meminit because it
	 * flushes the TLB via m->pml4->pa.
	 */
	mmuinit();

	ioinit();
	meminit();
	confinit();
	archinit();
	mallocinit();

	/* test malloc. It's easier to find out it's broken here, 
	 * not deep in some call chain.
	 * See next note. 
	 *
	void *v = malloc(1234);
	hi("v "); put64((uint64_t)v); hi("\n");
	free(v);
	hi("free ok\n");
	 */

	/*
	 * Acpiinit will cause the first malloc
	 * call to happen.
	 * If the system dies here it's probably due
	 * to malloc not being initialised
	 * correctly, or the data segment is misaligned
	 * (it's amazing how far you can get with
	 * things like that completely broken).
	 */
if (0){	acpiinit(); hi("	acpiinit();\n");}
	
	umeminit();
	trapinit();

	/*
	 * This is necessary with GRUB and QEMU.
	 * Without it an interrupt can occur at a weird vector,
	 * because the vector base is likely different, causing
	 * havoc. Do it before any APIC initialisation.
	 */
	i8259init(32);


	procinit0();
	mpsinit(maxcores);
	apiconline();
	/* Forcing to single core if desired */
	if(!nosmp) {
		sipi();
	}
	teardownidmap(m);
	timersinit();
	fpuinit();
	psinit(conf.nproc);
	initimage();
	links();

	keybinit();
	keybenable();
	mouseenable();

	devtabreset();
	pageinit();
	swapinit();
	userinit();
	/* Forcing to single core if desired */
	if(!nosmp) {
		nixsquids();
		testiccs();
	}

	print("CPU Freq. %dMHz\n", m->cpumhz);

	print("schedinit...\n");
	schedinit();
}
Esempio n. 20
0
File: main.c Progetto: 99years/plan9
void
main(u32int ax, u32int bx)
{
	vlong hz;

	memset(edata, 0, end - edata);

	/*
	 * ilock via i8250enable via i8250console
	 * needs m->machno, sys->machptr[] set, and
	 * also 'up' set to nil.
	 */
	cgapost(sizeof(uintptr)*8);
	memset(m, 0, sizeof(Mach));
	m->machno = 0;
	m->online = 1;
	m->nixtype = NIXTC;
	sys->machptr[m->machno] = &sys->mach;
	m->stack = PTR2UINT(sys->machstk);
	m->vsvm = sys->vsvmpage;
	up = nil;
	active.nonline = 1;
	active.exiting = 0;
	active.nbooting = 0;
	asminit();
	multiboot(ax, bx, 0);
	options(oargc, oargv);
	crapoptions();

	/*
	 * Need something for initial delays
	 * until a timebase is worked out.
	 */
	m->cpuhz = 2000000000ll;
	m->cpumhz = 2000;

	cgainit();
	i8250console("0");
	consputs = cgaconsputs;

	vsvminit(MACHSTKSZ, NIXTC);

	conf.nmach = 1;			

	fmtinit();
	print("\nNIX\n");
	if(vflag){
		print("&ax = %#p, ax = %#ux, bx = %#ux\n", &ax, ax, bx);
		multiboot(ax, bx, vflag);
	}

	m->perf.period = 1;
	if((hz = archhz()) != 0ll){
		m->cpuhz = hz;
		m->cyclefreq = hz;
		m->cpumhz = hz/1000000ll;
	}

	/*
	 * Mmuinit before meminit because it
	 * flushes the TLB via m->pml4->pa.
	 */
	mmuinit();

	ioinit();
	kbdinit();
	meminit();
	confinit();
	archinit();
	mallocinit();

	/*
	 * Acpiinit will cause the first malloc
	 * call to happen.
	 * If the system dies here it's probably due
	 * to malloc not being initialised
	 * correctly, or the data segment is misaligned
	 * (it's amazing how far you can get with
	 * things like that completely broken).
	 */
	acpiinit();
	
	umeminit();
	trapinit();
	printinit();

	/*
	 * This is necessary with GRUB and QEMU.
	 * Without it an interrupt can occur at a weird vector,
	 * because the vector base is likely different, causing
	 * havoc. Do it before any APIC initialisation.
	 */
	i8259init(32);


	procinit0();
	mpsinit(maxcores);
	apiconline();
	sipi();

	timersinit();
	kbdenable();
	fpuinit();
	psinit(conf.nproc);
	initimage();
	links();
	devtabreset();
	pageinit();
	swapinit();
	userinit();
	nixsquids();
testiccs();	
print("schedinit...\n");
	schedinit();
}
Esempio n. 21
0
void main()
{
  char s[200],cdir[200]="/",tmp[200];
  int a,b,ID=alloc_console();
  FILE *fp;
  meminit();
  fileinit();

  printf("ChaOS shell ID=%x\n",ID);

  do {
    printf(">");
    gets(s);

    if (!strcmp(s,"exit")) break;

    if (s[0]=='t'&&s[1]=='y'&&s[2]=='p'&&s[3]=='e'&&s[4]==' '){
        fp=fopen(s+5,"rb");
        while((a=fread(tmp,1,199,fp))) for (b=0;b<a;b++) putch(tmp[b]);
        fclose(fp);
        continue;
    }

    if (!strcmp(s,"dir")){
        showdir(cdir);continue;
    }

    if (!strcmp(s,"cls")){
       clrscr();
       continue;
    }

    if (s[0]=='c'&&s[1]=='d'&&s[2]==' '){
      if (s[3]=='.'&&s[4]=='.'&&s[5]==0){
         if (strlen(cdir)<=1) continue;
         b=strlen(cdir);b--;
         cdir[b]=0;
         for(b--;b>=0;b--) if (cdir[b]=='/'){ cdir[b+1]=0;break;}
         continue;
      }

      if (s[3]=='/')
         strcpy(tmp,s+3);
      else
         { strcpy(tmp,cdir);strcat(tmp,s+3);}
      if (tmp[strlen(tmp)-1]!='/') strcat(tmp,"/");
      if (strlen(tmp)>1){
        tmp[strlen(tmp)-1]=0;
        if (findfirst(tmp,&sr,_FF_NORMAL)==0){
           strcpy(cdir,tmp);strcat(cdir,"/");
        } else printf("not found: %s\n",tmp);
      } else strcpy(cdir,tmp);
      continue;
    }

    if (!strcmp(s,"mem")){
      printf("free = %i\n",get_free_mem()<<12);
      continue;
    }

    // Execute
    if (s[0]==0) continue;
    if (s[0]!='/'){ strcpy(tmp,cdir);strcat(tmp,s);strcpy(s,tmp); }
    if ((a=system(s))!=0)
       printf("not found: %s (%x)\n",s,a);

  } while(1);

  free_console(ID);
}