From: acevest Date: Sat, 3 Jan 2026 04:02:16 +0000 (+0800) Subject: 简单读取HPET相关寄存器 X-Git-Url: http://repos.zhaoyanbai.com/Mou_128.png?a=commitdiff_plain;h=d06cfebae51129b88dbf8654045e13f2ffdf0051;p=kernel.git 简单读取HPET相关寄存器 --- diff --git a/Makefile b/Makefile index 4349e0e..f752989 100644 --- 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 $<' diff --git a/include/apic.h b/include/apic.h index 54d9035..7d3aea9 100644 --- a/include/apic.h +++ b/include/apic.h @@ -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 // 伪中断向量寄存器 diff --git a/kernel/apic.c b/kernel/apic.c index 7e7c050..55b0b18 100644 --- a/kernel/apic.c +++ b/kernel/apic.c @@ -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 efa0e87..0efdfce 100755 --- 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 \