From: acevest Date: Sun, 22 Sep 2024 10:54:18 +0000 (+0800) Subject: 修复ENTER_CRITICAL_ZONE EXIT_CRITICAL_ZONE嵌套使用时会丢失EFLAGS.IF位信息的问题 X-Git-Url: http://zhaoyanbai.com/repos/%22http:/www.isc.org/icons/zpipe.c?a=commitdiff_plain;h=a0b5bf033e30083d690e99d2d2c664a3adf1dc21;p=kernel.git 修复ENTER_CRITICAL_ZONE EXIT_CRITICAL_ZONE嵌套使用时会丢失EFLAGS.IF位信息的问题 --- diff --git a/include/irq.h b/include/irq.h index b0002ba..647d469 100644 --- a/include/irq.h +++ b/include/irq.h @@ -79,14 +79,13 @@ bool irq_disabled(); void enter_critical_zone(); void exit_critical_zone(); -#define ENTER_CRITICAL_ZONE \ - do { \ - enter_critical_zone(); \ - } while (0) -#define EXIT_CRITICAL_ZONE \ - do { \ - exit_critical_zone(); \ - } while (0) +#define ENTER_CRITICAL_ZONE(x) \ + volatile uint32_t __critical_zone_eflags_##x = 0; \ + irq_save(__critical_zone_eflags_##x); + + +#define EXIT_CRITICAL_ZONE(x) \ + irq_restore(__critical_zone_eflags_##x); #define IRQ_CLOCK 0x00 #define IRQ_KEYBOARD 0x01 diff --git a/kernel/printk.c b/kernel/printk.c index 44f71e7..b5a5ef8 100644 --- a/kernel/printk.c +++ b/kernel/printk.c @@ -26,28 +26,29 @@ void serial_write(const char *buf, size_t size); extern tty_t *const default_tty; int printk(const char *fmtstr, ...) { static char pkbuf[1024]; - ENTER_CRITICAL_ZONE; + + ENTER_CRITICAL_ZONE(EFLAGS); char *args = (char *)(((char *)&fmtstr) + 4); int size = vsprintf(pkbuf, fmtstr, args); tty_write(default_tty, pkbuf, (size_t)size); serial_write(pkbuf, (size_t)size); - EXIT_CRITICAL_ZONE; + EXIT_CRITICAL_ZONE(EFLAGS); return 0; } extern tty_t *const debug_tty; int printd(const char *fmtstr, ...) { static char pdbuf[1024]; - ENTER_CRITICAL_ZONE; + ENTER_CRITICAL_ZONE(EFLAGS); char *args = (char *)(((char *)&fmtstr) + 4); int size = vsprintf(pdbuf, fmtstr, args); tty_write(debug_tty, pdbuf, (size_t)size); serial_write(pdbuf, (size_t)size); - EXIT_CRITICAL_ZONE; + EXIT_CRITICAL_ZONE(EFLAGS); return 0; } @@ -56,11 +57,11 @@ extern tty_t *const monitor_tty; int printlo(unsigned int xpos, unsigned int ypos, const char *fmtstr, ...) { static char plobuf[1024]; char *args = (char *)(((char *)&fmtstr) + 4); - ENTER_CRITICAL_ZONE; + ENTER_CRITICAL_ZONE(EFLAGS); int size = vsprintf(plobuf, fmtstr, args); tty_write_at(monitor_tty, xpos, ypos, plobuf, (size_t)size); - EXIT_CRITICAL_ZONE; + EXIT_CRITICAL_ZONE(EFLAGS); return 0; } diff --git a/qemu.sh b/qemu.sh index 9fd85e0..e620846 100755 --- a/qemu.sh +++ b/qemu.sh @@ -23,7 +23,6 @@ qemu-system-i386 \ -serial tcp::6666,server,nowait \ -drive file=HD.IMG,format=raw,index=0,media=disk \ -drive file=kernel.iso,index=1,media=cdrom \ - -drive file=HDb.IMG,format=raw,index=2,media=disk \ -name kernel \ -device ich9-ahci,id=ahci \ -vga std \ @@ -31,6 +30,7 @@ qemu-system-i386 \ -s -S \ & + #-drive file=HDb.IMG,format=raw,index=2,media=disk \ #-cpu qemu32,+apic \ #-cpu core2duo-v1,+apic \