Ejemplo n.º 1
0
int main(int argc, char **argv, char **envp)
{
	int fd_stdin=-1, fd_stdout=-1;
	pid_t pid;
	int retries = 0;
	int rootmounted = 0;
	char *rootdev = NULL;
	char *rootfstype = "unknown";
	char *rootfslabel = ROOTFSLABEL;
	char *initprg = "/sbin/init";

	conf.mountflags = MS_SYNCHRONOUS;
	
	open_console();

	/* create mountpoints /dev and /proc /rootfs */
	
	mkmountpoint("/dev");
	mkmountpoint("/proc");
	mkmountpoint("/rootfs");

	open_console();
	
	/* make sure /dev is mounted */
	if(mount("devtmpfs", "/dev",
		 "devtmpfs", 0,
		 "")) {
		if(fstdout) {
			if(fstdout) {
				fprintf(fstdout, "INIT: could not mount devtmpfs on /dev: %s\n", strerror(errno));
				fprintf(fstdout, "INIT: waiting 10 seconds ..\n");
				sleep(5);
				sleep(5);
			}
		}	
	}

	open_console();
	
	/* mount /proc */
	if(mount("proc", "/proc",
		 "proc", 0,
		 "")) {
		if(fstdout) {
			fprintf(fstdout, "INIT: could not mount proc on /proc: %s\n", strerror(errno));
			fprintf(fstdout, "INIT: waiting 10 seconds ..\n");
			sleep(5);
			sleep(5);
		}	
	}
	
	/* parse kernel commandline options */
	cmdline.autoresize = 1;
	cmdline_parse();
	
	if(cmdline.init) {
		initprg = cmdline.init;
	}
	
	if(cmdline.async) {
		conf.mountflags ^= MS_SYNCHRONOUS;
	}
	
	if(cmdline.usbreset) {
		usbreset();
		sleep(1);
	}
	
	if(cmdline.rootdelay > 0) {
		if(fstdout) fprintf(fstdout, "INIT: rootdelay, waiting %d seconds\n", cmdline.rootdelay);
		sleep(cmdline.rootdelay);
	}
	
	if(cmdline.rootdev) {
		struct stat statb;
		if(fstdout) fprintf(fstdout, "INIT: rootdev %s given on commandline\n", cmdline.rootdev);
		rootdev = cmdline.rootdev;
		if(stat(rootdev, &statb)) {
			if(fstdout) fprintf(fstdout, "INIT: rootdev %s not found!\n", rootdev);
			rootdev = NULL;
		}
	}
	
	if(!rootdev) {
		if(cmdline.rootfslabel) {
			if(strncmp(cmdline.rootfslabel, "LABEL=", 6)) {
				rootfslabel = malloc(strlen("LABEL=") + strlen(cmdline.rootfslabel) + 1);
				strcpy(rootfslabel, "LABEL=");
				strcat(rootfslabel, cmdline.rootfslabel);
			} else {
				rootfslabel = cmdline.rootfslabel;
			}
		}
		if(fstdout) fprintf(fstdout, "INIT: probing for rootdev labeled '%s'\n", rootfslabel);
		fsprobe_init();
		while( (rootdev = fsprobe_get_devname_by_spec(rootfslabel)) == NULL ) {
			retries++;
			if(retries == 15) usbreset();
			if(retries > 25) break;
			if(fstdout) fprintf(fstdout, "INIT: waiting for rootdevice to be available\n");
			sleep(2);
			fsprobe_init();
		}
	}
	
	if(!rootdev) {
		if(fstdout) {
			fprintf(fstdout, "INIT: could not find rootdevice\n");
			listdevices();
			fprintf(fstdout, "INIT: waiting 10 seconds ..\n");
			sleep(5);
			sleep(5);
			fprintf(fstdout, "INIT: guessing that rootdev is /dev/sda1\n\n");
		}
		rootdev="/dev/sda1";
	} else {
		if(fstdout) fprintf(fstdout, "INIT: using rootdev %s\n", rootdev);
	}
	sleep(1);

	/* if filesystem is of the ext family */
	if((!cmdline.rootfstype) || (!strncmp(cmdline.rootfstype, "ext", 3))) {
		int status = 0;
		int fsckok = 0;
		/* e2fsck -y rootdev */
		/* fork + exec("/e2fsck", "/e2fsck"-y", rootdev) */
		if((pid=fork())==0) {
			execl("/e2fsck", "/e2fsck", "-y", rootdev, NULL);
			exit(0);
		}
		if(pid != -1) {
			wait(&status);
			if(WIFEXITED(status)) {
				fprintf(fstdout, "INIT: e2fsck exited normally with exit code: %d\n", WEXITSTATUS(status));
				if(WEXITSTATUS(status)==0) fsckok=1;
			} else {
				fprintf(fstdout, "INIT: e2fsck exited abnormally\n");
			}
		}
		if(fsckok) {
			if(cmdline.autoresize) {
				sync();
				if((pid=fork())==0) {
					execl("/resize2fs", "/resize2fs", "-f", rootdev, NULL);
					exit(0);
				}
				if(pid != -1) wait(NULL);
				sync();
			}
		}
	}
	
	/* unlink /e2sck and /resize2fs to save some memory */
	if(unlink("/e2fsck")) {
		fprintf(fstdout, "INIT: unlink(\"/e2fsck\") failed: %s\n", strerror(errno));
	}
	if(unlink("/resize2fs")) {
		fprintf(fstdout, "INIT: unlink(\"/resize2fs\") failed: %s\n", strerror(errno));
	}
	
	if(cmdline.rootfstype) {
		/* mount /rootfs, try fstype supplied on kernel commandline */
		if(mount(rootdev, "/rootfs", cmdline.rootfstype, MS_NOATIME|MS_RDONLY|conf.mountflags, "")) {
			if(fstdout) fprintf(fstdout, "INIT: failed to mount (%s) %s: %s\n",
						 cmdline.rootfstype, rootdev, strerror(errno));
		} else {
			rootmounted = 1;
			rootfstype = cmdline.rootfstype;
		}
	}
	if(!rootmounted) {
		/* mount /rootfs, try ext2 */
		if(mount(rootdev, "/rootfs", "ext2", MS_NOATIME|MS_RDONLY|conf.mountflags, "")) {
			if(fstdout) fprintf(fstdout, "INIT: failed to mount (ext2) %s: %s\n", rootdev, strerror(errno));
			goto forever;
		}
		rootfstype = "ext2";
	}
	
	if(fstdout) fprintf(fstdout, "INIT: (%s) %s mounted.\n", rootfstype, rootdev);
	sleep(1);

	if(cmdline.install) {
		if(fstdout) {
			fprintf(fstdout, "INIT: INSTALL INVOKED!\nINSTALL: PROCEEDING IN 5 SECONDS!\n");
			sleep(5);
		}
		
		/* unpack install archive in initramfs root */
		{
			int fd;
			fd = open("/rootfs/install.tar", O_RDONLY);
			if(fd == -1) {
				if(fstdout) fprintf(fstdout, "INSTALL: failed to open '/rootfs/install.tar'\n");
			} else {
				if(fstdout) fprintf(fstdout, "INSTALL: '/rootfs/install.tar' opened ok\n");
				tar_extract(fd);
				close(fd);
			}
		}

		/* Be nice and prepare stdin and stdout for the install program */
		fd_stdin = open("/dev/console", O_RDONLY|O_NOCTTY);
		if(fd_stdin == -1) {
			if(fstdout)
				fprintf(fstdout, "INSTALL: open(\"/dev/console\", O_RDONLY) failed: %s\n", strerror(errno));
		} else {
			if(fd_stdin != 0) {
				dup2(fd_stdin, 0);
				close(fd_stdin);
			}
		}
		fd_stdout = open("/dev/console", O_WRONLY|O_NOCTTY);
		if(fd_stdout == -1) {
			if(fstdout)
				fprintf(fstdout, "INSTALL: open(\"/dev/console\", O_WRONLY) failed: %s\n", strerror(errno));
		} else { 
			if(fd_stdout != 1) {
				dup2(fd_stdout, 1);
				dup2(fd_stdout, 2);
				close(fd_stdout);
			}
		}

		/* exec "/install" */
		{
			char *iv[2];
		iv[0] = "/install";
		iv[1] = NULL;
		if(fstdout)
			fprintf(fstdout, "INSTALL: exec(\"/install\")\n");
		execve(iv[0], iv, envp);
		if(fstdout)
			fprintf(fstdout, "INSTALL: exec(\"/install\") failed\n");
		sleep(10);
		}
	}
	
	if (mount("/dev", "/rootfs/dev", NULL, MS_MOVE, NULL) < 0) {
		if(fstdout)
			fprintf(fstdout, "INIT: failed to mount moving /dev to /rootfs/dev\n");
		sleep(1);
	}
	if (mount("/proc", "/rootfs/proc", NULL, MS_MOVE, NULL) < 0) {
		if(fstdout)
			fprintf(fstdout, "INIT: failed to mount moving /proc to /rootfs/proc\n");
		sleep(1);
	}

	/*
         * mkdir /sbin
 	 * copy /rootfs/sbin/init to /sbin/init
         * mount --bind /rootfs/sbin/init /sbin/init
         */
	if(mkdir("/sbin", 0755)) {
		if(fstdout)
			fprintf(fstdout, "INIT: mkdir(\"/sbin\") failed: %s\n", strerror(errno));
		sleep(1);
	} else {
		int fd, ofd;
		ssize_t siz;
		struct stat statb;
		
		if(stat("/rootfs/sbin/init", &statb)) {
			if(fstdout) fprintf(fstdout, "INIT: stat(\"/rootfs/sbin/init\") failed: %s\n", strerror(errno));
			sleep(1);
			goto noinitcopy;
		}
		siz = statb.st_size;

		if(mount("tmpfs", "/sbin","tmpfs", 0,"")) {
			if(fstdout) fprintf(fstdout, "INIT: mount(\"tmpfs\", \"/sbin\") failed: %s\n", strerror(errno));
		}
		if( (fd = open("/rootfs/sbin/init", O_RDONLY)) == -1) {
			if(fstdout) fprintf(fstdout, "INIT: open(\"/rootfs/sbin/init\", O_RDONLY) failed: %s\n", strerror(errno));
			sleep(1);
			goto noinitcopy;
		}
		if( (ofd = open("/sbin/init", O_WRONLY|O_CREAT|O_TRUNC, 0755)) == -1) {
			if(fstdout) fprintf(fstdout, "INIT: open(\"/sbin/init\", O_WRONLY|O_CREAT|O_TRUNC) failed: %s\n", strerror(errno));
			sleep(1);
			close(fd);
			goto noinitcopy;
		}
		if(data(fd, siz, ofd)) {
			if(fstdout) fprintf(fstdout, "INIT: datacopy of /sbin/init failed: %s\n", strerror(errno));
			sleep(1);
			close(fd);
			close(ofd);
			goto noinitcopy;
		}
		close(fd);
		if(close(ofd)) {
			if(fstdout) fprintf(fstdout, "INIT: close(\"/sbin/init\") failed: %s\n", strerror(errno));
			sleep(1);
			goto noinitcopy;
		}
		if (mount("rootfs", "/", NULL, MS_REMOUNT|MS_NOATIME|MS_RDONLY, NULL) < 0) {
			if(fstdout)
				fprintf(fstdout, "INIT: failed to remount initramfs as read-only\n");
			sleep(1);
		}
		if (mount("tmpfs", "/sbin", NULL, MS_REMOUNT|MS_NOATIME|MS_RDONLY, NULL) < 0) {
			if(fstdout)
				fprintf(fstdout, "INIT: failed to remount \"/sbin\" as read-only\n");
			sleep(1);
		}
		
		if(mount("/sbin/init", "/rootfs/sbin/init", "tmpfs", MS_BIND|MS_RDONLY, NULL)) {
			if(mount("/sbin/init", "/rootfs/sbin/init", "tmpfs", MS_BIND, NULL)) {
				if(fstdout)
					fprintf(fstdout, "INIT: bind mount(\"/sbin/init\", \"/rootfs/sbin/init\") failed: %s\n", strerror(errno));
				sleep(1);
			}
		}
	}
noinitcopy:

	if(chdir("/rootfs")) {
		if(fstdout)
			fprintf(fstdout, "INIT: chdir(\"/rootfs\") failed: %s\n", strerror(errno));
		goto forever;
	}

	if (mount("/rootfs", "/", NULL, MS_MOVE, NULL) < 0) {
		if(fstdout)
			fprintf(fstdout, "INIT: failed to mount moving /rootfs to /\n");
		goto forever;
	}

        /*
	  Now, the init process may still access the old root via its
	  executable, shared libraries, standard input/output/error, and its
	  current root directory. All these references are dropped by the
	  following command:
	  
	  # exec chroot . /sbin/init <dev/console >dev/console 2>&1
	*/
	
	if(chroot(".")) {
		if(fstdout) {
			fprintf(fstdout, "INIT: chroot(\".\") failed: %s\n", strerror(errno));
			sleep(5);
			sleep(5);
		}
	}

	/* check if we need to copy default versions of some config files */
	{
		int remounted=0;
		chk_cfg_file(&remounted, "ssh/ssh_config");
		chk_cfg_file(&remounted, "ssh/sshd_config");
		chk_cfg_file(&remounted, "inetd.conf");
		chk_cfg_file(&remounted, "inittab");
		chk_cfg_file(&remounted, "login.defs");
		chk_cfg_file(&remounted, "limits");
		chk_cfg_file(&remounted, "login.access");
		if(remounted)
			if (mount("rootfs", "/", NULL, MS_REMOUNT|MS_NOATIME|MS_RDONLY|conf.mountflags, NULL) < 0) {
				if(fstdout)
					fprintf(fstdout, "INIT: failed to remount rootfs as read-only\n");
				sleep(1);
			}
	}
		
	fd_stdin = open("/dev/console", O_RDONLY|O_NOCTTY);
	if(fd_stdin == -1) {
		if(fstdout)
			fprintf(fstdout, "INIT: open(\"/dev/console\", O_RDONLY) failed: %s\n", strerror(errno));
	} else {
		if(fd_stdin != 0) {
			dup2(fd_stdin, 0);
			close(fd_stdin);
		}
	}
	fd_stdout = open("/dev/console", O_WRONLY|O_NOCTTY);
	if(fd_stdout == -1) {
		if(fstdout)
			fprintf(fstdout, "INIT: open(\"/dev/console\", O_WRONLY) failed: %s\n", strerror(errno));
	} else { 
		if(fd_stdout != 1) {
			dup2(fd_stdout, 1);
			dup2(fd_stdout, 2);
			close(fd_stdout);
		}
	}

	if(fstdout)
		fprintf(fstdout, "INIT: now execing \"%s\"\n", initprg);
	sleep(1);

	if(fstdout) {
		fclose(fstdout);
		fstdout = NULL;
	}
	argv[0] = initprg;
	execve(initprg, argv, envp);
	
	open_console();

	if(fstdout) {
		fprintf(fstdout, "INIT: execve(\"%s\") failed: %s\n", initprg, strerror(errno));
	}
forever:
	if(fstdout) {
		fprintf(fstdout, "INIT: pid is %u\n", getpid());
		fprintf(fstdout, "INIT: boot cannot proceed from here.\n");
		fprintf(fstdout, "INIT: turn off the computer.\n");
	}
	while(1) sleep(1000);
	return 2;
}
Ejemplo n.º 2
0
Archivo: boot_sys.c Proyecto: scan/seL4
static BOOT_CODE bool_t
try_boot_sys(
    unsigned long multiboot_magic,
    multiboot_info_t* mbi
)
{
    /* ==== following code corresponds to the "select" in abstract specification ==== */

    acpi_rsdt_t* acpi_rsdt; /* physical address of ACPI root */
    paddr_t mods_end_paddr; /* physical address where boot modules end */
    paddr_t load_paddr;
    word_t i;
    p_region_t ui_p_regs;
    multiboot_module_t *modules = (multiboot_module_t*)(word_t)mbi->mod_list;

    if (multiboot_magic != MULTIBOOT_MAGIC) {
        printf("Boot loader not multiboot compliant\n");
        return false;
    }
    cmdline_parse((const char *)(word_t)mbi->cmdline, &cmdline_opt);

    if ((mbi->flags & MULTIBOOT_INFO_MEM_FLAG) == 0) {
        printf("Boot loader did not provide information about physical memory size\n");
        return false;
    }

    if (!x86_cpuid_initialize()) {
        printf("Warning: Your x86 CPU has an unsupported vendor, '%s'.\n"
               "\tYour setup may not be able to competently run seL4 as "
               "intended.\n"
               "\tCurrently supported x86 vendors are AMD and Intel.\n",
               x86_cpuid_get_identity()->vendor_string);
    }

    if (!is_compiled_for_microarchitecture()) {
        printf("Warning: Your kernel was not compiled for the current microarchitecture.\n");
    }

#if CONFIG_MAX_NUM_NODES > 1
    /* copy boot code for APs to lower memory to run in real mode */
    if (!copy_boot_code_aps(mbi->mem_lower)) {
        return false;
    }
    /* Initialize any kernel TLS */
    mode_init_tls(0);
#endif

    /* initialize the memory. We track two kinds of memory regions. Physical memory
     * that we will use for the kernel, and physical memory regions that we must
     * not give to the user. Memory regions that must not be given to the user
     * include all the physical memory in the kernel window, but also includes any
     * important or kernel devices. */
    boot_state.mem_p_regs.count = 0;
    init_allocated_p_regions();
    if (mbi->flags & MULTIBOOT_INFO_MMAP_FLAG) {
        if (!parse_mem_map(mbi->mmap_length, mbi->mmap_addr)) {
            return false;
        }
    } else {
        /* calculate memory the old way */
        p_region_t avail;
        avail.start = HIGHMEM_PADDR;
        avail.end = ROUND_DOWN(avail.start + (mbi->mem_upper << 10), PAGE_BITS);
        if (!add_mem_p_regs(avail)) {
            return false;
        }
    }

    boot_state.ki_p_reg.start = PADDR_LOAD;
    boot_state.ki_p_reg.end = kpptr_to_paddr(ki_end);

    /* copy VESA information from multiboot header */
    if ((mbi->flags & MULTIBOOT_INFO_GRAPHICS_FLAG) == 0) {
        boot_state.vbe_info.vbeMode = -1;
        printf("Multiboot gave us no video information\n");
    } else {
        boot_state.vbe_info.vbeInfoBlock = *(seL4_VBEInfoBlock_t*)(seL4_Word)mbi->vbe_control_info;
        boot_state.vbe_info.vbeModeInfoBlock = *(seL4_VBEModeInfoBlock_t*)(seL4_Word)mbi->vbe_mode_info;
        boot_state.vbe_info.vbeMode = mbi->vbe_mode;
        printf("Got VBE info in multiboot. Current video mode is %d\n", mbi->vbe_mode);
        boot_state.vbe_info.vbeInterfaceSeg = mbi->vbe_interface_seg;
        boot_state.vbe_info.vbeInterfaceOff = mbi->vbe_interface_off;
        boot_state.vbe_info.vbeInterfaceLen = mbi->vbe_interface_len;
    }

    printf("Kernel loaded to: start=0x%lx end=0x%lx size=0x%lx entry=0x%lx\n",
           boot_state.ki_p_reg.start,
           boot_state.ki_p_reg.end,
           boot_state.ki_p_reg.end - boot_state.ki_p_reg.start,
           (paddr_t)_start
          );

    /* remapping legacy IRQs to their correct vectors */
    pic_remap_irqs(IRQ_INT_OFFSET);
    if (config_set(CONFIG_IRQ_IOAPIC)) {
        /* Disable the PIC so that it does not generate any interrupts. We need to
         * do this *before* we initialize the apic */
        pic_disable();
    }

    /* get ACPI root table */
    acpi_rsdt = acpi_init();
    if (!acpi_rsdt) {
        return false;
    }

    /* check if kernel configuration matches platform requirments */
    if (!acpi_fadt_scan(acpi_rsdt)) {
        return false;
    }

    if (!config_set(CONFIG_IOMMU) || cmdline_opt.disable_iommu) {
        boot_state.num_drhu = 0;
    } else {
        /* query available IOMMUs from ACPI */
        acpi_dmar_scan(
            acpi_rsdt,
            boot_state.drhu_list,
            &boot_state.num_drhu,
            MAX_NUM_DRHU,
            &boot_state.rmrr_list
        );
    }

    /* query available CPUs from ACPI */
    boot_state.num_cpus = acpi_madt_scan(acpi_rsdt, boot_state.cpus, &boot_state.num_ioapic, boot_state.ioapic_paddr);
    if (boot_state.num_cpus == 0) {
        printf("No CPUs detected\n");
        return false;
    }

    if (config_set(CONFIG_IRQ_IOAPIC)) {
        if (boot_state.num_ioapic == 0) {
            printf("No IOAPICs detected\n");
            return false;
        }
    } else {
        if (boot_state.num_ioapic > 0) {
            printf("Detected %d IOAPICs, but configured to use PIC instead\n", boot_state.num_ioapic);
        }
    }

    if (!(mbi->flags & MULTIBOOT_INFO_MODS_FLAG)) {
        printf("Boot loader did not provide information about boot modules\n");
        return false;
    }

    printf("Detected %d boot module(s):\n", mbi->mod_count);

    if (mbi->mod_count < 1) {
        printf("Expect at least one boot module (containing a userland image)\n");
        return false;
    }

    mods_end_paddr = 0;

    for (i = 0; i < mbi->mod_count; i++) {
        printf(
            "  module #%ld: start=0x%x end=0x%x size=0x%x name='%s'\n",
            i,
            modules[i].start,
            modules[i].end,
            modules[i].end - modules[i].start,
            (char *) (long)modules[i].name
        );
        if ((sword_t)(modules[i].end - modules[i].start) <= 0) {
            printf("Invalid boot module size! Possible cause: boot module file not found by QEMU\n");
            return false;
        }
        if (mods_end_paddr < modules[i].end) {
            mods_end_paddr = modules[i].end;
        }
    }
    mods_end_paddr = ROUND_UP(mods_end_paddr, PAGE_BITS);
    assert(mods_end_paddr > boot_state.ki_p_reg.end);

    printf("ELF-loading userland images from boot modules:\n");
    load_paddr = mods_end_paddr;

    load_paddr = load_boot_module(modules, load_paddr);
    if (!load_paddr) {
        return false;
    }

    /* calculate final location of userland images */
    ui_p_regs.start = boot_state.ki_p_reg.end;
    ui_p_regs.end = ui_p_regs.start + load_paddr - mods_end_paddr;

    printf(
        "Moving loaded userland images to final location: from=0x%lx to=0x%lx size=0x%lx\n",
        mods_end_paddr,
        ui_p_regs.start,
        ui_p_regs.end - ui_p_regs.start
    );
    memcpy((void*)ui_p_regs.start, (void*)mods_end_paddr, ui_p_regs.end - ui_p_regs.start);

    /* adjust p_reg and pv_offset to final load address */
    boot_state.ui_info.p_reg.start -= mods_end_paddr - ui_p_regs.start;
    boot_state.ui_info.p_reg.end   -= mods_end_paddr - ui_p_regs.start;
    boot_state.ui_info.pv_offset   -= mods_end_paddr - ui_p_regs.start;

    /* ==== following code corresponds to abstract specification after "select" ==== */

    if (!platAddDevices()) {
        return false;
    }

    /* Total number of cores we intend to boot */
    ksNumCPUs = boot_state.num_cpus;

    printf("Starting node #0 with APIC ID %lu\n", boot_state.cpus[0]);
    if (!try_boot_sys_node(boot_state.cpus[0])) {
        return false;
    }

    if (config_set(CONFIG_IRQ_IOAPIC)) {
        ioapic_init(1, boot_state.cpus, boot_state.num_ioapic);
    }

    /* initialize BKL before booting up APs */
    SMP_COND_STATEMENT(clh_lock_init());
    SMP_COND_STATEMENT(start_boot_aps());

    /* grab BKL before leaving the kernel */
    NODE_LOCK_SYS;

    printf("Booting all finished, dropped to user space\n");

    return true;
}
Ejemplo n.º 3
0
static void __init __start_xen(void)
{
    memcpy(0, exception_vectors, exception_vectors_end - exception_vectors);
    synchronize_caches(0, exception_vectors_end - exception_vectors);

    ticks_per_usec = timebase_freq / 1000000ULL;

    /* Parse the command-line options. */
    cmdline_parse(xen_cmdline);

    /* we need to be able to identify this CPU early on */
    init_boot_cpu();

    /* We initialise the serial devices very early so we can get debugging. */
    ns16550.io_base = 0x3f8;
    ns16550_init(0, &ns16550);
    ns16550.io_base = 0x2f8;
    ns16550_init(1, &ns16550);
    serial_init_preirq();

    init_console();
    console_start_sync(); /* Stay synchronous for early debugging. */

    rtas_init((void *)oftree);

    memory_init();

    printk("xen_cmdline:  %016lx\n", (ulong)xen_cmdline);
    printk("dom0_cmdline: %016lx\n", (ulong)dom0_cmdline);
    printk("dom0_addr:    %016lx\n", (ulong)dom0_addr);
    printk("dom0_len:     %016lx\n", (ulong)dom0_len);
    printk("initrd_start: %016lx\n", (ulong)initrd_start);
    printk("initrd_len:   %016lx\n", (ulong)initrd_len);

    printk("dom0: %016llx\n", *(unsigned long long *)dom0_addr);

#ifdef OF_DEBUG
    key_ofdump(0);
#endif
    percpu_init_areas();

    init_parea(0);
    cpu_initialize(0);

#ifdef CONFIG_GDB
    initialise_gdb();
    if (opt_earlygdb)
        debugger_trap_immediate();
#endif

    start_of_day();

    acm_init(NULL, 0);

    mpic_setup_this_cpu();

    /* Deal with secondary processors.  */
    if (opt_nosmp || ofd_boot_cpu == -1) {
        printk("nosmp: leaving secondary processors spinning forever\n");
    } else {
        printk("spinning up at most %d total processors ...\n", max_cpus);
        kick_secondary_cpus(max_cpus);
    }

    /* This cannot be called before secondary cpus are marked online.  */
    percpu_free_unused_areas();

    /* Create initial domain 0. */
    dom0 = domain_create(0, 0, DOM0_SSIDREF);
    if (dom0 == NULL)
        panic("Error creating domain 0\n");

    /* The Interrupt Controller will route everything to CPU 0 so we
     * need to make sure Dom0's vVCPU 0 is pinned to the CPU */
    dom0->vcpu[0]->cpu_affinity = cpumask_of_cpu(0);

    dom0->is_privileged = 1;

    /* scrub_heap_pages() requires IRQs enabled, and we're post IRQ setup... */
    local_irq_enable();
    /* Scrub RAM that is still free and so may go to an unprivileged domain. */
    scrub_heap_pages();

    if ((dom0_addr == 0) || (dom0_len == 0))
        panic("No domain 0 found.\n");

    if (construct_dom0(dom0, dom0_addr, dom0_len,
                       initrd_start, initrd_len,
                       dom0_cmdline) != 0) {
        panic("Could not set up DOM0 guest OS\n");
    }

    init_xenheap_pages(ALIGN_UP(dom0_addr, PAGE_SIZE),
                       ALIGN_DOWN(dom0_addr + dom0_len, PAGE_SIZE));
    if (initrd_start)
        init_xenheap_pages(ALIGN_UP(initrd_start, PAGE_SIZE),
                           ALIGN_DOWN(initrd_start + initrd_len, PAGE_SIZE));

    init_trace_bufs();

    console_endboot();

    /* Hide UART from DOM0 if we're using it */
    serial_endboot();

    console_end_sync();

    domain_unpause_by_systemcontroller(dom0);
#ifdef DEBUG_IPI
    ipi_torture_test();
#endif
    startup_cpu_idle_loop();
}
Ejemplo n.º 4
0
int main(int argc, char *argv[])
{
	transfer * st_sender =NULL;
	int chk_interval = 0, attach = 0, cap_num = 0;
	char *dst_ip = NULL;
	unsigned short dst_port = 0;
	int opt_idx = 0, opt_id = 0, arg_num = 0;
	void *arglist = NULL;
	pkt_cap_ctx_p p_cap_ctx = NULL;
	st_ctx_p p_st_ctx = NULL;
	cpu_set_t set;

	if (argc < 2) return 1;

	if (0 != cmdline_init()) {
		fprintf(stderr, "cmdline_init failed!\n");
		return 1;
	}

	if (0 != cmdline_parse(argc-1, &argv[1], opt_prof)) {
		fprintf(stderr, "cmdline_parse failed!\n");
		return 1;
	}

	while (-1 != cmdline_result_loop(&opt_idx, &opt_id, &arglist, &arg_num)) {
		switch (opt_id) {
			case OPT_HELP:
				return usage();

				break;
			case OPT_DEST:
				dst_ip = strdup(cmdline_get_arg(arglist, 0));
				dst_port = atoi(cmdline_get_arg(arglist, 1));

				break;
			case OPT_INTERVAL:
				chk_interval = atoi(cmdline_get_arg(arglist, 0));

				break;
			case OPT_CAP_NUM:
				cap_num = atoi(cmdline_get_arg(arglist, 0));

				break;
			case OPT_ATTACH:
				attach = atoi(cmdline_get_arg(arglist, 0));

				break;
			default:
				break;
		}
	}

	cmdline_show();
	cmdline_destroy();

	st_sender = new transfer(IS_CLIENT, SOCK_DGRAM, dst_ip, dst_port);
	if (!st_sender || true != st_sender->is_ok()) {
		return -1;
	}

	p_cap_ctx = pkt_cap_ctx_new(cap_num);
	MEM_ALLOC(p_st_ctx, st_ctx_p, sizeof(st_ctx_t), 1);

	int cpu_num = sysconf(_SC_NPROCESSORS_CONF);
	fprintf(stdout, "cpu num = %d\n", cpu_num);
	p_st_ctx->num = cap_num;
	p_st_ctx->chk_interval = chk_interval;
	p_st_ctx->p_cap_ctx = p_cap_ctx;
	p_st_ctx->sender = st_sender;
	if (attach) p_st_ctx->id = cap_num > cpu_num ? (cpu_num-1) : cap_num;
	else p_st_ctx->id = -1;

	pthread_t st_thd;
	if (0 != pthread_create(&st_thd, NULL, st_cb, (void*)p_st_ctx)) {
		fprintf(stderr, "create st_cb failed!\n");
		return 1;
	}

	pthread_t cap_thd;
	for (int i = 0; i < cap_num; i++) {
		if (attach) p_cap_ctx[i].id = cap_num > cpu_num ? (i%(cpu_num-1)) : i;
		else p_cap_ctx[i].id = -1;
		if (0 != pthread_create(&cap_thd, NULL, pkt_cap_cb, &p_cap_ctx[i])) {
			fprintf(stderr, "create pkt_cap_cb failed!\n");
			return 1;
		}
	}

	void *ret = NULL;
	pthread_join(st_thd, &ret);

	return 0;
}
Ejemplo n.º 5
0
static int config_init(int argc, char * * argv)
{
    char const * levels;
    char *       temp;
    char const * tok;

	if (cmdline_parse(argc, argv)<0) {
		return -1;
	}
	if (cmdline_get_version()) {
		cmdline_show_version();
		return -1;
	}
	if (cmdline_get_help()) {
		cmdline_show_help();
		return -1;
	}
	if (!cmdline_get_foreground()) {
		if (setup_daemon()<0) {
			return -1;
		}
	}
	if (prefs_load(cmdline_get_prefs_file())<0) {
		log_error("error loading configuration file %s",cmdline_get_prefs_file());
		return -1;
	}

    eventlog_clear_level();
    if ((levels = prefs_get_loglevels()))
    {
        if (!(temp = strdup(levels)))
        {
         eventlog(eventlog_level_fatal,"main","could not allocate memory for temp (exiting)");
         return -1;
        }

        tok = strtok(temp,","); /* strtok modifies the string it is passed */

        while (tok)
        {
        if (eventlog_add_level(tok)<0)
            eventlog(eventlog_level_error,"main","could not add log level \"%s\"",tok);
        tok = strtok(NULL,",");
        }

        free(temp);
    }

	if (cmdline_get_logstderr()) {
		eventlog_set(stderr);
	} else if (cmdline_get_logfile()) {
		if (eventlog_open(cmdline_get_logfile())<0) {
			log_error("error open eventlog file %s",cmdline_get_logfile());
			return -1;
		}
	} else {
		if (eventlog_open(prefs_get_logfile())<0) {
			log_error("error open eventlog file %s",prefs_get_logfile());
			return -1;
		}
	}
#ifdef USE_CHECK_ALLOC
	memlog_fp=fopen(cmdline_get_memlog_file(),"a");
	if (!memlog_fp) {
		log_warn("error open file %s for memory debug logging",cmdline_get_memlog_file());
	} else {
		check_set_file(memlog_fp);
	}
#endif
	return 0;
}
Ejemplo n.º 6
0
/* C entry point for boot CPU */
void __init start_xen(unsigned long boot_phys_offset,
                      unsigned long fdt_paddr,
                      unsigned long cpuid)
{
    size_t fdt_size;
    int cpus, i;
    const char *cmdline;

    setup_cache();

    percpu_init_areas();
    set_processor_id(0); /* needed early, for smp_processor_id() */

    smp_clear_cpu_maps();

    /* This is mapped by head.S */
    device_tree_flattened = (void *)BOOT_FDT_VIRT_START
        + (fdt_paddr & ((1 << SECOND_SHIFT) - 1));
    fdt_size = device_tree_early_init(device_tree_flattened, fdt_paddr);

    cmdline = device_tree_bootargs(device_tree_flattened);
    early_printk("Command line: %s\n", cmdline);
    cmdline_parse(cmdline);

    setup_pagetables(boot_phys_offset, get_xen_paddr());
    setup_mm(fdt_paddr, fdt_size);

    vm_init();
    dt_unflatten_host_device_tree();
    dt_irq_xlate = gic_irq_xlate;

    dt_uart_init();
    console_init_preirq();

    system_state = SYS_STATE_boot;

    processor_id();

    platform_init();

    smp_init_cpus();
    cpus = smp_get_max_cpus();

    init_xen_time();

    gic_init();

    set_current((struct vcpu *)0xfffff000); /* debug sanity */
    idle_vcpu[0] = current;

    init_traps();

    setup_virt_paging();

    p2m_vmid_allocator_init();

    softirq_init();

    tasklet_subsys_init();

    init_IRQ();

    gic_route_ppis();
    gic_route_spis();

    init_maintenance_interrupt();
    init_timer_interrupt();

    timer_init();

    init_idle_domain();

    rcu_init();

    arch_init_memory();

    local_irq_enable();
    local_abort_enable();

    smp_prepare_cpus(cpus);

    initialize_keytable();

    console_init_postirq();

    do_presmp_initcalls();

    for_each_present_cpu ( i )
    {
        if ( (num_online_cpus() < cpus) && !cpu_online(i) )
        {
            int ret = cpu_up(i);
            if ( ret != 0 )
                printk("Failed to bring up CPU %u (error %d)\n", i, ret);
        }
    }

    printk("Brought up %ld CPUs\n", (long)num_online_cpus());
    /* TODO: smp_cpus_done(); */

    do_initcalls();

    /* Create initial domain 0. */
    dom0 = domain_create(0, 0, 0);
    if ( IS_ERR(dom0) || (alloc_dom0_vcpu0() == NULL) )
            panic("Error creating domain 0");

    dom0->is_privileged = 1;
    dom0->target = NULL;

    if ( construct_dom0(dom0) != 0)
            panic("Could not set up DOM0 guest OS");

    /* Scrub RAM that is still free and so may go to an unprivileged domain. */
    scrub_heap_pages();

    init_constructors();

    console_endboot();

    /* Hide UART from DOM0 if we're using it */
    serial_endboot();

    system_state = SYS_STATE_active;

    domain_unpause_by_systemcontroller(dom0);

    /* Switch on to the dynamically allocated stack for the idle vcpu
     * since the static one we're running on is about to be freed. */
    memcpy(idle_vcpu[0]->arch.cpu_info, get_cpu_info(),
           sizeof(struct cpu_info));
    switch_stack_and_jump(idle_vcpu[0]->arch.cpu_info, init_done);
}
Ejemplo n.º 7
0
Archivo: setup.c Proyecto: caomw/xen
/* C entry point for boot CPU */
void __init start_xen(unsigned long boot_phys_offset,
                      unsigned long fdt_paddr,
                      unsigned long cpuid)
{
    size_t fdt_size;
    int cpus, i;
    paddr_t xen_paddr;
    const char *cmdline;
    struct bootmodule *xen_bootmodule;
    struct domain *dom0;
    struct xen_arch_domainconfig config;

    setup_cache();

    percpu_init_areas();
    set_processor_id(0); /* needed early, for smp_processor_id() */

    set_current((struct vcpu *)0xfffff000); /* debug sanity */
    idle_vcpu[0] = current;

    setup_virtual_regions(NULL, NULL);
    /* Initialize traps early allow us to get backtrace when an error occurred */
    init_traps();

    smp_clear_cpu_maps();

    /* This is mapped by head.S */
    device_tree_flattened = (void *)BOOT_FDT_VIRT_START
        + (fdt_paddr & ((1 << SECOND_SHIFT) - 1));
    fdt_size = boot_fdt_info(device_tree_flattened, fdt_paddr);

    cmdline = boot_fdt_cmdline(device_tree_flattened);
    printk("Command line: %s\n", cmdline);
    cmdline_parse(cmdline);

    /* Register Xen's load address as a boot module. */
    xen_bootmodule = add_boot_module(BOOTMOD_XEN,
                             (paddr_t)(uintptr_t)(_start + boot_phys_offset),
                             (paddr_t)(uintptr_t)(_end - _start + 1), NULL);
    BUG_ON(!xen_bootmodule);

    xen_paddr = get_xen_paddr();
    setup_pagetables(boot_phys_offset, xen_paddr);

    /* Update Xen's address now that we have relocated. */
    printk("Update BOOTMOD_XEN from %"PRIpaddr"-%"PRIpaddr" => %"PRIpaddr"-%"PRIpaddr"\n",
           xen_bootmodule->start, xen_bootmodule->start + xen_bootmodule->size,
           xen_paddr, xen_paddr + xen_bootmodule->size);
    xen_bootmodule->start = xen_paddr;

    setup_mm(fdt_paddr, fdt_size);

    /* Parse the ACPI tables for possible boot-time configuration */
    acpi_boot_table_init();

    end_boot_allocator();

    vm_init();
    dt_unflatten_host_device_tree();

    init_IRQ();

    platform_init();

    preinit_xen_time();

    gic_preinit();

    arm_uart_init();
    console_init_preirq();
    console_init_ring();

    system_state = SYS_STATE_boot;

    processor_id();

    smp_init_cpus();
    cpus = smp_get_max_cpus();

    init_xen_time();

    gic_init();

    p2m_vmid_allocator_init();

    softirq_init();

    tasklet_subsys_init();


    xsm_dt_init();

    init_maintenance_interrupt();
    init_timer_interrupt();

    timer_init();

    init_idle_domain();

    rcu_init();

    arch_init_memory();

    local_irq_enable();
    local_abort_enable();

    smp_prepare_cpus(cpus);

    initialize_keytable();

    console_init_postirq();

    do_presmp_initcalls();

    for_each_present_cpu ( i )
    {
        if ( (num_online_cpus() < cpus) && !cpu_online(i) )
        {
            int ret = cpu_up(i);
            if ( ret != 0 )
                printk("Failed to bring up CPU %u (error %d)\n", i, ret);
        }
    }

    printk("Brought up %ld CPUs\n", (long)num_online_cpus());
    /* TODO: smp_cpus_done(); */

    setup_virt_paging();

    iommu_setup();

    do_initcalls();

    /*
     * It needs to be called after do_initcalls to be able to use
     * stop_machine (tasklets initialized via an initcall).
     */
    apply_alternatives_all();

    /* Create initial domain 0. */
    /* The vGIC for DOM0 is exactly emulating the hardware GIC */
    config.gic_version = XEN_DOMCTL_CONFIG_GIC_NATIVE;
    config.nr_spis = gic_number_lines() - 32;

    dom0 = domain_create(0, 0, 0, &config);
    if ( IS_ERR(dom0) || (alloc_dom0_vcpu0(dom0) == NULL) )
            panic("Error creating domain 0");

    dom0->is_privileged = 1;
    dom0->target = NULL;

    if ( construct_dom0(dom0) != 0)
            panic("Could not set up DOM0 guest OS");

    /* Scrub RAM that is still free and so may go to an unprivileged domain. */
    scrub_heap_pages();

    init_constructors();

    console_endboot();

    /* Hide UART from DOM0 if we're using it */
    serial_endboot();

    system_state = SYS_STATE_active;

    /* Must be done past setting system_state. */
    unregister_init_virtual_region();

    domain_unpause_by_systemcontroller(dom0);

    /* Switch on to the dynamically allocated stack for the idle vcpu
     * since the static one we're running on is about to be freed. */
    memcpy(idle_vcpu[0]->arch.cpu_info, get_cpu_info(),
           sizeof(struct cpu_info));
    switch_stack_and_jump(idle_vcpu[0]->arch.cpu_info, init_done);
}
main (int32 argc, char *argv[])
{
    char *str;

#if 0
    ckd_debug(100000);
#endif
    
    E_INFO("%s COMPILED ON: %s, AT: %s\n\n", argv[0], __DATE__, __TIME__);
    
    /* Digest command line argument definitions */
    cmd_ln_define (defn);

    if ((argc == 2) && (strcmp (argv[1], "help") == 0)) {
	cmd_ln_print_definitions();
	exit(1); 
    }

    /* Look for default or specified arguments file */
    str = NULL;
    if ((argc == 2) && (argv[1][0] != '-'))
	str = argv[1];
    else if (argc == 1) {
	str = "s3align.arg";
	E_INFO("Looking for default argument file: %s\n", str);
    }
    if (str) {
	/* Build command line argument list from file */
	if ((argc = load_argfile (str, argv[0], &argv)) < 0) {
	    fprintf (stderr, "Usage:\n");
	    fprintf (stderr, "\t%s argument-list, or\n", argv[0]);
	    fprintf (stderr, "\t%s [argument-file] (default file: s3align.arg)\n\n",
		     argv[0]);
	    cmd_ln_print_definitions();
	    exit(1);
	}
    }
    
    cmdline_parse (argc, argv);
    
    if ((cmd_ln_access("-mdeffn") == NULL) ||
	(cmd_ln_access("-meanfn") == NULL) ||
	(cmd_ln_access("-varfn") == NULL)  ||
	(cmd_ln_access("-mixwfn") == NULL)  ||
	(cmd_ln_access("-tmatfn") == NULL) ||
	(cmd_ln_access("-dictfn") == NULL))
	E_FATAL("Missing -mdeffn, -meanfn, -varfn, -mixwfn, -tmatfn, or -dictfn argument\n");
    
    if ((cmd_ln_access("-ctlfn") == NULL) || (cmd_ln_access("-insentfn") == NULL))
	E_FATAL("Missing -ctlfn or -insentfn argument\n");

    if ((cmd_ln_access ("-s2stsegdir") == NULL) &&
	(cmd_ln_access ("-stsegdir") == NULL) &&
	(cmd_ln_access ("-phsegdir") == NULL) &&
	(cmd_ln_access ("-wdsegdir") == NULL) &&
	(cmd_ln_access ("-outsentfn") == NULL))
	E_FATAL("Missing output file/directory argument(s)\n");
    
    tm_utt = timing_new ();
    
    /*
     * Initialize log(S3-base).  All scores (probs...) computed in log domain to avoid
     * underflow.  At the same time, log base = 1.0001 (1+epsilon) to allow log values
     * to be maintained in int32 variables without significant loss of precision.
     */
    if (cmd_ln_access("-logbase") == NULL)
	logs3_init (1.0001);
    else {
	float32 logbase;
    
	logbase = *((float32 *) cmd_ln_access("-logbase"));
	if (logbase <= 1.0)
	    E_FATAL("Illegal log-base: %e; must be > 1.0\n", logbase);
	if (logbase > 1.1)
	    E_WARN("Logbase %e perhaps too large??\n", logbase);
	logs3_init ((float64) logbase);
    }

    /* Initialize feature stream type */
    feat_init ((char *) cmd_ln_access ("-feat"));
/* BHIKSHA: PASS CEPSIZE TO FEAT_CEPSIZE, 6 Jan 98 */
    cepsize = *((int32 *) cmd_ln_access("-ceplen"));
    cepsize = feat_cepsize (cepsize);
/* END CHANGES BY BHIKSHA */
    
    /* Read in input databases */
    models_init ();
    
    senscale = (int32 *) ckd_calloc (S3_MAX_FRAMES, sizeof(int32));
    
    tmr_utt = cyctimer_new ("U");
    tmr_gauden = cyctimer_new ("G");
    tmr_senone = cyctimer_new ("S");
    tmr_align = cyctimer_new ("A");

    /* Initialize align module */
    align_init ();
    printf ("\n");
    
    tot_nfr = 0;
    
    process_ctlfile ();

    if (tot_nfr > 0) {
	printf ("\n");
	printf("TOTAL FRAMES:       %8d\n", tot_nfr);
	printf("TOTAL CPU TIME:     %11.2f sec, %7.2f xRT\n",
	       tm_utt->t_tot_cpu, tm_utt->t_tot_cpu/(tot_nfr*0.01));
	printf("TOTAL ELAPSED TIME: %11.2f sec, %7.2f xRT\n",
	       tm_utt->t_tot_elapsed, tm_utt->t_tot_elapsed/(tot_nfr*0.01));
    }

#if (! WIN32)
    system ("ps aguxwww | grep s3align");
#endif

    /* Hack!! To avoid hanging problem under Linux */
    if (logfp) {
	fclose (logfp);
	*stdout = orig_stdout;
	*stderr = orig_stderr;
    }
    
    exit(0);
}
main (int32 argc, char *argv[])
{
    char *str;
    
#if 0
    ckd_debug(100000);
#endif
    
    /* Digest command line argument definitions */
    cmd_ln_define (defn);

    if ((argc == 2) && (strcmp (argv[1], "help") == 0)) {
	cmd_ln_print_definitions();
	exit(1); 
    }

    /* Look for default or specified arguments file */
    str = NULL;
    if ((argc == 2) && (argv[1][0] != '-'))
	str = argv[1];
    else if (argc == 1) {
	str = "s3decode.arg";
	E_INFO("Looking for default argument file: %s\n", str);
    }
    if (str) {
	/* Build command line argument list from file */
	if ((argc = load_argfile (str, argv[0], &argv)) < 0) {
	    fprintf (stderr, "Usage:\n");
	    fprintf (stderr, "\t%s argument-list, or\n", argv[0]);
	    fprintf (stderr, "\t%s [argument-file] (default file: s3decode.arg)\n\n",
		     argv[0]);
	    cmd_ln_print_definitions();
	    exit(1);
	}
    }
    
    cmdline_parse (argc, argv);

    /* Remove memory allocation restrictions */
    unlimit ();
    
#if (! WIN32)
    {
	char buf[1024];
	
	gethostname (buf, 1024);
	buf[1023] = '\0';
	E_INFO ("Executing on: %s\n", buf);
    }
#endif

    E_INFO("%s COMPILED ON: %s, AT: %s\n\n", argv[0], __DATE__, __TIME__);
    
    if ((cmd_ln_access("-mdeffn") == NULL) ||
	(cmd_ln_access("-dictfn") == NULL) ||
	(cmd_ln_access("-lmfn") == NULL))
	E_FATAL("Missing -mdeffn, -dictfn, or -lmfn argument\n");
    
    /*
     * Initialize log(S3-base).  All scores (probs...) computed in log domain to avoid
     * underflow.  At the same time, log base = 1.0001 (1+epsilon) to allow log values
     * to be maintained in int32 variables without significant loss of precision.
     */
    if (cmd_ln_access("-logbase") == NULL)
	logs3_init (1.0001);
    else {
	float32 logbase;
    
	logbase = *((float32 *) cmd_ln_access("-logbase"));
	if (logbase <= 1.0)
	    E_FATAL("Illegal log-base: %e; must be > 1.0\n", logbase);
	if (logbase > 1.1)
	    E_WARN("Logbase %e perhaps too large??\n", logbase);
	logs3_init ((float64) logbase);
    }
    
    /* Read in input databases */
    models_init ();

    /* Allocate timing object */
    tm_utt = timing_new ();
    tot_nfr = 0;
    
    /* Initialize forward Viterbi search module */
    dag_init ();
    printf ("\n");
    
    process_ctlfile ();

    printf ("\n");
    printf("TOTAL FRAMES:       %8d\n", tot_nfr);
    if (tot_nfr > 0) {
	printf("TOTAL CPU TIME:     %11.2f sec, %7.2f xRT\n",
	       tm_utt->t_tot_cpu, tm_utt->t_tot_cpu/(tot_nfr*0.01));
	printf("TOTAL ELAPSED TIME: %11.2f sec, %7.2f xRT\n",
	       tm_utt->t_tot_elapsed, tm_utt->t_tot_elapsed/(tot_nfr*0.01));
    }
    fflush (stdout);

#if (! WIN32)
    system ("ps auxwww | grep s3dag");
#endif

    /* Hack!! To avoid hanging problem under Linux */
    if (logfp) {
	fclose (logfp);
	*stdout = orig_stdout;
	*stderr = orig_stderr;
    }

    exit(0);
}
Ejemplo n.º 10
0
int menu(const menuItem Menu)
{
	signed char line_screen = 1;
	signed char line_menu = 0;
	displayMenu(Menu, line_menu);
	ssd1306InvertArea(0, MARGIN, HIGHLIGHT_LENGHT, HIGHLIGHT_HEIGHT);
	ssd1306Refresh();
	while (true)
	{
		int joystick = expanderJoyFiltered();
		// Exit Button JOYSTICK_LEFT
		switch (joystick)
		{
		case JOY_LEFT:
			return SUCCESS;
			break;
			// Joystick down
		case JOY_DOWN:
			//beeper
			if (Menu.line[line_menu + 1].name != null)
			{
				line_menu++;
				line_screen++;
				if (line_screen > MAX_LINE_SCREEN)
				{
					line_screen--;
					displayMenu(Menu, line_menu - (line_screen - 1));
					ssd1306InvertArea(0, line_screen * MARGIN,
							HIGHLIGHT_LENGHT, HIGHLIGHT_HEIGHT);
					ssd1306Refresh();
				}
				else
				{
					menuHighlightedMove((line_screen - 1) * ROW_HEIGHT + 1,
							(line_screen) * ROW_HEIGHT);
				}
			}
			break;
		case JOY_UP:
			//beeper
			if (line_screen == 1)
			{
				if (line_menu > 0)
				{
					line_menu--;
					displayMenu(Menu, line_menu);
					ssd1306InvertArea(0, MARGIN, HIGHLIGHT_LENGHT,
							HIGHLIGHT_HEIGHT);
					ssd1306Refresh();
				}
			}
			else
			{
				line_menu--;
				line_screen--;
				menuHighlightedMove((line_screen + 1) * ROW_HEIGHT - 1,
						(line_screen) * ROW_HEIGHT);
			}
			break;
		case JOY_RIGHT: // Validate button joystick right
			//hal_beeper_beep(app_context.beeper, 4000, 10);
			switch (Menu.line[line_menu].type)
			{
			case 'b':
				modifyBoolParam(Menu.line[line_menu].name,
						(unsigned char*) Menu.line[line_menu].param);
				break;
			case 'i':
				modifyLongParam(Menu.line[line_menu].name,
						(long*) (int*) Menu.line[line_menu].param);
				break;
			case 'l':
				modifyLongParam(Menu.line[line_menu].name,
						(long*) Menu.line[line_menu].param);
				break;
			case 'm':
				menu(*(const menuItem*) Menu.line[line_menu].param);
				break;
			case 'f':
				if (Menu.line[line_menu].param != null)
				{
					ssd1306ClearScreen();
					ssd1306Refresh();
					Menu.line[line_menu].param();
				}
				break;
			case 'g':
				graphMotorSettings(
						(float*) Menu.line[line_menu - 3].param,
						(float*) Menu.line[line_menu - 2].param,
						(float*) Menu.line[line_menu - 1].param);
				break;
			default:
				break;
			}
			displayMenu(Menu, line_menu - (line_screen - 1));
			ssd1306InvertArea(0, MARGIN * line_screen, HIGHLIGHT_LENGHT,
					HIGHLIGHT_HEIGHT);
			ssd1306Refresh();
			break;
			default:
				break;
		}
		cmdline_parse();
	}
	return -1;
}
Ejemplo n.º 11
0
Archivo: start.c Proyecto: mato/solo5
        ;

    cpu_init();
    platform_init(arg);

    /*
     * Switch away from the bootstrap stack (in boot.S) as early as possible.
     */
    _newstack(platform_mem_size(), _start2, 0);
}

static void _start2(void *arg __attribute__((unused)))
{
    static struct solo5_start_info si;

    si.cmdline = cmdline_parse(platform_cmdline());

    log(INFO, "            |      ___|\n");
    log(INFO, "  __|  _ \\  |  _ \\ __ \\\n");
    log(INFO, "\\__ \\ (   | | (   |  ) |\n");
    log(INFO, "____/\\___/ _|\\___/____/\n");

    mem_init();
    time_init();
    pci_enumerate();
    cpu_intr_enable();

    mem_lock_heap(&si.heap_start, &si.heap_size);
    solo5_exit(solo5_app_main(&si));
}
Ejemplo n.º 12
0
Archivo: init.c Proyecto: fixos/fixos
// Real entry point of the OS :
void init() {
	unsigned int freq;

	interrupt_init();

	earlyterm_init();
	earlyterm_clear();

	kbd_init();
	rtc_init();
	time_init();

	earlyterm_write("Kernel initialization...\n");

	set_kernel_print(&earlyterm_write);
	printk(LOG_INFO, "cmd args: '%s'\n", &cmdargs_begin);

	cmdline_parse(&cmdargs_begin, 1024);

	mmu_init();
	pm_init_pages();

	stimer_init();
	hwkbd_start_periodic_update();

	DBG_WAIT;

	interrupt_inhibit_all(0);


	// console initialisation as soon as possible
	dev_init();
	// add TTY device (on major 4)
	ttydev_device.init();
	dev_register_device(&ttydev_device, 4);

	// add virtual terminal TTYs
	vt_init();

	// USB initialisation
	usb_init();
	// add usb-acm TTY
	acm_usb_init();

	DBG_WAIT;

	// will be the last message displayed on early console
	printk(LOG_INFO, "Switching screen to tty1...\n  The display will be cleared.\n");
	console_make_active();

	// in all cases, Virtual Terminals should be made active (tty1)
	DBG_WAIT;
	vt_set_active(0);


	// need to be changed for "overclocking" :
	//freq_change(FREQ_STC_4, FREQ_DIV_1, FREQ_DIV_4);
	
	freq_time_calibrate();

	freq = freq_get_internal_hz();
	printk(LOG_INFO, "CPU freq : %d.%dMHz\n", freq/1000000, (freq/100000)%10);

	freq = freq_get_peripheral_hz();
	printk(LOG_INFO, "Peripheral freq : %d.%dMHz\n", freq/1000000, (freq/100000)%10);

	// initialize sysctl tables
	ctl_init();

	//test_keyboard_int();

	//test_virtual_mem();

	//asm volatile ("trapa #50");

	//DBG_WAIT;
	

	// Initializing VFS and device sub-sytems, mount platform filesystems,
	// register platform devices...
	
	vfs_init();
	vfs_file_init();

	vfs_register_fs(&smemfs_file_system, VFS_REGISTER_STATIC);
	vfs_register_fs(&protofs_file_system, VFS_REGISTER_STATIC);
	vfs_mount("protofs", NULL, VFS_MOUNT_ROOT);

	vfs_create("/", "dev", INODE_TYPE_PARENT, INODE_FLAG_READ | INODE_FLAG_EXEC, 0);
	vfs_create("/dev", "tty1", INODE_TYPE_DEV, INODE_FLAG_WRITE, 0x00040000);
	vfs_create("/dev", "tty2", INODE_TYPE_DEV, INODE_FLAG_WRITE, 0x00040001);
	vfs_create("/dev", "serial", INODE_TYPE_DEV, INODE_FLAG_WRITE, 0x00030000);

	vfs_create("/dev", "console", INODE_TYPE_DEV, INODE_FLAG_WRITE, 
			console_get_device());

	DBG_WAIT;

	// keyboard input for virtual terminals
	kbd_set_kstroke_handler(&vt_key_stroke);


	// mount additional filesystems
	vfs_create("/", "mnt", INODE_TYPE_PARENT, INODE_FLAG_WRITE, 0);
	vfs_create("/mnt", "smem", INODE_TYPE_PARENT, INODE_FLAG_WRITE, 0);

	vfs_mount("smemfs", "/mnt/smem", VFS_MOUNT_NORMAL);
	
	DBG_WAIT;

	// set /dev/display device
	_display_device.init();
	dev_register_device(&_display_device, 0x20);
	vfs_create("/dev", "display", INODE_TYPE_DEV, INODE_FLAG_WRITE, 0x00200001);


	// direct keyboard device on major 0x21
	fxkeyboard_device.init();
	dev_register_device(&fxkeyboard_device, 0x21);
	vfs_create("/dev", "keyboard", INODE_TYPE_DEV, INODE_FLAG_WRITE, 0x00210000);


	DBG_WAIT;

	//test_keymatrix();
//	test_keyboard();
	/*while(1) {
		char c;
		if(vfs_read(console, &c, 1) == 1) {
			vfs_write(console, &c, 1);
		}
	}*/

	DBG_WAIT;

	//test_vfs();

	//test_sdcard();

	//test_sleep_funcs();


	// EEPROM-related code commented to avoid useless write cycles ;)
	//test_eeprom();
	
	/*char mybuf[128];
	int len;

	len = usb_receive(USB_EP_ADDR_EP1OUT, mybuf, 10, 0);
	printk(LOG_DEBUG, "usb_receive ret=%d\n", len);
	if(len > 0) {
		mybuf[len] = '\0';
		printk(LOG_DEBUG, "content = '%s'\n", mybuf);
	}
	

	while(!_magic_lock);
	set_kernel_print(&print_usb_ep2);

	test_vfs();
*/

	// memory area subsystem
	mem_area_init();
	

	process_init();
	sched_init();
	test_process();
	

	printk(LOG_WARNING, "End of init job, sleeping...\n");
	while(1)
		printk(LOG_WARNING, "IER: 0x%x 0x%x\n", USB.IFR0.BYTE, USB.IFR1.BYTE);
}
Ejemplo n.º 13
0
static Token* cmdline_parse(Cmdline *cmdline, Token *word, UT_array *parent)
{
  char ch;
  bool seek;
  Cmdstr cmd = {.ed = 0};
  if (word)
    cmd.st = word->start;

  QUEUE *stack = &cmd.stack;
  QUEUE_INIT(stack);

  cmd.args = list_new(cmdline);
  stack_push(stack, cmd.args);
  Token *headref = stack_head(stack);
  utarray_new(cmd.chlds, &chld_icd);

  check_flags(cmdline, &cmd);

  int idx = 0;
  while ((word = (Token*)utarray_next(cmdline->tokens, word))) {
    char *str = token_val(word, VAR_STRING);

    if (word->quoted) {
      push(*word, stack, word->start);
      pop(stack, cmdline, &idx);
      continue;
    }

    switch(ch = str[0]) {
      case '(':
        cmdline->lvl++;
        word = cmdline_parse(cmdline, word, cmd.chlds);
        ((Cmdstr*)utarray_back(cmd.chlds))->idx = idx - 1;
        if (!word)
          goto breakout;
        break;
      case ')':
        if (cmdline->lvl < 1)
          break;
        cmdline->lvl--;
        cmd.ed = word->start;
        goto breakout;
      case '[':
        push(list_new(cmdline), stack, word->start);
        stack_head(stack)->start = word->start;
        break;
      case ']':
        if (!valid_arry(cmdline, stack, headref))
          break;
        stack_head(stack)->end = word->end;
        push_arry_container(cmdline, headref, word);
        pop(stack, cmdline, &idx);
        break;
      case '|':
        if (cmdline->lvl < 1) {
          cmd.bar = true;
          cmd.ed = word->start;
          goto breakout;
        }
      /*FALLTHROUGH*/
      case '.':
      case ':':
      case ',':
        break;
      case '%':
      case '$':
        word = valid_var(cmdline, word, ch);
      case '!':
        if (valid_exec(cmdline, &cmd, word))
          break;
      /*FALLTHROUGH*/
      default:
        seek = seek_ahead(cmdline, stack, word);
        push(*word, stack, word->start);
        if (!seek)
          pop(stack, cmdline, &idx);
    }
  }
breakout:
  while (!QUEUE_EMPTY(stack))
    stack_pop(stack);

  utarray_push_back(parent, &cmd);
  return word;
}

void cmdline_build_tokens(Cmdline *cmdline, char *line)
{
  log_msg("CMDSTR", "cmdline_build_tokens");
  SWAP_ALLOC_PTR(cmdline->line, strdup(line));
  Token *word = NULL;
  while ((word = (Token*)utarray_next(cmdline->tokens, word)))
    free(word->var.vval.v_string);
  utarray_clear(cmdline->tokens);
  cmdline_tokenize(cmdline);
}