debug(timer): timer_init 读 PIT 计数器,验证 PIT 是否在走

中断仍不送达 timer_handler(无 H)。读 PIT 计数器(latch+读 0x40)打印:
- 计数在 1~1193 之间变化 → PIT 正常,问题在中断送达(PIC/APIC/IDT)
- 计数为 0/不变 → PIT 本身没跑(outb 未生效/环境问题)
用后移除。
This commit is contained in:
TermiNexus committed 2026-08-26 18:29:20 +08:00
1 parent 57c4092d19
commit 471cfa16bf
1 file changed
+9
+9
View File
@@ -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