From: acevest Date: Mon, 15 Nov 2021 08:36:09 +0000 (+0800) Subject: preempt_cnt从task_union中提出来做为全局变量 X-Git-Url: http://zhaoyanbai.com/repos/Bv9ARM.ch04.html?a=commitdiff_plain;h=24c66363f8daeebe8297bba0fe21cc3337f98d3f;p=kernel.git preempt_cnt从task_union中提出来做为全局变量 --- diff --git a/boot/multiboot.S b/boot/multiboot.S index 0974769..b4313f3 100644 --- a/boot/multiboot.S +++ b/boot/multiboot.S @@ -13,7 +13,6 @@ * *-------------------------------------------------------------------------- */ -#define ASM_FILE #define ASM #include "boot.h" #include "system.h" @@ -183,4 +182,4 @@ multiboot2_header_bgn: .short MULTIBOOT_HEADER_TAG_END .short 0 .long 8 -multiboot2_header_end: \ No newline at end of file +multiboot2_header_end: diff --git a/boot/multiboot2.h b/boot/multiboot2.h index d0f36d3..94e16b8 100644 --- a/boot/multiboot2.h +++ b/boot/multiboot2.h @@ -87,7 +87,7 @@ #define MULTIBOOT_CONSOLE_FLAGS_CONSOLE_REQUIRED 1 #define MULTIBOOT_CONSOLE_FLAGS_EGA_TEXT_SUPPORTED 2 -#ifndef ASM_FILE +#ifndef ASM typedef unsigned char multiboot_uint8_t; typedef unsigned short multiboot_uint16_t; @@ -375,6 +375,6 @@ struct multiboot_tag_load_base_addr { multiboot_uint32_t load_base_addr; }; -#endif /* ! ASM_FILE */ +#endif /* ! ASM */ -#endif /* ! MULTIBOOT_HEADER */ \ No newline at end of file +#endif /* ! MULTIBOOT_HEADER */ diff --git a/drivers/console.c b/drivers/console.c index 15854fb..59b2f7b 100644 --- a/drivers/console.c +++ b/drivers/console.c @@ -85,6 +85,7 @@ int cnsl_kbd_write(char ch) { if (ch == '\n') { clear(&cnsl.wr_q); + return 0; // TODO FIX while (get(&cnsl.sc_q, &ch)) put(&cnsl.rd_q, ch); wake_up(&rdwq); } diff --git a/include/system.h b/include/system.h index 6746bcf..a301f3b 100644 --- a/include/system.h +++ b/include/system.h @@ -255,4 +255,14 @@ void system_delay(); #define KRNL_INIT_STACK_SIZE 4096 +#ifndef ASM +// 内核进程 +void root_task_entry(); +void init_task_entry(); +void disk_task_entry(); +void user_task_entry(); + +extern uint32_t preempt_count; +#endif + #endif //_SYSTEM_H diff --git a/include/task.h b/include/task.h index 2e698dd..add3602 100644 --- a/include/task.h +++ b/include/task.h @@ -15,8 +15,6 @@ #define TASK_SIZE 4096 -#define TI_preempt_cnt 0 - #ifndef ASM #include #include @@ -42,8 +40,6 @@ typedef struct wait_queue_head { typedef union task_union { struct { - unsigned long preempt_cnt; - unsigned long esp0; /* kernel stack */ /* for context switch */ diff --git a/kernel/clock.c b/kernel/clock.c index a682214..8e8be8f 100644 --- a/kernel/clock.c +++ b/kernel/clock.c @@ -25,8 +25,8 @@ void clk_handler(unsigned int irq, pt_regs_t *regs, void *dev_id) { printl(MPL_CLOCK, "clock irq: %d", jiffies); } - unsigned long iflags; - irq_save(iflags); + // unsigned long iflags; + // irq_save(iflags); task_union *p = 0; task_union *t = 0; @@ -39,5 +39,5 @@ void clk_handler(unsigned int irq, pt_regs_t *regs, void *dev_id) { } } - irq_restore(iflags); + // irq_restore(iflags); } diff --git a/kernel/i8259.c b/kernel/i8259.c index 69c4e37..1c01157 100644 --- a/kernel/i8259.c +++ b/kernel/i8259.c @@ -106,11 +106,35 @@ void mask_ack_i8259_irq(unsigned int irq) { } } +void ack_i8259_irq(unsigned int irq) { + unsigned char mask = 0; + + if (irq & 8) // Slave + { +#if PIC_AEOI + // ... +#else + // Specific EOI to slave + outb(0x60 + (irq & 0x07), PIC_SLAVE_CMD); + // Specific EOI to master + outb(0x60 + (PIC_CASCADE_IR & 0x07), PIC_MASTER_CMD); +#endif + } else // Master + { +#if PIC_AEOI + // ... +#else + // Specific EOI to master + outb(0x60 + irq, PIC_MASTER_CMD); +#endif + } +} + irq_chip_t i8259_chip = { .name = "XT-PIC", .enable = enable_i8259_irq, .disable = disable_i8259_irq, - .ack = mask_ack_i8259_irq, + .ack = ack_i8259_irq, }; void do_i8259_IRQ(pt_regs_t *regs, unsigned int irq) {} diff --git a/kernel/interrupts.S b/kernel/interrupts.S index 4a20308..2281a23 100644 --- a/kernel/interrupts.S +++ b/kernel/interrupts.S @@ -53,6 +53,7 @@ DEF_IRQ(0,F) .global _irq_handler .extern irq_handler .extern schedule +.extern preempt_count _irq_handler: SAVE_REGS @@ -69,7 +70,7 @@ _irq_handler: movl %esp, %eax call irq_handler - cmpl $0, TI_preempt_cnt(%ebp) + cmpl $0, (preempt_count) jnz restore_regs call schedule diff --git a/kernel/irq.c b/kernel/irq.c index b947705..54beee6 100644 --- a/kernel/irq.c +++ b/kernel/irq.c @@ -18,6 +18,7 @@ #include #include #include +#include #include irq_desc_t irq_desc[NR_IRQS]; @@ -41,27 +42,28 @@ __attribute__((regparm(1))) void irq_handler(pt_regs_t *regs) { irq_action_t *action = p->action; - atomic_inc(&(current->preempt_cnt)); + atomic_inc(&preempt_count); unsigned long esp; asm("movl %%esp, %%eax" : "=a"(esp)); - printl(MPL_PREEMPT, "current %08x cr3 %08x preempt %d esp %08x", current, current->cr3, current->preempt_cnt, esp); + printl(MPL_PREEMPT, "current %08x cr3 %08x preempt %d esp %08x", current, current->cr3, preempt_count, esp); p->chip->ack(irq); - sti(); while (action && action->handler) { action->handler(irq, regs, action->dev_id); action = action->next; } - cli(); - p->chip->enable(irq); + // sti(); + // .... + // cli(); - atomic_dec(&(current->preempt_cnt)); + atomic_dec(&preempt_count); } -int request_irq(unsigned int irq, void (*handler)(unsigned int, pt_regs_t *, void *), const char *devname, void *dev_id) { +int request_irq(unsigned int irq, void (*handler)(unsigned int, pt_regs_t *, void *), const char *devname, + void *dev_id) { irq_action_t *p; if (irq >= NR_IRQS) return -EINVAL; diff --git a/kernel/sched.c b/kernel/sched.c index fd5a8c7..8b445b1 100644 --- a/kernel/sched.c +++ b/kernel/sched.c @@ -52,7 +52,6 @@ LIST_HEAD(delay_tasks); void init_root_task() { int i; - root_task.preempt_cnt = 0; root_task.pid = get_next_pid(); root_task.ppid = 0; root_task.state = TASK_RUNNING; diff --git a/kernel/system.c b/kernel/system.c index 2cba453..0b90a7e 100644 --- a/kernel/system.c +++ b/kernel/system.c @@ -190,4 +190,6 @@ TSS tss; Desc idt[NIDT] __attribute__((__aligned__(8))); Desc gdt[NGDT] __attribute__((__aligned__(8))); char gdtr[6] __attribute__((__aligned__(4))); -char idtr[6] __attribute__((__aligned__(4))); \ No newline at end of file +char idtr[6] __attribute__((__aligned__(4))); + +uint32_t preempt_count = 0x00; \ No newline at end of file diff --git a/kernel/task_disk.c b/kernel/task_disk.c index 6be1a2f..5ba8cbb 100644 --- a/kernel/task_disk.c +++ b/kernel/task_disk.c @@ -11,6 +11,8 @@ void disk_task_entry() { while (1) { - schedule(); + // TODO + asm("hlt;"); + //schedule(); } -} \ No newline at end of file +} diff --git a/kernel/task_root.c b/kernel/task_root.c index 8a97414..77ac5df 100644 --- a/kernel/task_root.c +++ b/kernel/task_root.c @@ -19,9 +19,6 @@ #include #include -void disk_task_entry(); -void init_task_entry(); -void user_task_entry(); int do_fork(pt_regs_t *regs, unsigned long flags); void kernel_task(char *name, void *entry) {