__asm__ __volatile__("pushl %0; popfl" ::"g"(x) : "memory", "cc"); \
} while (0)
+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 IRQ_CLOCK 0x00
#define IRQ_KEYBOARD 0x01
#define IRQ_CASCADE 0x02
irq_chip_t no_irq_chip = {.name = "none", .enable = enable_no_irq_chip, .disable = disable_no_irq_chip};
irq_desc_t no_irq_desc = {.chip = &no_irq_chip, .action = NULL, .status = 0, .depth = 0};
+
+// 单CPU
+static volatile uint32_t __critical_zone_eflags;
+void enter_critical_zone() { irq_save(__critical_zone_eflags); }
+void exit_critical_zone() { irq_restore(__critical_zone_eflags); }
char pkbuf[1024];
extern tty_t *const default_tty;
int printk(const char *fmtstr, ...) {
- unsigned long iflags;
- irq_save(iflags);
+ ENTER_CRITICAL_ZONE;
+
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);
- irq_restore(iflags);
+
+ EXIT_CRITICAL_ZONE;
return 0;
}
extern tty_t *const debug_tty;
char pdbuf[1024];
int printd(const char *fmtstr, ...) {
- unsigned long iflags;
- irq_save(iflags);
+ ENTER_CRITICAL_ZONE;
+
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);
- irq_restore(iflags);
+
+ EXIT_CRITICAL_ZONE;
return 0;
}
char plobuf[1024];
extern tty_t *const monitor_tty;
int printlo(unsigned int xpos, unsigned int ypos, const char *fmtstr, ...) {
- unsigned long iflags;
- irq_save(iflags);
+ ENTER_CRITICAL_ZONE;
+
char *args = (char *)(((char *)&fmtstr) + 4);
int size = vsprintf(plobuf, fmtstr, args);
tty_write_at(monitor_tty, xpos, ypos, plobuf, (size_t)size);
- irq_restore(iflags);
+
+ EXIT_CRITICAL_ZONE;
return 0;
}