Initial import of ViperOS

This commit is contained in:
Viper
2026-07-19 12:38:20 +08:00
commit 6813947181
104 changed files with 26710 additions and 0 deletions

View File

@@ -0,0 +1,26 @@
import asm
import t, c
PIT_CHANNEL0: t.CDefine = 0x40
PIT_CHANNEL1: t.CDefine = 0x41
PIT_CHANNEL2: t.CDefine = 0x42
PIT_COMMAND: t.CDefine = 0x43
def pit_init(frequency: t.CInt):
# 参数验证:确保频率为正数
if frequency <= 0: return
# 计算除数使用16位无符号整数
divisor: t.CUInt32T = 1193180 / frequency
# 发送命令字通道0先低后高模式3方波二进制计数
asm.outb(PIT_COMMAND, 0x36)
asm.io_wait()
# 写入低字节
asm.outb(PIT_CHANNEL0, divisor & 0xFF)
asm.io_wait()
# 写入高字节
asm.outb(PIT_CHANNEL0, (divisor >> 8) & 0xFF)
asm.io_wait()