From patchwork Thu Feb 24 21:48:05 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony Liguori X-Patchwork-Id: 84493 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 5D1A6B70CF for ; Fri, 25 Feb 2011 08:48:59 +1100 (EST) Received: from localhost ([127.0.0.1]:36787 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Psj3O-0003Mx-TS for incoming@patchwork.ozlabs.org; Thu, 24 Feb 2011 16:48:54 -0500 Received: from [140.186.70.92] (port=38544 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Psj2X-0003LZ-4B for qemu-devel@nongnu.org; Thu, 24 Feb 2011 16:48:02 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Psj2V-00043D-W4 for qemu-devel@nongnu.org; Thu, 24 Feb 2011 16:48:00 -0500 Received: from e8.ny.us.ibm.com ([32.97.182.138]:59648) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Psj2V-000438-S0 for qemu-devel@nongnu.org; Thu, 24 Feb 2011 16:47:59 -0500 Received: from d01relay07.pok.ibm.com (d01relay07.pok.ibm.com [9.56.227.147]) by e8.ny.us.ibm.com (8.14.4/8.13.1) with ESMTP id p1OHTOsu025684 for ; Thu, 24 Feb 2011 12:29:24 -0500 Received: from d01av04.pok.ibm.com (d01av04.pok.ibm.com [9.56.224.64]) by d01relay07.pok.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id p1OLlwYQ1957924 for ; Thu, 24 Feb 2011 16:47:58 -0500 Received: from d01av04.pok.ibm.com (loopback [127.0.0.1]) by d01av04.pok.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id p1OLlwPA032148 for ; Thu, 24 Feb 2011 16:47:58 -0500 Received: from localhost.localdomain (sig-9-65-47-229.mts.ibm.com [9.65.47.229]) by d01av04.pok.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id p1OLlsLP031906; Thu, 24 Feb 2011 16:47:57 -0500 From: Anthony Liguori To: kvm@vger.kernel.org Date: Thu, 24 Feb 2011 15:48:05 -0600 Message-Id: <1298584085-13129-4-git-send-email-aliguori@us.ibm.com> X-Mailer: git-send-email 1.7.0.4 In-Reply-To: <1298584085-13129-1-git-send-email-aliguori@us.ibm.com> References: <1298584085-13129-1-git-send-email-aliguori@us.ibm.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) X-Received-From: 32.97.182.138 Cc: Anthony Liguori , qemu-devel@nongnu.org, Avi Kivity Subject: [Qemu-devel] [PATCH 3/3] kvm-unit-tests: make I/O more friendly to existing QEMU hardware X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Use the serial port for printf() and use the Bochs bios exit port if the testdev port isn't available. This unconditionally switches to use the serial port but tries to use the testdev exit port since that lets you pass an exit status. Signed-off-by: Anthony Liguori diff --git a/lib/x86/io.c b/lib/x86/io.c index 894f398..edc9437 100644 --- a/lib/x86/io.c +++ b/lib/x86/io.c @@ -1,13 +1,53 @@ #include "libcflat.h" #include "smp.h" +#include "io.h" static struct spinlock lock; +static int serial_iobase = 0x3f8; +static int serial_inited = 0; + +static void serial_outb(char ch) +{ + u8 lsr; + + do { + lsr = inb(serial_iobase + 0x05); + } while (!(lsr & 0x20)); + + outb(ch, serial_iobase + 0x00); +} + +static void serial_init(void) +{ + u8 lcr; + + /* set DLAB */ + lcr = inb(serial_iobase + 0x03); + lcr |= 0x80; + outb(lcr, serial_iobase + 0x03); + + /* set baud rate to 115200 */ + outb(0x01, serial_iobase + 0x00); + outb(0x00, serial_iobase + 0x01); + + /* clear DLAB */ + lcr = inb(serial_iobase + 0x03); + lcr &= ~0x80; + outb(lcr, serial_iobase + 0x03); +} static void print_serial(const char *buf) { unsigned long len = strlen(buf); + unsigned long i; - asm volatile ("rep/outsb" : "+S"(buf), "+c"(len) : "d"(0xf1)); + if (!serial_inited) { + serial_init(); + } + + for (i = 0; i < len; i++) { + serial_outb(buf[i]); + } } void puts(const char *s) @@ -19,5 +59,14 @@ void puts(const char *s) void exit(int code) { - asm volatile("out %0, %1" : : "a"(code), "d"((short)0xf4)); + static const char shutdown_str[8] = "Shutdown"; + int i; + + /* test device exit (with status) */ + outl(code, 0xf4); + + /* if that failed, try the Bochs poweroff port */ + for (i = 0; i < 8; i++) { + outb(shutdown_str[i], 0x8900); + } }