From 18115aae5321dd559ef25e0097ea27f632aab1cc Mon Sep 17 00:00:00 2001
From: Yuri Zaporozhets <yuriz@qrv-systems.net>
Date: Tue, 5 Nov 2024 22:30:49 +0100
Subject: [PATCH] bios_emulator: for non-x86, print warnings if PM_{inp, outp}*
 access is attempted

Currently the PM_{inp,outp}* macros are completely broken on non-x86 architectures,
because they will essentially access random memory locations if called (and produce
a lot of rightful compilation warnings too). For now, replace those macros with
warnings (until the code is fixed), so the user at least knows that the emulator
attempted to access some x86 I/O port.

Signed-off-by: Yuri Zaporozhets <yuriz@qrv-systems.net>
---
 drivers/bios_emulator/biosemui.h | 41 ++++++++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)

diff --git a/drivers/bios_emulator/biosemui.h b/drivers/bios_emulator/biosemui.h
index 954cd883158..739a17cae5f 100644
--- a/drivers/bios_emulator/biosemui.h
+++ b/drivers/bios_emulator/biosemui.h
@@ -128,6 +128,7 @@ typedef struct {
 	u32 finalVal;
 } BE_portInfo;
 
+#if defined(X86EMU_RAW_IO)
 #define PM_inpb(port)	inb(port)
 #define PM_inpw(port)	inw(port)
 #define PM_inpd(port)	inl(port)
@@ -135,6 +136,46 @@ typedef struct {
 #define PM_outpw(port, val)	outw(val, port)
 #define PM_outpd(port, val)	outl(val, port)
 
+#else
+
+/*
+ * Until the emulator code is fixed, at least print warnings.
+ */
+
+static inline u8 PM_inpb(u16 port)
+{
+	printf("x86 port 0x%x read attempt, returning 0\n", port);
+	return 0;
+}
+
+static inline u16 PM_inpw(u16 port)
+{
+	printf("x86 port 0x%x read attempt, returning 0\n", port);
+	return 0;
+}
+
+static inline u32 PM_inpd(u16 port)
+{
+	printf("x86 port 0x%x read attempt, returning 0\n", port);
+	return 0;
+}
+
+static inline void PM_outpb(u16 port, u8 val)
+{
+	printf("x86 port 0x%x write attempt, ignoring\n", port);
+}
+
+static inline void PM_outpw(u16 port, u16 val)
+{
+	printf("x86 port 0x%x write attempt, ignoring\n", port);
+}
+
+static inline void PM_outpd(u16 port, u32 val)
+{
+	printf("x86 port 0x%x write attempt, ignoring\n", port);
+}
+#endif
+
 #define LOG_inpb(port)	PM_inpb(port)
 #define LOG_inpw(port)	PM_inpw(port)
 #define LOG_inpd(port)	PM_inpd(port)