x86 realmode: Use x86emu register file + defines

By using the (global) register file as defined by x86emu,
we can use the same register access for YABEL and realmode
interrupt handlers.

- the x86 realmode interrupt handlers changed in signature
- to access registers, use X86_$REGNAME now (eg. X86_EAX)
- x86_exception_handler still uses struct eregs *regs to
  avoid spilling the x86emu register file stuff everywhere

Coccinelle script that handled most of this commit:
  @ inthandler @
  identifier FUNC, regs;
  @@
  int FUNC(
  -struct eregs *regs
  +void
   )
  { ... }

  @ depends on inthandler @
  identifier regs;
  @@
  -regs->eax
  +X86_EAX

  @ depends on inthandler @
  identifier regs;
  @@
  -regs->ebx
  +X86_EBX

  @ depends on inthandler @
  identifier regs;
  @@
  -regs->ecx
  +X86_ECX

  @ depends on inthandler @
  identifier regs;
  @@
  -regs->edx
  +X86_EDX

  @ depends on inthandler @
  identifier regs;
  @@
  -regs->esi
  +X86_ESI

  @ depends on inthandler @
  identifier regs;
  @@
  -regs->edi
  +X86_EDI

  @ depends on inthandler @
  identifier regs;
  @@
  -regs->eflags
  +X86_EFLAGS

  @ depends on inthandler @
  identifier regs;
  @@
  -regs->vector
  +M.x86.intno

Change-Id: I60cc2c36646fe4b7f97457b1e297e3df086daa36
Signed-off-by: Patrick Georgi <patrick.georgi@secunet.com>
Reviewed-on: http://review.coreboot.org/1891
Tested-by: build bot (Jenkins)
Reviewed-by: Stefan Reinauer <stefan.reinauer@coreboot.org>
diff --git a/src/devices/oprom/realmode/x86_interrupts.c b/src/devices/oprom/realmode/x86_interrupts.c
index b4ff135..b3764f9 100644
--- a/src/devices/oprom/realmode/x86_interrupts.c
+++ b/src/devices/oprom/realmode/x86_interrupts.c
@@ -27,6 +27,8 @@
 #include <arch/io.h>
 #include <arch/registers.h>
 #include "x86.h"
+/* we use x86emu's register file representation */
+#include <x86emu/regs.h>
 
 // errors go in AH. Just set these up so that word assigns
 // will work. KISS.
@@ -38,27 +40,27 @@
 	PCIBIOS_BADREG = 0x8700
 };
 
-int int10_handler(struct eregs *regs)
+int int10_handler(void)
 {
 	int res=0;
 	static u8 cursor_row=0, cursor_col=0;
-	switch((regs->eax & 0xff00)>>8) {
+	switch((X86_EAX & 0xff00)>>8) {
 	case 0x01: // Set cursor shape
 		res = 1;
 		break;
 	case 0x02: // Set cursor position
-		if (cursor_row != ((regs->edx >> 8) & 0xff) ||
-		    cursor_col >= (regs->edx & 0xff)) {
+		if (cursor_row != ((X86_EDX >> 8) & 0xff) ||
+		    cursor_col >= (X86_EDX & 0xff)) {
 			printk(BIOS_INFO, "\n");
 		}
-		cursor_row = (regs->edx >> 8) & 0xff;
-		cursor_col = regs->edx & 0xff;
+		cursor_row = (X86_EDX >> 8) & 0xff;
+		cursor_col = X86_EDX & 0xff;
 		res = 1;
 		break;
 	case 0x03: // Get cursor position
-		regs->eax &= 0x00ff;
-		regs->ecx = 0x0607;
-		regs->edx = (cursor_row << 8) | cursor_col;
+		X86_EAX &= 0x00ff;
+		X86_ECX = 0x0607;
+		X86_EDX = (cursor_row << 8) | cursor_col;
 		res = 1;
 		break;
 	case 0x06: // Scroll up
@@ -66,48 +68,48 @@
 		res = 1;
 		break;
 	case 0x08: // Get Character and Mode at Cursor Position
-		regs->eax = 0x0f00 | 'A'; // White on black 'A'
+		X86_EAX = 0x0f00 | 'A'; // White on black 'A'
 		res = 1;
 		break;
 	case 0x09: // Write Character and attribute
 	case 0x0e: // Write Character
-		printk(BIOS_INFO, "%c", regs->eax & 0xff);
+		printk(BIOS_INFO, "%c", X86_EAX & 0xff);
 		res = 1;
 		break;
 	case 0x0f: // Get video mode
-		regs->eax = 0x5002; //80x25
-		regs->ebx &= 0x00ff;
+		X86_EAX = 0x5002; //80x25
+		X86_EBX &= 0x00ff;
 		res = 1;
 		break;
         default:
 		printk(BIOS_WARNING, "Unknown INT10 function %04x!\n",
-				regs->eax & 0xffff);
+				X86_EAX & 0xffff);
 		break;
 	}
 	return res;
 }
 
-int int12_handler(struct eregs *regs)
+int int12_handler(void)
 {
-	regs->eax = 64 * 1024;
+	X86_EAX = 64 * 1024;
 	return 1;
 }
 
-int int16_handler(struct eregs *regs)
+int int16_handler(void)
 {
 	int res=0;
-	switch((regs->eax & 0xff00)>>8) {
+	switch((X86_EAX & 0xff00)>>8) {
 	case 0x00: // Check for Keystroke
-		regs->eax = 0x6120; // Space Bar, Space
+		X86_EAX = 0x6120; // Space Bar, Space
 		res = 1;
 		break;
 	case 0x01: // Check for Keystroke
-		regs->eflags |= 1<<6; // Zero Flag set (no key available)
+		X86_EFLAGS |= 1<<6; // Zero Flag set (no key available)
 		res = 1;
 		break;
         default:
 		printk(BIOS_WARNING, "Unknown INT16 function %04x!\n",
-				regs->eax & 0xffff);
+				X86_EAX & 0xffff);
 		break;
 	}
 	return res;
@@ -116,9 +118,9 @@
 #define PCI_CONFIG_SPACE_TYPE1	(1 << 0)
 #define PCI_SPECIAL_CYCLE_TYPE1	(1 << 4)
 
-int int1a_handler(struct eregs *regs)
+int int1a_handler(void)
 {
-	unsigned short func = (unsigned short)regs->eax;
+	unsigned short func = (unsigned short)X86_EAX;
 	int retval = 1;
 	unsigned short devid, vendorid, devfn;
 	/* Use short to get rid of gabage in upper half of 32-bit register */
@@ -131,19 +133,19 @@
 
 	switch (func) {
 	case 0xb101: /* PCIBIOS Check */
-		regs->edx = 0x20494350;	/* ' ICP' */
-		regs->eax &= 0xffff0000; /* Clear AH / AL */
-		regs->eax |= PCI_CONFIG_SPACE_TYPE1 | PCI_SPECIAL_CYCLE_TYPE1;
+		X86_EDX = 0x20494350;	/* ' ICP' */
+		X86_EAX &= 0xffff0000; /* Clear AH / AL */
+		X86_EAX |= PCI_CONFIG_SPACE_TYPE1 | PCI_SPECIAL_CYCLE_TYPE1;
 		// last bus in the system. Hard code to 255 for now.
 		// dev_enumerate() does not seem to tell us (publically)
-		regs->ecx = 0xff;
-		regs->edi = 0x00000000;	/* protected mode entry */
+		X86_ECX = 0xff;
+		X86_EDI = 0x00000000;	/* protected mode entry */
 		retval = 1;
 		break;
 	case 0xb102: /* Find Device */
-		devid = regs->ecx;
-		vendorid = regs->edx;
-		devindex = regs->esi;
+		devid = X86_ECX;
+		vendorid = X86_EDX;
+		devindex = X86_ESI;
 		dev = 0;
 		while ((dev = dev_find_device(vendorid, devid, dev))) {
 			if (devindex <= 0)
@@ -152,18 +154,18 @@
 		}
 		if (dev) {
 			unsigned short busdevfn;
-			regs->eax &= 0xffff00ff; /* Clear AH */
-			regs->eax |= PCIBIOS_SUCCESSFUL;
+			X86_EAX &= 0xffff00ff; /* Clear AH */
+			X86_EAX |= PCIBIOS_SUCCESSFUL;
 			// busnum is an unsigned char;
 			// devfn is an int, so we mask it off.
 			busdevfn = (dev->bus->secondary << 8)
 			    | (dev->path.pci.devfn & 0xff);
 			printk(BIOS_DEBUG, "0x%x: return 0x%x\n", func, busdevfn);
-			regs->ebx = busdevfn;
+			X86_EBX = busdevfn;
 			retval = 1;
 		} else {
-			regs->eax &= 0xffff00ff; /* Clear AH */
-			regs->eax |= PCIBIOS_NODEV;
+			X86_EAX &= 0xffff00ff; /* Clear AH */
+			X86_EAX |= PCIBIOS_NODEV;
 			retval = 0;
 		}
 		break;
@@ -173,57 +175,57 @@
 	case 0xb10d: /* Write Config Dword */
 	case 0xb10c: /* Write Config Word */
 	case 0xb10b: /* Write Config Byte */
-		devfn = regs->ebx & 0xff;
-		bus = regs->ebx >> 8;
-		reg = regs->edi;
+		devfn = X86_EBX & 0xff;
+		bus = X86_EBX >> 8;
+		reg = X86_EDI;
 		dev = dev_find_slot(bus, devfn);
 		if (!dev) {
 			printk(BIOS_DEBUG, "0x%x: BAD DEVICE bus %d devfn 0x%x\n", func, bus, devfn);
 			// Or are we supposed to return PCIBIOS_NODEV?
-			regs->eax &= 0xffff00ff; /* Clear AH */
-			regs->eax |= PCIBIOS_BADREG;
+			X86_EAX &= 0xffff00ff; /* Clear AH */
+			X86_EAX |= PCIBIOS_BADREG;
 			retval = 0;
 			return retval;
 		}
 		switch (func) {
 		case 0xb108: /* Read Config Byte */
 			byte = pci_read_config8(dev, reg);
-			regs->ecx = byte;
+			X86_ECX = byte;
 			break;
 		case 0xb109: /* Read Config Word */
 			word = pci_read_config16(dev, reg);
-			regs->ecx = word;
+			X86_ECX = word;
 			break;
 		case 0xb10a: /* Read Config Dword */
 			dword = pci_read_config32(dev, reg);
-			regs->ecx = dword;
+			X86_ECX = dword;
 			break;
 		case 0xb10b: /* Write Config Byte */
-			byte = regs->ecx;
+			byte = X86_ECX;
 			pci_write_config8(dev, reg, byte);
 			break;
 		case 0xb10c: /* Write Config Word */
-			word = regs->ecx;
+			word = X86_ECX;
 			pci_write_config16(dev, reg, word);
 			break;
 		case 0xb10d: /* Write Config Dword */
-			dword = regs->ecx;
+			dword = X86_ECX;
 			pci_write_config32(dev, reg, dword);
 			break;
 		}
 
 #if CONFIG_REALMODE_DEBUG
 		printk(BIOS_DEBUG, "0x%x: bus %d devfn 0x%x reg 0x%x val 0x%x\n",
-			     func, bus, devfn, reg, regs->ecx);
+			     func, bus, devfn, reg, X86_ECX);
 #endif
-		regs->eax &= 0xffff00ff; /* Clear AH */
-		regs->eax |= PCIBIOS_SUCCESSFUL;
+		X86_EAX &= 0xffff00ff; /* Clear AH */
+		X86_EAX |= PCIBIOS_SUCCESSFUL;
 		retval = 1;
 		break;
 	default:
 		printk(BIOS_ERR, "UNSUPPORTED PCIBIOS FUNCTION 0x%x\n", func);
-		regs->eax &= 0xffff00ff; /* Clear AH */
-		regs->eax |= PCIBIOS_UNSUPPORTED;
+		X86_EAX &= 0xffff00ff; /* Clear AH */
+		X86_EAX |= PCIBIOS_UNSUPPORTED;
 		retval = 0;
 		break;
 	}