/* * boot でメモリを使用する機構の初期化。 * * 第1引数で指定したメモリの最後から、第2引数で指定した分だけを * malloc で使用する。 * */ static void init_malloc (void *last, int size) { (BYTE *)alloc_reg = (BYTE *)last - size; alloc_reg->size = size; alloc_reg->next = alloc_reg; #ifdef nodef boot_printf ("init_malloc: last = 0x%x\n", last); boot_printf ("init_malloc: alloc_reg = 0x%x\n", alloc_reg); boot_printf ("init_malloc: alloc_reg->size = %d\n", alloc_reg->size); boot_printf ("init_malloc: alloc_reg->next = 0x%x\n", alloc_reg->next); #endif }
void bootloader_main(void) { /* Init hardware */ hw_init(); /* Initialize elf-loader environment */ init_elf_loader(); /* Load the nano kernel. Doing this will install exception vectors */ boot_printf("Boot: loading nano kernel ...\n"); nano_init_t * nano_init = (nano_init_t *)load_nano(); //We have to rederive this as an executable cap nano_init = (nano_init_t*)cheri_setoffset(cheri_getpcc(),cheri_getoffset(nano_init)); /* TODO: we could have some boot exception vectors if we want exception handling in boot. */ /* These should be in ROM as a part of the boot image (i.e. make a couple more dedicated sections */ cp0_status_bev_set(0); boot_printf("Boot: loading kernel ...\n"); size_t entry = load_kernel(); boot_printf("Boot: loading init ...\n"); boot_info_t *bi = load_init(); size_t invalid_length = bi->init_end; capability phy_start = cheri_setbounds(cheri_setoffset(cheri_getdefault(), MIPS_KSEG0), invalid_length); /* Do we actually need this? */ //boot_printf("Invalidating %p length %lx:\n", phy_start, invalid_length); //caches_invalidate(phy_start, invalid_length); register_t mem_size = bi->init_end - bi->nano_end; /* Jumps to the nano kernel init. This will completely destroy boot and so we can never return here. * All registers will be cleared apart from a specified few. mem_size of memory will be left unmanaged and the * rest will be returned as a reservation. The third argument is an extra argument to the kernel */ boot_printf("Jumping to nano kernel...\n"); BOOT_PRINT_CAP(nano_init); nano_init(mem_size, entry, bi->init_begin - bi->kernel_begin, bi->init_entry); }
/************************************************************************** * init_memory * * */ void init_memory (void) { volatile int *p; last_addr = (void *)&end; #ifdef PC9801 outb (0x00f2, 0); /* 1M 以上の領域を使用できるようにする。*/ #elif IBMPC /* IBMPC (互換機) で A20 をイネーブルにする。 * 0xD1 -> out (0x64) * 0xDF -> out (0x60) */ enable_A20 (); #endif for (p = (int *)0x100000; (int)p < 0xf000000; (int)p += 0x100000) { *p = 0; *p = 0xAA; if (*p != 0xAA) break; } boot_printf ("Extended Memory = %d K bytes\n", ((int)p - 0x100000) / 1000); boot_printf ("USE Memory = %d bytes\n", last_addr); ext_mem = ((int)p - 0x100000); base_mem = BASE_MEM; real_mem = ext_mem + BASE_MEM; #ifdef nodef /* malloc 機構の初期化 */ init_malloc ((void *)(2 * 1024 * 1024), MALLOC_SIZE); #endif /* 640K バイトから下位 100 K バイトの領域を malloc 用に使用する */ init_malloc ((void *)(640 * 1024), MALLOC_SIZE); }