vgabios: fix compilation after x86emu changes

This utility links in coreboot code, and has been broken for a while
again after removing some hacks from coreboot. I hadn't realized how
bad it was broken last time, and since most of this stuff is still
in a pretty bad shape, I decided to throw all of the changes together.

Signed-off-by: Stefan Reinauer <stefan.reinauer@coreboot.org>

Change-Id: If3e4399b1b0e947433b97caa29962ef66ea2993d
Reviewed-on: http://review.coreboot.org/11736
Tested-by: build bot (Jenkins)
Reviewed-by: Patrick Georgi <pgeorgi@google.com>
This commit is contained in:
Stefan Reinauer 2015-09-28 13:12:04 -07:00 committed by Stefan Reinauer
parent 3acece2362
commit 850e7d4884
14 changed files with 145 additions and 84 deletions

View File

@ -6,35 +6,57 @@
# /usr/lib/... # /usr/lib/...
# #
CC = gcc TOP ?= ../..
CFLAGS = -O2 -g -fomit-frame-pointer
CC ?= gcc
CFLAGS ?= -O2 -g -fomit-frame-pointer
CFLAGS += -Wall -Wundef -Wstrict-prototypes -Wmissing-prototypes CFLAGS += -Wall -Wundef -Wstrict-prototypes -Wmissing-prototypes
CFLAGS += -Wwrite-strings -Wredundant-decls -Wno-trigraphs CFLAGS += -Wwrite-strings -Wredundant-decls -Wstrict-aliasing -Wshadow -Wextra
CFLAGS += -Wstrict-aliasing -Wshadow -Wextra
INCLUDES = -Iinclude -I../../src/device/oprom/include/ -I../../src --include include/stdtypes.h # TODO check host architecture
CBCFLAGS = -DCONFIG_ARCH_X86=1 -Wno-sign-compare -Wno-unused-but-set-variable -Wno-unused-parameter
INTOBJS = int10.o int15.o int16.o int1a.o inte6.o INCLUDES = -Iinclude -I$(TOP)/src/device/oprom/include/
X86EMUOBJS = sys.o decode.o ops.o ops2.o prim_ops.o fpu.o debug.o CBINCLUDES = -I$(TOP)/src --include include/stdtypes.h
OBJS = testbios.o helper_exec.o helper_mem.o $(INTOBJS) $(X86EMUOBJS) CBINCLUDES += --include $(TOP)/src/commonlib/include/commonlib/loglevel.h
CBINCLUDES += -include stdio.h
# user space pci is the only option right now. SOURCE = int10.c int15.c int16.c int1a.c inte6.c testbios.c
OBJS += pci-userspace.o SOURCE += helper_exec.c helper_mem.c pci-userspace.c
X86EMU = sys.c decode.c ops.c ops2.c prim_ops.c fpu.c debug.c
X86EMU_DIR = $(TOP)/src/device/oprom/x86emu
X86EMU_SOURCE = $(addprefix $(X86EMU_DIR)/, $(X86EMU))
OBJECTS:=$(SOURCE:.c=.o) $(X86EMU:.c=.o)
LIBS=-lpci LIBS=-lpci
all: testbios all: dep testbios
testbios: $(OBJS) testbios: $(OBJECTS)
printf " LINK $(notdir $@)\n"
$(CC) $(CFLAGS) -o $@ $^ $(LIBS) $(CC) $(CFLAGS) -o $@ $^ $(LIBS)
helper_exec.o: helper_exec.c test.h dep: $(SOURCE) $(X86EMU_SOURCE) Makefile
$(CC) $(CFLAGS) $(INCLUDES) -MM $(SOURCE) > .dependencies
$(CC) $(CFLAGS) $(INCLUDES) $(CBCFLAGS) $(CBINCLUDES) -MM $(X86EMU_SOURCE) >> .dependencies
clean: clean:
rm -f *.o *~ testbios rm -f *.o *~ testbios
%.o: ../../src/device/oprom/x86emu/%.c distclean: clean
$(CC) $(CFLAGS) $(INCLUDES) -include stdio.h -c -o $@ $^ rm -f .dependencies
%.o: $(X86EMU_DIR)/%.c
printf " CC (x86emu) $(notdir $<)\n"
$(CC) $(CFLAGS) $(CBCFLAGS) $(INCLUDES) $(CBINCLUDES) -c -o $@ $<
%.o: %.c %.o: %.c
printf " CC $(notdir $<)\n"
$(CC) $(CFLAGS) $(INCLUDES) -c -o $@ $< $(CC) $(CFLAGS) $(INCLUDES) -c -o $@ $<
.PHONY: all clean distclean
.SILENT:
-include .dependencies

View File

@ -14,21 +14,13 @@
* in xf86EnableIO(). Otherwise we won't trap * in xf86EnableIO(). Otherwise we won't trap
* on PIO. * on PIO.
*/ */
#include <x86emu/x86emu.h>
#include "helper_exec.h"
#include "test.h"
#include <sys/io.h> #include <sys/io.h>
#include <sys/time.h> #include <sys/time.h>
#include <stdio.h> #include <stdio.h>
#include <stdtypes.h>
#include <x86emu/x86emu.h>
int port_rep_inb(u16 port, u32 base, int d_f, u32 count); #include "helper_exec.h"
u8 x_inb(u16 port); #include "testbios.h"
u16 x_inw(u16 port);
void x_outb(u16 port, u8 val);
void x_outw(u16 port, u16 val);
u32 x_inl(u16 port);
void x_outl(u16 port, u32 val);
/* general software interrupt handler */ /* general software interrupt handler */
u32 getIntVect(int num) u32 getIntVect(int num)
@ -59,6 +51,8 @@ int run_bios_int(int num)
return 1; return 1;
} }
#if 0
int port_rep_inb(u16 port, u32 base, int d_f, u32 count) int port_rep_inb(u16 port, u32 base, int d_f, u32 count)
{ {
register int inc = d_f ? -1 : 1; register int inc = d_f ? -1 : 1;
@ -125,6 +119,8 @@ int port_rep_outl(u16 port, u32 base, int d_f, u32 count)
return dst - base; return dst - base;
} }
#endif
u8 x_inb(u16 port) u8 x_inb(u16 port)
{ {
u8 val; u8 val;
@ -175,6 +171,7 @@ void x_outl(u16 port, u32 val)
outl(val, port); outl(val, port);
} }
#if 0
u8 Mem_rb(int addr) u8 Mem_rb(int addr)
{ {
return (*current->mem->rb) (current, addr); return (*current->mem->rb) (current, addr);
@ -204,6 +201,7 @@ void Mem_wl(int addr, u32 val)
{ {
(*current->mem->wl) (current, addr, val); (*current->mem->wl) (current, addr, val);
} }
#endif
void getsecs(unsigned long *sec, unsigned long *usec) void getsecs(unsigned long *sec, unsigned long *usec)
{ {

View File

@ -1,2 +1,32 @@
#ifndef __HELPER_EXEC_H__
#define __HELPER_EXEC_H__
u32 getIntVect(int num); u32 getIntVect(int num);
int run_bios_int(int num); int run_bios_int(int num);
void pushw(u16 val);
int port_rep_inb(u16 port, u32 base, int d_f, u32 count);
int port_rep_inw(u16 port, u32 base, int d_f, u32 count);
int port_rep_inl(u16 port, u32 base, int d_f, u32 count);
int port_rep_outb(u16 port, u32 base, int d_f, u32 count);
int port_rep_outw(u16 port, u32 base, int d_f, u32 count);
int port_rep_outl(u16 port, u32 base, int d_f, u32 count);
u8 x_inb(u16 port);
u16 x_inw(u16 port);
void x_outb(u16 port, u8 val);
void x_outw(u16 port, u16 val);
u32 x_inl(u16 port);
void x_outl(u16 port, u32 val);
u8 Mem_rb(int addr);
u16 Mem_rw(int addr);
u32 Mem_rl(int addr);
void Mem_wb(int addr, u8 val);
void Mem_ww(int addr, u16 val);
void Mem_wl(int addr, u32 val);
void getsecs(unsigned long *sec, unsigned long *usec);
u8 bios_checksum(u8 * start, int size);
#endif

View File

@ -1,4 +1,6 @@
#ifndef _CONSOLE_CONSOLE_H #ifndef _CONSOLE_CONSOLE_H
#define _CONSOLE_CONSOLE_H #define _CONSOLE_CONSOLE_H
#define CONFIG_X86EMU_DEBUG 1 #define CONFIG_X86EMU_DEBUG 1
int printk(int msg_level, const char *fmt, ...) __attribute__((format(printf, 2, 3)));
#endif #endif

View File

@ -1,9 +1,7 @@
#include <stdio.h> #include <stdio.h>
#include "test.h" #include <stdtypes.h>
#include "pci.h" #include "testbios.h"
void x86emu_dump_xregs(void);
extern ptr current;
extern int verbose; extern int verbose;
@ -16,7 +14,7 @@ extern int verbose;
* arise. What are "Not Implemented" throughout are video memory accesses. * arise. What are "Not Implemented" throughout are video memory accesses.
* Also, very little input validity checking is done here. * Also, very little input validity checking is done here.
*/ */
int int42_handler() int int42_handler(void)
{ {
#if 0 #if 0
if (verbose && X86_AH != 0x0e) { if (verbose && X86_AH != 0x0e) {

View File

@ -1,12 +1,11 @@
#include <stdio.h> #include <stdio.h>
#include "test.h" #include <stdtypes.h>
#include "testbios.h"
void x86emu_dump_xregs();
int int15_handler(void) int int15_handler(void)
{ {
printf("\nint15 encountered.\n"); printf("\nint15 encountered.\n");
//x86emu_dump_xregs(); x86emu_dump_xregs();
X86_EAX = 0; X86_EAX = 0;
return 1; return 1;
} }

View File

@ -1,7 +1,9 @@
#include <stdio.h> #include <stdio.h>
#include "testbios.h"
int int16_handler(void) int int16_handler(void)
{ {
printf("\nint16: keyboard not supported right now.\n"); printf("\nint16: keyboard not supported right now.\n");
x86emu_dump_xregs();
return 1; return 1;
} }

View File

@ -1,5 +1,6 @@
#include <stdio.h> #include <stdio.h>
#include "test.h" #include <stdtypes.h>
#include "testbios.h"
#include "pci-userspace.h" #include "pci-userspace.h"
#define DEBUG_INT1A #define DEBUG_INT1A
@ -8,13 +9,11 @@
#define DEVICE_NOT_FOUND 0x86 #define DEVICE_NOT_FOUND 0x86
#define BAD_REGISTER_NUMBER 0x87 #define BAD_REGISTER_NUMBER 0x87
void x86emu_dump_xregs(void);
extern int verbose; extern int verbose;
int int1A_handler(void)
int int1A_handler()
{ {
PCITAG tag; PCITAG tag = NULL;
pciVideoPtr pvp = NULL; pciVideoPtr pvp = NULL;
if (verbose) { if (verbose) {
@ -40,7 +39,7 @@ int int1A_handler()
if (X86_DX == pvp->vendor_id && X86_CX == pvp->device_id && X86_ESI == 0) { if (X86_DX == pvp->vendor_id && X86_CX == pvp->device_id && X86_ESI == 0) {
X86_EAX = X86_AL | (SUCCESSFUL << 8); X86_EAX = X86_AL | (SUCCESSFUL << 8);
X86_EFLAGS &= ~((unsigned long) 0x01); /* clear carry flag */ X86_EFLAGS &= ~((unsigned long) 0x01); /* clear carry flag */
X86_EBX = pciSlotBX(pvp); X86_EBX = pciSlotBX(tag); // XXX used to be pvp, but both are NULL
} }
#ifdef SHOW_ALL_DEVICES #ifdef SHOW_ALL_DEVICES
else if ((pvp = xf86FindPciDeviceVendor(X86_EDX, X86_ECX, X86_ESI, pvp))) { else if ((pvp = xf86FindPciDeviceVendor(X86_EDX, X86_ECX, X86_ESI, pvp))) {

View File

@ -1,6 +1,7 @@
#include <stdio.h> #include <stdio.h>
#include "testbios.h"
int intE6_handler() int intE6_handler(void)
{ {
#if 0 #if 0
pciVideoPtr pvp; pciVideoPtr pvp;
@ -14,5 +15,6 @@ int intE6_handler()
X86_ES = 0; /* standard pc es */ X86_ES = 0; /* standard pc es */
#endif #endif
printf("intE6 not supported right now.\n"); printf("intE6 not supported right now.\n");
x86emu_dump_xregs();
return 1; return 1;
} }

View File

@ -1,6 +1,5 @@
#include <stdio.h> #include <stdio.h>
#include <pci/pci.h> #include "pci-userspace.h"
#include "pci.h"
#ifdef PCI_LIB_VERSION #ifdef PCI_LIB_VERSION
#define LIBPCI_CHECK_VERSION(major,minor,micro) \ #define LIBPCI_CHECK_VERSION(major,minor,micro) \

View File

@ -1,9 +1,13 @@
#include "pci.h" #ifndef __PCI_USERSPACE_H__
#define __PCI_USERSPACE_H__
#include <pci/pci.h>
typedef unsigned long pciaddr_t; typedef unsigned long pciaddr_t;
typedef u8 byte; typedef u8 byte;
typedef u16 word; typedef u16 word;
#if 0
struct pci_dev { struct pci_dev {
struct pci_dev *next; /* Next device in the chain */ struct pci_dev *next; /* Next device in the chain */
word bus; /* Higher byte can select host bridges */ word bus; /* Higher byte can select host bridges */
@ -32,7 +36,7 @@ struct pci_filter {
int bus, slot, func; /* -1 = ANY */ int bus, slot, func; /* -1 = ANY */
int vendor, device; int vendor, device;
}; };
#endif
#define PCITAG struct pci_filter * #define PCITAG struct pci_filter *
#define pciVideoPtr struct pci_dev * #define pciVideoPtr struct pci_dev *
@ -44,7 +48,8 @@ int pciExit(void);
PCITAG findPci(unsigned short bx); PCITAG findPci(unsigned short bx);
u32 pciSlotBX(pciVideoPtr pvp); //u32 pciSlotBX(pciVideoPtr pvp);
u32 pciSlotBX(PCITAG tag);
void pciWriteLong(PCITAG tag, u32 idx, u32 data); void pciWriteLong(PCITAG tag, u32 idx, u32 data);
void pciWriteWord(PCITAG tag, u32 idx, u16 data); void pciWriteWord(PCITAG tag, u32 idx, u16 data);
@ -53,3 +58,5 @@ void pciWriteByte(PCITAG tag, u32 idx, u8 data);
u32 pciReadLong(PCITAG tag, u32 idx); u32 pciReadLong(PCITAG tag, u32 idx);
u16 pciReadWord(PCITAG tag, u32 idx); u16 pciReadWord(PCITAG tag, u32 idx);
u8 pciReadByte(PCITAG tag, u32 idx); u8 pciReadByte(PCITAG tag, u32 idx);
#endif

View File

@ -1,2 +0,0 @@
void x_outb(u16 port, u8 val);
#define outb x_outb

View File

@ -6,26 +6,18 @@
#include <fcntl.h> #include <fcntl.h>
#include <getopt.h> #include <getopt.h>
#include <string.h> #include <string.h>
#include <stdarg.h>
#include <stdtypes.h>
#define die(x) { perror(x); exit(1); } #define die(x) { perror(x); exit(1); }
#define warn(x) { perror(x); } #define warn(x) { perror(x); }
#include <x86emu/x86emu.h> #include <x86emu/x86emu.h>
#include <console/console.h>
#include "helper_exec.h" #include "helper_exec.h"
#include "test.h" #include "testbios.h"
#include "pci-userspace.h" #include "pci-userspace.h"
int X86EMU_set_debug(int debug);
void x86emu_dump_xregs(void);
int int15_handler(void);
int int16_handler(void);
int int1A_handler(void);
#ifndef _PC
int int42_handler(void);
#endif
int intE6_handler(void);
void pushw(u16 val);
unsigned short get_device(char *arg_val); unsigned short get_device(char *arg_val);
extern int teststart, testend; extern int teststart, testend;
@ -39,7 +31,7 @@ int verbose = 0;
/* Interrupt multiplexer */ /* Interrupt multiplexer */
void do_int(int num) static void do_int(int num)
{ {
int ret = 0; int ret = 0;
@ -84,7 +76,7 @@ void do_int(int num)
} }
} }
unsigned char *mapitin(char *file, off_t where, size_t size) static unsigned char *mapitin(char *file, off_t where, size_t size)
{ {
void *z; void *z;
@ -101,21 +93,13 @@ unsigned char *mapitin(char *file, off_t where, size_t size)
} }
u8 x_inb(u16 port);
u16 x_inw(u16 port);
void x_outb(u16 port, u8 val);
void x_outw(u16 port, u16 val);
u32 x_inl(u16 port);
void x_outl(u16 port, u32 val);
X86EMU_pioFuncs myfuncs = { X86EMU_pioFuncs myfuncs = {
x_inb, x_inw, x_inl, x_inb, x_inw, x_inl,
x_outb, x_outw, x_outl x_outb, x_outw, x_outl
}; };
void usage(char *name) static void usage(char *name)
{ {
printf printf
("Usage: %s [-c codesegment] [-s size] [-b base] [-i ip] [-t] <filename> ... \n", ("Usage: %s [-c codesegment] [-s size] [-b base] [-i ip] [-t] <filename> ... \n",
@ -129,7 +113,7 @@ int main(int argc, char **argv)
int i, c, trace = 0; int i, c, trace = 0;
unsigned char *cp; unsigned char *cp;
char *filename; char *filename;
size_t size = 0; ssize_t size = 0;
int base = 0; int base = 0;
int have_size = 0, have_base = 0, have_ip = 0, have_cs = 0; int have_size = 0, have_base = 0, have_ip = 0, have_cs = 0;
int have_devfn = 0; int have_devfn = 0;
@ -138,9 +122,6 @@ int main(int argc, char **argv)
unsigned char *fsegptr; unsigned char *fsegptr;
unsigned short initialip = 0, initialcs = 0, devfn = 0; unsigned short initialip = 0, initialcs = 0, devfn = 0;
X86EMU_intrFuncs intFuncs[256]; X86EMU_intrFuncs intFuncs[256];
void X86EMU_setMemBase(void *base, size_t size);
void x86emu_dump_xregs(void);
int X86EMU_set_debug(int debug);
int debugflag = 0; int debugflag = 0;
const char *optstring = "vh?b:i:c:s:tpd:"; const char *optstring = "vh?b:i:c:s:tpd:";
@ -192,7 +173,6 @@ int main(int argc, char **argv)
have_size = 1; have_size = 1;
break; break;
case 'p': case 'p':
printf("Parsing rom images not implemented.\n");
parse_rom = 1; parse_rom = 1;
break; break;
case 'f': case 'f':
@ -250,6 +230,9 @@ int main(int argc, char **argv)
initialip = 0x0003; initialip = 0x0003;
} }
if (parse_rom)
printf("Parsing rom images not implemented.\n");
//printf("Point 1 int%x vector at %x\n", 0x42, getIntVect(0x42)); //printf("Point 1 int%x vector at %x\n", 0x42, getIntVect(0x42));
if (initialip == 0x0003) { if (initialip == 0x0003) {
@ -314,7 +297,7 @@ int main(int argc, char **argv)
for (i = 0; i < 0x10000; i++) for (i = 0; i < 0x10000; i++)
wrb(0xf0000 + i, fsegptr[i]); wrb(0xf0000 + i, fsegptr[i]);
} else { } else {
char *date = "01/01/99"; const char *date = "01/01/99";
for (i = i; date[i]; i++) for (i = i; date[i]; i++)
wrb(0xffff5 + i, date[i]); wrb(0xffff5 + i, date[i]);
wrb(0xffff7, '/'); wrb(0xffff7, '/');
@ -391,3 +374,16 @@ unsigned short get_device(char *arg_val)
return devfn; return devfn;
} }
int printk(int msg_level, const char *fmt, ...)
{
va_list args;
int i;
printf ("<%d> ", msg_level);
va_start(args, fmt);
i = vprintf(fmt, args);
va_end(args);
return i;
}

View File

@ -1,11 +1,20 @@
/* $XFree86: xc/programs/Xserver/hw/xfree86/int10/xf86x86emu.h,v 1.2 2001/01/06 20:19:13 tsi Exp $ */ /* Derived from:
/*
* XFree86 int10 module * XFree86 int10 module
* execute BIOS int 10h calls in x86 real mode environment * execute BIOS int 10h calls in x86 real mode environment
* Copyright 1999 Egbert Eich * Copyright 1999 Egbert Eich
*/ */
#ifndef XF86X86EMU_H_
#define XF86X86EMU_H_ #ifndef __TESTBIOS_H__
#define __TESTBIOS_H__
void x86emu_dump_xregs(void);
int int15_handler(void);
int int16_handler(void);
int int1A_handler(void);
int int42_handler(void);
int intE6_handler(void);
#include <stdtypes.h>
#include <x86emu/x86emu.h> #include <x86emu/x86emu.h>
#define M _X86EMU_env #define M _X86EMU_env