Cleanup a20 code.
authorKevin O'Connor <kevin@koconnor.net>
Sun, 16 Nov 2008 14:17:02 +0000 (09:17 -0500)
committerKevin O'Connor <kevin@koconnor.net>
Sun, 16 Nov 2008 14:17:02 +0000 (09:17 -0500)
Fix two apparent bugs - set_a20() returned new status instead of old
    status and handle_152402() checked wrong bit.
Add bit definition for the a20 enable bit: A20_ENABLE_BIT
Allow ioport.h #defines to be used in romlayout.S.

Makefile
src/ioport.h
src/romlayout.S
src/system.c

index d5804f37a6edae86e2a8dc62956ba64b511519d3..7bfb34535ec23cd1f4f90d2d8c3c933550a638d0 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -84,7 +84,7 @@ $(OUT)%.16.s: %.c
 
 $(OUT)%.lds: %.lds.S
        @echo "  Precompiling $<"
-       $(Q)$(CPP) -P $< -o $@
+       $(Q)$(CPP) -P -D__ASSEMBLY__ $< -o $@
 
 
 $(OUT)blob.16.s: ; $(call whole-compile, $(CFLAGS16) -S, $(addprefix src/, $(SRC16)),$@)
@@ -92,7 +92,7 @@ $(OUT)blob.16.s: ; $(call whole-compile, $(CFLAGS16) -S, $(addprefix src/, $(SRC
 TABLEASM=$(addprefix $(OUT), $(patsubst %.c,%.proc.16.s,$(TABLESRC)))
 $(OUT)romlayout16.o: romlayout.S $(OUT)blob.16.s $(TABLEASM)
        @echo "  Generating 16bit layout of $@"
-       $(Q)$(CC) $(CFLAGS16) -c $< -o $@
+       $(Q)$(CC) $(CFLAGS16) -c -D__ASSEMBLY__ $< -o $@
 
 $(OUT)romlayout32.o: ; $(call whole-compile, $(CFLAGS), $(addprefix src/, $(SRC32)),$@)
 
index 196fe531a9a26650d2bd580e1e01ac76cdae320c..633ed0ed2aefc77ac478efecabbe35a3b53565fc 100644 (file)
@@ -6,8 +6,6 @@
 #ifndef __IOPORT_H
 #define __IOPORT_H
 
-#include "types.h" // u8
-
 #define PORT_DMA_ADDR_2        0x0004
 #define PORT_DMA_CNT_2         0x0005
 #define PORT_DMA1_MASK_REG     0x000a
 #define PORT_QEMU_CFG_DATA     0x0511
 #define PORT_BIOS_APM          0x8900
 
-// PORT_KBD_CTRLB bitdefs
-#define KBD_REFRESH (1<<4)
+// PORT_A20 bitdefs
+#define A20_ENABLE_BIT 0x02
 
+#ifndef __ASSEMBLY__
+
+#include "types.h" // u8
 
 static inline void outb(u8 value, u16 port) {
     __asm__ __volatile__("outb %b0, %w1" : : "a"(value), "Nd"(port));
@@ -101,4 +102,6 @@ static inline void outsl(u16 port, u32 *data, u32 count) {
                  : "+c"(count), "+S"(data) : "d"(port) : "memory");
 }
 
+#endif // !__ASSEMBLY__
+
 #endif // ioport.h
index f7c2b022070598d487610bce1e584524f8dfe228..e7c08bc430dd0c49525c336d75b0f76c444f6856 100644 (file)
@@ -5,7 +5,8 @@
 //
 // This file may be distributed under the terms of the GNU GPLv3 license.
 
-#include "config.h"
+#include "config.h" // CONFIG_*
+#include "ioport.h" // PORT_A20
 
 
 /****************************************************************
@@ -145,9 +146,9 @@ transition32:
         cli
 
         // enable a20
-        inb $0x92, %al
-        orb $0x02, %al
-        outb %al, $0x92
+        inb $PORT_A20, %al
+        orb $A20_ENABLE_BIT, %al
+        outb %al, $PORT_A20
 
         // Set segment descriptors
         lidt %cs:pmode_IDT_info
@@ -190,9 +191,9 @@ __call16_from32:
         movw %ax, %gs
 
         // disable a20
-        inb $0x92, %al
-        andb $~0x02, %al
-        outb %al, $0x92
+        inb $PORT_A20, %al
+        andb $~A20_ENABLE_BIT, %al
+        outb %al, $PORT_A20
 
         // Jump to 16bit mode
         ljmpw $SEG32_MODE16_CS, $1f
index f4e42635a89774fc3566a8afce863ecfa5693426..11b1cc8cc7639c246a967d9473faa19916e4293c 100644 (file)
@@ -19,12 +19,12 @@ set_a20(u8 cond)
     // get current setting first
     u8 newval, oldval = inb(PORT_A20);
     if (cond)
-        newval = oldval | 0x02;
+        newval = oldval | A20_ENABLE_BIT;
     else
-        newval = oldval & ~0x02;
+        newval = oldval & ~A20_ENABLE_BIT;
     outb(newval, PORT_A20);
 
-    return (newval & 0x02) != 0;
+    return (oldval & A20_ENABLE_BIT) != 0;
 }
 
 static void
@@ -44,7 +44,7 @@ handle_152401(struct bregs *regs)
 static void
 handle_152402(struct bregs *regs)
 {
-    regs->al = !!(inb(PORT_A20) & 0x20);
+    regs->al = (inb(PORT_A20) & A20_ENABLE_BIT) != 0;
     set_code_success(regs);
 }