public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Christoffer Dall <christoffer.dall@linaro.org>
To: Andrew Jones <drjones@redhat.com>
Cc: kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu, gleb@redhat.com
Subject: Re: [PATCH 9/9] arm: add vectors support
Date: Mon, 21 Oct 2013 10:59:10 +0100	[thread overview]
Message-ID: <20131021095910.GC39411@lvm> (raw)
In-Reply-To: <20131020163533.GA2072@hawk.usersys.redhat.com>

On Sun, Oct 20, 2013 at 06:35:34PM +0200, Andrew Jones wrote:
> On Thu, Oct 17, 2013 at 11:58:43AM -0700, Christoffer Dall wrote:
> > On Thu, Oct 17, 2013 at 12:38:59PM +0200, Andrew Jones wrote:
> > > On Wed, Oct 16, 2013 at 06:06:42PM -0700, Christoffer Dall wrote:
> > > > > +++ b/arm/cstart.S
> > > > > @@ -1,5 +1,6 @@
> > > > >  
> > > > >  #define CR_B	(1 << 7)
> > > > > +#define CR_V	(1 << 13)
> > > > >  
> > > > >  .arm
> > > > >  
> > > > > @@ -12,6 +13,13 @@ start:
> > > > >  	push	{ r0-r3 }		@push r3 too for 8-byte alignment
> > > > >  
> > > > >  	mrc	p15, 0, r8, c1, c0, 0	@r8 = sctrl
> > > > > +
> > > > > +	/* set up vector table */
> > > > > +	bic	r8, #CR_V		@sctrl.V = 0
> > > > > +	mcr	p15, 0, r8, c1, c0, 0
> > > > > +	ldr	r0, =vector_table	@vbar = vector_table
> > > > > +	mcr     p15, 0, r0, c12, c0, 0
> > > > > +
> > > > >  	bl	get_endianness
> > > > >  	bl	io_init
> > > > >  
> > > > > @@ -41,6 +49,44 @@ halt:
> > > > >  1:	wfi
> > > > >  	b	1b
> > > > >  
> > > > > +vector_common:
> > > > > +	add	r2, sp, #(14 * 4)
> > > > 
> > > > this looks weird, what are you pointing to here?
> > > 
> > > What sp was at the time of exception. So if you look at ex_regs->sp,
> > > then you'll see what sp was when the exception occurred, not that plus
> > > what we're pushing on now for the handler.
> > > 
> > 
> > Hmmm, so you're assuming that all exceptions will be taken from SVC
> > mode?  I assume we will run tests in more than SVC mode, no?
> > 
> > Also note that the lr you're pushing here is not the lr at the time the
> > exception occurs, but the return address from the exception.  If the SVC
> > instruction is executed from SVC mode, the original lr is lost iirc, and
> > the caller needs to save it.  If you're from user mode, something like
> > 
> >     stm sp, {r0-lr}^
> > 
> > will take care of this for you, and if you're from svc
> > mode, you may want consider doing something like
> > 
> >     push {sp, lr}
> >     push {r0-r12}
> > 
> > instead (assuming this is only ever compiled in ARM mode, not Thumb2, in
> > which case the whole thing gets more complicated.
> 
> I think the lr pushing should be ok. That part is done in the macro that
> all vectors start with.  It got snipped from this mail, so here it is
> 
> .macro m_vector, v
> 	push    { r0-r12,lr }
> 	mov     r1, \v
> 	b       vector_common
> .endm

You push this lr after taking the exception, so the lr will point to the
instruction following the trap instruction itself; if your convention is
that the regs struct is the lr as it was when the trap was generated,
well then, things don't match.  If the exception is taken from SVC mode,
I'm not sure there's a proper way to get this information though, so it
really depends on how you imagine this to be used...

> 
> I realize it may still not be correct, just as the calculated sp
> may not be correct, depending on which mode,vector combo is used,
> but I was expecting to have different paths in the C code for
> fixing it up. Although that said, I haven't thought about it a
> bunch yet, so maybe it won't work that way...
> 

I think it may be worth taking an extra look at how the kernel handles
all this and somewhat replicate some of what we're doing, but again, it
depends on what the goal here is.

The SP calculation is probably correct, but it's error-prone and bound
to confuse people IMHO, but it's up to you at this point.

-Christoffer

  reply	other threads:[~2013-10-21  9:59 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-10-14 16:23 [PATCH 0/9] kvm-unit-tests/arm: initial drop Andrew Jones
2013-10-14 16:23 ` [PATCH 1/9] remove unused files Andrew Jones
2013-10-16 12:52   ` Gleb Natapov
2013-10-16 13:13     ` Alexander Graf
2013-10-16 13:18     ` Andrew Jones
2013-10-14 16:23 ` [PATCH 2/9] makefile and run_tests tweaks Andrew Jones
2013-10-14 16:23 ` [PATCH 3/9] clean root dir of all x86-ness Andrew Jones
2013-10-17  1:06   ` Christoffer Dall
2013-10-17  9:35     ` Andrew Jones
2013-10-17 19:01       ` Christoffer Dall
2013-10-20 16:37         ` Andrew Jones
2013-10-14 16:23 ` [PATCH 4/9] Introduce a simple iomap structure Andrew Jones
2013-10-14 16:23 ` [PATCH 5/9] Add halt() and some error codes Andrew Jones
2013-10-14 16:23 ` [PATCH 6/9] Introduce virtio-testdev Andrew Jones
2013-10-15  8:39   ` Andrew Jones
2013-10-17  1:06   ` Christoffer Dall
2013-10-17  9:51     ` Andrew Jones
2013-10-17 19:01       ` Christoffer Dall
2013-10-17  1:06   ` Christoffer Dall
2013-10-14 16:23 ` [PATCH 7/9] arm: replace arbitrary divisions Andrew Jones
2013-10-17  1:06   ` Christoffer Dall
2013-10-17 10:03     ` Andrew Jones
2013-10-17 18:59       ` Christoffer Dall
2013-10-14 16:23 ` [PATCH 8/9] arm: initial drop Andrew Jones
2013-10-17  1:06   ` Christoffer Dall
2013-10-17 10:16     ` Andrew Jones
2013-10-17 13:28       ` Andrew Jones
2013-10-17 18:39         ` Christoffer Dall
2013-10-14 16:23 ` [PATCH 9/9] arm: add vectors support Andrew Jones
2013-10-17  1:06   ` Christoffer Dall
2013-10-17 10:38     ` Andrew Jones
2013-10-17 18:58       ` Christoffer Dall
2013-10-20 16:35         ` Andrew Jones
2013-10-21  9:59           ` Christoffer Dall [this message]
2013-11-20 23:06 ` [PATCH 0/9] kvm-unit-tests/arm: initial drop María Soler Heredia
2013-11-26 17:23   ` Andrew Jones
2013-12-29  9:24 ` Christoffer Dall
2014-01-02 18:56   ` Andrew Jones

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20131021095910.GC39411@lvm \
    --to=christoffer.dall@linaro.org \
    --cc=drjones@redhat.com \
    --cc=gleb@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=kvmarm@lists.cs.columbia.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox