3 * \brief x86_32 kernel bootup code.
7 * Copyright (c) 2007-2013 ETH Zurich.
10 * This file is distributed under the terms in the attached LICENSE file.
11 * If you do not find this file, copies can be found by writing to:
12 * ETH Zurich D-INFK, Universitaetstr. 6, CH-8092 Zurich. Attn: Systems Group.
17 #include <paging_kernel_arch.h>
19 #include <kernel_multiboot.h>
22 #include <barrelfish_kpi/cpu.h>
24 #include <getopt/getopt.h>
26 #include <barrelfish_kpi/init.h>
27 #include <arch/x86/apic.h>
30 #include <barrelfish_kpi/paging_arch.h>
31 #include <barrelfish_kpi/syscalls.h>
32 #include <target/x86/barrelfish_kpi/coredata_target.h>
36 #include <arch/x86/startup_x86.h>
38 /// Quick way to find the base address of a cnode capability
39 #define CNODE(cte) (cte)->cap.u.cnode.cnode
42 * init's needed boot pages.
44 #define INIT_PDIR_SIZE X86_32_PDIR_ENTRIES(X86_32_INIT_SPACE_LIMIT)
45 #define INIT_PTABLE_SIZE X86_32_PTABLE_ENTRIES(X86_32_INIT_SPACE_LIMIT)
46 #define INIT_PAGE_BITMAP X86_32_PTABLE_PRESENT
48 /// Pointer to bootinfo structure for init
49 static struct bootinfo *bootinfo = (struct bootinfo *)BOOTINFO_BASE;
51 static struct spawn_state spawn_state;
55 * Page directory pointer table for init user address space.
57 static union x86_32_pdpte_entry *init_pdpte; //[INIT_PDPT_SIZE][PTABLE_SIZE]
61 * Page directory for init user address space.
63 static union x86_32_pdir_entry *init_pdir; //[INIT_PDPT_SIZE][INIT_PDIR_SIZE][PTABLE_SIZE]
66 * Page tables for init user address space.
68 static union x86_32_ptable_entry *init_ptable; //[INIT_PDPT_SIZE][INIT_PDIR_SIZE][INIT_PTABLE_SIZE][PTABLE_SIZE]
71 * \brief Convert elf flags to page flags
73 * \param flags ELF64 program segment flags.
77 * Not all combinations may be supported by an architecture
79 static paging_x86_32_flags_t paging_elf_to_page_flags(uint32_t flags)
81 paging_x86_32_flags_t pageflags = 0;
83 pageflags |= flags & PF_R ? PTABLE_USER_SUPERVISOR : 0;
84 pageflags |= flags & PF_W ? PTABLE_READ_WRITE : 0;
85 pageflags |= flags & PF_X ? 0 : PTABLE_EXECUTE_DISABLE;
91 * \brief Map init user-space memory.
93 * This function maps pages of the init user-space module. It expects
94 * the virtual base address 'vbase' of a program segment of the init executable,
95 * its size 'size' and its ELF64 access control flags. It maps pages
96 * to the sequential area of physical memory, given by 'base'. If you
97 * want to allocate physical memory frames as you go, you better use
98 * startup_alloc_init().
100 * \param vbase Virtual base address of program segment.
101 * \param base Physical base address of program segment.
102 * \param size Size of program segment in bytes.
103 * \param flags ELF64 access control flags of program segment.
105 errval_t startup_map_init(lvaddr_t vbase, lpaddr_t base, size_t size,
110 paging_align(&vbase, &base, &size, BASE_PAGE_SIZE);
111 assert(vbase + size < X86_32_INIT_SPACE_LIMIT);
114 for(vaddr = vbase; vaddr < vbase + size;
115 vaddr += BASE_PAGE_SIZE, base += BASE_PAGE_SIZE) {
117 union x86_32_ptable_entry *ptable_base = &init_ptable[
118 + X86_32_PDPTE_BASE(vaddr) * X86_32_PTABLE_SIZE * X86_32_PTABLE_SIZE
119 + X86_32_PDIR_BASE(vaddr) * X86_32_PTABLE_SIZE
120 + X86_32_PTABLE_BASE(vaddr)];
122 debug(SUBSYS_PAGING, "Mapping 4K page: vaddr = 0x%x, base = 0x%x, "
123 "PDPTE_BASE = %u, PDIR_BASE = %u, "
124 "PTABLE_BASE = %u -- ", vaddr, base, X86_32_PDPTE_BASE(vaddr),
125 X86_32_PDIR_BASE(vaddr), X86_32_PTABLE_BASE(vaddr));
127 union x86_32_ptable_entry *ptable_base = &init_ptable[
128 X86_32_PDIR_BASE(vaddr) * X86_32_PTABLE_SIZE
129 + X86_32_PTABLE_BASE(vaddr)];
131 debug(SUBSYS_PAGING, "Mapping 4K page: vaddr = 0x%"PRIxLVADDR
132 ", base = 0x%"PRIxLPADDR", "
133 "PDIR_BASE = %"PRIuLPADDR", "
134 "PTABLE_BASE = %"PRIuLPADDR" -- ", vaddr, base,
135 X86_32_PDIR_BASE(vaddr), X86_32_PTABLE_BASE(vaddr));
138 if(!X86_32_IS_PRESENT(ptable_base)) {
139 debug(SUBSYS_PAGING, "mapped!\n");
140 paging_x86_32_map(ptable_base, base,
141 INIT_PAGE_BITMAP | paging_elf_to_page_flags(flags));
143 debug(SUBSYS_PAGING, "already existing!\n");
150 /// Create physical address range or RAM caps to unused physical memory
151 static void create_phys_caps(lpaddr_t init_alloc_addr)
156 // map first meg of RAM, which contains lots of crazy BIOS tables
157 err = create_caps_to_cnode(0, X86_32_START_KERNEL_PHYS,
158 RegionType_PlatformData, &spawn_state, bootinfo);
159 assert(err_is_ok(err));
162 /* Walk multiboot MMAP structure, and create appropriate caps for memory */
163 char *mmap_addr = MBADDR_ASSTRING(glbl_core_data->mmap_addr);
164 genpaddr_t last_end_addr = 0;
166 for(char *m = mmap_addr; m < mmap_addr + glbl_core_data->mmap_length;) {
167 struct multiboot_mmap *mmap = (struct multiboot_mmap * SAFE)TC(m);
169 debug(SUBSYS_STARTUP, "MMAP %llx--%llx Type %"PRIu32"\n",
170 mmap->base_addr, mmap->base_addr + mmap->length,
174 // XXX: Remove intersecting regions
176 for(int i = 0; i < bootinfo->regions_length; i++) {
177 struct mem_region *r = &bootinfo->regions[i];
179 // Remove intersecting regions (earlier additions take precedence)
180 if((r->base + (1 << r->bits) >= mmap->base_addr
181 && r->base + (1 << r->bits) <= mmap->base_addr + mmap->length)
182 || (r->base >= mmap->base_addr
183 && r->base <= mmap->base_addr + mmap->length)) {
194 if (last_end_addr >= init_alloc_addr
195 && mmap->base_addr > last_end_addr) {
196 /* we have a gap between regions. add this as a physaddr range */
197 debug(SUBSYS_STARTUP, "physical address range %llx--%llx\n",
198 last_end_addr, mmap->base_addr);
200 err = create_caps_to_cnode(last_end_addr,
201 mmap->base_addr - last_end_addr,
202 RegionType_PhyAddr, &spawn_state, bootinfo);
203 assert(err_is_ok(err));
206 if (mmap->type == MULTIBOOT_MEM_TYPE_RAM) {
207 genpaddr_t base_addr = mmap->base_addr;
208 genpaddr_t end_addr = base_addr + mmap->length;
210 // only map RAM which is greater than init_alloc_addr
211 if (end_addr > local_phys_to_gen_phys(init_alloc_addr)) {
212 if (base_addr < local_phys_to_gen_phys(init_alloc_addr)) {
213 base_addr = local_phys_to_gen_phys(init_alloc_addr);
217 if(base_addr >= X86_32_PADDR_SPACE_SIZE) {
218 printk(LOG_NOTE, "skipping RAM [%llx--%llx] out of "
219 "mappable space\n", base_addr, end_addr);
220 last_end_addr = mmap->base_addr + mmap->length;
224 if(end_addr > X86_32_PADDR_SPACE_SIZE) {
225 printk(LOG_NOTE, "shortening RAM [%llx--%llx] to mappable "
226 "space [0--%llx]\n", base_addr, end_addr,
227 X86_32_PADDR_SPACE_LIMIT);
228 end_addr = X86_32_PADDR_SPACE_SIZE;
233 // XXX: Do not create ram caps for memory the kernel cannot
234 // address to prevent kernel objects from being created there
235 if(base_addr >= PADDR_SPACE_LIMIT) {
236 last_end_addr = mmap->base_addr + mmap->length;
240 if (end_addr > PADDR_SPACE_LIMIT) {
241 end_addr = PADDR_SPACE_LIMIT;
245 debug(SUBSYS_STARTUP, "RAM %llx--%llx\n", base_addr, end_addr);
247 assert(end_addr >= base_addr);
248 err = create_caps_to_cnode(base_addr, end_addr - base_addr,
249 RegionType_Empty, &spawn_state, bootinfo);
250 assert(err_is_ok(err));
252 } else if (mmap->base_addr > local_phys_to_gen_phys(init_alloc_addr)) {
253 /* XXX: The multiboot spec just says that mapping types other than
254 * RAM are "reserved", but GRUB always maps the ACPI tables as type
255 * 3, and things like the IOAPIC tend to show up as type 2 or 4,
256 * so we map all these regions as platform data
258 debug(SUBSYS_STARTUP, "platform %llx--%llx\n", mmap->base_addr,
259 mmap->base_addr + mmap->length);
260 assert(mmap->base_addr > local_phys_to_gen_phys(init_alloc_addr));
261 err = create_caps_to_cnode(mmap->base_addr, mmap->length,
262 RegionType_PlatformData, &spawn_state, bootinfo);
263 assert(err_is_ok(err));
266 last_end_addr = mmap->base_addr + mmap->length;
270 // Assert that we have some physical address space
271 assert(last_end_addr != 0);
273 if (last_end_addr < X86_32_PADDR_SPACE_SIZE) {
275 * FIXME: adding the full range results in too many caps to add
276 * to the cnode (and we can't handle such big caps in user-space
277 * yet anyway) so instead we limit it to something much smaller
279 genpaddr_t size = X86_32_PADDR_SPACE_SIZE - last_end_addr;
280 const genpaddr_t phys_region_limit = 1ULL << 32; // PCI implementation limit
281 if (last_end_addr > phys_region_limit) {
282 size = 0; // end of RAM is already too high!
283 } else if (last_end_addr + size > phys_region_limit) {
284 size = phys_region_limit - last_end_addr;
286 debug(SUBSYS_STARTUP, "end physical address range %llx--%llx\n",
287 last_end_addr, last_end_addr + size);
288 err = create_caps_to_cnode(last_end_addr, size,
289 RegionType_PhyAddr, &spawn_state, bootinfo);
290 assert(err_is_ok(err));
294 #define NEEDED_KERNEL_SPACE \
295 ((SIZE_KERNEL_IMAGE & 0x1000 ) == SIZE_KERNEL_IMAGE ? \
296 SIZE_KERNEL_IMAGE : \
297 (SIZE_KERNEL_IMAGE & 0xfffffffffffff000) + 0x1000)
299 #define OBJSPERPAGE_CTE (1 << (BASE_PAGE_BITS - OBJBITS_CTE))
302 static void init_page_tables(struct spawn_state *st, alloc_phys_func alloc_phys)
304 /* Allocate memory for init's page tables */
306 init_pdpte = (void *)local_phys_to_mem(alloc_phys(X86_32_PDPTE_SIZE
307 * sizeof(union x86_32_pdpte_entry)));
309 init_pdir = (void *)local_phys_to_mem(
310 alloc_phys(X86_32_PTABLE_SIZE * INIT_PDIR_SIZE
311 * sizeof(union x86_32_pdir_entry)));
312 init_ptable = (void *)local_phys_to_mem(
313 alloc_phys(X86_32_PTABLE_SIZE * INIT_PDIR_SIZE
314 * INIT_PTABLE_SIZE * sizeof(union x86_32_ptable_entry)));
316 /* Page table setup */
317 /* Initialize init page tables */
318 for(size_t j = 0; j < INIT_PDIR_SIZE; j++) {
319 paging_x86_32_clear_pdir(&init_pdir[j]);
320 for(size_t k = 0; k < INIT_PTABLE_SIZE; k++) {
321 paging_x86_32_clear_ptable(&init_ptable[j * X86_32_PTABLE_SIZE + k]);
324 /* Map pagetables into pageCN */
325 int pagecn_pagemap = 0;
327 // Map PDPTE into first slot in pagecn
328 caps_create_new(ObjType_VNode_x86_32_pdpt,
329 mem_to_local_phys((lvaddr_t)init_pdpte),
331 caps_locate_slot(CNODE(st->pagecn), pagecn_pagemap++));
333 // Map PDIR into successive slots in pagecn
334 for(size_t i = 0; i < INIT_PDIR_SIZE; i++) {
335 caps_create_new(ObjType_VNode_x86_32_pdir,
336 mem_to_local_phys((lvaddr_t)init_pdir) + i * BASE_PAGE_SIZE,
338 caps_locate_slot(CNODE(st->pagecn), pagecn_pagemap++));
340 // Map page tables into successive slots in pagecn
341 for(size_t i = 0; i < INIT_PTABLE_SIZE; i++) {
342 caps_create_new(ObjType_VNode_x86_32_ptable,
343 mem_to_local_phys((lvaddr_t)init_ptable) + i * BASE_PAGE_SIZE,
345 caps_locate_slot(CNODE(st->pagecn), pagecn_pagemap++));
347 // Connect all page tables to page directories.
348 // init's memory manager expects page tables within the pagecn to
349 // already be connected to the corresponding directories. To avoid
350 // unneccessary special cases, we connect them here.
351 for(lvaddr_t vaddr = 0; vaddr < X86_32_INIT_SPACE_LIMIT;
352 vaddr += BASE_PAGE_SIZE) {
354 union x86_32_pdpte_entry *pdpte_base =
355 &init_pdpte[X86_32_PDPTE_BASE(vaddr)];
356 union x86_32_pdir_entry *pdir_base =
357 &init_pdir[X86_32_PDPTE_BASE(vaddr) * X86_32_PTABLE_SIZE +
358 X86_32_PDIR_BASE(vaddr)];
359 union x86_32_ptable_entry *ptable_base =
360 &init_ptable[X86_32_PDPTE_BASE(vaddr) * X86_32_PTABLE_SIZE *
361 X86_32_PTABLE_SIZE + X86_32_PDIR_BASE(vaddr) *
362 X86_32_PTABLE_SIZE + X86_32_PTABLE_BASE(vaddr)];
364 paging_x86_32_map_pdpte(pdpte_base, mem_to_local_phys((lvaddr_t)pdir_base));
366 union x86_32_pdir_entry *pdir_base =
367 &init_pdir[X86_32_PDIR_BASE(vaddr)];
368 union x86_32_ptable_entry *ptable_base =
369 &init_ptable[X86_32_PDIR_BASE(vaddr) * X86_32_PTABLE_SIZE +
370 X86_32_PTABLE_BASE(vaddr)];
372 paging_x86_32_map_table(pdir_base,
373 mem_to_local_phys((lvaddr_t)ptable_base));
376 /* Switch to init's VSpace */
378 paging_x86_32_context_switch(mem_to_local_phys((lvaddr_t)init_pdpte));
380 paging_x86_32_context_switch(mem_to_local_phys((lvaddr_t)init_pdir));
383 /***** VSpace available *****/
385 /* Map cmdline args R/W into VSpace at ARGS_BASE */
387 paging_x86_32_map_pdpte(&init_pdpte[X86_32_PDPTE_BASE(ARGS_BASE)],
388 mem_to_local_phys((lvaddr_t)init_pdir));
390 paging_x86_32_map_table(&init_pdir[X86_32_PDIR_BASE(ARGS_BASE)],
391 mem_to_local_phys((lvaddr_t)init_ptable));
392 for (int i = 0; i < ARGS_SIZE / BASE_PAGE_SIZE; i++) {
393 paging_x86_32_map(&init_ptable[X86_32_PTABLE_BASE(ARGS_BASE) + i],
394 st->args_page + i * BASE_PAGE_SIZE,
395 INIT_PAGE_BITMAP | paging_elf_to_page_flags(PF_R | PF_W));
399 static struct dcb *spawn_init_common(struct spawn_state *st, const char *name,
400 int argc, const char *argv[],
401 lpaddr_t bootinfo_phys,
402 alloc_phys_func alloc_phys)
406 /* Perform arch-independent spawn */
408 struct dcb *init_dcb = spawn_module(st, name, argc, argv, bootinfo_phys,
409 ARGS_BASE, alloc_phys, ¶maddr);
411 /* Init page tables */
412 init_page_tables(st, alloc_phys);
414 /* Map dispatcher R/W into VSpace starting at vaddr 0x204000
415 * (Starting after Bootinfo pages)*/
417 paging_x86_32_map_pdpte(&init_pdpte[X86_32_PDPTE_BASE(DISPATCHER_BASE)],
418 mem_to_local_phys((lvaddr_t)init_pdir));
420 paging_x86_32_map_table(&init_pdir[X86_32_PDIR_BASE(DISPATCHER_BASE)],
421 mem_to_local_phys((lvaddr_t)init_ptable));
422 for (int i = 0; i < DISPATCHER_SIZE / BASE_PAGE_SIZE; i++) {
423 paging_x86_32_map(&init_ptable[X86_32_PTABLE_BASE(DISPATCHER_BASE) + i],
424 mem_to_local_phys(init_dcb->disp) + i * BASE_PAGE_SIZE,
425 INIT_PAGE_BITMAP | paging_elf_to_page_flags(PF_R | PF_W));
428 struct dispatcher_shared_generic *init_disp =
429 get_dispatcher_shared_generic(init_dcb->disp);
430 struct dispatcher_shared_x86_32 *init_disp_x86_32 =
431 get_dispatcher_shared_x86_32(init_dcb->disp);
433 registers_set_param(&init_disp_x86_32->enabled_save_area, paramaddr);
435 // Map IO cap in task cnode
436 struct cte *iocap = caps_locate_slot(CNODE(st->taskcn), TASKCN_SLOT_IO);
437 err = caps_create_new(ObjType_IO, 0, 0, 0, iocap);
438 assert(err_is_ok(err));
440 /* Set fields in DCB */
443 init_dcb->vspace = mem_to_local_phys((lvaddr_t)init_pdpte);
445 init_dcb->vspace = mem_to_local_phys((lvaddr_t)init_pdir);
448 /* Initialize dispatcher */
449 init_disp->disabled = true;
450 strncpy(init_disp->name, argv[0], DISP_NAME_LEN);
452 /* tell init the vspace addr of its dispatcher */
453 init_disp->udisp = DISPATCHER_BASE;
455 init_disp_x86_32->disabled_save_area.edi = DISPATCHER_BASE;
456 init_disp_x86_32->disabled_save_area.fs = 0;
457 init_disp_x86_32->disabled_save_area.gs = 0;
458 init_disp_x86_32->disabled_save_area.cs = USER_CS;
459 init_disp_x86_32->disabled_save_area.ss = USER_SS;
460 init_disp_x86_32->disabled_save_area.eflags = USER_EFLAGS;
465 struct dcb *spawn_bsp_init(const char *name, alloc_phys_func alloc_phys)
469 /* Only the first core can run this code */
470 assert(apic_is_bsp());
472 /* Allocate bootinfo */
473 lpaddr_t bootinfo_phys = alloc_phys(BOOTINFO_SIZE);
474 memset((void *)local_phys_to_mem(bootinfo_phys), 0, BOOTINFO_SIZE);
476 /* Construct cmdline args */
477 char bootinfochar[16];
478 snprintf(bootinfochar, sizeof(bootinfochar), "%"PRIuLPADDR, BOOTINFO_BASE);
480 const char *argv[6] = { "init", bootinfochar };
484 if(glbl_core_data->urpc_frame_base != 0) {
486 snprintf(coreidchar, sizeof(coreidchar), "%d",
487 glbl_core_data->src_core_id);
488 argv[argc++] = coreidchar;
490 char chan_id_char[30];
491 snprintf(chan_id_char, sizeof(chan_id_char), "chanid=%"PRIu32,
492 glbl_core_data->chan_id);
493 argv[argc++] = chan_id_char;
495 char urpc_frame_base_char[30];
496 snprintf(urpc_frame_base_char, sizeof(urpc_frame_base_char),
497 "frame=%" PRIuGENPADDR, glbl_core_data->urpc_frame_base);
498 argv[argc++] = urpc_frame_base_char;
502 struct dcb *init_dcb = spawn_init_common(&spawn_state, name, argc, argv,
503 bootinfo_phys, alloc_phys);
505 /* Map bootinfo R/W into VSpace at vaddr 0x200000 (BOOTINFO_BASE) */
507 paging_x86_32_map_pdpte(&init_pdpte[0], mem_to_local_phys((lvaddr_t)init_pdir));
508 paging_x86_32_map_table(&init_pdir[1], mem_to_local_phys((lvaddr_t)init_ptable));
509 for (int i = 0; i < BOOTINFO_SIZE / BASE_PAGE_SIZE; i++) {
510 paging_x86_32_map(&init_ptable[i], bootinfo_phys + i * BASE_PAGE_SIZE,
511 INIT_PAGE_BITMAP | paging_elf_to_page_flags(PF_R|PF_W));
514 paging_x86_32_map_table(&init_pdir[0], mem_to_local_phys((lvaddr_t)init_ptable));
515 for (int i = 0; i < BOOTINFO_SIZE / BASE_PAGE_SIZE; i++) {
516 paging_x86_32_map(&init_ptable[i + 512], bootinfo_phys + i * BASE_PAGE_SIZE,
517 INIT_PAGE_BITMAP | paging_elf_to_page_flags(PF_R|PF_W));
521 /* Load init ELF32 binary */
522 struct multiboot_modinfo *module = multiboot_find_module(name);
523 if (module == NULL) {
524 panic("Could not find init module!");
527 err = elf_load(EM_386, startup_alloc_init, &spawn_state,
528 local_phys_to_mem(module->mod_start),
529 MULTIBOOT_MODULE_SIZE(*module), &init_ep);
530 if (err_is_fail(err)) {
531 //err_print_calltrace(err);
532 panic("ELF load of init module failed!");
535 struct dispatcher_shared_x86_32 *init_disp_x86_32 =
536 get_dispatcher_shared_x86_32(init_dcb->disp);
537 init_disp_x86_32->disabled_save_area.eip = init_ep;
539 /* Create caps for init to use */
540 create_module_caps(&spawn_state);
541 lpaddr_t init_alloc_end = alloc_phys(0); // XXX
542 create_phys_caps(init_alloc_end);
544 /* Fill bootinfo struct */
545 bootinfo->mem_spawn_core = NEEDED_KERNEL_SPACE; // Size of kernel
547 /* for (int i = 0; i < bootinfo->regions_length; i++) { */
548 /* printf("%d region %d: 0x%09" PRIxPTR " - 0x%09lx (%lu MB, %u bits)\n", */
549 /* bootinfo->regions[i].mr_type, i, bootinfo->regions[i].mr_base, */
550 /* bootinfo->regions[i].mr_base + (1UL<<bootinfo->regions[i].mr_bits), */
551 /* bootinfo->regions[i].mr_bits >= 20 */
552 /* ? 1UL << (bootinfo->regions[i].mr_bits - 20) : 0, */
553 /* bootinfo->regions[i].mr_bits); */
557 // If app core, map (static) URPC channel
558 if(kernel_scckernel != 0) {
559 printf("SCC app kernel, frame at: 0x%x\n", kernel_scckernel);
560 #define TASKCN_SLOT_MON_URPC (TASKCN_SLOTS_USER+6) ///< Frame cap for urpc comm.
562 err = caps_create_new(ObjType_Frame, kernel_scckernel, 13, 13,
563 caps_locate_slot(CNODE(taskcn), TASKCN_SLOT_MON_URPC));
564 assert(err_is_ok(err));
571 struct dcb *spawn_app_init(struct x86_core_data *core_data,
572 const char *name, alloc_phys_func alloc_phys)
576 /* Construct cmdline args */
577 // Core id of the core that booted this core
579 snprintf(coreidchar, sizeof(coreidchar), "%d", core_data->src_core_id);
581 // IPI channel id of core that booted this core
583 snprintf(chanidchar, sizeof(chanidchar), "chanid=%"PRIu32, core_data->chan_id);
585 // Arch id of the core that booted this core
587 snprintf(archidchar, sizeof(archidchar), "archid=%d",
588 core_data->src_arch_id);
590 const char *argv[5] = { name, coreidchar, chanidchar, archidchar };
594 char urpc_frame_base_char[30];
595 snprintf(urpc_frame_base_char, sizeof(urpc_frame_base_char),
596 "frame=%" PRIuGENPADDR, core_data->urpc_frame_base);
597 argv[argc++] = urpc_frame_base_char;
600 struct dcb *init_dcb = spawn_init_common(&spawn_state, name, argc, argv,
604 struct cte *urpc_frame_cte = caps_locate_slot(CNODE(spawn_state.taskcn),
605 TASKCN_SLOT_MON_URPC);
606 // XXX: Create as devframe so the memory is not zeroed out
607 err = caps_create_new(ObjType_DevFrame, core_data->urpc_frame_base,
608 core_data->urpc_frame_bits,
609 core_data->urpc_frame_bits, urpc_frame_cte);
610 assert(err_is_ok(err));
611 urpc_frame_cte->cap.type = ObjType_Frame;
612 lpaddr_t urpc_ptr = gen_phys_to_local_phys(urpc_frame_cte->cap.u.frame.base);
614 /* Map urpc frame at MON_URPC_BASE */
616 paging_x86_32_map_pdpte(&init_pdpte[X86_32_PDPTE_BASE(MON_URPC_BASE)],
617 mem_to_local_phys((lvaddr_t)init_pdir));
619 paging_x86_32_map_table(&init_pdir[X86_32_PDIR_BASE(MON_URPC_BASE)],
620 mem_to_local_phys((lvaddr_t)init_ptable));
621 for (int i = 0; i < MON_URPC_SIZE / BASE_PAGE_SIZE; i++) {
622 paging_x86_32_map(&init_ptable[X86_32_PTABLE_BASE(MON_URPC_BASE) + i],
623 urpc_ptr + i * BASE_PAGE_SIZE,
624 INIT_PAGE_BITMAP | paging_elf_to_page_flags(PF_R | PF_W));
627 // elf load the domain
628 genvaddr_t entry_point;
629 err = elf_load(EM_386, startup_alloc_init, &spawn_state,
630 local_phys_to_mem(core_data->monitor_binary),
631 core_data->monitor_binary_size, &entry_point);
632 if (err_is_fail(err)) {
633 //err_print_calltrace(err);
634 panic("ELF load of init module failed!");
637 struct dispatcher_shared_x86_32 *init_disp_x86_32 =
638 get_dispatcher_shared_x86_32(init_dcb->disp);
639 init_disp_x86_32->disabled_save_area.eip = entry_point;