⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 traps.c

📁 一个完整的GUI界面OS,单盘启动 实现了多线程、FAT32文件读写
💻 C
字号:

//-----------------------------------------------------------------------------------------------------------------------
//          Kernel Traps Gate For FireXOS  1.10 
//
//          Version  1.10
//
//          Create by  xiaofan                                   2004.9.20
//
//          Update by xiaofan                                    2004.9.20
//------------------------------------------------------------------------------------------------------------------------

#include "Traps.h"
#include "Io.h"
#include "GraphicDriver.h"
#include "Console.h"
#include "PageAlloc.h"


//--------------------------------------------------------------------------------------------------------------------------////  核心崩溃蓝屏////--------------------------------------------------------------------------------------------------------------------------
static void KernelBuleScreen(void)
{
	KernelSetBkColor(0x0000FF);
	KernelClearBk();
	KernelSetTextColor(0xFFFFFF);
	KernelTextOut(0,32,"Kernel Bule Screen ");
	KernelTextOut(0,64,  "---------------------------------------------------------------------------------------------------------------------");
	KernelTextOut(0,480,"---------------------------------------------------------------------------------------------------------------------");
	KernelTextOut(480,496,"FireX OS Kernel Version 1.10");
	KernelTextOut(480,512,"CopyRight For XiaoFan 2004 ~ 2008");

}


void KernelPanic(char* str)
{
	KernelBuleScreen();
  KernelTextOut(16,80,str);
  while(1);
}

//--------------------------------------------------------------------------------------------------------------------------////  核心崩溃////--------------------------------------------------------------------------------------------------------------------------
static void KernelDie(char* str,long esp_ptr,long nr)
{
	KernelBuleScreen();
	KernelPrintf(16,80,"The Kernel Die Because of : %s",str);
	while(1);
}

//--------------------------------------------------------------------------------------------------------------------------////  双出错处理函数////--------------------------------------------------------------------------------------------------------------------------
void DoDoubleFault(long esp, long error_code)
{
	KernelDie("double fault",esp,error_code);
}

//--------------------------------------------------------------------------------------------------------------------------////  一般性保护出错处理函数////--------------------------------------------------------------------------------------------------------------------------
void DoGeneralProtection(long * esp, long error_code,long fs,long es,long ds,
																			                        long ebp,long esi,long edi,long edx,long ecx,long ebx,long eax)
{
	KernelBuleScreen();
	KernelPrintf(16,80,    "The Kernel Traps for General Protection");
	KernelPrintf(16,128,  "CS    --->   %08x     EIP   --->  %08x ",esp[1],esp[0]);
	KernelPrintf(16,144,  "ESP   --->   %08x     EBP   --->  %08x ",(long)esp,ebp);
	while(1);
}

//--------------------------------------------------------------------------------------------------------------------------////  除法出错处理函数////--------------------------------------------------------------------------------------------------------------------------
void DoDivideError(long esp, long error_code)
{
	KernelDie("divide error",esp,error_code);
}

//--------------------------------------------------------------------------------------------------------------------------////  DEBUG处理函数////--------------------------------------------------------------------------------------------------------------------------
void DoInt3(long * esp, long error_code,
												long fs,long es,long ds,
												long ebp,long esi,long edi,
												long edx,long ecx,long ebx,long eax)
{
	int tr;
	__asm__("str %%ax":"=a" (tr):"0" (0));
  KernelBuleScreen();
  KernelPrintf(16,80,  "The Kernel Traps for DEBUG");
	KernelPrintf(16,128, "CS        --->  %08x     EIP        --->  %08x ",esp[1],esp[0]);
	KernelPrintf(16,144, "USER_ESP  --->  %08x     USER_SS    --->  %08x ",esp[3],esp[4]);
	KernelPrintf(16,160, "KNL_ESP   --->  %08x     EFLAGS     --->  %08x ",(long)esp,esp[2]);
	while(1);
}


//--------------------------------------------------------------------------------------------------------------------------////  非屏蔽中断出错处理函数////--------------------------------------------------------------------------------------------------------------------------
void DoNmi(long esp, long error_code)
{
	KernelDie("nmi",esp,error_code);
}

//--------------------------------------------------------------------------------------------------------------------------////  DEBUG处理函数////--------------------------------------------------------------------------------------------------------------------------
void DoDebug(long esp, long error_code)
{
	KernelDie("debug",esp,error_code);
}


//--------------------------------------------------------------------------------------------------------------------------////  溢出出错处理函数////--------------------------------------------------------------------------------------------------------------------------
void DoOverFlow(long esp, long error_code)
{
	KernelDie("overflow",esp,error_code);
}

//--------------------------------------------------------------------------------------------------------------------------////  边界检查出错处理函数////--------------------------------------------------------------------------------------------------------------------------
void DoBounds(long esp, long error_code)
{
	KernelDie("bounds",esp,error_code);
}


//--------------------------------------------------------------------------------------------------------------------------////  无效指令出错处理函数////--------------------------------------------------------------------------------------------------------------------------
void DoInvalidOp(long * esp, long error_code,
														long fs,long es,long ds,
														long ebp,long esi,long edi,
														long edx,long ecx,long ebx,long eax)
{
  KernelBuleScreen();
	KernelPrintf(16,80,  "The Kernel Traps for invalid operation");
	KernelPrintf(16,128,"CS   --->  %08x     EIP   --->  %08x ",esp[1],esp[0]);
	KernelPrintf(16,144,"ESP  --->  %08x     EBP   --->  %08x ",(long)esp,ebp);
	while(1);

}


//--------------------------------------------------------------------------------------------------------------------------////  无效设备出错处理函数////--------------------------------------------------------------------------------------------------------------------------
void DoDeviceNotAvailable(long esp, long error_code)
{
	KernelDie("device not available",esp,error_code);
}

//--------------------------------------------------------------------------------------------------------------------------////  协处理器段超出出错处理函数////--------------------------------------------------------------------------------------------------------------------------
void DoCoprocessorSegmentOverrun(long esp, long error_code)
{
	KernelDie("coprocessor segment overrun",esp,error_code);
}

//--------------------------------------------------------------------------------------------------------------------------////  无效任务状态段出错处理函数////--------------------------------------------------------------------------------------------------------------------------
void DoInvalidTSS(long esp,long error_code)
{
	KernelDie("invalid TSS",esp,error_code);
}


//--------------------------------------------------------------------------------------------------------------------------////  段无效出错处理函数////--------------------------------------------------------------------------------------------------------------------------
void DoSegmentNotPresent(long esp,long error_code)
{
	KernelDie("segment not present",esp,error_code);
}


//--------------------------------------------------------------------------------------------------------------------------////  堆栈段溢出出错处理函数////--------------------------------------------------------------------------------------------------------------------------
void DoStackSegment(long esp,long error_code)
{
	KernelDie("stack segment",esp,error_code);
}

//--------------------------------------------------------------------------------------------------------------------------////  协处理器出错处理函数////--------------------------------------------------------------------------------------------------------------------------
void DoCoprocessorError(long esp, long error_code)
{
	KernelDie("coprocessor error",esp,error_code);
}

//--------------------------------------------------------------------------------------------------------------------------////  页面出错处理函数////--------------------------------------------------------------------------------------------------------------------------
void DoPageFault(long esp, long error_code)
{
	KernelDie("page fault",esp,error_code);
}


//--------------------------------------------------------------------------------------------------------------------------////  缺页处理函数////--------------------------------------------------------------------------------------------------------------------------
void DoNoPage(unsigned long error_code,unsigned long address)
{
	//KernelBuleScreen();
	//KernelPrintf(16,80, "The Kernel Die Because of : No Page");
	//KernelPrintf(16,128,"The Page Fault Line Address = %08x",address);
	NoPage(address);
	//while(1);
	
}

//--------------------------------------------------------------------------------------------------------------------------////  页保护处理函数////--------------------------------------------------------------------------------------------------------------------------
void DoWpPage(unsigned long error_code,unsigned long address)
{
	KernelBuleScreen();
	KernelPrintf(16,80, "The Kernel Die Because of : Page Protected");
	KernelPrintf(16,128,"The Page Fault Line Address = %08x",address);
	while(1);
	
}


//--------------------------------------------------------------------------------------------------------------------------////  保留出错处理函数////--------------------------------------------------------------------------------------------------------------------------
void DoReserved(long esp, long error_code)
{
	KernelDie("reserved (15,17-31) error",esp,error_code);
}

//--------------------------------------------------------------------------------------------------------------------------////  陷阱门初始化函数////--------------------------------------------------------------------------------------------------------------------------
void TrapInit(void)
{
	int i;

  ConsolePrintf("Set the traps gate");

	SetTrapGate(0,&DivideError);
	SetTrapGate(1,&Debug);
	SetTrapGate(2,&Nmi);
	SetSystemGate(3,&Int3);	/* int3-5 can be called from all */
	SetSystemGate(4,&OverFlow);
	SetSystemGate(5,&Bounds);
	SetTrapGate(6,&InvalidOp);
	SetTrapGate(7,&DeviceNotAvailable);
	SetTrapGate(8,&DoubleFault);
	SetTrapGate(9,&CoprocessorSegmentOverrun);
	SetTrapGate(10,&InvalidTSS);
	SetTrapGate(11,&SegmentNotPresent);
	SetTrapGate(12,&StackSegment);
	SetTrapGate(13,&GeneralProtection);
	SetTrapGate(14,&PageFault);
	SetTrapGate(15,&Reserved);
	SetTrapGate(16,&CoprocessorError);

	for(i=17;i<48;i++)
		SetTrapGate(i,&Reserved);

	ConsolePrintOK();

	//outb_p(inb_p(0x21)&0xfb,0x21);         //允许8259的IRQ2中断请求
	//outb(inb_p(0xA1)&0xdf,0xA1);           //允许8259的IRQ13中断请求
	//set_trap_gate(39,&parallel_interrupt); //并行口中断



}

⌨️ 快捷键说明

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