diff mbox

[PULL] boot-wrappe: boot kernel in Hyp mode

Message ID 877gze5vlp.fsf@rustcorp.com.au
State New
Headers show

Pull-request

git://github.com/rustyrussell/boot-wrapper.git rusty-wip

Commit Message

Rusty Russell Feb. 22, 2012, 10:52 p.m. UTC
On Wed, 22 Feb 2012 09:14:42 +0000, Dave Martin <dave.martin@linaro.org> wrote:
> > So I think this is needed for the moment?
> 
> I should have clarified -- the compiler doesn't understand that
> option.  (For 'hyp', did you mean 'hvc'?)

Oops.  Yeah, that works.

OK, final result is below, and pushed to github again:

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            |   26 ++++++++++++++++++++++++--
 config-default.mk |    3 ++-
 monitor.S         |   19 ++++++++++++++-----
 3 files changed, 40 insertions(+), 8 deletions(-)


Thanks,
Rusty.

Comments

Peter Maydell Feb. 24, 2012, 1:20 p.m. UTC | #1
On 22 February 2012 22:52, Rusty Russell <rusty@rustcorp.com.au> wrote:
> +# GAS needs armv7-a+virt to understand 'hvc'.
> +CPPFLAGS       += -march=armv7-a -Wa,-march=armv7-a+virt -marm

Rather than this, it would be better to put
       .arch_extension virt

at the top of boot.S (the way we currently do for 'sec' so we can
use smc). Otherwise you'll require everybody with a custom config.mk
to update it with the CPPFLAGS change.

-- PMM
Dave Martin Feb. 24, 2012, 2:28 p.m. UTC | #2
On Fri, Feb 24, 2012 at 1:20 PM, Peter Maydell <peter.maydell@linaro.org> wrote:
> On 22 February 2012 22:52, Rusty Russell <rusty@rustcorp.com.au> wrote:
>> +# GAS needs armv7-a+virt to understand 'hvc'.
>> +CPPFLAGS       += -march=armv7-a -Wa,-march=armv7-a+virt -marm
>
> Rather than this, it would be better to put
>       .arch_extension virt

That works, sure.

Cheers
---Dave
diff mbox

Patch

diff --git a/boot.S b/boot.S
index cf8bdb0..ef444dc 100644
--- a/boot.S
+++ b/boot.S
@@ -104,12 +104,34 @@  _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.
+	hvc	#0
+
+/* 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 /* fiq */
+
+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 +507,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/config-default.mk b/config-default.mk
index 6c73934..8786c62 100644
--- a/config-default.mk
+++ b/config-default.mk
@@ -84,7 +84,8 @@  endif # SYSTEM = realvire_eb
 ifeq ($(SYSTEM),vexpress)
 
 CPPFLAGS	+= -DSMP
-CPPFLAGS	+= -march=armv7-a -marm
+# GAS needs armv7-a+virt to understand 'hvc'.
+CPPFLAGS	+= -march=armv7-a -Wa,-march=armv7-a+virt -marm
 #CPPFLAGS	+= -DTHUMB2_KERNEL
 CPPFLAGS	+= -DVEXPRESS
 
diff --git a/monitor.S b/monitor.S
index 052ab1e..dea8551 100644
--- a/monitor.S
+++ b/monitor.S
@@ -25,7 +25,7 @@ 
 	@
 1:
 	ldr	sp, =_monitor_stack
-	push	{r11, r12}
+	push	{r10-r12}
 
 	cmp	r7, #0xffffffff
 	beq	_non_sec
@@ -36,15 +36,20 @@ 
 	movnes	pc, lr
 	and	r12, r7, #0xf
 	cmp	r12, #0x0
-	popgt	{r11, r12}
+	popgt   {r10-r12}
 	movgts	pc, lr
 
 	@ 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}
+	popne	{r10-r12}
 	movnes	pc, lr
 
 	@ Jump to the right function
@@ -68,15 +73,19 @@  _non_sec:
 	ldr	r11, =0x131
 	orr	r12, r12, r11
 	mcr	p15, 0, r12, c1, c1, 0
-	pop	{r11, r12}
+	pop	{r10-r12}
 	movs	pc, lr
 
 	@
 	@ 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}
+	mcr	p15, 0, r10, c1, c1, 0		@ Restore SCR
+	pop	{r10-r12}
 	movs	pc, lr
 
 	.ltorg