From patchwork Mon Aug 3 14:41:25 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 6930091 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id ED1799F358 for ; Mon, 3 Aug 2015 14:42:06 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id DC7B82060E for ; Mon, 3 Aug 2015 14:42:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 271DA20614 for ; Mon, 3 Aug 2015 14:42:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754037AbbHCOl5 (ORCPT ); Mon, 3 Aug 2015 10:41:57 -0400 Received: from mx1.redhat.com ([209.132.183.28]:33460 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753171AbbHCOl4 (ORCPT ); Mon, 3 Aug 2015 10:41:56 -0400 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (Postfix) with ESMTPS id 1647D91EA2; Mon, 3 Aug 2015 14:41:56 +0000 (UTC) Received: from hawk.localdomain.com (dhcp-1-112.brq.redhat.com [10.34.1.112]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t73EfYNp006138; Mon, 3 Aug 2015 10:41:54 -0400 From: Andrew Jones To: kvm@vger.kernel.org, kvm-ppc@vger.kernel.org Cc: dgibson@redhat.com, david@gibson.dropbear.id.au, agraf@suse.de, thuth@redhat.com, lvivier@redhat.com, pbonzini@redhat.com Subject: [kvm-unit-tests PATCH 08/14] powerpc/ppc64: add HV putchar Date: Mon, 3 Aug 2015 16:41:25 +0200 Message-Id: <1438612891-3718-9-git-send-email-drjones@redhat.com> In-Reply-To: <1438612891-3718-1-git-send-email-drjones@redhat.com> References: <1438612891-3718-1-git-send-email-drjones@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add the hvcall for putchar and use it in puts. That, along with a couple more lines in start to prepare for C code, and a branch to main(), gets us "hello world". Run with qemu-system-ppc64 -M pseries \ -bios powerpc/boot_rom.bin \ -display none -serial stdio \ -kernel powerpc/selftest.elf (We're still not relocating yet, that comes in a later patch. Thus, testing hello-world at this point requires a hacked QEMU and linking the unit test at QEMU's kernel load address.) Signed-off-by: Andrew Jones --- lib/powerpc/io.c | 15 +++++++++++++-- powerpc/Makefile.common | 1 + powerpc/cstart64.S | 27 +++++++++++++++++++++++++++ 3 files changed, 41 insertions(+), 2 deletions(-) diff --git a/lib/powerpc/io.c b/lib/powerpc/io.c index cf3b6347e1e46..a7eaafeca9205 100644 --- a/lib/powerpc/io.c +++ b/lib/powerpc/io.c @@ -6,15 +6,26 @@ * This work is licensed under the terms of the GNU LGPL, version 2. */ #include +#include + +extern void halt(int code); +extern void putchar(int c); + +static struct spinlock uart_lock; void io_init(void) { } -void puts(const char *s __unused) +void puts(const char *s) { + spin_lock(&uart_lock); + while (*s) + putchar(*s++); + spin_unlock(&uart_lock); } -void exit(int code __unused) +void exit(int code) { + halt(code); } diff --git a/powerpc/Makefile.common b/powerpc/Makefile.common index 5cd3ea8085038..d6356540918a5 100644 --- a/powerpc/Makefile.common +++ b/powerpc/Makefile.common @@ -26,6 +26,7 @@ CFLAGS += -ffreestanding CFLAGS += -Wextra CFLAGS += -O2 CFLAGS += -I lib -I lib/libfdt +CFLAGS += -Wa,-mregnames asm-offsets = lib/$(ARCH)/asm-offsets.h include scripts/asm-offsets.mak diff --git a/powerpc/cstart64.S b/powerpc/cstart64.S index d9b77f44f9e0e..d7c51cd352ee4 100644 --- a/powerpc/cstart64.S +++ b/powerpc/cstart64.S @@ -6,14 +6,41 @@ * This work is licensed under the terms of the GNU LGPL, version 2. */ +#define HVSC .long 0x44000022 +#define H_PUT_TERM_CHAR 0x58 + +#define LOAD_REG_IMMEDIATE(reg,expr) \ + lis reg,(expr)@highest; \ + ori reg,reg,(expr)@higher; \ + rldicr reg,reg,32,31; \ + oris reg,reg,(expr)@h; \ + ori reg,reg,(expr)@l; + +#define LOAD_REG_ADDR(reg,name) \ + ld reg,name@got(r2) + .section .init .globl start start: + LOAD_REG_IMMEDIATE(r1, stackptr) + LOAD_REG_IMMEDIATE(r2, tocptr) + bl .main + bl .exit b halt .text +.align 3 .globl halt halt: 1: b 1b + +.globl putchar +putchar: + sldi r6, r3, 56 + li r3, H_PUT_TERM_CHAR + li r4, 0 /* vty-reg 0 means to use the default vty */ + li r5, 1 /* sending just 1 byte */ + HVSC + blr