kernel_init.c

来自「操作系统试验!通过这个试验」· C语言 代码 · 共 64 行

C
64
字号
#include <multiboot.h>    	/* for boot_info */#include <lmm.public.h>		/* for lmm_remove_free() */#include <stdio.h>		/* for lprintf_kern() */#include <x86/seg.h>		/* for install_user_segs() */#include <x86/pic.h>      	/* for pic_init() */#include <x86/base_irq.h> 	/* for base_irq_master/slave */#include <x86/pio.h>#include <interrupts.h>#include <timer_defines.h>#include <kernel_init.h>#include <keyhelp.h>extern lmm_t malloc_lmm;		/* state for kernel memory allocation. */extern struct multiboot_info boot_info;	/* Info about system gathered by the boot loader */void kernel_init(){	/*	* Tell the kernel memory allocator which memory it can't use.	* It already knows not to touch kernel image.	*/	lmm_remove_free( &malloc_lmm, (void*)USER_MEM_START, USER_MEM_SIZE );	lmm_remove_free( &malloc_lmm, (void*)0, 0x100000 );		/*	 * init the PIC so that IRQs and exception handlers	 * don't overlap in the IDT.	 */	pic_init( BASE_IRQ_MASTER_BASE, BASE_IRQ_SLAVE_BASE );		/*	 * Install interrupt handler	 */	/* ... */	/* 	 * Programmable Interval Timer here.	 * 	 */	/* ... */}unsigned int keyboard_handler(struct trap_state *ts){	/*Your keyboard handler*/	/* ... */	return 0;}unsigned int timer_handler(struct trap_state *ts){	/* Your timer handler here*/	/* ... */	return 0;}char readchar(){	return 0;}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?