📄 interrupt.cpp
字号:
#include "system.h"
#include "interrupt.h"
#include "video.h"
struct_pyos_InterruptItem class_pyos_Interrupt::m_Idt[ 256 ] ; // 中断描述符表项
struct_pyos_Idtr class_pyos_Interrupt::m_Idtr ; // 中断描述符
/* 初始化中断控制器 8259A */
void class_pyos_Interrupt::Init8259A()
{
// 给中断寄存器编程
// 发送 ICW1 : 使用 ICW4,级联工作
class_pyos_System::ToPort( 0x20 , 0x11 ) ;
class_pyos_System::ToPort( 0xa0 , 0x11 ) ;
// 发送 ICW2,中断起始号从 0x20 开始(第一片)及 0x28开始(第二片)
class_pyos_System::ToPort( 0x21 , 0x20 ) ;
class_pyos_System::ToPort( 0xa1 , 0x28 ) ;
// 发送 ICW3
class_pyos_System::ToPort( 0x21 , 0x4 ) ;
class_pyos_System::ToPort( 0xa1 , 0x2 ) ;
// 发送 ICW4
class_pyos_System::ToPort( 0x21 , 0x1 ) ;
class_pyos_System::ToPort( 0xa1 , 0x1 ) ;
// 设置中断屏蔽位 OCW1 ,屏蔽所有中断请求
class_pyos_System::ToPort( 0x21 , 0xff ) ;
class_pyos_System::ToPort( 0xa1 , 0xff ) ;
}
/* 初始化中断向量表 */
void class_pyos_Interrupt::InitInterruptTable()
{
/* 设置中断门描述符,指向一个哑中断,在需要的时候再填写 */
struct_pyos_InterruptItem tmp ;
tmp.Offset_0_15 = ( unsigned int )pyos_asm_interrupt_handle_for_default ;
tmp.Offset_16_31 = ( unsigned int )pyos_asm_interrupt_handle_for_default >> 16 ;
tmp.SegSelector = 0x8 ; // 代码段
tmp.UnUsed = 0 ;
tmp.P = 1 ;
tmp.DPL = 0 ;
tmp.Saved_1_1_0 = 6 ;
tmp.Saved_0 = 0 ;
tmp.D = 1 ;
for( int i = 0 ; i < 256 ; ++i ){
m_Idt[ i ] = tmp ;
}
m_Idtr.IdtAddr = m_Idt ;
m_Idtr.IdtLengthLimit = 256 * 8 -1 ; // 共 256项,每项占8个字节
// 内嵌汇编,载入 ldt
__asm__( "lidt %0" : "=m"( m_Idtr ) ) ; //载入GDT表
}
/* 初始化中断服务 */
void class_pyos_Interrupt::Init()
{
/* 初始化中断可编程控件器 8259A */
Init8259A() ;
/* 初始化中断向量表 */
InitInterruptTable() ;
/* 许可键盘中断 */
class_pyos_System::ToPort( 0x21 , 0xfd ) ;
/* 汇编指令,开中断 */
__asm__( "sti" ) ;
}
/* 默认中断处理函数 */
extern "C" void pyos_interrupt_handle_for_default()
{
/* 处理中断 */
/* 读 0x60 端口,获得键盘扫描码 */
char ch = class_pyos_System::FromPort( 0x60 ) ;
/* 显示键盘扫描码 */
class_pyos_Video::PrintMessage( ch ) ;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -