console: Print a warning if a print is lost

Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
diff --git a/src/console.rs b/src/console.rs
index 4d6e80a..9bf2c24 100644
--- a/src/console.rs
+++ b/src/console.rs
@@ -5,6 +5,7 @@
 use crate::syscalls;
 use core::cell::Cell;
 use core::fmt;
+use core::fmt::Write;
 use core::mem;
 
 // Global console
@@ -41,11 +42,17 @@
     allow_buffer: [u8; 64],
 }
 
+pub static mut MISSED_PRINT: bool = false;
+
 pub fn get_global_console() -> Option<Console> {
     unsafe {
         if let Some(con) = CONSOLE.take() {
             Some(con)
         } else {
+            // If we get here then either the console was never initalised
+            // or someone else took it. Set MISSED_PRINT to true so that we
+            // can warn the user.
+            MISSED_PRINT = true;
             None
         }
     }
@@ -89,8 +96,15 @@
         Ok(())
     }
 
-    pub fn set_global_console(self) {
+    pub fn set_global_console(mut self) {
         unsafe {
+            if MISSED_PRINT {
+                // Someone tried to print while we were or someone tried
+                // to print before initalisation, print a warning here.
+                let _ = write!(self, "A print was dropped while the console was locked");
+                MISSED_PRINT = false;
+            }
+
             CONSOLE = Some(self);
         }
     }