:: commit b3385b80272f5c861c87dda536e812451cff5036

mintsuki <mintsuki@protonmail.com> — 2024-07-20 17:30

parents: ed915c3157

bios/a20: Improve a20_check(). Could fix #386

diff --git a/common/sys/a20.s2.c b/common/sys/a20.s2.c
index 4adfc947..0c55e737 100644
--- a/common/sys/a20.s2.c
+++ b/common/sys/a20.s2.c
@@ -8,15 +8,26 @@
 #include <lib/real.h>
 
 bool a20_check(void) {
-    if (mminw(0x7dfe) != mminw(0x7dfe + 0x100000))
-        return true;
+    bool ret = false;
+    uint16_t orig = mminw(0x7dfe);
+
+    mmoutw(0x7dfe, 0x1234);
+
+    if (mminw(0x7dfe) != mminw(0x7dfe + 0x100000)) {
+        ret = true;
+        goto out;
+    }
 
     mmoutw(0x7dfe, ~mminw(0x7dfe));
 
-    if (mminw(0x7dfe) != mminw(0x7dfe + 0x100000))
-        return true;
+    if (mminw(0x7dfe) != mminw(0x7dfe + 0x100000)) {
+        ret = true;
+        goto out;
+    }
 
-    return false;
+out:
+    mmoutw(0x7dfe, orig);
+    return ret;
 }
 
 // Keyboard controller method code below taken from:
tab: 248 wrap: offon