From 09f10a2eb2964b911786711cd47e738abd3a561b Mon Sep 17 00:00:00 2001 From: acevest Date: Mon, 26 Jan 2026 22:33:12 +0800 Subject: [PATCH] =?utf8?q?=E5=B0=9D=E8=AF=95=E6=B7=BB=E5=8A=A0=E8=83=BD?= =?utf8?q?=E4=BF=AE=E5=A4=8Dbochs=E5=BC=82=E5=B8=B8=E6=8F=90=E7=A4=BAAPIC?= =?utf8?q?=E5=86=99=E5=9C=B0=E5=9D=80=E6=9C=AA=E5=AF=B9=E9=BD=90=E7=9A=84?= =?utf8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- kernel/ap.c | 2 +- kernel/apic.c | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/kernel/ap.c b/kernel/ap.c index 418c80d..bb059c4 100644 --- a/kernel/ap.c +++ b/kernel/ap.c @@ -118,7 +118,7 @@ void ap_kernel_entry() { if (r.ecx & (1 << 21)) { printk("x2apic supported\n"); } else { - panic("x2apic not supported\n"); + printk("x2apic not supported\n"); } } else { panic("local apic not supported\n"); diff --git a/kernel/apic.c b/kernel/apic.c index 0b2fe8b..4faf1dc 100644 --- a/kernel/apic.c +++ b/kernel/apic.c @@ -36,8 +36,18 @@ void apic_write_lapic(uint32_t offset, uint32_t value) { void apic_write64_lapic(uint32_t offset, uint64_t value) { assert(offset < PAGE_SIZE); + assert((offset % 8) == 0); +#if 1 uint8_t* base = (uint8_t*)fixid_to_vaddr(FIX_LAPIC_BASE); *(volatile uint64_t*)(base + offset) = value; +#else + // 在bochs上得用下面这段代码,否则会提示 + // PANIC + // Device: [APIC0 ] + // Message: APIC write at unaligned address 0x0000fee00304 + uint8_t* base = (uint8_t*)fixid_to_vaddr(FIX_LAPIC_BASE); + *(volatile uint32_t*)(base + offset) = (uint32_t)value; +#endif } uint32_t apic_get_lapic_id() { @@ -117,7 +127,7 @@ void lapic_init() { x2apic = true; printk("x2apic supported\n"); } else { - // panic("x2apic not supported\n"); + printk("x2apic not supported\n"); } } else { panic("local apic not supported\n"); -- 2.47.0