From a0b5bf033e30083d690e99d2d2c664a3adf1dc21 Mon Sep 17 00:00:00 2001 From: acevest Date: Sun, 22 Sep 2024 18:54:18 +0800 Subject: [PATCH] =?utf8?q?=E4=BF=AE=E5=A4=8DENTER=5FCRITICAL=5FZONE=20EXIT?= =?utf8?q?=5FCRITICAL=5FZONE=E5=B5=8C=E5=A5=97=E4=BD=BF=E7=94=A8=E6=97=B6?= =?utf8?q?=E4=BC=9A=E4=B8=A2=E5=A4=B1EFLAGS.IF=E4=BD=8D=E4=BF=A1=E6=81=AF?= =?utf8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- include/irq.h | 15 +++++++-------- kernel/printk.c | 13 +++++++------ qemu.sh | 2 +- 3 files changed, 15 insertions(+), 15 deletions(-) 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 \ -- 2.44.0