From: acevest Date: Fri, 19 May 2023 16:39:16 +0000 (+0800) Subject: preempt_count改为irq_reenter X-Git-Url: http://zhaoyanbai.com/repos/Bv9ARM.pdf?a=commitdiff_plain;h=89590b2efba872fdd92b654b7e94d90aae6df1e8;p=kernel.git preempt_count改为irq_reenter --- diff --git a/include/system.h b/include/system.h index bc5f2c3..f30d7cc 100644 --- a/include/system.h +++ b/include/system.h @@ -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 diff --git a/kernel/interrupts.S b/kernel/interrupts.S index 2281a23..f86f75e 100644 --- a/kernel/interrupts.S +++ b/kernel/interrupts.S @@ -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 diff --git a/kernel/irq.c b/kernel/irq.c index ff12eb7..a7a89d9 100644 --- a/kernel/irq.c +++ b/kernel/irq.c @@ -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, diff --git a/kernel/system.c b/kernel/system.c index fa0d783..48dded1 100644 --- a/kernel/system.c +++ b/kernel/system.c @@ -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