From patchwork Tue Apr 19 17:26:28 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 8882221 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 21E649F39A for ; Tue, 19 Apr 2016 17:27:03 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 4DD5C20251 for ; Tue, 19 Apr 2016 17:27:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7B189202D1 for ; Tue, 19 Apr 2016 17:27:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933400AbcDSR0w (ORCPT ); Tue, 19 Apr 2016 13:26:52 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57609 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753179AbcDSR0u (ORCPT ); Tue, 19 Apr 2016 13:26:50 -0400 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5EF9746267; Tue, 19 Apr 2016 17:26:50 +0000 (UTC) Received: from thinkpad.redhat.com (ovpn-112-40.ams2.redhat.com [10.36.112.40]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u3JHQd9E016430; Tue, 19 Apr 2016 13:26:47 -0400 From: Laurent Vivier To: kvm@vger.kernel.org, kvm-ppc@vger.kernel.org Cc: drjones@redhat.com, thuth@redhat.com, dgibson@redhat.com, pbonzini@redhat.com, Laurent Vivier Subject: [kvm-unit-tests PATCH 2/2] powerpc: restore TOC pointer Date: Tue, 19 Apr 2016 19:26:28 +0200 Message-Id: <1461086788-3102-3-git-send-email-lvivier@redhat.com> In-Reply-To: <1461086788-3102-1-git-send-email-lvivier@redhat.com> References: <1461086788-3102-1-git-send-email-lvivier@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.9 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 As the TOC pointer can be corrupted by the main program, we must restore it in the exception handler. As we know where we are loaded, we can now compute it easily. To compute it only in the common part of the exception handler (call_handler), store the address of call_handler at an absolute address in memory to be able to call the handler from the exception table (as SLOF does). Reported-by: Thomas Huth Signed-off-by: Laurent Vivier Reviewed-by: Thomas Huth --- powerpc/cstart64.S | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/powerpc/cstart64.S b/powerpc/cstart64.S index c47b67d..1ddfa13 100644 --- a/powerpc/cstart64.S +++ b/powerpc/cstart64.S @@ -13,6 +13,8 @@ #include "spapr.h" +#define P_HANDLER 0x2ff8 + .section .init /* @@ -46,6 +48,11 @@ start: add r4, r4, r31 bl relocate + /* compute address of call_handler */ + + LOAD_REG_ADDR(r4, call_handler) + std r4, P_HANDLER(0) + /* relocate vector table to base address 0x0 (MSR_IP = 0) */ /* source: r4, dest end: r5, destination: r6 */ @@ -166,6 +173,12 @@ call_handler: mfsrr1 r0 std r0, _MSR(r1) + /* restore TOC pointer */ + + LOAD_REG_IMMEDIATE(r31, SPAPR_KERNEL_LOAD_ADDR) + ld r2, (p_toc - start)(r31) + add r2, r2, r31 + /* FIXME: build stack frame */ /* call generic handler */ @@ -221,7 +234,7 @@ call_handler: mfctr r0 std r0,_CTR(r1) - LOAD_REG_ADDR(r0, call_handler) + ld r0, P_HANDLER(0) mtctr r0 li r0,\vec @@ -245,3 +258,5 @@ VECTOR(0x900) .align 7 .globl __end_interrupts __end_interrupts: + .org P_HANDLER + .llong 0