]> hydra-www.ietfng.org Git - xv6-public/commitdiff
Replace pushcli/popcli because seginit runs too late.
authorPeter H. Froehlich <peter.hans.froehlich@gmail.com>
Wed, 21 Oct 2015 01:42:18 +0000 (21:42 -0400)
committerPeter H. Froehlich <peter.hans.froehlich@gmail.com>
Wed, 21 Oct 2015 01:42:18 +0000 (21:42 -0400)
debug.c

diff --git a/debug.c b/debug.c
index 20fe2d3ed8514d914b6e3ef346b5da291b5ecd52..365dcbdd4d75421c3059ecd8317e08d666e68778 100644 (file)
--- a/debug.c
+++ b/debug.c
@@ -2,22 +2,40 @@
 // Requires that QEMU was started with a second serial port, otherwise
 // debug output is suppressed.
 //
-// We want to allow debug output as early as possible and from anywhere,
-// including the spinlock code. This requires a custom lock to make sure
-// output is complete and consistent.
+// We want to allow debug output as early as possible and from anywhere.
+// This requires custom locking code to ensure our output is consistent,
+// the existing spinlocks as well as pushcli/popcli cannot be used until
+// after seginit() has set up "cpu" correctly.
 
 #include "types.h"
 #include "defs.h"
 #include "x86.h"
+#include "mmu.h"
 #include "uart.h"
 
 static int uart;  // do we have a second uart?
 static volatile uint locked;  // custom lock
+static volatile uint intena;  // custom xcli/xsti
+
+static void
+xcli(void)
+{
+  intena = readeflags() & FL_IF;
+  // possible race, see TRICKS though
+  cli();
+}
+
+static void
+xsti(void)
+{
+  if(intena)
+    sti();
+}
 
 static void
 lock(void)
 {
-  pushcli();
+  xcli();
   while(xchg(&locked, 1) != 0)
     ;
 }
@@ -26,7 +44,7 @@ static void
 unlock(void)
 {
   xchg(&locked, 0);
-  popcli();
+  xsti();
 }
 
 static int