/* Given fname, find the bootinfo module associated with it. Return NULL on failure */ static L4_BootRec_t * find_bootrec(const char *fname) { L4_KernelInterfacePage_t *kip; L4_BootRec_t *rec; void *bootinfo; unsigned num_recs, objs; /* Iterate through bootinfo */ kip = L4_GetKernelInterface(); bootinfo = (void*) L4_BootInfo(kip); num_recs = L4_BootInfo_Entries(bootinfo); rec = L4_BootInfo_FirstEntry(bootinfo); while(num_recs > 0) { L4_Word_t type; /* find what type it is */ type = L4_BootRec_Type(rec); objs = 0; if (type == L4_BootInfo_Module && (strcmp(L4_Module_Cmdline(rec), fname) == 0)) { /* Found it! */ break; } rec = L4_BootRec_Next(rec); num_recs--; } if (num_recs > 0) { return rec; } else { return NULL; } }
void freevms_main(void) { char *command_line; # define ROOT_DEVICE_LENGTH 80 char root_device[ROOT_DEVICE_LENGTH]; # define CONSOLE_DEVICE_LENGTH 80 char console_device[CONSOLE_DEVICE_LENGTH]; L4_BootRec_t *boot_record; L4_KernelInterfacePage_t *kip; L4_ProcDesc_t *main_proc_desc; L4_ThreadId_t root_tid; L4_ThreadId_t s0_tid; L4_Word_t api_flags; L4_Word_t boot_info; L4_Word_t i; L4_Word_t kernel_id; L4_Word_t kernel_interface; L4_Word_t num_boot_info_entries; L4_Word_t num_processors; L4_Word_t page_bits; L4_Word_t pagesize; struct vms$meminfo mem_info; vms$pd_initialized = 0; notice("\n"); notice(">>> FreeVMS %s (R)\n", FREEVMS_VERSION); notice("\n"); kip = (L4_KernelInterfacePage_t *) L4_KernelInterface(&kernel_interface, &api_flags, &kernel_id); notice(SYSBOOT_I_SYSBOOT "leaving kernel privileges\n"); notice(SYSBOOT_I_SYSBOOT "launching FreeVMS kernel with executive " "privileges\n"); root_tid = L4_Myself(); s0_tid = L4_GlobalId(kip->ThreadInfo.X.UserBase, 1); notice(SYSBOOT_I_SYSBOOT "booting main processor\n"); for(page_bits = 0; !((1 << page_bits) & L4_PageSizeMask(kip)); page_bits++); pagesize = (((vms$pointer) 1) << page_bits); notice(SYSBOOT_I_SYSBOOT "computing page size: %d bytes\n", (int) pagesize); num_processors = L4_NumProcessors((void *) kip); switch(num_processors - 1) { case 0: break; case 1: notice(SYSBOOT_I_SYSBOOT "booting %d secondary processor\n", (int) (num_processors - 1)); break; default: notice(SYSBOOT_I_SYSBOOT "booting %d secondary processors\n", (int) (num_processors - 1)); break; } for(i = 0; i < num_processors; i++) { main_proc_desc = L4_ProcDesc((void *) kip, i); notice(SYSBOOT_I_SYSBOOT "CPU%d EXTFREQ=%d MHz, INTFREQ=%d MHz\n", (int) i, (int) (main_proc_desc->X.ExternalFreq / 1000), (int) (main_proc_desc->X.InternalFreq / 1000)); } L4_Sigma0_GetPage(L4_nilthread, L4_Fpage(L4_BootInfo(kip), pagesize)); boot_info = L4_BootInfo((void *) kip); num_boot_info_entries = L4_BootInfo_Entries((void *) boot_info); boot_record = L4_BootInfo_FirstEntry((void *) boot_info); for(i = 2; i < num_boot_info_entries; i++) { PANIC(L4_BootRec_Type(boot_record) != L4_BootInfo_SimpleExec); command_line = L4_SimpleExec_Cmdline(boot_record); if ((strstr(command_line, "vmskernel.sys") != NULL) && (i == 3)) { break; } boot_record = L4_BootRec_Next(boot_record); } PANIC(L4_BootRec_Type(boot_record) != L4_BootInfo_SimpleExec); command_line = L4_SimpleExec_Cmdline(boot_record); notice(SYSBOOT_I_SYSBOOT "parsing command line: %s\n", command_line); sys$parsing(command_line, (char *) "root", root_device, ROOT_DEVICE_LENGTH); notice(SYSBOOT_I_SYSBOOT "selecting root device: %s\n", root_device); sys$parsing(command_line, (char *) "console", console_device, CONSOLE_DEVICE_LENGTH); notice(SYSBOOT_I_SYSBOOT "selecting console device: %s\n", console_device); dbg$virtual_memory = (strstr(command_line, " dbg$virtual_memory") != NULL) ? 1 : 0; dbg$sys_pagefault = (strstr(command_line, " dbg$sys_pagefault") != NULL) ? 1 : 0; dbg$vms_pagefault = (strstr(command_line, " dbg$vms_pagefault") != NULL) ? 1 : 0; // Starting virtual memory subsystem sys$mem_init(kip, &mem_info, pagesize); sys$bootstrap(&mem_info, pagesize); sys$objtable_init(); sys$utcb_init(kip); sys$pd_init(&mem_info); sys$thread_init(kip); sys$populate_init_objects(&mem_info, pagesize); dev$init(); names$init(); sys$pager(kip, &mem_info, pagesize, root_device); sys$init(kip, &mem_info, pagesize, root_device); sys$loop(); notice(">>> System halted\n"); return; }
int main (void) { L4_Word_t total; printf("\n\nHasenpfeffer operating system\n"); printf("Copyright (C) 2005,2006. Senko Rasic <*****@*****.**>\n\n"); printf("Initializing root task...\n"); L4_KernelInterfacePage_t *kip = (L4_KernelInterfacePage_t *) L4_GetKernelInterface(); void *bi = (void *) L4_BootInfo(kip); // we need to preload these I/O pages // ATA L4_Sigma0_GetPage(L4_nilthread, L4_Fpage(0x0000, 4096)); // KIP L4_Sigma0_GetPage(L4_nilthread, L4_Fpage(L4_BootInfo(kip), 4096)); L4_BootRec_t *br = NULL; if (L4_BootInfo_Valid((void *) bi)) { int n = L4_BootInfo_Entries(bi); br = L4_BootInfo_FirstEntry(bi); while (--n) { /* touch roottask data from here, because sigma0 only gives pages to initial *thread* */ if (L4_BootRec_Type(br) == L4_BootInfo_SimpleExec) { L4_Word_t mi; for (mi = 0; mi < L4_Module_Size(br); mi += 4096) { L4_Sigma0_GetPage(L4_nilthread, L4_Fpage(L4_Module_Start(br) + mi, 4096)); } } br = L4_BootRec_Next(br); } } else { printf("panic: invalid bootinfo data\n"); return 0; } memory_init(); total = memory_get_free(); printf("Creating root memory manager...\n"); mman_tid = create_local_thread("root memory manager", kip, 1, memman, 4096); thread_init(mman_tid); printf("Initializing root task manager...\n"); HpfCapability full, newthread, newtask; task_manager_init(&full, &newtask, &newthread); dir_paths[0] = "/process/TaskManager"; dir_caps[0] = full; n_paths = 1; printf("Loading initial programs...\n"); int n = L4_BootInfo_Entries(bi); br = L4_BootInfo_FirstEntry(bi); int first_program = 1; while (--n) { if (L4_BootRec_Type(br) == L4_BootInfo_Module) { L4_ThreadId_t tid = launch(br); if (first_program) { first_program = 0; // this is the root directory server if (hermes_capability(tid, &(dir_caps[1]))) { // dir_paths[1] = "/process/DirectoryService"; dir_paths[1] = ""; // <- catch-all n_paths = 2; } } } br = L4_BootRec_Next(br); } printf("Init done, running...\n\n"); task_manager_main(); return 0; }
static unsigned int sys$bootinfo_find_initial_objects(L4_KernelInterfacePage_t *kip, unsigned int max, struct initial_obj *initial_objs) { char data_name[INITIAL_NAME_MAX]; L4_BootRec_t *record; L4_Word_t dsize; L4_Word_t dstart; L4_Word_t tsize; L4_Word_t tstart; L4_Word_t type; unsigned int count; unsigned int flags; unsigned int num_recs; unsigned int objects; void *bootinfo; # define DIT_INITIAL 32L // Root task bootinfo = (void*) L4_BootInfo(kip); count = 0; // Check bootinfo validity if (L4_BootInfo_Valid(bootinfo) == 0) { return(0); } num_recs = L4_BootInfo_Entries(bootinfo); record = L4_BootInfo_FirstEntry(bootinfo); while(num_recs > 0) { PANIC(record == NULL); type = L4_BootRec_Type(record); objects = 0; switch(type) { case L4_BootInfo_Module: sys$add_initial_object(initial_objs++, L4_Module_Cmdline(record), L4_Module_Start(record), (L4_Module_Start(record) + L4_Module_Size(record)) - 1, 0, VMS$IOF_APP | VMS$IOF_PHYS); objects = 1; break; case L4_BootInfo_SimpleExec: if (L4_SimpleExec_Flags(record) & DIT_INITIAL) { flags = VMS$IOF_ROOT | VMS$IOF_VIRT; } else { flags = VMS$IOF_APP; } tstart = L4_SimpleExec_TextVstart(record); tsize = L4_SimpleExec_TextSize(record); dstart = L4_SimpleExec_DataVstart(record); dsize = L4_SimpleExec_DataSize(record); sys$add_initial_object(initial_objs++, L4_SimpleExec_Cmdline(record), tstart, (tstart + tsize) - 1, L4_SimpleExec_InitialIP(record), flags | VMS$IOF_PHYS); objects = 1; if ((!((dstart < (tstart + tsize) && dstart >= tstart))) && (dsize != 0)) { sys$strncpy(data_name, L4_SimpleExec_Cmdline(record), INITIAL_NAME_MAX - 5); sys$strncat(data_name, ".data", INITIAL_NAME_MAX); sys$add_initial_object(initial_objs++, data_name, dstart, dstart + dsize - 1, 0, VMS$IOF_ROOT | VMS$IOF_VIRT | VMS$IOF_PHYS); objects++; } break; case L4_BootInfo_Multiboot: sys$add_initial_object(initial_objs++, "MultiBoot information", L4_MBI_Address(record), L4_MBI_Address(record) + 0xFFF, 0, VMS$IOF_PHYS | VMS$IOF_BOOT | VMS$IOF_VIRT); objects = 1; break; default: PANIC(1); break; } if (objects > 0) { count += objects; if (count == max) goto overflow; } record = L4_BootRec_Next(record); num_recs--; } sys$add_initial_object(initial_objs++, "Boot", (vms$pointer) bootinfo, (vms$pointer) bootinfo + (L4_BootInfo_Size(bootinfo) - 1), 0, VMS$IOF_BOOT | VMS$IOF_PHYS | VMS$IOF_VIRT); count++; overflow: return count; }