Xen: Autodetect debug I/O port at runtime instead of via Kconfig

This allows a common image which supports Xen to still print debug

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
diff --git a/src/Kconfig b/src/Kconfig
index 8120ff7..8932c9e 100644
--- a/src/Kconfig
+++ b/src/Kconfig
@@ -361,11 +361,4 @@
             information by outputing strings in a special port present in the
             IO space.
 
-    config DEBUG_IO_PORT
-        depends on DEBUG_IO
-        hex "Debug IO port address"
-        default 0x0402
-        help
-            Bochs uses the 0x0402 address by default, whereas Xen
-            makes the 0xe9 IO address available for guests use.
 endmenu
diff --git a/src/output.c b/src/output.c
index 37c4942..83de7f4 100644
--- a/src/output.c
+++ b/src/output.c
@@ -23,6 +23,8 @@
 
 #define DEBUG_TIMEOUT 100000
 
+u16 DebugOutputPort VAR16VISIBLE = 0x402;
+
 void
 debug_serial_setup(void)
 {
@@ -77,7 +79,7 @@
         return;
     if (CONFIG_DEBUG_IO)
         // Send character to debug port.
-        outb(c, CONFIG_DEBUG_IO_PORT);
+        outb(c, GET_GLOBAL(DebugOutputPort));
     if (c == '\n')
         debug_serial('\r');
     debug_serial(c);
diff --git a/src/util.h b/src/util.h
index dbee0e5..ef8ec7c 100644
--- a/src/util.h
+++ b/src/util.h
@@ -231,6 +231,7 @@
 void check_preempt(void);
 
 // output.c
+extern u16 DebugOutputPort;
 void debug_serial_setup(void);
 void panic(const char *fmt, ...)
     __attribute__ ((format (printf, 1, 2))) __noreturn;
diff --git a/src/xen.c b/src/xen.c
index b18cca2..41aab98 100644
--- a/src/xen.c
+++ b/src/xen.c
@@ -65,6 +65,10 @@
         dprintf(1, "Found hypervisor signature \"%s\" at %x\n",
                 signature, base);
         if (strcmp(signature, "XenVMMXenVMM") == 0) {
+            /* Set debug_io_port first, so the following messages work. */
+            DebugOutputPort = 0xe9;
+            dprintf(1, "SeaBIOS (version %s)\n\n", VERSION);
+            dprintf(1, "Found Xen hypervisor signature at %x\n", base);
             if ((eax - base) < 2)
                 panic("Insufficient Xen cpuid leaves. eax=%x at base %x\n",
                       eax, base);
@@ -72,6 +76,8 @@
             break;
         }
     }
+    if (!xen_cpuid_base)
+        dprintf(1, "No Xen hypervisor found.\n");
 }
 
 static int hypercall_xen_version( int cmd, void *arg)