]> Zhao Yanbai Git Server - kernel.git/commitdiff
preempt_count改为irq_reenter
authoracevest <zhaoyanbai@126.com>
Fri, 19 May 2023 16:39:16 +0000 (00:39 +0800)
committeracevest <zhaoyanbai@126.com>
Fri, 19 May 2023 16:39:16 +0000 (00:39 +0800)
include/system.h
kernel/interrupts.S
kernel/irq.c
kernel/system.c

index bc5f2c313ac169e64df1cdbfd4fc2ad3aa3c502a..f30d7ccf8eeec53b41e95cd7a08a1535c6f5cfd6 100644 (file)
@@ -267,7 +267,7 @@ void init_task_entry();
 void disk_task_entry();
 void user_task_entry();
 
-extern uint32_t preempt_count;
+extern int irq_reenter;
 #endif
 
 #endif  //_SYSTEM_H
index 2281a232e0ab2c5523caee79d6879dc02cf76634..f86f75e234b07f273a322be1b8ba548bc60cbe18 100644 (file)
@@ -53,7 +53,7 @@ DEF_IRQ(0,F)
 .global _irq_handler
 .extern irq_handler
 .extern schedule
-.extern preempt_count
+.extern irq_reenter
 _irq_handler:
     SAVE_REGS
 
@@ -70,7 +70,7 @@ _irq_handler:
     movl    %esp, %eax
     call    irq_handler
 
-    cmpl    $0, (preempt_count)
+    cmpl    $0, (irq_reenter)
     jnz     restore_regs
 
     call    schedule
index ff12eb7c37e2b725972660910c5dfb46790e0d35..a7a89d9624cbe3e0e20d9c1e32177396c598ce3b 100644 (file)
@@ -32,39 +32,45 @@ irq_desc_t no_irq_desc = {.chip = &no_irq_chip, .action = NULL, .status = 0, .de
 
 __attribute__((regparm(1))) void irq_handler(pt_regs_t *regs) {
     unsigned int irq = regs->irq;
-
     if (irq >= NR_IRQS) {
         printk("invalid irq %d\n", irq);
         return;
     }
 
     irq_desc_t *p = irq_desc + irq;
-
     irq_action_t *action = p->action;
 
-    // atomic_inc(&preempt_count);
-    preempt_count++;  // 还没到多处理器,暂时不用atomic_inc
+    // 屏蔽当前中断
+    p->chip->disable(irq);
 
+    // 发送EOI
     p->chip->ack(irq);
 
-    unsigned long irq_flags;
-    irq_save(irq_flags);
+    if (irq_reenter == 0) {
+        // 可以切换到中断栈
+    }
+
+    irq_reenter++;
 
+    // 开中断执行中断处理函数
     enable_irq();
 
     unsigned long esp;
     asm("movl %%esp, %%eax" : "=a"(esp));
-    printl(MPL_PREEMPT, "current %08x cr3 %08x preempt %d esp %08x", current, current->cr3, preempt_count, esp);
+    printl(MPL_PREEMPT, "current %08x cr3 %08x reenter %d esp %08x", current, current->cr3, irq_reenter, esp);
 
     while (action && action->handler) {
         action->handler(irq, regs, action->dev_id);
         action = action->next;
     }
 
-    irq_restore(irq_flags);
-    // atomic_dec(&preempt_count);
-    preempt_count--;
-    enable_irq();
+    // 关全局中断
+    disable_irq();
+
+    irq_reenter--;
+
+    // 解除屏蔽当前中断
+    p->chip->enable(irq);
 }
 
 int request_irq(unsigned int irq, void (*handler)(unsigned int, pt_regs_t *, void *), const char *devname,
index fa0d78344e850f0d87d3dff309e08199d029cbcd..48dded146ab7983aac43bfd4c67243304b4eccca 100644 (file)
@@ -192,4 +192,4 @@ Desc gdt[NGDT] __attribute__((__aligned__(8)));
 char gdtr[6] __attribute__((__aligned__(4)));
 char idtr[6] __attribute__((__aligned__(4)));
 
-uint32_t preempt_count = 0x00;
\ No newline at end of file
+int irq_reenter = 0x00;
\ No newline at end of file