From patchwork Tue Feb 21 04:11:20 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rusty Russell X-Patchwork-Id: 6847 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id E49FC23E01 for ; Tue, 21 Feb 2012 04:11:55 +0000 (UTC) Received: from mail-iy0-f180.google.com (mail-iy0-f180.google.com [209.85.210.180]) by fiordland.canonical.com (Postfix) with ESMTP id 8244AA1857F for ; Tue, 21 Feb 2012 04:11:55 +0000 (UTC) Received: by iabz7 with SMTP id z7so11775055iab.11 for ; Mon, 20 Feb 2012 20:11:55 -0800 (PST) Received: from mr.google.com ([10.42.131.129]) by 10.42.131.129 with SMTP id z1mr24702559ics.53.1329797515052 (num_hops = 1); Mon, 20 Feb 2012 20:11:55 -0800 (PST) Received: by 10.42.131.129 with SMTP id z1mr19743539ics.53.1329797514865; Mon, 20 Feb 2012 20:11:54 -0800 (PST) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.231.11.10 with SMTP id r10csp74520ibr; Mon, 20 Feb 2012 20:11:54 -0800 (PST) Received: by 10.68.212.130 with SMTP id nk2mr57565935pbc.69.1329797513418; Mon, 20 Feb 2012 20:11:53 -0800 (PST) Received: from ozlabs.org (ozlabs.org. [203.10.76.45]) by mx.google.com with ESMTPS id t9si22721296pbi.223.2012.02.20.20.11.52 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 20 Feb 2012 20:11:53 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of rusty@ozlabs.org designates 203.10.76.45 as permitted sender) client-ip=203.10.76.45; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of rusty@ozlabs.org designates 203.10.76.45 as permitted sender) smtp.mail=rusty@ozlabs.org Received: by ozlabs.org (Postfix, from userid 1011) id 60AA2B6FA1; Tue, 21 Feb 2012 15:11:47 +1100 (EST) From: Rusty Russell To: Peter Maydell Cc: patches@linaro.org, Marc Zyngier , Dave Martin Subject: [PULL] boot-wrappe: boot kernel in Hyp mode In-Reply-To: <87boou8l7g.fsf@rustcorp.com.au> References: <1329330098-31636-1-git-send-email-dave.martin@linaro.org> <1329330098-31636-2-git-send-email-dave.martin@linaro.org> <87boou8l7g.fsf@rustcorp.com.au> User-Agent: Notmuch/0.6.1-1 (http://notmuchmail.org) Emacs/23.3.1 (i686-pc-linux-gnu) Date: Tue, 21 Feb 2012 14:41:20 +1030 Message-ID: <874nuk7rmf.fsf@rustcorp.com.au> MIME-Version: 1.0 X-Gm-Message-State: ALoCoQmUKAizG2JgoBeoD1UDgXXoh1E6Ji1VuTrV7hK7FydFGZlN5BOgM0rKJmXN4Qov8Y+kZYFQ This rolls together all the fixes into a nice single commit. I could push directly but prefer to go through Peter. Sorry this took so long. The following changes since commit 14dcbbd384abc25d475fd2021db3007a22383e46: boot-wrapper: Support reading kernel/initrd via semihosting (2012-02-05 13:07:07 -0500) are available in the git repository at: git://github.com/rustyrussell/boot-wrapper.git rusty-wip Rusty Russell (1): Boot kernel in hyp mode. boot.S | 27 +++++++++++++++++++++++++-- monitor.S | 23 ++++++++++++++--------- 2 files changed, 39 insertions(+), 11 deletions(-) commit 998f08afd28156867c7a0020981ccd57f7f3b0ec Author: Rusty Russell Date: Tue Feb 21 14:32:29 2012 +1030 Boot kernel in hyp mode. Leave the old monitor stub there for the moment, so we can boot current Christoff kernels. Includes fixes by Dave Martin to make it actually work :) Signed-off-by: Rusty Russell diff --git a/boot.S b/boot.S index cf8bdb0..0f61c3c 100644 --- a/boot.S +++ b/boot.S @@ -104,12 +104,35 @@ _start: orr r0, r0, r1 mcr p15, 0, r0, c1, c1, 2 - @ Change to NS-mode + @ Leave monitor.S trap in place for the transition... mov r0, #0xf0000000 mcr p15, 0, r0, c12, c0, 1 @ Monitor vector base address + + @ Set up hvbar so hvc comes back here. + ldr r0, =vectors + mov r7, #0xfffffff0 + smc #0 @ Set HVBAR + + @ We can't call hvc from secure mode, so drop down first. mov r7, #0xffffffff smc #0 @ Change to NS-mode + @ This is how we enter hyp mode, for booting the next stage. + @ This is an hvc instruction (GAS doesn't like it) + .long 0xe1400070 + +/* Once we get rid of monitor.S, use these smc vectors too! */ +vectors: + .word 0 /* reset */ + .word 0 /* undef */ + .word 0 /* svc */ + .word 0 /* pabt */ + .word 0 /* dabt */ + b into_hyp_mode /* hvc */ + .word 0 /* irq */ + .word 0 /* fix */ + +into_hyp_mode: @ Check CPU nr again mrc p15, 0, r0, c0, c0, 5 @ MPIDR (ARMv7 only) and r0, r0, #15 @ CPU number @@ -485,7 +508,7 @@ sh_cmdline: @ Semihosting command line will be written here #else /* not SEMIHOSTING */ - .org 0x100 + .org 0x200 @ Static ATAGS for when kernel/etc are compiled into the ELF file atags: @ ATAG_CORE diff --git a/monitor.S b/monitor.S index 052ab1e..334186e 100644 --- a/monitor.S +++ b/monitor.S @@ -25,7 +25,7 @@ @ 1: ldr sp, =_monitor_stack - push {r11, r12} + push {r10-r12,lr} cmp r7, #0xffffffff beq _non_sec @@ -36,16 +36,19 @@ movnes pc, lr and r12, r7, #0xf cmp r12, #0x0 - popgt {r11, r12} - movgts pc, lr + ldmgtfd sp!, {r10-r12,pc}^ @ Check the VMID is 0 + mrc p15, 0, r10, c1, c1, 0 @ SCR + orr r11, r10, #1 @ SCR.NS = 1 + mcr p15, 0, r11, c1, c1, 0 + isb mrrc p15, 6, r12, r11, c2 + mcr p15, 0, r10, c1, c1, 0 @ Restore SCR lsr r11, r11, #16 and r11, r11, #0xff cmp r11, #0 - popne {r11, r12} - movnes pc, lr + ldmnefd sp!, {r10-r12,pc}^ @ Jump to the right function and r12, r7, #0xf @@ -68,16 +71,18 @@ _non_sec: ldr r11, =0x131 orr r12, r12, r11 mcr p15, 0, r12, c1, c1, 0 - pop {r11, r12} - movs pc, lr + ldmfd sp!, {r10-r12,pc}^ @ @ Read/Write HVBAR @ _write_hvbar: + orr r11, r10, #1 @ SCR.NS = 1 (r10 already = SCR) + mcr p15, 0, r11, c1, c1, 0 + isb mcr p15, 4, r0, c12, c0, 0 - pop {r11, r12} - movs pc, lr + mcr p15, 0, r10, c1, c1, 0 @ Restore SCR + ldmfd sp!, {r10-r12,pc}^ .ltorg