[refactor] 整理注释
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
#include <pic.h>
|
||||
#include <serial.h>
|
||||
|
||||
// Defined in isr.S — 256 ISR stubs
|
||||
// isr.S 中定义的 256 个 ISR 桩函数
|
||||
extern "C" void* isr_stub_table[256];
|
||||
|
||||
static idt_entry g_idt[256];
|
||||
@@ -15,7 +15,7 @@ void idt_set_handler(UINT8 vector, isr_handler_t handler) {
|
||||
g_handlers[vector] = handler;
|
||||
}
|
||||
|
||||
// Called from isr.S common handler
|
||||
// 由 isr.S 通用处理函数调用
|
||||
extern "C" void isr_dispatch(trap_frame* frame) {
|
||||
UINT8 vector = (UINT8)frame->vector;
|
||||
|
||||
@@ -31,14 +31,14 @@ extern "C" void isr_dispatch(trap_frame* frame) {
|
||||
}
|
||||
}
|
||||
|
||||
// IDT helpers (defined in idt_helpers.S)
|
||||
// IDT 辅助函数(定义在 idt_helpers.S)
|
||||
extern "C" void idt_load(UINT64 base, UINT16 limit);
|
||||
|
||||
static void idt_set_entry(UINT8 vector, UINT64 handler_addr) {
|
||||
g_idt[vector].offset_low = handler_addr & 0xFFFF;
|
||||
g_idt[vector].selector = 0x08; // kernel code segment
|
||||
g_idt[vector].selector = 0x08; // 内核代码段
|
||||
g_idt[vector].ist = 0;
|
||||
g_idt[vector].type_attr = 0x8E; // present, DPL=0, 64-bit interrupt gate
|
||||
g_idt[vector].type_attr = 0x8E; // 存在,DPL=0,64 位中断门
|
||||
g_idt[vector].offset_mid = (handler_addr >> 16) & 0xFFFF;
|
||||
g_idt[vector].offset_high = (handler_addr >> 32) & 0xFFFFFFFF;
|
||||
g_idt[vector].reserved = 0;
|
||||
@@ -47,18 +47,18 @@ static void idt_set_entry(UINT8 vector, UINT64 handler_addr) {
|
||||
void idt_init(void) {
|
||||
serial_write("IDT: initializing 256 entries\n");
|
||||
|
||||
// Clear IDT
|
||||
// 清空 IDT
|
||||
for (SSINT32 i = 0; i < 256; i++) {
|
||||
g_idt[i] = {0};
|
||||
g_handlers[i] = NULL;
|
||||
}
|
||||
|
||||
// Install all 256 ISR stubs
|
||||
// 安装所有 256 个 ISR 桩函数
|
||||
for (SSINT32 i = 0; i < 256; i++) {
|
||||
idt_set_entry(i, (UINT64)isr_stub_table[i]);
|
||||
}
|
||||
|
||||
// Load IDT
|
||||
// 加载 IDT
|
||||
g_idt_ptr.limit = sizeof(g_idt) - 1;
|
||||
g_idt_ptr.base = (UINT64)&g_idt[0];
|
||||
idt_load(g_idt_ptr.base, g_idt_ptr.limit);
|
||||
|
||||
+11
-11
@@ -13,37 +13,37 @@ static inline UINT8 inb(UINT16 port) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
// 慢速 PIC 的小延迟
|
||||
static void pic_wait(void) {
|
||||
// Small delay for slow PICs
|
||||
ASM("jmp 1f\n\t1: jmp 1f\n\t1:");
|
||||
}
|
||||
|
||||
void pic_init(void) {
|
||||
serial_write("PIC: remapping 8259 PIC\n");
|
||||
|
||||
// Save masks
|
||||
// 保存掩码
|
||||
UINT8 mask1 = inb(PIC1_DATA);
|
||||
UINT8 mask2 = inb(PIC2_DATA);
|
||||
|
||||
// ICW1: begin initialization, ICW4 needed
|
||||
// ICW1:开始初始化,需要 ICW4
|
||||
outb(PIC1_CMD, 0x11); pic_wait();
|
||||
outb(PIC2_CMD, 0x11); pic_wait();
|
||||
|
||||
// ICW2: vector offset
|
||||
outb(PIC1_DATA, PIC_IRQ_BASE); // IRQ 0-7 → vector 0x20-0x27
|
||||
// ICW2:向量偏移
|
||||
outb(PIC1_DATA, PIC_IRQ_BASE); // IRQ 0-7 → 向量 0x20-0x27
|
||||
pic_wait();
|
||||
outb(PIC2_DATA, PIC_IRQ_BASE + 8); // IRQ 8-15 → vector 0x28-0x2F
|
||||
outb(PIC2_DATA, PIC_IRQ_BASE + 8); // IRQ 8-15 → 向量 0x28-0x2F
|
||||
pic_wait();
|
||||
|
||||
// ICW3: cascading
|
||||
outb(PIC1_DATA, 0x04); pic_wait(); // slave on IRQ 2
|
||||
outb(PIC2_DATA, 0x02); pic_wait(); // cascade identity
|
||||
// ICW3:级联
|
||||
outb(PIC1_DATA, 0x04); pic_wait(); // 从片在 IRQ 2
|
||||
outb(PIC2_DATA, 0x02); pic_wait(); // 级联标识
|
||||
|
||||
// ICW4: 8086 mode
|
||||
// ICW4:8086 模式
|
||||
outb(PIC1_DATA, 0x01); pic_wait();
|
||||
outb(PIC2_DATA, 0x01); pic_wait();
|
||||
|
||||
// Restore masks
|
||||
// 恢复掩码
|
||||
outb(PIC1_DATA, mask1);
|
||||
outb(PIC2_DATA, mask2);
|
||||
|
||||
|
||||
@@ -25,14 +25,14 @@ void pit_init(void) {
|
||||
|
||||
UINT32 divisor = PIT_BASE_FREQ / PIT_TICK_HZ;
|
||||
|
||||
// Command byte: channel 0, lobyte/hibyte, rate generator, binary
|
||||
// 命令字节:通道 0,低/高字节,速率生成器,二进制
|
||||
outb(PIT_COMMAND_PORT, 0x36);
|
||||
|
||||
// Send divisor (low byte first, then high byte)
|
||||
// 发送除数(先低字节后高字节)
|
||||
outb(PIT_CHANNEL0_DATA, (UINT8)(divisor & 0xFF));
|
||||
outb(PIT_CHANNEL0_DATA, (UINT8)((divisor >> 8) & 0xFF));
|
||||
|
||||
// Unmask IRQ 0 (timer)
|
||||
// 取消屏蔽 IRQ 0(定时器)
|
||||
pic_unmask_irq(0);
|
||||
|
||||
serial_write("PIT: divisor = ");
|
||||
|
||||
Reference in New Issue
Block a user