void start(uint32_t* modulep, void* physbase, void* physfree) { struct smap_t { uint64_t base, length; uint32_t type; }__attribute__((packed)) *smap; while(modulep[0] != 0x9001) modulep += modulep[1]+2; physfree = init_pages(physfree); for(smap = (struct smap_t*)(modulep+2); smap < (struct smap_t*)((char*)modulep+modulep[1]+2*4); ++smap) { if (smap->type == 1 /* memory */ && smap->length != 0) { printf("Available Physical Memory [%x-%x]\n", smap->base, smap->base + smap->length); physfree = make_pages(smap->base, smap->length, physfree); } } printf("KERNEL IN [%p:%p:%x]\n", physbase, physfree, &kernmem); setup_paging(physbase, physfree, 0xb8000, 0xbb200, &kernmem); printf("tarfs in [%p:%p]\n", &_binary_tarfs_start, &_binary_tarfs_end); init_tarfs(&_binary_tarfs_start, &_binary_tarfs_end); idts_setup(); PIC_setup(); process_init(); __asm__ volatile("sti"); init(); }
void kmain(void) { init_bss(); init_ro(); setup_kernel_memory(); setup_pages(); setup_ints(); setup_tss(); setup_paging(); setup_faults(); setup_fs(); setup_syscalls(); init_devs(); char vendor[12]; if (has_cpuid()) { cpuid_string(0, vendor); dprintf("CPU Vendor ID: %s\n"); } fexec("/prgm/start", 0, NULL, NULL); start_scheduler(); asm volatile ("sti"); asm volatile ("hlt"); /* We should never reach this */ assert(0); }
main() { int t, d; // reposition stack within first 16M //LI即将imme(立即数)赋值给a寄存器,此处a=4M asm(LI, 4*1024*1024); //kernel sp指针指向a(4M) asm(SSP); setup_paging(); out(1,'1'); halt(0); }