diff --git a/VKernel/Kernel/platform/pch/timer.vp b/VKernel/Kernel/platform/pch/timer.vp index da8cd0e..96637ab 100644 --- a/VKernel/Kernel/platform/pch/timer.vp +++ b/VKernel/Kernel/platform/pch/timer.vp @@ -2,6 +2,7 @@ import platform.pch.pic as pic 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 asm import t, c @@ -13,6 +14,7 @@ ticks: t.CStatic | t.CVolatile | t.CUInt64T = 0 seconds: t.CStatic | t.CVolatile | t.CUInt32T = 0 milliseconds: t.CStatic | t.CVolatile | t.CUInt32T = 0 timer_running: t.CStatic | t.CVolatile | bool = False +_dbg_once: t.CInt = 0 def timer_init(): global ticks, seconds, milliseconds, timer_running @@ -25,7 +27,11 @@ def timer_init(): pit.pit_init(TIMER_FREQUENCY) def timer_handler(): - global ticks, seconds, milliseconds, timer_running + global ticks, seconds, milliseconds, timer_running, _dbg_once + # [DBG] 一次性打印:'H' 出现说明定时 ISR 被调用(用后移除) + if _dbg_once == 0: + _dbg_once = 1 + serial.puts("H") if not timer_running: pic.eoi(0) apic.eoi() @@ -95,7 +101,13 @@ def timer_get_time(out_seconds: t.CUInt32T | t.CPtr, out_milliseconds: t.CUInt32 def timer_msleep(ms: t.CUInt32T): target: t.CUInt64T = ticks + (ms + MILLISECONDS_PER_TICK - 1) / MILLISECONDS_PER_TICK + _spin: t.CUInt64T = 0 while ticks < target: + # [DBG] 自旋计数:每 1M 次迭代打印 s——hlt 能唤醒说明中断触发 + # (用后移除) + _spin += 1 + if (_spin & 0xFFFFF) == 0: + serial.puts("s") asm.sti() asm.hlt() sched.Scheduler._yield()