简介
以前做延时操作时都是使用循环,让cpu不断的循环。但是一个潜在的问题是浪费cpu资源,在循环中cpu将不能执行其他任务。
目标
使用8259A 的IRQ0 实现时钟中断。
1.kernel.s
打开IRQ0中断控制
mov al, 11111000b ;CPU只接收主8259A,IRQ0,IRQ1,IRQ2管线发送的信号,其他管线发送信号一概忽略
设置中断向量,新增IRQ0中断向量设置 .0x20:
标签
;中断描述符表
LABEL_IDT:
%rep 0x20
Gate SelectorCode32, SpuriousHandler,0, DA_386IGate
%endrep
;8259A IRQ0 定时器中断
.0x20:
Gate SelectorCode32, TimerHandler,0, DA_386IGate
;键盘中断向量(8259A 键盘中断向量0x20,IRQ1 是键盘中断请求,0x20 + IRQ[n] = 0x21
.0x21:
Gate SelectorCode32, KeyboardHandler,0, DA_386IGate
汇编调用C 语言实现中断操作
;定时器中断
LabelTimerHandler:
TimerHandler equ LabelTimerHandler - $$
push es
push ds
pushad
mov eax, esp
push eax
call int_timer
pop eax
mov esp, eax
popad
pop ds
pop es
iretd
2.抽取os中可以公共使用部分的代码
global_def.h
#ifndef GLOBAL_DEF