Don't save/restore flags and ebp on external calls - saves on stack space.
It isn't necessary to save ebp - just mark it as clobbered.
The only important flag to save/restore is irqs - manually fixup all callers.
diff --git a/TODO b/TODO
index 603d763..e9c9d86 100644
--- a/TODO
+++ b/TODO
@@ -1,4 +1,5 @@
-Audit all sti/cli calls.
+Audit all sti/cli calls. Audit all call16 calls to make sure flags is
+setup properly with respect to irqs.
Audit statements where a 32bit intermediary changes meaning of a 16bit
comparison.
diff --git a/src/boot.c b/src/boot.c
index b1fa050..c75bc1b 100644
--- a/src/boot.c
+++ b/src/boot.c
@@ -63,7 +63,10 @@
static void
try_boot(u16 seq_nr)
{
+ irq_enable();
+
SET_IPL(sequence, seq_nr);
+
u16 bootseg;
u8 bootdrv = 0;
u16 bootdev, bootip;
@@ -210,7 +213,6 @@
{
if (CONFIG_ATA)
ata_detect();
- irq_enable();
struct bregs br;
memset(&br, 0, sizeof(br));
call16_int(0x19, &br);
diff --git a/src/clock.c b/src/clock.c
index c653c1f..b9d75a3 100644
--- a/src/clock.c
+++ b/src/clock.c
@@ -356,6 +356,7 @@
struct bregs br;
memset(&br, 0, sizeof(br));
call16_int(0x4a, &br);
+ irq_disable();
}
if (!(registerC & 0x40))
goto done;
diff --git a/src/mouse.c b/src/mouse.c
index 569488b..6c21499 100644
--- a/src/mouse.c
+++ b/src/mouse.c
@@ -397,8 +397,6 @@
u32 func = GET_EBDA(far_call_pointer);
asm volatile(
- "pushl %%ebp\n"
- "pushfl\n"
"pushl %0\n"
"pushw %w1\n" // status
"pushw %w2\n" // X
@@ -406,11 +404,10 @@
"pushw $0\n" // Z
"lcallw *8(%%esp)\n"
"addl $12, %%esp\n"
- "popfl\n"
- "popl %%ebp\n"
+ "cld\n"
: "+a" (func), "+b" (status), "+c" (X), "+d" (Y)
:
- : "esi", "edi"
+ : "esi", "edi", "ebp", "cc"
);
}
diff --git a/src/romlayout.S b/src/romlayout.S
index 9f0541a..d525345 100644
--- a/src/romlayout.S
+++ b/src/romlayout.S
@@ -50,6 +50,8 @@
set_entry32:
pushl $0xf0000000
+ cld
+
// Fall through to transition32 function below
@@ -92,8 +94,6 @@
movw %ax, %fs
movw %ax, %gs
- cld
-
retl
// Call a 16bit function from 32bit mode.
diff --git a/src/util.h b/src/util.h
index 7d5b7c8..4df595a 100644
--- a/src/util.h
+++ b/src/util.h
@@ -45,6 +45,7 @@
// XXX - move this to a c file and use PANIC PORT.
#define BX_PANIC(fmt, args...) do { \
bprintf(0, fmt , ##args); \
+ irq_disable(); \
for (;;) \
hlt(); \
} while (0)
@@ -83,22 +84,20 @@
eoi_master_pic();
}
+// Call a function with a specified register state. Note that on
+// return, the interrupt enable/disable flag may be altered.
static inline
void call16(struct bregs *callregs)
{
asm volatile(
- "pushl %%ebp\n" // Save state
- "pushfl\n"
#ifdef MODE16
"calll __call16\n"
#else
"calll __call16_from32\n"
#endif
- "popfl\n" // Restore state
- "popl %%ebp\n"
: "+a" (callregs), "+m" (*callregs)
:
- : "ebx", "ecx", "edx", "esi", "edi");
+ : "ebx", "ecx", "edx", "esi", "edi", "ebp", "cc");
}
static inline