2015-10-21 22:00:41 +02:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2004-07-08 19:18:27 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <sys/io.h>
|
|
|
|
#include <sys/mman.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <getopt.h>
|
2006-04-23 21:16:09 +02:00
|
|
|
#include <string.h>
|
2015-09-28 22:12:04 +02:00
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdtypes.h>
|
2004-07-08 19:18:27 +02:00
|
|
|
#define die(x) { perror(x); exit(1); }
|
2004-11-28 05:39:45 +01:00
|
|
|
#define warn(x) { perror(x); }
|
2004-07-08 19:18:27 +02:00
|
|
|
|
2010-03-23 16:53:38 +01:00
|
|
|
#include <x86emu/x86emu.h>
|
2015-09-28 22:12:04 +02:00
|
|
|
#include <console/console.h>
|
2015-10-21 22:00:41 +02:00
|
|
|
#include <arch/byteorder.h>
|
|
|
|
#include "device.h"
|
|
|
|
|
2015-09-28 22:12:04 +02:00
|
|
|
#include "testbios.h"
|
2004-07-08 19:18:27 +02:00
|
|
|
#include "pci-userspace.h"
|
2015-09-28 22:12:04 +02:00
|
|
|
int X86EMU_set_debug(int debug);
|
2015-10-21 22:00:41 +02:00
|
|
|
|
|
|
|
biosemu_device_t bios_device;
|
2006-04-23 21:16:09 +02:00
|
|
|
|
2004-07-08 19:18:27 +02:00
|
|
|
extern int teststart, testend;
|
|
|
|
|
2015-10-21 22:00:41 +02:00
|
|
|
#define BIOSMEM_SIZE (1024 * 1024)
|
|
|
|
unsigned char biosmem[BIOSMEM_SIZE];
|
2004-07-08 19:18:27 +02:00
|
|
|
|
|
|
|
int verbose = 0;
|
|
|
|
|
2015-09-28 22:12:04 +02:00
|
|
|
static unsigned char *mapitin(char *file, off_t where, size_t size)
|
2004-07-08 19:18:27 +02:00
|
|
|
{
|
|
|
|
void *z;
|
|
|
|
|
|
|
|
int fd = open(file, O_RDWR, 0);
|
|
|
|
|
|
|
|
if (fd < 0)
|
|
|
|
die(file);
|
|
|
|
z = mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, where);
|
|
|
|
if (z == (void *) -1)
|
|
|
|
die("mmap");
|
|
|
|
close(fd);
|
|
|
|
|
|
|
|
return z;
|
2015-10-21 22:00:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
2004-07-08 19:18:27 +02:00
|
|
|
|
2015-10-21 22:00:41 +02:00
|
|
|
if ( need_pack == 1) {
|
|
|
|
devfn = bus<<8 | (dev<<3) | fn;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
devfn = strtol(tok, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
return devfn;
|
2004-07-08 19:18:27 +02:00
|
|
|
}
|
|
|
|
|
2015-10-21 22:00:41 +02:00
|
|
|
int printk(int msg_level, const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
int i;
|
2004-07-08 19:18:27 +02:00
|
|
|
|
2017-07-20 00:53:53 +02:00
|
|
|
putchar('<');
|
|
|
|
putchar('0' + msg_level);
|
|
|
|
putchar('>');
|
|
|
|
putchar(' ');
|
2015-10-21 22:00:41 +02:00
|
|
|
va_start(args, fmt);
|
|
|
|
i = vprintf(fmt, args);
|
|
|
|
va_end(args);
|
|
|
|
|
|
|
|
return i;
|
|
|
|
}
|
2004-07-08 19:18:27 +02:00
|
|
|
|
2015-09-28 22:12:04 +02:00
|
|
|
static void usage(char *name)
|
2004-07-08 19:18:27 +02:00
|
|
|
{
|
|
|
|
printf
|
|
|
|
("Usage: %s [-c codesegment] [-s size] [-b base] [-i ip] [-t] <filename> ... \n",
|
|
|
|
name);
|
|
|
|
}
|
|
|
|
|
2015-10-21 22:00:41 +02:00
|
|
|
/* 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);
|
|
|
|
|
|
|
|
|
2004-07-08 19:18:27 +02:00
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
2015-10-21 22:00:41 +02:00
|
|
|
int ret;
|
2018-06-05 08:41:29 +02:00
|
|
|
char *absegname = NULL;
|
|
|
|
void *abseg = NULL;
|
2015-10-21 22:00:41 +02:00
|
|
|
int c, trace = 0;
|
2004-07-08 19:18:27 +02:00
|
|
|
unsigned char *cp;
|
|
|
|
char *filename;
|
2015-09-28 22:12:04 +02:00
|
|
|
ssize_t size = 0;
|
2004-07-08 19:18:27 +02:00
|
|
|
int base = 0;
|
|
|
|
int have_size = 0, have_base = 0, have_ip = 0, have_cs = 0;
|
2006-04-23 21:16:09 +02:00
|
|
|
int have_devfn = 0;
|
2004-07-08 19:18:27 +02:00
|
|
|
int parse_rom = 0;
|
2015-10-21 22:00:41 +02:00
|
|
|
//char *fsegname = 0;
|
|
|
|
//unsigned char *fsegptr;
|
2004-07-08 19:18:27 +02:00
|
|
|
unsigned short initialip = 0, initialcs = 0, devfn = 0;
|
2015-10-21 22:00:41 +02:00
|
|
|
//X86EMU_intrFuncs intFuncs[256];
|
2004-07-08 19:18:27 +02:00
|
|
|
int debugflag = 0;
|
2015-10-21 22:00:41 +02:00
|
|
|
struct device *dev;
|
2004-07-08 19:18:27 +02:00
|
|
|
|
2015-10-21 22:00:41 +02:00
|
|
|
//const char *optstring = "vh?b:i:c:s:tpd:";
|
2004-07-08 19:18:27 +02:00
|
|
|
const char *optstring = "vh?b:i:c:s:tpd:";
|
|
|
|
while (1) {
|
|
|
|
int option_index = 0;
|
|
|
|
static struct option long_options[] = {
|
|
|
|
{"verbose", 0, 0, 'v'},
|
|
|
|
{"help", 0, 0, 'h'},
|
|
|
|
{"trace", 0, 0, 't'},
|
|
|
|
{"base", 1, 0, 'b'},
|
2015-10-21 22:00:41 +02:00
|
|
|
//{"fseg", 1, 0, 'f'},
|
2004-07-08 19:18:27 +02:00
|
|
|
{"instructionpointer", 1, 0, 'i'},
|
|
|
|
{"codesegment", 1, 0, 'c'},
|
|
|
|
{"absegment", 1, 0, 'a'},
|
|
|
|
{"size", 1, 0, 's'},
|
|
|
|
{"parserom", 0, 0, 'p'},
|
|
|
|
{"device", 1, 0, 'd'},
|
|
|
|
{"debug", 1, 0, 'D'},
|
|
|
|
{0, 0, 0, 0}
|
|
|
|
};
|
|
|
|
c = getopt_long(argc, argv, optstring, long_options, &option_index);
|
|
|
|
if (c == -1)
|
|
|
|
break;
|
|
|
|
switch (c) {
|
|
|
|
case 'v':
|
|
|
|
verbose = 1;
|
|
|
|
break;
|
|
|
|
case 'h':
|
|
|
|
case '?':
|
|
|
|
usage(argv[0]);
|
|
|
|
return 0;
|
|
|
|
case 't':
|
|
|
|
trace = 1;
|
|
|
|
break;
|
2015-10-21 22:00:41 +02:00
|
|
|
//case 'b':
|
|
|
|
// base = strtol(optarg, 0, 0);
|
|
|
|
// have_base = 1;
|
|
|
|
// break;
|
2004-07-08 19:18:27 +02:00
|
|
|
case 'i':
|
|
|
|
initialip = strtol(optarg, 0, 0);
|
|
|
|
have_ip = 1;
|
|
|
|
break;
|
|
|
|
case 'c':
|
|
|
|
initialcs = strtol(optarg, 0, 0);
|
|
|
|
have_cs = 1;
|
|
|
|
break;
|
|
|
|
case 's':
|
|
|
|
size = strtol(optarg, 0, 0);
|
|
|
|
have_size = 1;
|
|
|
|
break;
|
|
|
|
case 'p':
|
|
|
|
parse_rom = 1;
|
|
|
|
break;
|
2015-10-21 22:00:41 +02:00
|
|
|
// case 'f':
|
|
|
|
// fsegname = optarg;
|
|
|
|
// break;
|
2004-07-08 19:18:27 +02:00
|
|
|
case 'a':
|
|
|
|
absegname = optarg;
|
|
|
|
break;
|
|
|
|
case 'd':
|
2006-04-23 21:16:09 +02:00
|
|
|
devfn = get_device(optarg);
|
|
|
|
have_devfn = 1;
|
2004-07-08 19:18:27 +02:00
|
|
|
break;
|
|
|
|
case 'D':
|
|
|
|
debugflag = strtol(optarg, 0, 0);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
printf("Unknown option \n");
|
|
|
|
usage(argv[0]);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (optind >= argc) {
|
|
|
|
printf("Filename missing.\n");
|
|
|
|
usage(argv[0]);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (optind < argc) {
|
|
|
|
printf("running file %s\n", argv[optind]);
|
|
|
|
filename = argv[optind];
|
|
|
|
optind++;
|
|
|
|
/* normally we would do continue, but for
|
|
|
|
* now only one filename is supported.
|
|
|
|
*/
|
|
|
|
/* continue; */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!have_size) {
|
|
|
|
printf("No size specified. defaulting to 32k\n");
|
|
|
|
size = 32 * 1024;
|
|
|
|
}
|
|
|
|
if (!have_base) {
|
|
|
|
printf("No base specified. defaulting to 0xc0000\n");
|
|
|
|
base = 0xc0000;
|
|
|
|
}
|
2015-10-21 22:00:41 +02:00
|
|
|
//if (!have_cs) {
|
|
|
|
// printf("No initial code segment specified. defaulting to 0xc000\n");
|
|
|
|
// initialcs = 0xc000;
|
|
|
|
//}
|
2004-07-08 19:18:27 +02:00
|
|
|
if (!have_ip) {
|
|
|
|
printf
|
|
|
|
("No initial instruction pointer specified. defaulting to 0x0003\n");
|
|
|
|
initialip = 0x0003;
|
|
|
|
}
|
|
|
|
|
2015-09-28 22:12:04 +02:00
|
|
|
if (parse_rom)
|
|
|
|
printf("Parsing rom images not implemented.\n");
|
|
|
|
|
2004-07-08 19:18:27 +02:00
|
|
|
//printf("Point 1 int%x vector at %x\n", 0x42, getIntVect(0x42));
|
2015-10-21 22:00:41 +02:00
|
|
|
#if 0
|
2006-04-23 21:16:09 +02:00
|
|
|
if (initialip == 0x0003) {
|
|
|
|
if ((devfn == 0) || (have_devfn == 0)) {
|
|
|
|
printf("WARNING! It appears you are trying to run an option ROM.\n");
|
|
|
|
printf(" (initial ip = 0x0003)\n");
|
|
|
|
if (have_devfn) {
|
|
|
|
printf(" However, the device you have specified is 0x00\n");
|
|
|
|
printf(" It is very unlikely that your device is at this address\n");
|
|
|
|
printf(" Please check your -d option\n");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
printf(" Please specify a device with -d\n");
|
|
|
|
printf(" The default is not likely to work\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-10-21 22:00:41 +02:00
|
|
|
#endif
|
2010-04-27 08:56:47 +02:00
|
|
|
|
2004-07-08 19:18:27 +02:00
|
|
|
if (absegname) {
|
|
|
|
abseg = mapitin(absegname, (off_t) 0xa0000, 0x20000);
|
|
|
|
if (!abseg)
|
|
|
|
die(absegname);
|
|
|
|
}
|
|
|
|
|
|
|
|
ioperm(0, 0x400, 1);
|
|
|
|
|
2004-11-28 05:39:45 +01:00
|
|
|
if (iopl(3) < 0) {
|
|
|
|
warn("iopl failed, continuing anyway");
|
|
|
|
}
|
2004-07-08 19:18:27 +02:00
|
|
|
|
|
|
|
/* Emergency sync ;-) */
|
|
|
|
sync();
|
|
|
|
sync();
|
|
|
|
|
|
|
|
/* Setting up interrupt environment.
|
|
|
|
* basically this means initializing PCI and
|
|
|
|
* intXX handlers.
|
|
|
|
*/
|
2015-10-21 22:00:41 +02:00
|
|
|
pci_initialize();
|
2004-07-08 19:18:27 +02:00
|
|
|
|
2015-10-21 22:00:41 +02:00
|
|
|
#if 0
|
2004-07-08 19:18:27 +02:00
|
|
|
for (i = 0; i < 256; i++)
|
|
|
|
intFuncs[i] = do_int;
|
|
|
|
X86EMU_setupIntrFuncs(intFuncs);
|
2015-10-21 22:00:41 +02:00
|
|
|
#endif
|
2004-07-08 19:18:27 +02:00
|
|
|
cp = mapitin(filename, (off_t) 0, size);
|
|
|
|
|
2006-04-23 21:16:09 +02:00
|
|
|
if (devfn) {
|
|
|
|
printf("Loading ax with BusDevFn = %x\n",devfn);
|
|
|
|
}
|
2010-04-27 08:56:47 +02:00
|
|
|
|
2015-10-21 22:00:41 +02:00
|
|
|
#if 0
|
2004-07-08 19:18:27 +02:00
|
|
|
current->ax = devfn ? devfn : 0xff;
|
|
|
|
current->dx = 0x80;
|
|
|
|
// current->ip = 0;
|
|
|
|
for (i = 0; i < size; i++)
|
|
|
|
wrb(base + i, cp[i]);
|
|
|
|
|
|
|
|
if (fsegname) {
|
|
|
|
fsegptr = mapitin(fsegname, (off_t) 0, 0x10000);
|
|
|
|
for (i = 0; i < 0x10000; i++)
|
|
|
|
wrb(0xf0000 + i, fsegptr[i]);
|
|
|
|
} else {
|
2015-09-28 22:12:04 +02:00
|
|
|
const char *date = "01/01/99";
|
2004-07-08 19:18:27 +02:00
|
|
|
for (i = i; date[i]; i++)
|
|
|
|
wrb(0xffff5 + i, date[i]);
|
|
|
|
wrb(0xffff7, '/');
|
|
|
|
wrb(0xffffa, '/');
|
|
|
|
}
|
|
|
|
/* cpu setup */
|
|
|
|
X86_AX = devfn ? devfn : 0xff;
|
|
|
|
X86_DX = 0x80;
|
|
|
|
X86_EIP = initialip;
|
|
|
|
X86_CS = initialcs;
|
|
|
|
|
|
|
|
/* Initialize stack and data segment */
|
|
|
|
X86_SS = 0x0030;
|
|
|
|
X86_DS = 0x0040;
|
|
|
|
X86_SP = 0xfffe;
|
|
|
|
/* We need a sane way to return from bios
|
|
|
|
* execution. A hlt instruction and a pointer
|
|
|
|
* to it, both kept on the stack, will do.
|
|
|
|
*/
|
|
|
|
pushw(0xf4f4); /* hlt; hlt */
|
|
|
|
pushw(X86_SS);
|
|
|
|
pushw(X86_SP + 2);
|
|
|
|
|
|
|
|
X86_ES = 0x0000;
|
2015-10-21 22:00:41 +02:00
|
|
|
#endif
|
2004-07-08 19:18:27 +02:00
|
|
|
|
|
|
|
if (trace) {
|
|
|
|
printf("Switching to single step mode.\n");
|
2005-01-11 04:18:39 +01:00
|
|
|
//X86EMU_trace_on();
|
2004-07-08 19:18:27 +02:00
|
|
|
}
|
|
|
|
if (debugflag) {
|
2015-10-21 22:00:41 +02:00
|
|
|
printf("Enable Debug = %x.\n",debugflag);
|
2005-01-11 04:18:39 +01:00
|
|
|
//X86EMU_set_debug(debugflag);
|
2004-07-08 19:18:27 +02:00
|
|
|
}
|
2015-10-21 22:00:41 +02:00
|
|
|
#if 0
|
2004-07-08 19:18:27 +02:00
|
|
|
X86EMU_exec();
|
2015-10-21 22:00:41 +02:00
|
|
|
#endif
|
2006-04-23 21:16:09 +02:00
|
|
|
|
2015-10-21 22:00:41 +02:00
|
|
|
ret = biosemu(biosmem, BIOSMEM_SIZE, dev, base);
|
2010-04-27 08:56:47 +02:00
|
|
|
|
2015-10-21 22:00:41 +02:00
|
|
|
#if 0
|
|
|
|
current = &p;
|
|
|
|
X86EMU_setMemBase(biosmem, sizeof(biosmem));
|
|
|
|
M.abseg = (unsigned long)abseg;
|
|
|
|
X86EMU_setupPioFuncs(&myfuncs);
|
|
|
|
#endif
|
2006-04-23 21:16:09 +02:00
|
|
|
|
2015-10-21 22:00:41 +02:00
|
|
|
/* Cleaning up */
|
|
|
|
pci_exit();
|
2006-04-23 21:16:09 +02:00
|
|
|
|
2015-10-21 22:00:41 +02:00
|
|
|
return 0;
|
2006-04-23 21:16:09 +02:00
|
|
|
}
|