void mainthread(void *cmdline) { int rv, fd; rv = rump_init(); bmk_printf("rump kernel init complete, rv %d\n", rv); writestr(1, "Hello, stdout!\n"); bmk_printf("open(/notexisting): "); fd = rump_sys_open("/notexisting", 0); if (fd == -1) { int errno = *bmk_sched_geterrno(); if (errno == RUMP_ENOENT) { bmk_printf("No such file or directory. All is well.\n"); } else { bmk_printf("Something went wrong. errno = %d\n", errno); } } else { bmk_printf("Success?! fd=%d\n", fd); } rump_sys_reboot(0, NULL); }
bmk_platform_halt(const char *panicstring) { if (panicstring) bmk_printf("PANIC: %s\n", panicstring); bmk_printf("baremetal halted (well, spinning ...)\n"); for (;;) continue; }
bmk_platform_halt(const char *panicstring) { if (panicstring) bmk_printf("PANIC: %s\n", panicstring); bmk_printf("halted\n"); for (;;) hlt(); }
int rumpuser_getparam(const char *name, void *buf, size_t buflen) { int rv = 0; if (buflen <= 1) return BMK_EINVAL; if (bmk_strcmp(name, RUMPUSER_PARAM_NCPU) == 0 || bmk_strcmp(name, "RUMP_VERBOSE") == 0) { bmk_strncpy(buf, "1", buflen-1); } else if (bmk_strcmp(name, RUMPUSER_PARAM_HOSTNAME) == 0) { bmk_strncpy(buf, "rumprun", buflen-1); /* for memlimit, we have to implement int -> string ... */ } else if (bmk_strcmp(name, "RUMP_MEMLIMIT") == 0) { unsigned long memsize; char tmp[64]; char *res = buf; unsigned i, j; /* use 50% memory for rump kernel, with an upper limit */ memsize = MIN(MEMSIZE_HILIMIT, bmk_platform_memsize()/2); if (memsize < MEMSIZE_WARNLIMIT) { bmk_printf("rump kernel warning: low on physical " "memory quota (%lu bytes)\n", memsize); bmk_printf("rump kernel warning: " "suggest increasing guest allocation\n"); } for (i = 0; memsize > 0; i++) { bmk_assert(i < sizeof(tmp)-1); tmp[i] = (memsize % 10) + '0'; memsize = memsize / 10; } if (i >= buflen) { rv = BMK_EINVAL; } else { res[i] = '\0'; for (j = i; i > 0; i--) { res[j-i] = tmp[i-1]; } } } else { rv = BMK_ENOENT; } return rv; }
void bmk_multiboot(struct multiboot_info *mbi) { unsigned long cmdlinelen; char *cmdline; bmk_printf_init(bmk_cons_putc, NULL); bmk_core_init(BMK_THREAD_STACK_PAGE_ORDER, PAGE_SIZE); bmk_printf("rump kernel bare metal multibootstrap\n\n"); /* save the command line before something overwrites it */ cmdline = (char *)(uintptr_t)mbi->cmdline; cmdlinelen = bmk_strlen(cmdline); if (cmdlinelen >= BMK_MULTIBOOT_CMDLINE_SIZE) bmk_platform_halt("command line too long, " "increase BMK_MULTIBOOT_CMDLINE_SIZE"); bmk_strcpy(bmk_multiboot_cmdline, cmdline); if ((mbi->flags & MULTIBOOT_MEMORY_INFO) == 0) bmk_platform_halt("multiboot memory info not available\n"); if (parsemem(mbi->mmap_addr, mbi->mmap_length) != 0) bmk_platform_halt("multiboot memory parse failed"); bmk_intr_init(); }
/* * Allocate a 2^n chunk of pages, aligned at 2^n. This is currently * for the benefit of thread stack allocation, and should be going * away in some time when the migration to TLS is complete. */ static void * alignedpgalloc(int shift) { struct stackcache *sc; int align = 1<<shift; size_t alignedoff; void *rv; if (shift == BMK_THREAD_STACK_PAGE_ORDER && (sc = LIST_FIRST(&cacheofstacks)) != NULL) { LIST_REMOVE(sc, sc_entries); return sc; } if (align > MAXPAGEALIGN) align = MAXPAGEALIGN; /* need to leave this much space until the next aligned alloc */ alignedoff = (bmk_membase + currentpg*PAGE_SIZE) % (align*PAGE_SIZE); if (alignedoff) currentpg += align - (alignedoff>>PAGE_SHIFT); rv = bmk_allocpg(1<<shift); if (((unsigned long)rv & (align*PAGE_SIZE-1)) != 0) { bmk_printf("wanted %d aligned, got memory at %p\n", align, rv); bmk_platform_halt("fail"); } return rv; }
static char * jsonordie(void) { if (hardcoded_jsoncfg[0] == '\0') bmk_platform_halt("could not get configuration"); bmk_printf("using hardcoded_jsoncfg\n"); return hardcoded_jsoncfg; }
void bmk_mainthread(void *cmdline) { int rv; rump_boot_setsigmodel(RUMP_SIGMODEL_IGNORE); rv = rump_init(); bmk_printf("rump kernel init complete, rv %d\n", rv); while(1); }
void bmk_platform_freepg2(void *mem, int shift) { if (shift == BMK_THREAD_STACK_PAGE_ORDER) { struct stackcache *sc = mem; LIST_INSERT_HEAD(&cacheofstacks, sc, sc_entries); return; } bmk_printf("WARNING: freepg2 called! (%p, %d)\n", mem, shift); }
void x86_boot(struct multiboot_info *mbi) { cons_init(); bmk_printf("rump kernel bare metal bootstrap\n\n"); cpu_init(); bmk_sched_init(); multiboot(mbi); spl0(); bmk_sched_startmain(bmk_mainthread, multiboot_cmdline); }