/* 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; } }
L4_ThreadId_t vmctrl_get_root_tid( void ) { void *kip = L4_GetKernelInterface(); // sigma0 = 0 + L4_ThreadIdUserBase(kip) // sigma1 = 1 + L4_ThreadIdUserBase(kip) // root task = 2 + L4_ThreadIdUserBase(kip) return L4_GlobalId( 2+L4_ThreadIdUserBase(kip), 1 ); }
int vmctrl_detect_l4( void ) { signal_handler_t old; void *kip; // On x86, L4_GetKernelInterface() is implemented with an illegal // instruction, and is thus a good way to test whether we are running on // L4 or not. old = signal( SIGILL, (signal_handler_t)illegal_instruction_signal ); kip = L4_GetKernelInterface(); if( old != SIG_ERR ) signal( SIGILL, old ); return NULL != kip; }
int main( int argc, char *argv[] ) { L4_ThreadId_t earmmgr, locator; L4_MsgTag_t tag; L4_Msg_t msg; L4_Word_t logid = 0; L4_Word_t guid = 0; L4_Word_t budget = 0; CORBA_Environment ipc_env; if( argc < 3 ) usage(argv[0]); guid = strtoul(argv[1], NULL, 0); logid = strtoul(argv[2], NULL, 0); budget = strtoul(argv[3], NULL, 0); locator = L4_GlobalId( 2+L4_ThreadIdUserBase(L4_GetKernelInterface()), 1 ); printf("locator %p\n", locator.raw); ipc_env = idl4_default_environment; IResourcemon_query_interface( locator, UUID_IEarm_Manager, &earmmgr, &ipc_env ); if( ipc_env._major == CORBA_USER_EXCEPTION ) { CORBA_exception_free(&ipc_env); return -ENODEV; } else if( ipc_env._major != CORBA_NO_EXCEPTION ) { CORBA_exception_free(&ipc_env); return -EIO; } printf("earm mgr %p\n", earmmgr.raw); printf("Setting guid %d logid %d budget %d\n", guid, logid, budget); ipc_env = idl4_default_environment; IEarm_Manager_budget_resource( earmmgr, guid, logid, budget, &ipc_env ); }
void calibrate_delay_loop(void) { L4_KernelInterfacePage_t *kip = L4_GetKernelInterface(); L4_Time_t readp = { .raw = kip->ClockInfo.X.ReadPrecision }; clock_step = time_in_us(readp); if(clock_step > 1000000) { printf("kernel reports scheduleprecision of %u µs (too high!)\n", clock_step); abort(); } hz = 1000000 / clock_step; printf("calibrating delay loop... (hz %u, clock_step %u)\n", hz, clock_step); iters_per_tick = measure(15); assert(iters_per_tick > 0); printf(" %lu.%02lu BogoMIPS (%lu iters / tick)\n", iters_per_tick / (500000 / hz), (iters_per_tick / (5000 / hz)) % 100, iters_per_tick); #if 0 /* testing. */ for(int i=1; i<=25; i++) { L4_Clock_t start = L4_SystemClock(); do { delay_loop(200); } while(L4_SystemClock().raw < start.raw + 1); int ticks = i * 2; delay_loop(iters_per_tick * ticks); L4_Clock_t end = L4_SystemClock(); if(start.raw + ticks != end.raw) { printf("wanted to wait for %d ticks, waited for %d\n", ticks, (int)(end.raw - start.raw)); } } #endif }
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; }