]> Zhao Yanbai Git Server - kernel.git/commitdiff
尝试添加能修复bochs异常提示APIC写地址未对齐的问题
authoracevest <zhaoyanbai@126.com>
Mon, 26 Jan 2026 14:33:12 +0000 (22:33 +0800)
committeracevest <zhaoyanbai@126.com>
Mon, 26 Jan 2026 14:33:12 +0000 (22:33 +0800)
kernel/ap.c
kernel/apic.c

index 418c80de0df73c0bda632e883a9d77d3b69501af..bb059c4406086499c4d305f3380452eec4ec3902 100644 (file)
@@ -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");
index 0b2fe8bfbbc954d9332f935f0c9e736df9e95f7d..4faf1dc48663a475b90583fb1c78b60f9e1a273c 100644 (file)
@@ -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");