Repos / kernel.git / commitdiff
summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 9b27a80)
raw | patch | inline | side by side (parent: 9b27a80)
| author | zhaoyanbai <zhaoyanbai@126.com> | |
| Fri, 19 May 2023 16:39:16 +0000 (00:39 +0800) | ||
| committer | zhaoyanbai <zhaoyanbai@126.com> | |
| Fri, 19 May 2023 16:39:16 +0000 (00:39 +0800) |
| include/system.h | patch | blob | history | |
| kernel/interrupts.S | patch | blob | history | |
| kernel/irq.c | patch | blob | history | |
| kernel/system.c | patch | blob | history |
diff --git a/include/system.h b/include/system.h
--- a/include/system.h
+++ b/include/system.h
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
--- a/kernel/interrupts.S
+++ b/kernel/interrupts.S
.global _irq_handler
.extern irq_handler
.extern schedule
-.extern preempt_count
+.extern irq_reenter
_irq_handler:
SAVE_REGS
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
--- 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
--- a/kernel/system.c
+++ b/kernel/system.c
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