]> Zhao Yanbai Git Server - kernel.git/commitdiff
简单读取HPET相关寄存器
authoracevest <zhaoyanbai@126.com>
Sat, 3 Jan 2026 04:02:16 +0000 (12:02 +0800)
committeracevest <zhaoyanbai@126.com>
Sat, 3 Jan 2026 04:02:16 +0000 (12:02 +0800)
Makefile
include/apic.h
kernel/apic.c
qemu.sh

index 4349e0e2f5857d8dde04afeebc264abbf65a847f..f7529899648c8097b08549c9aa32dd565776cccc 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -82,7 +82,7 @@ ${KERNELBIN}: print_flags ${OBJS}
        @echo 'LD ${KERNELBIN}'
        @${LD} ${LDFLAGS} $(OBJS) -o $@ > $(SYSTEMMAP)
        @nm -a $@ > kernel.sym
-# rm kernel/setup.c.o
+       rm kernel/setup.c.o
 
 %.S.o: %.S ${HEADER_FILES}
        @echo 'CC $<'
index 54d903533cf09289e35f54430961132a711e3926..7d3aea9f7e90a9d1cf0e2bd7ca6cf0ff64c6960e 100644 (file)
@@ -28,6 +28,9 @@
 #define LAPIC_PPR 0xA0
 #define LAPIC_EOI 0xB0
 #define LAPIC_LDR 0xD0
+
+// Destination Format Register
+// x2APIC模式下,不再支持平坦模式,仅剩集群模式,以至于x2APIC模式废除了DFR寄存器
 #define LAPIC_DFR 0xE0
 
 // 伪中断向量寄存器
index 7e7c050ac81aaaeeec409145cdaf54a41de2e3cc..55b0b189b85a19745fe1b4bd768bdf9dff15f5b6 100644 (file)
@@ -310,6 +310,35 @@ void ioapic_init() {
     ioapic_rte_write(IOAPIC_RTE(1), 0x20 + 1);
     irq_set_chip(0x00, &ioapic_chip);
     irq_set_chip(0x01, &ioapic_chip);
+
+    // HPTC: High Precision Timer Control Register
+    // bit[1:0] 地址映射范围选择域
+    //       取值      地址映射范围
+    //        00: 0xFED00000 - 0xFED003FF
+    //        01: 0xFED01000 - 0xFED013FF
+    //        10: 0xFED02000 - 0xFED023FF
+    //        11: 0xFED03000 - 0xFED033FF
+    // bit[7] 地址映射使能标志位,用于控制HPET设备访问地址的开启与否
+    //        只有它置位时芯片组才会将HPET配置寄存器映射到内存空间
+    uint32_t* pHPTC = (uint32_t*)((uint8_t*)rcba_virt_base + 0x3404);
+    printk("HPTC: %08x\n", *pHPTC);
+    *pHPTC = (1 << 7) | (0x00);
+    printk("HPTC: %08x\n", *pHPTC);
+
+    vaddr_t hpet_base = (vaddr_t)ioremap(0xFED00000, 0x3FF);
+    printk("HPET base %08x mapped to %08x\n", 0xFED00000, hpet_base);
+
+    uint64_t GCAP_ID = 0;
+    GCAP_ID = *(volatile uint32_t*)(hpet_base + 4);
+    GCAP_ID <<= 32;
+    GCAP_ID |= *(volatile uint32_t*)(hpet_base + 0);
+    printk("GCAP_ID: %016x\n", GCAP_ID);
+
+    uint64_t iddd = *(volatile uint64_t*)(hpet_base + 0);
+    printk("GCAP_ID: %016x\n", iddd);
+    // asm("cli;hlt;");
+    // TODO
+    // iounmap(hpet_base);
 }
 
 void disable_i8259();
diff --git a/qemu.sh b/qemu.sh
index efa0e87091504a87b7c5e40165bc22f2de4e62e3..0efdfce3d4d2e46302bfbf65552762bed5d16068 100755 (executable)
--- a/qemu.sh
+++ b/qemu.sh
@@ -39,7 +39,7 @@ qemu-system-i386 \
     # nc -U /tmp/qemu-monitor.sock
 
     # -d int,cpu_reset \
-
+    # -monitor unix:/tmp/qemu-monitor.sock,server,nowait \
     # -machine pc-q35-9.2  \
     # -cpu qemu32,+apic \
     # -cpu qemu32,+x2apic \