]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
Initial commit
authorPekka Enberg <penberg@cs.helsinki.fi>
Mon, 22 Mar 2010 19:25:28 +0000 (21:25 +0200)
committerPekka Enberg <penberg@cs.helsinki.fi>
Mon, 22 Mar 2010 19:41:24 +0000 (21:41 +0200)
Signed-off-by: Pekka Enberg <penberg@cs.helsinki.fi>
tools/kvm/Makefile [new file with mode: 0644]
tools/kvm/include/kvm/cpu.h [new file with mode: 0644]
tools/kvm/kvm.c [new file with mode: 0644]

diff --git a/tools/kvm/Makefile b/tools/kvm/Makefile
new file mode 100644 (file)
index 0000000..a0cde18
--- /dev/null
@@ -0,0 +1,14 @@
+PROGRAM        = kvm
+
+OBJS   += kvm.o
+
+CFLAGS += -Iinclude
+
+all: $(PROGRAM)
+
+$(PRORAM): $(OBJS)
+       $(CC) $(OBJS) -o $@
+
+clean:
+       rm -f $(OBJS) $(PROGRAM)
+.PHONY: clean
diff --git a/tools/kvm/include/kvm/cpu.h b/tools/kvm/include/kvm/cpu.h
new file mode 100644 (file)
index 0000000..ced2e5e
--- /dev/null
@@ -0,0 +1,42 @@
+#ifndef KVM__CPU_H
+#define KVM__CPU_H
+
+#include <stdint.h>
+
+enum eflag_bits {
+       EFLAGS_CF               = (1UL << 0),   /* Carry Flag */
+       EFLAGS_PF               = (1UL << 2),   /* Parity Flag */
+       EFLAGS_AF               = (1UL << 4),   /* Auxiliary Carry Flag */
+       EFLAGS_ZF               = (1UL << 6),   /* Zero Flag */
+       EFLAGS_SF               = (1UL << 7),   /* Sign Flag */
+       EFLAGS_TF               = (1UL << 8),   /* Trap Flag */
+       EFLAGS_IF               = (1UL << 9),   /* Interrupt Enable Flag */
+       EFLAGS_DF               = (1UL << 10),  /* Direction Flag */
+       EFLAGS_OF               = (1UL << 11),  /* Overflow Flag */
+       EFLAGS_NT               = (1UL << 14),  /* Nested Task */
+       EFLAGS_RF               = (1UL << 16),  /* Resume Flag */
+       EFLAGS_VM               = (1UL << 17),  /* Virtual-8086 Mode */
+       EFLAGS_AC               = (1UL << 18),  /* Alignment Check */
+       EFLAGS_VIF              = (1UL << 19),  /* Virtual Interrupt Flag */
+       EFLAGS_VIP              = (1UL << 20),  /* Virtual Interrupt Pending */
+       EFLAGS_ID               = (1UL << 21),  /* ID Flag */
+};
+
+struct cpu_registers {
+       uint32_t                eax;
+       uint32_t                ebx;
+       uint32_t                ecx;
+       uint32_t                edx;
+       uint32_t                esp;
+       uint32_t                ebp;
+       uint32_t                esi;
+       uint32_t                edi;
+       uint32_t                eip;
+       uint32_t                eflags;
+};
+
+struct cpu {
+       struct cpu_registers    regs;   
+};
+
+#endif /* KVM__CPU_H */
diff --git a/tools/kvm/kvm.c b/tools/kvm/kvm.c
new file mode 100644 (file)
index 0000000..1ea3ff8
--- /dev/null
@@ -0,0 +1,37 @@
+#include "kvm/cpu.h"
+
+#include <stdlib.h>
+#include <fcntl.h>
+
+static void die(const char *s)
+{
+       perror(s);
+       exit(1);
+}
+
+static void cpu__reset(struct cpu *self)
+{
+       self->regs.eip          = 0x000fff0UL;
+       self->regs.eflags       = 0x0000002UL;
+}
+
+static struct cpu *cpu__new(void)
+{
+       return calloc(1, sizeof(struct cpu));
+}
+
+int main(int argc, char *argv[])
+{
+       struct cpu *cpu;
+       int fd;
+
+       fd = open("/dev/kvm", O_RDWR);
+       if (fd < 0)
+               die("open");
+
+       cpu = cpu__new();
+
+       cpu__reset(cpu);
+
+       return 0;
+}