Redo testbios utility to use all of YABEL

Drop buggy duplicate implementation of intXX handlers
and provide enough glue to use all of YABEL.

Change-Id: I2db77a56a2a991cb84876456dcbb3a843a0d9754
Signed-off-by: Stefan Reinauer <stefan.reinauer@coreboot.org>
Reviewed-on: https://review.coreboot.org/12117
Reviewed-by: Ronald G. Minnich <rminnich@gmail.com>
Tested-by: build bot (Jenkins)
This commit is contained in:
Stefan Reinauer
2015-10-21 13:00:41 -07:00
committed by Stefan Reinauer
parent eb960f1af9
commit 05082737a9
20 changed files with 906 additions and 1656 deletions

View File

@@ -1,3 +1,18 @@
/*
* This file is part of the coreboot project.
*
* Copyright (C) 2016 Google Inc
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
@@ -7,75 +22,28 @@
#include <getopt.h>
#include <string.h>
#include <stdarg.h>
#include <stdtypes.h>
#define die(x) { perror(x); exit(1); }
#define warn(x) { perror(x); }
#include <x86emu/x86emu.h>
#include <console/console.h>
#include "helper_exec.h"
#include <arch/byteorder.h>
#include "device.h"
#include "testbios.h"
#include "pci-userspace.h"
int X86EMU_set_debug(int debug);
unsigned short get_device(char *arg_val);
biosemu_device_t bios_device;
extern int teststart, testend;
_ptr p;
ptr current = 0;
unsigned char biosmem[1024 * 1024];
#define BIOSMEM_SIZE (1024 * 1024)
unsigned char biosmem[BIOSMEM_SIZE];
int verbose = 0;
/* Interrupt multiplexer */
static void do_int(int num)
{
int ret = 0;
printf("int%x vector at %x\n", num, getIntVect(num));
/* This is a pInt leftover */
current->num = num;
switch (num) {
#ifndef _PC
case 0x10:
case 0x42:
case 0x6D:
if (getIntVect(num) == 0xFF065) {
ret = int42_handler();
}
break;
#endif
case 0x15:
ret = int15_handler();
break;
case 0x16:
ret = int16_handler();
break;
case 0x1A:
ret = int1A_handler();
break;
case 0xe6:
ret = intE6_handler();
break;
default:
break;
}
if (!ret)
ret = run_bios_int(num);
if (!ret) {
printf("\nint%x: not implemented\n", num);
//x86emu_dump_xregs();
}
}
static unsigned char *mapitin(char *file, off_t where, size_t size)
{
void *z;
@@ -90,14 +58,57 @@ static unsigned char *mapitin(char *file, off_t where, size_t size)
close(fd);
return z;
}
X86EMU_pioFuncs myfuncs = {
x_inb, x_inw, x_inl,
x_outb, x_outw, x_outl
};
static unsigned short get_device(char *arg_val)
{
unsigned short devfn=0;
long bus=0,dev=0,fn=0,need_pack=0;
char *tok;
tok = strsep(&arg_val,":");
if (arg_val != NULL) {
bus = strtol(tok,0,16);
need_pack = 1;
}
else {
arg_val = tok;
}
tok = strsep(&arg_val,".");
if (arg_val != NULL) {
dev = strtol(tok,0,16);
fn = strtol(arg_val,0,16);
need_pack = 1;
}
else {
if (need_pack ==1 && (strlen(tok))) {
dev = strtol(tok,0,16);
}
}
if ( need_pack == 1) {
devfn = bus<<8 | (dev<<3) | fn;
}
else {
devfn = strtol(tok, 0, 0);
}
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;
}
static void usage(char *name)
{
@@ -106,11 +117,24 @@ static void usage(char *name)
name);
}
/* main entry into YABEL biosemu, arguments are:
* *biosmem = pointer to virtual memory
* biosmem_size = size of the virtual memory
* *dev = pointer to the device to be initialised
* rom_addr = address of the OptionROM to be executed, if this is = 0, YABEL
* will look for an ExpansionROM BAR and use the code from there.
*/
u32
biosemu(u8 *biosmem, u32 biosmem_size, struct device * dev, unsigned long
rom_addr);
int main(int argc, char **argv)
{
int ret;
char *absegname = 0;
void *abseg = 0;
int i, c, trace = 0;
int c, trace = 0;
unsigned char *cp;
char *filename;
ssize_t size = 0;
@@ -118,12 +142,14 @@ int main(int argc, char **argv)
int have_size = 0, have_base = 0, have_ip = 0, have_cs = 0;
int have_devfn = 0;
int parse_rom = 0;
char *fsegname = 0;
unsigned char *fsegptr;
//char *fsegname = 0;
//unsigned char *fsegptr;
unsigned short initialip = 0, initialcs = 0, devfn = 0;
X86EMU_intrFuncs intFuncs[256];
//X86EMU_intrFuncs intFuncs[256];
int debugflag = 0;
struct device *dev;
//const char *optstring = "vh?b:i:c:s:tpd:";
const char *optstring = "vh?b:i:c:s:tpd:";
while (1) {
int option_index = 0;
@@ -132,7 +158,7 @@ int main(int argc, char **argv)
{"help", 0, 0, 'h'},
{"trace", 0, 0, 't'},
{"base", 1, 0, 'b'},
{"fseg", 1, 0, 'f'},
//{"fseg", 1, 0, 'f'},
{"instructionpointer", 1, 0, 'i'},
{"codesegment", 1, 0, 'c'},
{"absegment", 1, 0, 'a'},
@@ -156,10 +182,10 @@ int main(int argc, char **argv)
case 't':
trace = 1;
break;
case 'b':
base = strtol(optarg, 0, 0);
have_base = 1;
break;
//case 'b':
// base = strtol(optarg, 0, 0);
// have_base = 1;
// break;
case 'i':
initialip = strtol(optarg, 0, 0);
have_ip = 1;
@@ -175,9 +201,9 @@ int main(int argc, char **argv)
case 'p':
parse_rom = 1;
break;
case 'f':
fsegname = optarg;
break;
// case 'f':
// fsegname = optarg;
// break;
case 'a':
absegname = optarg;
break;
@@ -220,10 +246,10 @@ int main(int argc, char **argv)
printf("No base specified. defaulting to 0xc0000\n");
base = 0xc0000;
}
if (!have_cs) {
printf("No initial code segment specified. defaulting to 0xc000\n");
initialcs = 0xc000;
}
//if (!have_cs) {
// printf("No initial code segment specified. defaulting to 0xc000\n");
// initialcs = 0xc000;
//}
if (!have_ip) {
printf
("No initial instruction pointer specified. defaulting to 0x0003\n");
@@ -234,7 +260,7 @@ int main(int argc, char **argv)
printf("Parsing rom images not implemented.\n");
//printf("Point 1 int%x vector at %x\n", 0x42, getIntVect(0x42));
#if 0
if (initialip == 0x0003) {
if ((devfn == 0) || (have_devfn == 0)) {
printf("WARNING! It appears you are trying to run an option ROM.\n");
@@ -250,6 +276,7 @@ int main(int argc, char **argv)
}
}
}
#endif
if (absegname) {
abseg = mapitin(absegname, (off_t) 0xa0000, 0x20000);
@@ -257,10 +284,6 @@ int main(int argc, char **argv)
die(absegname);
}
current = &p;
X86EMU_setMemBase(biosmem, sizeof(biosmem));
M.abseg = (unsigned long)abseg;
X86EMU_setupPioFuncs(&myfuncs);
ioperm(0, 0x400, 1);
if (iopl(3) < 0) {
@@ -275,17 +298,20 @@ int main(int argc, char **argv)
* basically this means initializing PCI and
* intXX handlers.
*/
pciInit();
pci_initialize();
#if 0
for (i = 0; i < 256; i++)
intFuncs[i] = do_int;
X86EMU_setupIntrFuncs(intFuncs);
#endif
cp = mapitin(filename, (off_t) 0, size);
if (devfn) {
printf("Loading ax with BusDevFn = %x\n",devfn);
}
#if 0
current->ax = devfn ? devfn : 0xff;
current->dx = 0x80;
// current->ip = 0;
@@ -322,68 +348,33 @@ int main(int argc, char **argv)
pushw(X86_SP + 2);
X86_ES = 0x0000;
#endif
if (trace) {
printf("Switching to single step mode.\n");
//X86EMU_trace_on();
}
if (debugflag) {
printf("Enable Debug = %x.\n",debugflag);
//X86EMU_set_debug(debugflag);
}
#if 0
X86EMU_exec();
#endif
ret = biosemu(biosmem, BIOSMEM_SIZE, dev, base);
#if 0
current = &p;
X86EMU_setMemBase(biosmem, sizeof(biosmem));
M.abseg = (unsigned long)abseg;
X86EMU_setupPioFuncs(&myfuncs);
#endif
/* Cleaning up */
pciExit();
pci_exit();
return 0;
}
unsigned short get_device(char *arg_val)
{
unsigned short devfn=0;
long bus=0,dev=0,fn=0,need_pack=0;
char *tok;
tok = strsep(&arg_val,":");
if (arg_val != NULL) {
bus = strtol(tok,0,16);
need_pack = 1;
}
else {
arg_val = tok;
}
tok = strsep(&arg_val,".");
if (arg_val != NULL) {
dev = strtol(tok,0,16);
fn = strtol(arg_val,0,16);
need_pack = 1;
}
else {
if (need_pack ==1 && (strlen(tok))) {
dev = strtol(tok,0,16);
}
}
if ( need_pack == 1) {
devfn = bus<<8 | (dev<<3) | fn;
}
else {
devfn = strtol(tok, 0, 0);
}
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;
}