From patchwork Fri Nov 11 14:53:26 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?6Zmz6Z+L5Lu7?= X-Patchwork-Id: 125179 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 7B46AB6F9B for ; Sat, 12 Nov 2011 01:54:04 +1100 (EST) Received: from localhost ([::1]:41573 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ROsUR-0000t9-M2 for incoming@patchwork.ozlabs.org; Fri, 11 Nov 2011 09:53:59 -0500 Received: from eggs.gnu.org ([140.186.70.92]:41570) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ROsUC-0000cd-3I for qemu-devel@nongnu.org; Fri, 11 Nov 2011 09:53:45 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ROsU7-0005Oj-LN for qemu-devel@nongnu.org; Fri, 11 Nov 2011 09:53:44 -0500 Received: from csmailer.cs.nctu.edu.tw ([140.113.235.130]:54484) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ROsU5-0005OC-P6 for qemu-devel@nongnu.org; Fri, 11 Nov 2011 09:53:39 -0500 Received: from csmailer.cs.nctu.edu.tw (localhost [127.0.0.1]) by csmailer.cs.nctu.edu.tw (Postfix) with ESMTP id 1D52B41B; Fri, 11 Nov 2011 22:51:42 +0800 (CST) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=cs.nctu.edu.tw; h=from:to :cc:subject:date:message-id:in-reply-to:references; s=rsa1024; bh=21d355E5miK2ARFDK3ZxDvpKSig=; b=JAPJiikMxHOiXCvZcEmnxX4h7Bb/ Ky32Op43en3J3w3Ea1/BnaxMJoSPmgnPqE2gwLr9ycW1Xl7W0XCz3SvFOKSaE7up 1D7kVE8clCRWnTrXs1CUbYmogglUsILhnxpk8qLKArewsCH86J26A7AHDHR6FciC 3Cnt/oWJU0zULj8= Received: from alumni.cs.nctu.edu.tw (alumni.cs.nctu.edu.tw [140.113.235.116]) by csmailer.cs.nctu.edu.tw (Postfix) with ESMTP id 13C7F41A; Fri, 11 Nov 2011 22:51:42 +0800 (CST) Received: (from chenwj@localhost) by alumni.cs.nctu.edu.tw (8.14.4/8.14.4/Submit) id pABErYFc034781; Fri, 11 Nov 2011 22:53:34 +0800 (CST) (envelope-from chenwj) From: =?UTF-8?q?Chen=20Wei-Ren=20=28=E9=99=B3=E9=9F=8B=E4=BB=BB=29?= To: qemu-devel@nongnu.org Date: Fri, 11 Nov 2011 22:53:26 +0800 Message-Id: <1321023211-34566-2-git-send-email-chenwj@iis.sinica.edu.tw> X-Mailer: git-send-email 1.7.3.5 In-Reply-To: <1321023211-34566-1-git-send-email-chenwj@iis.sinica.edu.tw> References: <1321023211-34566-1-git-send-email-chenwj@iis.sinica.edu.tw> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 140.113.235.130 Cc: Chen Wei-Ren Subject: [Qemu-devel] [PATCH 1/6 v2] tests/qruncom.c: Remove libqemu.a example X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Chen Wei-Ren Remove libqemu example since libqemu.a is not available anymore. Signed-off-by: Chen Wei-Ren --- tests/qruncom.c | 284 ------------------------------------------------------- 1 files changed, 0 insertions(+), 284 deletions(-) delete mode 100644 tests/qruncom.c diff --git a/tests/qruncom.c b/tests/qruncom.c deleted file mode 100644 index 2e93aaf..0000000 --- a/tests/qruncom.c +++ /dev/null @@ -1,284 +0,0 @@ -/* - * Example of use of user mode libqemu: launch a basic .com DOS - * executable - */ -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "cpu.h" - -//#define SIGTEST - -int cpu_get_pic_interrupt(CPUState *env) -{ - return -1; -} - -uint64_t cpu_get_tsc(CPUState *env) -{ - return 0; -} - -static void set_gate(void *ptr, unsigned int type, unsigned int dpl, - unsigned long addr, unsigned int sel) -{ - unsigned int e1, e2; - e1 = (addr & 0xffff) | (sel << 16); - e2 = (addr & 0xffff0000) | 0x8000 | (dpl << 13) | (type << 8); - stl((uint8_t *)ptr, e1); - stl((uint8_t *)ptr + 4, e2); -} - -uint64_t idt_table[256]; - -/* only dpl matters as we do only user space emulation */ -static void set_idt(int n, unsigned int dpl) -{ - set_gate(idt_table + n, 0, dpl, 0, 0); -} - -void g_free(void *ptr) -{ - free(ptr); -} - -void *g_malloc(size_t size) -{ - return malloc(size); -} - -void *g_malloc0(size_t size) -{ - void *ptr; - ptr = g_malloc(size); - if (!ptr) - return NULL; - memset(ptr, 0, size); - return ptr; -} - -void *qemu_vmalloc(size_t size) -{ - return memalign(4096, size); -} - -void qemu_vfree(void *ptr) -{ - free(ptr); -} - -void qemu_printf(const char *fmt, ...) -{ - va_list ap; - va_start(ap, fmt); - vprintf(fmt, ap); - va_end(ap); -} - -/* XXX: this is a bug in helper2.c */ -int errno; - -/**********************************************/ - -#define COM_BASE_ADDR 0x10100 - -static void usage(void) -{ - printf("qruncom version 0.1 (c) 2003 Fabrice Bellard\n" - "usage: qruncom file.com\n" - "user mode libqemu demo: run simple .com DOS executables\n"); - exit(1); -} - -static inline uint8_t *seg_to_linear(unsigned int seg, unsigned int reg) -{ - return (uint8_t *)((seg << 4) + (reg & 0xffff)); -} - -static inline void pushw(CPUState *env, int val) -{ - env->regs[R_ESP] = (env->regs[R_ESP] & ~0xffff) | ((env->regs[R_ESP] - 2) & 0xffff); - *(uint16_t *)seg_to_linear(env->segs[R_SS].selector, env->regs[R_ESP]) = val; -} - -static void host_segv_handler(int host_signum, siginfo_t *info, - void *puc) -{ - if (cpu_signal_handler(host_signum, info, puc)) { - return; - } - abort(); -} - -int main(int argc, char **argv) -{ - uint8_t *vm86_mem; - const char *filename; - int fd, ret, seg; - CPUState *env; - - if (argc != 2) - usage(); - filename = argv[1]; - - vm86_mem = mmap((void *)0x00000000, 0x110000, - PROT_WRITE | PROT_READ | PROT_EXEC, - MAP_FIXED | MAP_ANON | MAP_PRIVATE, -1, 0); - if (vm86_mem == MAP_FAILED) { - perror("mmap"); - exit(1); - } - - /* load the MSDOS .com executable */ - fd = open(filename, O_RDONLY); - if (fd < 0) { - perror(filename); - exit(1); - } - ret = read(fd, vm86_mem + COM_BASE_ADDR, 65536 - 256); - if (ret < 0) { - perror("read"); - exit(1); - } - close(fd); - - /* install exception handler for CPU emulator */ - { - struct sigaction act; - - sigfillset(&act.sa_mask); - act.sa_flags = SA_SIGINFO; - // act.sa_flags |= SA_ONSTACK; - - act.sa_sigaction = host_segv_handler; - sigaction(SIGSEGV, &act, NULL); - sigaction(SIGBUS, &act, NULL); - } - - // cpu_set_log(CPU_LOG_TB_IN_ASM | CPU_LOG_TB_OUT_ASM | CPU_LOG_EXEC); - - env = cpu_init("qemu32"); - - cpu_x86_set_cpl(env, 3); - - env->cr[0] = CR0_PG_MASK | CR0_WP_MASK | CR0_PE_MASK; - /* NOTE: hflags duplicates some of the virtual CPU state */ - env->hflags |= HF_PE_MASK | VM_MASK; - - /* flags setup : we activate the IRQs by default as in user - mode. We also activate the VM86 flag to run DOS code */ - env->eflags |= IF_MASK | VM_MASK; - - /* init basic registers */ - env->eip = 0x100; - env->regs[R_ESP] = 0xfffe; - seg = (COM_BASE_ADDR - 0x100) >> 4; - - cpu_x86_load_seg_cache(env, R_CS, seg, - (seg << 4), 0xffff, 0); - cpu_x86_load_seg_cache(env, R_SS, seg, - (seg << 4), 0xffff, 0); - cpu_x86_load_seg_cache(env, R_DS, seg, - (seg << 4), 0xffff, 0); - cpu_x86_load_seg_cache(env, R_ES, seg, - (seg << 4), 0xffff, 0); - cpu_x86_load_seg_cache(env, R_FS, seg, - (seg << 4), 0xffff, 0); - cpu_x86_load_seg_cache(env, R_GS, seg, - (seg << 4), 0xffff, 0); - - /* exception support */ - env->idt.base = (unsigned long)idt_table; - env->idt.limit = sizeof(idt_table) - 1; - set_idt(0, 0); - set_idt(1, 0); - set_idt(2, 0); - set_idt(3, 3); - set_idt(4, 3); - set_idt(5, 3); - set_idt(6, 0); - set_idt(7, 0); - set_idt(8, 0); - set_idt(9, 0); - set_idt(10, 0); - set_idt(11, 0); - set_idt(12, 0); - set_idt(13, 0); - set_idt(14, 0); - set_idt(15, 0); - set_idt(16, 0); - set_idt(17, 0); - set_idt(18, 0); - set_idt(19, 0); - - /* put return code */ - *seg_to_linear(env->segs[R_CS].selector, 0) = 0xb4; /* mov ah, $0 */ - *seg_to_linear(env->segs[R_CS].selector, 1) = 0x00; - *seg_to_linear(env->segs[R_CS].selector, 2) = 0xcd; /* int $0x21 */ - *seg_to_linear(env->segs[R_CS].selector, 3) = 0x21; - pushw(env, 0x0000); - - /* the value of these registers seem to be assumed by pi_10.com */ - env->regs[R_ESI] = 0x100; - env->regs[R_ECX] = 0xff; - env->regs[R_EBP] = 0x0900; - env->regs[R_EDI] = 0xfffe; - - /* inform the emulator of the mmaped memory */ - page_set_flags(0x00000000, 0x110000, - PAGE_WRITE | PAGE_READ | PAGE_EXEC | PAGE_VALID); - - for(;;) { - ret = cpu_x86_exec(env); - switch(ret) { - case EXCP0D_GPF: - { - int int_num, ah; - int_num = *(uint8_t *)(env->segs[R_CS].base + env->eip + 1); - if (int_num != 0x21) - goto unknown_int; - ah = (env->regs[R_EAX] >> 8) & 0xff; - switch(ah) { - case 0x00: /* exit */ - exit(0); - case 0x02: /* write char */ - { - uint8_t c = env->regs[R_EDX]; - write(1, &c, 1); - } - break; - case 0x09: /* write string */ - { - uint8_t c; - for(;;) { - c = *seg_to_linear(env->segs[R_DS].selector, env->regs[R_EAX]); - if (c == '$') - break; - write(1, &c, 1); - } - env->regs[R_EAX] = (env->regs[R_EAX] & ~0xff) | '$'; - } - break; - default: - unknown_int: - fprintf(stderr, "unsupported int 0x%02x\n", int_num); - cpu_dump_state(env, stderr, fprintf, 0); - // exit(1); - } - env->eip += 2; - } - break; - default: - fprintf(stderr, "unhandled cpu_exec return code (0x%x)\n", ret); - cpu_dump_state(env, stderr, fprintf, 0); - exit(1); - } - } -}