From: Hollis Blanchard Subject: [PATCH 2 of 6] Register a debug MMIO handler, and implement putc() and exit() with it Date: Tue, 15 Jan 2008 16:43:40 -0600 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Cc: kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org, kvm-ppc-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org To: Avi Kivity Return-path: In-Reply-To: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: kvm-devel-bounces-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org Errors-To: kvm-devel-bounces-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org List-Id: kvm.vger.kernel.org # HG changeset patch # User Hollis Blanchard # Date 1200436754 21600 # Node ID f058f7e0e9e2f47beb19114a4ee3c7c44ac03aa0 # Parent c6e8bf3f9f7c9705a0ad29f44fa148fe80a365ff The return code from exit() will propagate all the way out to shell, which will enable some automated testing. Signed-off-by: Hollis Blanchard --- 1 file changed, 58 insertions(+), 7 deletions(-) user/main-ppc.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++++------ diff --git a/user/main-ppc.c b/user/main-ppc.c --- a/user/main-ppc.c +++ b/user/main-ppc.c @@ -37,6 +37,8 @@ #include #include +#include "iotable.h" + static int gettid(void) { return syscall(__NR_gettid); @@ -45,6 +47,8 @@ kvm_context_t kvm; kvm_context_t kvm; #define IPI_SIGNAL (SIGRTMIN + 4) + +struct io_table mmio_table; static int ncpus = 1; static sem_t init_sem; @@ -92,18 +96,63 @@ static int test_pre_kvm_run(void *opaque return 0; } +static int mmio_handler(void *opaque, int len, int is_write, uint64_t offset, + uint64_t *data) +{ + int r = 0; + + switch (offset) { + case 0: /* putc */ + putc(*(char *)data, stdout); + fflush(stdout); + break; + case 1: /* exit */ + r = *(char *)data; + break; + default: + printf("%s: offset %"PRIx64" len %d data %"PRIx64"\n", + __func__, offset, len, *(uint64_t *)data); + r = -EINVAL; + } + + return r; +} + static int test_mem_read(void *opaque, uint64_t addr, uint8_t *data, int len) { + struct io_table_entry *iodev; + +#if 0 printf("%s: addr %"PRIx64" len %d\n", __func__, addr, len); - memset(data, 0, len); - return 0; +#endif + + iodev = io_table_lookup(&mmio_table, addr); + if (!iodev) { + printf("couldn't find device\n"); + return -ENODEV; + } + + return iodev->handler(iodev->opaque, len, 0, addr - iodev->start, + (uint64_t *)data); } static int test_mem_write(void *opaque, uint64_t addr, uint8_t *data, int len) { + struct io_table_entry *iodev; + +#if 0 printf("%s: addr %"PRIx64" len %d data %"PRIx64"\n", __func__, addr, len, *(uint64_t *)data); - return 0; +#endif + + iodev = io_table_lookup(&mmio_table, addr); + if (!iodev) { + printf("couldn't find device\n"); + return -ENODEV; + } + + return iodev->handler(iodev->opaque, len, 1, addr - iodev->start, + (uint64_t *)data); } static int test_dcr_read(uint32_t dcrn, uint32_t *data) @@ -173,11 +222,13 @@ void sync_caches(void *mem, unsigned lon static void init_vcpu(int n, unsigned long entry) { + /* XXX must set initial TLB state and stack struct kvm_regs regs = { .pc = entry, }; kvm_set_regs(kvm, 0, ®s); + */ sigemptyset(&ipi_sigmask); sigaddset(&ipi_sigmask, IPI_SIGNAL); @@ -324,7 +375,7 @@ int main(int argc, char **argv) for (i = 0; i < ncpus; ++i) sem_wait(&init_sem); - kvm_run(kvm, 0); - - return 0; -} + io_table_register(&mmio_table, 0xf0000000, 64, mmio_handler, NULL); + + return kvm_run(kvm, 0); +} ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/