Don't save/restore flags and ebp on external calls - saves on stack space.
authorKevin O'Connor <kevin@koconnor.net>
Wed, 12 Mar 2008 00:38:33 +0000 (20:38 -0400)
committerKevin O'Connor <kevin@koconnor.net>
Wed, 12 Mar 2008 00:38:33 +0000 (20:38 -0400)
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.

TODO
src/boot.c
src/clock.c
src/mouse.c
src/romlayout.S
src/util.h

diff --git a/TODO b/TODO
index 603d763851f8e1d242213695dfdd51d669257f2d..e9c9d864b42bc800594ad51a4a176324c1dfe1e7 100644 (file)
--- 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.
index b1fa050f86d4efb2f5afc6b7ab549a35f14bf511..c75bc1b24804d3de7410f292f408760f500d89b7 100644 (file)
@@ -63,7 +63,10 @@ print_boot_failure(u16 type, u8 reason)
 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 @@ begin_boot()
 {
     if (CONFIG_ATA)
         ata_detect();
-    irq_enable();
     struct bregs br;
     memset(&br, 0, sizeof(br));
     call16_int(0x19, &br);
index c653c1f3bc38062e9d14c8393b4f422252d0c303..b9d75a3cd5a431a0aea15af20d7ab9e16466aa78 100644 (file)
@@ -356,6 +356,7 @@ handle_70()
         struct bregs br;
         memset(&br, 0, sizeof(br));
         call16_int(0x4a, &br);
+        irq_disable();
     }
     if (!(registerC & 0x40))
         goto done;
index 569488b7372b1f86102ced587f63293554f0eec9..6c214997e67cfb744145446b5c1b9a2cfa63ba77 100644 (file)
@@ -397,8 +397,6 @@ int74_function()
 
     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 @@ int74_function()
         "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"
         );
 }
 
index 9f0541a7c00b41c23c5bc9e083058c4813281158..d5253457593b25880a9e4991a0d1c343e2c51d18 100644 (file)
@@ -50,6 +50,8 @@ post16:
 set_entry32:
         pushl $0xf0000000
 
+        cld
+
         // Fall through to transition32 function below
 
 
@@ -92,8 +94,6 @@ transition32:
         movw %ax, %fs
         movw %ax, %gs
 
-        cld
-
         retl
 
 // Call a 16bit function from 32bit mode.
index 7d5b7c8b1eaeab746346dd6ab58ce5699f45e3f6..4df595a3eb4b0fc25b15981939bedb40869a267a 100644 (file)
@@ -45,6 +45,7 @@ static inline void hlt(void)
 // 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_both_pics()
     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