From patchwork Thu May 9 14:23:34 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 2544251 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 8432FDF24C for ; Thu, 9 May 2013 14:24:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753562Ab3EIOYF (ORCPT ); Thu, 9 May 2013 10:24:05 -0400 Received: from mail-we0-f178.google.com ([74.125.82.178]:55168 "EHLO mail-we0-f178.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753594Ab3EIOXr (ORCPT ); Thu, 9 May 2013 10:23:47 -0400 Received: by mail-we0-f178.google.com with SMTP id q57so2888567wes.23 for ; Thu, 09 May 2013 07:23:46 -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=kCAgoODUz+78b30U4LHvHH0Nh4W71Psy+bKo6hqQuyA=; b=iy31gJ0FbUxxibFoZGWq2//BTkJl9cDXHq49Sloww64zxN/wAY5a0ECj9VAPEKedp7 nGllXIJaKLuw3RuuykfQLuBHcbXYuk+ueFCfPCsg1z0J/ybv1Fucp7ehWFYFnnjgdTyS j1+TaIcb9ECu0K2Vh+nvQYbJ/CG9l2fDexl33N42XwNAc8JCdaKcvna8MvH0vC2/w17H +k8fsvcnuaMTqv9WCSMYzo1cOnuQSldYwUaG81IffjTLPbubpa78iDsvI8ap/LQkLnrt QeoZ4dHI9VX5pFZh8NBksQGjrPlOdF7ZJx4qC4+Vnmufjr8K0++enJgcXC+0ram/XqgK WHSQ== X-Received: by 10.194.109.198 with SMTP id hu6mr18575128wjb.5.1368109426360; Thu, 09 May 2013 07:23:46 -0700 (PDT) Received: from playground.lan (93-34-176-20.ip50.fastwebnet.it. [93.34.176.20]) by mx.google.com with ESMTPSA id q20sm4786961wiv.7.2013.05.09.07.23.44 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Thu, 09 May 2013 07:23:45 -0700 (PDT) From: Paolo Bonzini To: kvm@vger.kernel.org Subject: [PATCH kvm-unit-tests 2/2] realmode: print to serial port Date: Thu, 9 May 2013 16:23:34 +0200 Message-Id: <1368109414-6458-3-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.1.4 In-Reply-To: <1368109414-6458-1-git-send-email-pbonzini@redhat.com> References: <1368109414-6458-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 | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 63 insertions(+), 2 deletions(-) diff --git a/x86/realmode.c b/x86/realmode.c index 71c8a7d..67582b5 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,73 @@ 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(); + } + + 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 {