From: acevest Date: Mon, 26 Jan 2026 14:33:12 +0000 (+0800) Subject: 尝试添加能修复bochs异常提示APIC写地址未对齐的问题 X-Git-Url: http://repos.zhaoyanbai.com/Mou_128.png?a=commitdiff_plain;h=09f10a2eb2964b911786711cd47e738abd3a561b;p=kernel.git 尝试添加能修复bochs异常提示APIC写地址未对齐的问题 --- 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");