mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* SVC32 and SP
@ 2012-05-17 22:06 Carlo Caione
  2012-05-18  9:41 ` Sascha Hauer
  0 siblings, 1 reply; 4+ messages in thread
From: Carlo Caione @ 2012-05-17 22:06 UTC (permalink / raw)
  To: barebox

Hi,
I was debugging the problem with barebox and qemu-linaro as I
described in a previous post.
This is what I have discovered.

The problem is in the strlen function that seems to get corrupted
runtime during barebox initialization. The problem seems related to
the switch to SVC32 mode together with the __mmu_cache_flush
implementation.
Before setting the cpu to SVC32 mode, the Stack Pointer is correctly
set to 0x4020fcb0, but, immediately after the writing in the cpsr
register (__asm__ __volatile__("msr cpsr, %0" : : "r"(r));) the Stack
Pointer (now R13_SVC) is in 0x40205cb0 that is in the middle of the
.text section (and precisely in the middle of the strlen routine).
The problem is that in the __mmu_cache_flush disassembly I have a huge
push {r0, r1, r2, r3, r4, r5, r6, r7, r9, r10, r11} that overwrites
the strlen function and corrupts the code.

I'm using:
arm-none-eabi-gcc (Sourcery CodeBench Lite 2011.09-69) 4.6.1
QEMU emulator version 1.0.91 (qemu-linaro from git)

--
Carlo Caione

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: SVC32 and SP
  2012-05-17 22:06 SVC32 and SP Carlo Caione
@ 2012-05-18  9:41 ` Sascha Hauer
  2012-05-21 19:31   ` Carlo Caione
  0 siblings, 1 reply; 4+ messages in thread
From: Sascha Hauer @ 2012-05-18  9:41 UTC (permalink / raw)
  To: Carlo Caione; +Cc: barebox

On Fri, May 18, 2012 at 12:06:00AM +0200, Carlo Caione wrote:
> Hi,
> I was debugging the problem with barebox and qemu-linaro as I
> described in a previous post.
> This is what I have discovered.
> 
> The problem is in the strlen function that seems to get corrupted
> runtime during barebox initialization. The problem seems related to
> the switch to SVC32 mode together with the __mmu_cache_flush
> implementation.
> Before setting the cpu to SVC32 mode, the Stack Pointer is correctly
> set to 0x4020fcb0, but, immediately after the writing in the cpsr
> register (__asm__ __volatile__("msr cpsr, %0" : : "r"(r));) the Stack
> Pointer (now R13_SVC) is in 0x40205cb0 that is in the middle of the
> .text section (and precisely in the middle of the strlen routine).
> The problem is that in the __mmu_cache_flush disassembly I have a huge
> push {r0, r1, r2, r3, r4, r5, r6, r7, r9, r10, r11} that overwrites
> the strlen function and corrupts the code.

Can you try and remove the call to __mmu_cache_flush in start.c?

I think this call shouldn't be there at all. A (pre-) bootloader should
always manage to call the next image with the caches properly flushed,
otherwise we are doomed in barebox anyway.

The problem with the armv7 __mmu_cache_flush implementation is that
it uses the stack which we haven't configured at that time.

I thought I had already wired up a patch for this, but it seems I
haven't.

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: SVC32 and SP
  2012-05-18  9:41 ` Sascha Hauer
@ 2012-05-21 19:31   ` Carlo Caione
  2012-05-21 19:37     ` Sascha Hauer
  0 siblings, 1 reply; 4+ messages in thread
From: Carlo Caione @ 2012-05-21 19:31 UTC (permalink / raw)
  To: Sascha Hauer; +Cc: barebox

On Fri, May 18, 2012 at 11:41 AM, Sascha Hauer <s.hauer@pengutronix.de> wrote:
> On Fri, May 18, 2012 at 12:06:00AM +0200, Carlo Caione wrote:
>> Hi,
>> I was debugging the problem with barebox and qemu-linaro as I
>> described in a previous post.
>> This is what I have discovered.
>>
>> The problem is in the strlen function that seems to get corrupted
>> runtime during barebox initialization. The problem seems related to
>> the switch to SVC32 mode together with the __mmu_cache_flush
>> implementation.
>> Before setting the cpu to SVC32 mode, the Stack Pointer is correctly
>> set to 0x4020fcb0, but, immediately after the writing in the cpsr
>> register (__asm__ __volatile__("msr cpsr, %0" : : "r"(r));) the Stack
>> Pointer (now R13_SVC) is in 0x40205cb0 that is in the middle of the
>> .text section (and precisely in the middle of the strlen routine).
>> The problem is that in the __mmu_cache_flush disassembly I have a huge
>> push {r0, r1, r2, r3, r4, r5, r6, r7, r9, r10, r11} that overwrites
>> the strlen function and corrupts the code.
>
> Can you try and remove the call to __mmu_cache_flush in start.c?

Everything is fine if I comment out __mmu_cache_flush()

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: SVC32 and SP
  2012-05-21 19:31   ` Carlo Caione
@ 2012-05-21 19:37     ` Sascha Hauer
  0 siblings, 0 replies; 4+ messages in thread
From: Sascha Hauer @ 2012-05-21 19:37 UTC (permalink / raw)
  To: Carlo Caione; +Cc: barebox

On Mon, May 21, 2012 at 09:31:51PM +0200, Carlo Caione wrote:
> On Fri, May 18, 2012 at 11:41 AM, Sascha Hauer <s.hauer@pengutronix.de> wrote:
> > On Fri, May 18, 2012 at 12:06:00AM +0200, Carlo Caione wrote:
> >> Hi,
> >> I was debugging the problem with barebox and qemu-linaro as I
> >> described in a previous post.
> >> This is what I have discovered.
> >>
> >> The problem is in the strlen function that seems to get corrupted
> >> runtime during barebox initialization. The problem seems related to
> >> the switch to SVC32 mode together with the __mmu_cache_flush
> >> implementation.
> >> Before setting the cpu to SVC32 mode, the Stack Pointer is correctly
> >> set to 0x4020fcb0, but, immediately after the writing in the cpsr
> >> register (__asm__ __volatile__("msr cpsr, %0" : : "r"(r));) the Stack
> >> Pointer (now R13_SVC) is in 0x40205cb0 that is in the middle of the
> >> .text section (and precisely in the middle of the strlen routine).
> >> The problem is that in the __mmu_cache_flush disassembly I have a huge
> >> push {r0, r1, r2, r3, r4, r5, r6, r7, r9, r10, r11} that overwrites
> >> the strlen function and corrupts the code.
> >
> > Can you try and remove the call to __mmu_cache_flush in start.c?
> 
> Everything is fine if I comment out __mmu_cache_flush()

Ok, thanks for testing. I'll prepare a patch for this

Sascha


-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2012-05-21 19:37 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-05-17 22:06 SVC32 and SP Carlo Caione
2012-05-18  9:41 ` Sascha Hauer
2012-05-21 19:31   ` Carlo Caione
2012-05-21 19:37     ` Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox