summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStuart Bennett <sb476@cam.ac.uk>2007-11-15 18:59:17 +0000
committerStuart Bennett <sb476@cam.ac.uk>2007-11-16 00:15:13 +0000
commit3b995b1ab9f5518ce22c7e4cae59ab32a549ee80 (patch)
tree0357d9c48af7a4031f05143d72aff1b82fc0ba18
parentff54a36e1548e03f9ae9f571505dce4b6f90f206 (diff)
Inttool. Some similarities to vbetool.
-rw-r--r--inttool.c86
-rw-r--r--makefile14
2 files changed, 98 insertions, 2 deletions
diff --git a/inttool.c b/inttool.c
new file mode 100644
index 0000000..810f85a
--- /dev/null
+++ b/inttool.c
@@ -0,0 +1,86 @@
+/*
+Run (video) BIOS code for various purposes
+
+Copyright Stuart Bennett <sb476@cam.ac.uk>
+
+Based on vbetool.c, Copyright Matthew Garrett <mjg59@srcf.ucam.org>
+
+This program is released under the terms of the GNU General Public License,
+version 2
+*/
+
+#include <pci/pci.h>
+#include <assert.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/ioctl.h>
+#include <sys/types.h>
+#include <sys/io.h>
+#include <sys/kd.h>
+#include <sys/stat.h>
+#include <errno.h>
+
+#include "lrmi.h"
+
+int do_int(unsigned pci_device)
+{
+ int error = 0;
+ struct LRMI_regs r;
+ memset(&r, 0, sizeof(r));
+
+ /* Several machines seem to want the device that they're POSTing in
+ here */
+ r.eax = pci_device;
+
+ /* 0xc000 is the video option ROM. The init code for each
+ option ROM is at 0x0003 - so jump to c000:0003 and start running */
+ r.cs = 0xc000;
+ r.ip = 0x0003;
+
+ /* This is all heavily cargo culted but seems to work */
+ r.edx = 0x80;
+ r.ds = 0x0040;
+
+ if (!LRMI_call(&r)) {
+ fprintf(stderr,
+ "Error: something went wrong performing real mode call\n");
+ error = 1;
+ }
+
+ return error;
+}
+
+int main(int argc, char *argv[])
+{
+ static struct pci_access *pacc;
+ struct pci_dev *p;
+ unsigned int c;
+ unsigned int pci_id;
+ int error;
+
+ if (!LRMI_init()) {
+ fprintf(stderr, "Failed to initialise LRMI (Linux Real-Mode Interface).\n");
+ exit(1);
+ }
+
+ ioperm(0, 1024, 1);
+ iopl(3);
+
+ pacc = pci_alloc();
+ pacc->numeric_ids = 1;
+ pci_init(pacc);
+
+ pci_scan_bus(pacc);
+
+ for (p = pacc->devices; p; p = p->next) {
+ c = pci_read_word(p, PCI_CLASS_DEVICE);
+ if (c == 0x300) {
+ pci_id = (p->bus << 8) + (p->dev << 3) + (p->func & 0x7);
+ return (do_int(pci_id));
+ }
+ }
+
+ return 0;
+}
diff --git a/makefile b/makefile
index 68e2d72..4a8f872 100644
--- a/makefile
+++ b/makefile
@@ -32,6 +32,8 @@
TARGETLIB = libx86emu.a
+PROG=inttool
+
OBJS=\
debug.o \
decode.o \
@@ -41,7 +43,15 @@ ops2.o \
prim_ops.o \
sys.o
-all: $(TARGETLIB)
+ITOBJS=\
+inttool.o \
+thunk.o \
+x86-common.o
+
+all: $(PROG)
+
+$(PROG): $(TARGETLIB) $(ITOBJS)
+ gcc $(ITOBJS) $(TARGETLIB) -lpci -s -o $(PROG)
$(TARGETLIB): $(OBJS)
ar r $(TARGETLIB) $(OBJS)
@@ -55,6 +65,6 @@ CFLAGS = -DDEBUG -Wall -O3
distclean: clean
clean:
- rm -f *.a *.o *~
+ rm -f *.a *.o *~ $(PROG)
install: