void _cstartup( unsigned int r0, unsigned int r1, unsigned int r2 ) { /*__bss_start__ and __bss_end__ are defined in the linker script */ int* bss = &__bss_start__; int* bss_end = &__bss_end__; /* Clear the BSS section See http://en.wikipedia.org/wiki/.bss for further information on the BSS section See https://sourceware.org/newlib/libc.html#Stubs for further information on the c-library stubs */ while( bss < bss_end ) *bss++ = 0; /* We should never return from main ... */ kernel_main( r0, r1, r2 ); /* ... but if we do, safely trap here */ while(1) { /* EMPTY! */ } }
int main(void) { extern int kernel_main(bool system_main_init_stat); // 只能在main() 内使用 system_init(); kernel_main(true); system_exit(); }
void kernel_init(boot_info_t bootInfo) { tty_init(); multiboot_init(bootInfo.multiboot_magic, bootInfo.multiboot_addr); if(a20_enable()) { serial_writestring(1, "A20 enable failed - triggering panic\n"); kernel_panic(); }; gdt_install(); idt_install(); irq_install(); _protected_mode_init(); paging_init(); _paging_enable(); PIC_init(); serial_init(); keyboard_init(); timer_init(); serial_writestring(1, "End kernel_init\n"); kernel_main(); };
/** @brief C entry point */ void mb_entry(mbinfo_t *info, void *istack) { int argc; char **argv; char **envp; /* Want (kilobytes*1024)/PAGE_SIZE, but definitely avoid overflow */ n_phys_frames = (info->mem_upper+1024)/(PAGE_SIZE/1024); assert(n_phys_frames > (USER_MEM_START/PAGE_SIZE)); // LMM: init malloc_lmm and reserve memory holding this executable mb_util_lmm(info, &malloc_lmm); // LMM: don't give out memory under 1 megabyte lmm_remove_free(&malloc_lmm, (void*)0, 0x100000); // LMM: don't give out memory between USER_MEM_START and infinity lmm_remove_free(&malloc_lmm, (void*)USER_MEM_START, -8 - USER_MEM_START); // lmm_dump(&malloc_lmm); mb_util_cmdline(info, &argc, &argv, &envp); // Having done that, let's tell Simics we've booted. sim_booted(argv[0]); /* Disable floating-point unit: * inadvisable for kernel, requires context-switch code for users */ set_cr0(get_cr0() | CR0_EM); /* Initialize the PIC so that IRQs use different IDT slots than * CPU-defined exceptions. */ interrupt_setup(); kernel_main(info, argc, argv, envp); }
void multiboot_main(unsigned int boot_info_pa) { int argc = 0; char **argv = 0; int ret; /* Copy the multiboot_info structure into our pre-reserved area. This avoids one loose fragment of memory that has to be avoided. */ boot_info = *(struct multiboot_info*)phystokv(boot_info_pa); /* * Initialize the processor tables. ie default handlers etc. */ base_cpu_setup(); /* * Initialize the floating point unit. */ /*base_fpu_init();*/ /* Initialize the memory allocator and find all available memory. */ base_multiboot_init_mem(); /* Parse the command line into nice POSIX-like args and environment. */ base_multiboot_init_cmdline(&argc, &argv); enable_interrupts(); /* Invoke the main program. */ ret = kernel_main(argc, argv, environ); printf( "base_multiboot_main.c: kernel main returned with code %d\n", ret ); while(1); }
void boot_64(uint32_t magic, uint32_t multiboot) { // checking multiboot magic variable. VGA_AT(0,0) = VGA_ENTRY('H', WHITE_ON_BLACK); if (magic != MULTIBOOT_BOOTLOADER_MAGIC) { VGA_AT(0,1) = VGA_ENTRY('!', WHITE_ON_BLACK); kernel_panic(); } // copying multiboot data. VGA_AT(0,1) = VGA_ENTRY('E', WHITE_ON_BLACK); multiboot_info_t *info = (multiboot_info_t *)kernel_p2v((uintptr_t)multiboot); switch (multiboot_copy(info)) { case MULTIBOOT_TOO_MANY_MEMORY_MAPS: VGA_AT(0,2) = VGA_ENTRY('?', WHITE_ON_BLACK); kernel_panic(); case MULTIBOOT_TOO_MANY_MODULES: VGA_AT(0,2) = VGA_ENTRY('?', WHITE_ON_BLACK); kernel_panic(); case MULTIBOOT_TOO_MANY_ELF_HEADERS: VGA_AT(0,2) = VGA_ENTRY('.', WHITE_ON_BLACK); kernel_panic(); } // we no longer need the original memory map at zero address. VGA_AT(0,2) = VGA_ENTRY('L', WHITE_ON_BLACK); page_set_pdpt(0, 0, 0); page_invalidate_all(); // initialize page allocators. VGA_AT(0,3) = VGA_ENTRY('L', WHITE_ON_BLACK); lomem_init(); himem_init(); // initialize CPUs. VGA_AT(0,4) = VGA_ENTRY('B', WHITE_ON_BLACK); cpu_enable_features(); cpu_init(); service_init(); gdt_init(); // adds per-cpu TSS into GDT. tss_update(); // initialize interrupt handling. VGA_AT(0,5) = VGA_ENTRY('E', WHITE_ON_BLACK); pic_init(); idt_init(); // kick-start the core service. VGA_AT(0,6) = VGA_ENTRY('N', WHITE_ON_BLACK); kernel_start_core(); // start scheduler and do stuff. VGA_AT(0,7) = VGA_ENTRY('D', WHITE_ON_BLACK); kernel_main(); }
extern "C" FIASCO_FASTCALL FIASCO_INIT void __main(unsigned checksum_ro) { /* set global to be used in the constructors */ Boot_info::set_checksum_ro(checksum_ro); Boot_info::init(); atexit(&static_destruction); static_construction(); kernel_main(); exit(0); }
void _cstartup(unsigned int r0, unsigned int r1, unsigned int r2) { unsigned int * bss = &__bss_start__; unsigned int * bss_end = &__bss_end__; /* clear the bss section */ while( bss < bss_end ) { *bss++ = 0; } kernel_main(r0, r1, r2); while(1); }
void _cstartup(unsigned int r0, unsigned int r1, unsigned int r2) { int* bss = &__bss_start__; int* bss_end = &__bss_end__; /* clear the bss section (write 0) */ while (bss < bss_end) *bss++ = 0; /* Main should never return */ kernel_main(r0, r1, r2); /* But make sure of that */ while (1) ; }
int main() { unsigned int tid; boot(); sys_create(15, NameServer, &tid); sys_create(15, ClockServer, &tid); sys_create(12, InputServer, &tid); sys_create(12, OutputServer, &tid); sys_create(13, TimerTask, &tid); sys_create(1, go, &tid); sys_create(10, SensorServer, &tid); sys_create(10, TrainController, &tid); kernel_main(); shutdown(); return 0; }
void x86_kernel_main(struct multiboot *multiboot) { init_output(); init_paging(multiboot); init_acpi(); init_descriptor_tables(); kprint("Stack pointer: "); kprint_hexnl(read_esp()); kprint("Mod count: "); kprint_hexnl(multiboot->mods_count); kprint("Kernel phys end : "); kprint_hexnl((u32)&__phys_end); kprint("Mod addr start : "); kprint_hexnl(*(u32*)(phys_to_virt(multiboot->mods_addr))); kprint("Mod addr end : "); kprint_hexnl(*(u32*)(phys_to_virt(multiboot->mods_addr) + 4)); //init_tasking(); kernel_main(); if (multiboot->mods_count == 13) { kprint("Executing module..\n"); typedef void (*module_fun)(void); u32 modaddr = phys_to_virt(multiboot->mods_addr); modaddr = phys_to_virt(*(u32*)modaddr); //kprint_hexnl(modaddr); //kprint_hexnl(*(u32*)modaddr); module_fun module = (module_fun)modaddr; module(); kprint("Modadr is "); } }
__attribute__((noreturn)) void mmu_init_step2(void) { idt_init(); mmu_memorymanager(); kernel_main(); }