From patchwork Thu May 9 14:55:05 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 2544341 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id 15F87DF24C for ; Thu, 9 May 2013 14:55:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753562Ab3EIOz2 (ORCPT ); Thu, 9 May 2013 10:55:28 -0400 Received: from mail-wg0-f45.google.com ([74.125.82.45]:58955 "EHLO mail-wg0-f45.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754407Ab3EIOzR (ORCPT ); Thu, 9 May 2013 10:55:17 -0400 Received: by mail-wg0-f45.google.com with SMTP id l18so3266382wgh.24 for ; Thu, 09 May 2013 07:55:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:sender:from:to:subject:date:message-id:x-mailer :in-reply-to:references; bh=EaE6vPetPW5+OqV96yEH/nthsoKBEkhwDLYiq5xhT3o=; b=mwb8g22GMCqUvELFCOLkGnssjyya7jNjxioAKsifExCrbr84gjcsN0oO93WpBu7S2+ 3U6q3qlcQrpEeYuK+IbZvnKyHStclYA/MXzbl3YtZwWWMI2ZyeYOsASmMXdniw1JHXhq J1iCyCSbk64J5+d0b4wu/jfCI5dJfpvfsO4Y1IqQA225KgJKhJgeChWVni6P4hidcJvT bakxpDr+hI1KE8WQKKXfdyGiX7LWoly+vl6FBEEvWKJLhSJB4n+1p/dWv2QVE8eLE/tK cTjoIczKSz8DPT/7RU4m0p65GZH9I6up+49FP+dp9wLZgKDViLRkx4m2RNHq43zKL0ZE mV7A== X-Received: by 10.180.184.11 with SMTP id eq11mr18071269wic.30.1368111315976; Thu, 09 May 2013 07:55:15 -0700 (PDT) Received: from playground.lan (93-34-176-20.ip50.fastwebnet.it. [93.34.176.20]) by mx.google.com with ESMTPSA id q20sm4969266wiv.7.2013.05.09.07.55.14 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Thu, 09 May 2013 07:55:15 -0700 (PDT) From: Paolo Bonzini To: kvm@vger.kernel.org Subject: [PATCH kvm-unit-tests v2 3/3] realmode: print to serial port Date: Thu, 9 May 2013 16:55:05 +0200 Message-Id: <1368111305-9076-4-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.1.4 In-Reply-To: <1368111305-9076-1-git-send-email-pbonzini@redhat.com> References: <1368111305-9076-1-git-send-email-pbonzini@redhat.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org The realmode test is still printing to the old debug port at 0xf1. Use the serial port instead. Signed-off-by: Paolo Bonzini --- x86/realmode.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 64 insertions(+), 2 deletions(-) diff --git a/x86/realmode.c b/x86/realmode.c index 71c8a7d..981be08 100644 --- a/x86/realmode.c +++ b/x86/realmode.c @@ -1,3 +1,7 @@ +#ifndef USE_SERIAL +#define USE_SERIAL +#endif + asm(".code16gcc"); typedef unsigned char u8; @@ -22,16 +26,74 @@ static int strlen(const char *str) return n; } +static void outb(u8 data, u16 port) +{ + asm volatile("out %0, %1" : : "a"(data), "d"(port)); +} + +#ifdef USE_SERIAL +static int serial_iobase = 0x3f8; +static int serial_inited = 0; + +static u8 inb(u16 port) +{ + u8 data; + asm volatile("in %1, %0" : "=a"(data) : "d"(port)); + return data; +} + +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); +} +#endif + static void print_serial(const char *buf) { unsigned long len = strlen(buf); - +#ifdef USE_SERIAL + unsigned long i; + if (!serial_inited) { + serial_init(); + serial_inited = 1; + } + + for (i = 0; i < len; i++) { + serial_outb(buf[i]); + } +#else asm volatile ("addr32/rep/outsb" : "+S"(buf), "+c"(len) : "d"(0xf1)); +#endif } static void exit(int code) { - asm volatile("out %0, %1" : : "a"(code), "d"((short)0xf4)); + outb(code, 0xf4); } struct regs {