From: Anthony Liguori <aliguori@us.ibm.com>
To: kvm@vger.kernel.org
Cc: Anthony Liguori <aliguori@us.ibm.com>,
qemu-devel@nongnu.org, Avi Kivity <avi@redhat.com>
Subject: [Qemu-devel] [PATCH 3/3] kvm-unit-tests: make I/O more friendly to existing QEMU hardware
Date: Thu, 24 Feb 2011 15:48:05 -0600 [thread overview]
Message-ID: <1298584085-13129-4-git-send-email-aliguori@us.ibm.com> (raw)
In-Reply-To: <1298584085-13129-1-git-send-email-aliguori@us.ibm.com>
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 <aliguori@us.ibm.com>
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);
+ }
}
--
1.7.0.4
next prev parent reply other threads:[~2011-02-24 21:48 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-02-24 21:48 [Qemu-devel] [RFC PATCH 0/3] Make kvm-unit-tests more friendly to upstream QEMU Anthony Liguori
2011-02-24 21:48 ` [Qemu-devel] [PATCH 1/3] kvm-unit-tests: add x86 port io accessors Anthony Liguori
2011-02-27 12:44 ` [Qemu-devel] " Avi Kivity
2011-02-27 14:01 ` Anthony Liguori
2011-02-27 15:32 ` Avi Kivity
2011-02-24 21:48 ` [Qemu-devel] [PATCH 2/3] kvm-unit-tests: do not set level sensitive irq when initializing the PIC Anthony Liguori
2011-02-27 12:46 ` [Qemu-devel] " Avi Kivity
2011-02-24 21:48 ` Anthony Liguori [this message]
2011-02-27 12:49 ` [Qemu-devel] Re: [PATCH 3/3] kvm-unit-tests: make I/O more friendly to existing QEMU hardware Avi Kivity
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1298584085-13129-4-git-send-email-aliguori@us.ibm.com \
--to=aliguori@us.ibm.com \
--cc=avi@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).