From: acevest Date: Mon, 29 May 2023 15:05:06 +0000 (+0800) Subject: 添加硬盘和键盘的中断下半部逻辑处理 X-Git-Url: http://zhaoyanbai.com/repos/%22http:/www.isc.org/icons/zpipe.c?a=commitdiff_plain;h=d2630e3ea28be5c0cc42924ab87bc650a2af0214;p=kernel.git 添加硬盘和键盘的中断下半部逻辑处理 --- diff --git a/drivers/ide.c b/drivers/ide.c index 30fa230..edf0144 100644 --- a/drivers/ide.c +++ b/drivers/ide.c @@ -555,18 +555,17 @@ extern ide_pci_controller_t ide_pci_controller; volatile uint32_t disk_inter_cnt = 0; -void ide_irq_handler(unsigned int irq, pt_regs_t *regs, void *devid) { - // printk("ide irq handler %d \n", irq); +void ide_irq_bh_handler() { + disk_inter_cnt++; + + // up里不会立即重新调度进程 + up(&disk_intr_sem); +} +void ide_irq_handler(unsigned int irq, pt_regs_t *regs, void *devid) { // printk("ide irq %d handler pci status: 0x%02x\n", irq, ata_pci_bus_status()); -#if 1 - disk_inter_cnt++; - up(&disk_intr_sem); -#else - ide_pci_controller.done = 1; - wake_up(&ide_wait_queue_head); -#endif + add_irq_bh_handler(ide_irq_bh_handler); } void ide_init() { diff --git a/drivers/keyboard.c b/drivers/keyboard.c index 4864bf3..a3b953b 100644 --- a/drivers/keyboard.c +++ b/drivers/keyboard.c @@ -27,12 +27,10 @@ void poweroff(); void ide_debug(); void ide_status(); void debug_sched(); -void vga_dbg_toggle(); + int debug_wait_queue_put(unsigned int v); -// void ide_dma_pci_lba48(); -void vga_switch(unsigned int nr); -void kbd_debug(unsigned char scan_code); +void kbd_debug(uint8_t scan_code); char kbd_char_tbl[] = { 0, 0, '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '=', '\b', 0, 'q', 'w', 'e', 'r', 't', 'y', @@ -54,28 +52,28 @@ char kbd_char_tbl[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; -void kbd_handler(unsigned int irq, pt_regs_t *regs, void *dev_id) { - unsigned char scan_code; - - scan_code = inb(0x60); - +// TODO 改造成环形缓冲区 +uint8_t scan_code; +void kbd_bh_handler() { kbd_debug(scan_code); - - if (0x80 & scan_code) // break code - { + if (0x80 & scan_code) { // break code return; } - - unsigned int inx = scan_code & 0xFF; + uint8_t inx = scan_code & 0xFF; char ch = kbd_char_tbl[inx]; cnsl_kbd_write(ch); } +void kbd_handler(unsigned int irq, pt_regs_t *regs, void *dev_id) { + scan_code = inb(0x60); + add_irq_bh_handler(kbd_bh_handler); +} + extern tty_t default_tty; extern tty_t monitor_tty; extern tty_t debug_tty; -void kbd_debug(unsigned char scan_code) { +void kbd_debug(uint8_t scan_code) { static unsigned long kbd_cnt = 0; printl(MPL_KEYBOARD, "keyboard irq: %d scan code %02x", kbd_cnt++, scan_code); diff --git a/include/semaphore.h b/include/semaphore.h index 7d0c139..72f6a52 100644 --- a/include/semaphore.h +++ b/include/semaphore.h @@ -23,9 +23,15 @@ typedef struct semaphore { void semaphore_init(semaphore_t *s, unsigned int v); +// down +// 如果s->cnt > 0不会立即重新调度进程 +// 如果s->cnt == 0 会重新调度进程 void down(semaphore_t *s); + +// up +// 只会唤醒进程,但不会立即重新调度进程 void up(semaphore_t *s); #define DECLARE_MUTEX(name) semaphore_t name = SEMAPHORE_INITIALIZER(name, 1) void mutex_lock(semaphore_t *); -void mutex_unlock(semaphore_t *); \ No newline at end of file +void mutex_unlock(semaphore_t *); diff --git a/kernel/semaphore.c b/kernel/semaphore.c index 36c8484..29b42ad 100644 --- a/kernel/semaphore.c +++ b/kernel/semaphore.c @@ -78,4 +78,4 @@ volatile void up(semaphore_t *s) { } void mutex_lock(semaphore_t *s) { down(s); } -void mutex_unlock(semaphore_t *s) { up(s); } \ No newline at end of file +void mutex_unlock(semaphore_t *s) { up(s); }