xn_err_t sys_xn_shutdown(void) { #ifndef EXOPC void *f; size_t nbytes, nblocks; #endif /* DRE */ /* Flush registry */ try(xr_clean(XN_ALL)); try(xr_flushall(XN_ALL)); #ifndef EXOPC /* Flush free map. */ f = db_get_freemap(&nbytes); printf("nbytes = %d, fnbytes = %d\n", nbytes, super_block.f_nbytes); assert(nbytes == super_block.f_nbytes); nblocks = bytes_to_blocks(nbytes); sync_write(super_block.f_db, f, nblocks); /* Do last to make atomic. */ super_block.clean = 1; super_block.cookie = compute_cookie(&super_block); sync_write(SUPER_BLOCK_DB, &super_block, 1); disk_shutdown(); #endif tmplt_shutdown(); return XN_SUCCESS; /* Should reboot. */ } xn_err_t sys_xn_format(void) { fatal(Not implemented); return XN_SUCCESS; } /* This will be a method. */ xn_err_t sys_install_mount(char *name, db_t *db, size_t nelem, xn_elem_t t, cap_t c) { xn_elem_t res; ensure(write_accessible(db, sizeof *db), XN_CANNOT_ACCESS); /* DRE */ xn_in_kernel = 1; res = root_install(name, db, nelem, t, c); xn_in_kernel = 0; sys_return(res); }
int main(void) { int res; udelay(2000000); debug_init(); printf("\n\nBootOS Stage 2 starting.\n"); printf("Waiting for thread 1...\n"); while(!_thread1_active); printf("Thread 1 is alive, all systems go.\n"); exceptions_init(); lv2_cleanup(); mm_init(); #ifdef USE_NETWORK net_init(); gstate = STATE_START; while(1) { net_poll(); if(sequence()) break; } #endif #ifdef AUTO_HDD static FATFS fatfs; DSTATUS stat; stat = disk_initialize(0); if (stat & ~STA_PROTECT) fatal("disk_initialize() failed"); printf("Mounting filesystem...\n"); res = f_mount(0, &fatfs); if (res != FR_OK) fatal("f_mount() failed"); printf("Reading kboot.conf...\n"); res = readfile("/kboot.conf", conf_buf, MAX_KBOOTCONF_SIZE-1); if (res <= 0) { printf("Could not read kboot.conf (%d), panicking\n", res); lv1_panic(0); } conf_buf[res] = 0; kbootconf_parse(); if (conf.num_kernels == 0) { printf("No kernels found in configuration file. Panicing...\n"); lv1_panic(0); } boot_entry = conf.default_idx; printf("Starting to boot '%s'\n", conf.kernels[boot_entry].label); printf("Loading kernel (%s)...\n", conf.kernels[boot_entry].kernel); kernel_buf = mm_highmem_freestart(); res = readfile(conf.kernels[boot_entry].kernel, kernel_buf, mm_highmem_freesize()); if (res <= 0) { printf("Could not read kernel (%d), panicking\n", res); lv1_panic(0); } printf("Kernel size: %d\n", res); if (kernel_load(kernel_buf, res) != 0) { printf("Failed to load kernel. Rebooting...\n"); lv1_panic(1); } if (conf.kernels[boot_entry].initrd && conf.kernels[boot_entry].initrd[0]) { initrd_buf = mm_highmem_freestart(); res = readfile(conf.kernels[boot_entry].initrd, initrd_buf, mm_highmem_freesize()); if (res <= 0) { printf("Could not read initrd (%d), panicking\n", res); lv1_panic(0); } printf("Initrd size: %d\n", res); mm_highmem_reserve(res); kernel_set_initrd(initrd_buf, res); } kernel_build_cmdline(conf.kernels[boot_entry].parameters, conf.kernels[boot_entry].root); f_mount(0, NULL); disk_shutdown(0); mm_shutdown(); kernel_launch(); #endif printf("Loading embedded kernel...\n"); kernel_buf = mm_highmem_freestart(); printf("Decompressing kernel to %lX...\n", (u64) kernel_buf); res = unzpipe (kernel_buf, __vmlinux, &kernel_sz); if (res) { printf("Cannot decompress kernel, error %d.\n", res); lv1_panic(1); } printf("Kernel size: %ld\n", kernel_sz); if (kernel_load(kernel_buf, kernel_sz) != 0) { printf("Failed to load embedded kernel. Rebooting...\n"); lv1_panic(1); } kernel_build_cmdline("video=ps3fb:mode:0 panic=5", "/dev/sda1"); shutdown_and_launch(); printf("End of main() reached! Rebooting...\n"); lv1_panic(1); return 0; }