From 471cfa16bfd16fa14d2c02f577b8ab3ebdd93a80 Mon Sep 17 00:00:00 2001 From: TermiNexus Date: Wed, 26 Aug 2026 18:29:20 +0800 Subject: [PATCH] =?UTF-8?q?debug(timer):=20timer=5Finit=20=E8=AF=BB=20PIT?= =?UTF-8?q?=20=E8=AE=A1=E6=95=B0=E5=99=A8=EF=BC=8C=E9=AA=8C=E8=AF=81=20PIT?= =?UTF-8?q?=20=E6=98=AF=E5=90=A6=E5=9C=A8=E8=B5=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 中断仍不送达 timer_handler(无 H)。读 PIT 计数器(latch+读 0x40)打印: - 计数在 1~1193 之间变化 → PIT 正常,问题在中断送达(PIC/APIC/IDT) - 计数为 0/不变 → PIT 本身没跑(outb 未生效/环境问题) 用后移除。 --- VKernel/Kernel/platform/pch/timer.vp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/VKernel/Kernel/platform/pch/timer.vp b/VKernel/Kernel/platform/pch/timer.vp index 96637ab..5fb19b4 100644 --- a/VKernel/Kernel/platform/pch/timer.vp +++ b/VKernel/Kernel/platform/pch/timer.vp @@ -3,6 +3,7 @@ import platform.pch.pit as pit import sched.sched as sched import drivers.core.cpu.apic as apic import drivers.serial.uart.serial as serial +import viperlib import asm import t, c @@ -25,6 +26,14 @@ def timer_init(): timer_running = True c.Asm("mfence", op=[t.ASM_DESCR.CLOBBER_MEMORY]) pit.pit_init(TIMER_FREQUENCY) + # [DBG] 读 PIT 计数器验证是否在走(用后移除) + asm.outb(0x43, 0x00) # latch channel 0 + _lo: t.CUInt8T = asm.inb(0x40) + _hi: t.CUInt8T = asm.inb(0x40) + _cnt: t.CInt = t.CInt(_lo) | (t.CInt(_hi) << 8) + _cb: t.CArray[t.CChar, 40] + viperlib.snprintf(c.Addr(_cb), 40, "[PIT] cnt=%d\n", _cnt) + serial.puts(c.Addr(_cb)) def timer_handler(): global ticks, seconds, milliseconds, timer_running, _dbg_once