Tahina
Posts: 4
Joined: Fri Feb 09, 2018 3:38 pm

[SOLVED] Multicore tries... work not everytime

Fri Feb 09, 2018 4:19 pm

Hello great community

Thanks to all the things I read on the different threads, I've managed to make several tries working with my RPi 3 and bare metal.

Now I'm working on multicore. It seems as simple as "str" the address of a function @ 0x40 000 000 + 0x9c/0xac/0xbc.
I have made a simple program that works blinking 2 leds, one for core 0 and another one for core 1.

Then I have a much longer program. I put the exact same piece of code

Code: Select all

	ldr r2,=_funccore1
	ldr r3,=0x40000000
	str r2,[r3,#0x9c]
to use the core1, but it seems that _funccore1 is never executed, as the "checking led" never switches on, and it's the initial code of _funccore1.

I am sure (as I checked via another led) that the code for core 0 just before and just after the declaration of the address for core 1 are executed, so I am puzzled...

I've read that it may depend on the config.txt file, but I use the same for the simple kernel.img and for the more longer one (I have not changed the original config file).

Are there known situations when it wouldn't work ?

Thank you
Last edited by Tahina on Mon Feb 12, 2018 12:14 pm, edited 3 times in total.

LdB
Posts: 826
Joined: Wed Dec 07, 2016 2:29 pm

Re: Multicore tries... works not everytime

Sat Feb 10, 2018 1:48 am

The functionality is provided by the stub loader
https://github.com/raspberrypi/tools/bl ... armstub7.S

That is it assumes your code is at 0x8000 and has come thru the normal bootload sequence.

You talked about a config file and if you are using the kernel old line and starting the cores at 0x0 the bootstub you are using will do it's own core parking and you simply redirect them to your function. The other 3 cores are probably just spinning wheels in a loop.

So yes there are situations it doesn't work, that is when you don't use the bootload stub that provide the functionality :)

Tahina
Posts: 4
Joined: Fri Feb 09, 2018 3:38 pm

Re: Multicore tries... work not everytime

Sat Feb 10, 2018 8:15 am

Thank you Mr LdB.
As I said, I use the exact same boot files between the 2 programs, I just change the new compiled kernel.img. And I follow the same initial condition (starting at 0x8000, I checked with the kernel.list file).
I don't understand, my code at 0x8000 is (from the kernel.list file):

Code: Select all

    8000:	e3a0d902 	mov	 sp, #32768	; 0x8000
    8004:	e1a0500e 	mov r5, lr
    8008:	eb0002e6 	bl 8ba8 <Initialisedebugled>
    800c:	eb000314 	bl 8c64 <ledoff>
    8010:	e3a03002 	mov r3, #2
    8014:	eb00031b 	bl 8c88 <blink>
    8018:	e3a03101 	mov r3, #1073741824	; 0x40000000
    801c:	e59f2020 	ldr r2, [pc, #32]	; 8044 <hang+0x8>
    8020:	e583209c 	str r2, [r3, #156]	; 0x9c
    ...
with

Code: Select all

    8044:	00008208 	andeq	r8, r0, r8, lsl #4
and my code for the core 1 at 0x8208:

Code: Select all

00008208 <core1>:
    8208:	e3a03003 	mov r3, #3
    820c:	eb00029d 	bl 8c88 <blink>
    ...
The function "Initialisedebugled" set to output mode a GPIO linked to a led for debugging.
The function "blink" just blink the led r3 times and wait approximately 3 sec.
The led is blinking twice, but isn't blinking after...

LdB
Posts: 826
Joined: Wed Dec 07, 2016 2:29 pm

Re: Multicore tries... work not everytime

Sun Feb 11, 2018 5:21 am

The core will be going there (I use almost identical code) you have something wrong with the code at the function :-)

My code is (I just put a label where I want it to jump)

Code: Select all

mov  r1, #1073741824				;@ 0x40000000
   	 ldr r2, =multicore1_start				;@ Address of Core1Setup call
	str r2, [r1, #156]					;@ Write
	
	// ...  snip 
	
multicore1_start:	
	 
All I can suggest is you have forgotten it's a different core and it is uninitialized and doesn't have a SP set and is still in HYPERVISOR mode.
It looks just like core 0 did when it started execution at 0x8000.

Can't suggest much beyond that without more code especially blink which I assume hits the mailbox.

Schnoogle
Posts: 41
Joined: Sun Feb 11, 2018 4:47 pm

Re: Multicore tries... work not everytime

Sun Feb 11, 2018 4:50 pm

Hi there,

even if I'm also quite new to RPi3 and bare metal I've also tried to get the additional cores up and running.
It turned out to me, that writing to the Mailbox3 of the respective core is not enough as the core is some kind of "suspended" with the WFE command. If you trigger a SEV command right after setting the adress the core should start in his mailbox than is should pick up and run.
This is what helped me at least to get my cores running..

BR Schnoogle

Tahina
Posts: 4
Joined: Fri Feb 09, 2018 3:38 pm

Re: Multicore tries... work not everytime

Sun Feb 11, 2018 6:04 pm

Mr LdB, thank you so much for your precious help, you are right, I forgot that I need to set the stack pointer for each core, so I add a "mov sp,#0x6000" at the very beginning of "core1" and a "mov sp, #0x5000" at the very beginning of "core2".

It still doesn't work, but I really don't know what you mean with "HYPERVISOR mode"... Sorry...

My Initialisedebugled function is:

Code: Select all

Initialisedebugled :
	push {r0-r3,lr}
	ldr r0,=0x3f200000	@ output mode for the GPIO 26 where the LED is
	ldr r2,[r0,#2*4]
	mov r1,#001				
	lsl r1,#6*3
	orr r2,r1
	str r2,[r0,#2*4]
	pop {r0-r3,pc}
then LED activity:

Code: Select all

.global ledon
ledon:
	push {r0-r1,lr}
	ldr r0,=0x3f200000
	mov r1,#001
	lsl r1,#26
	str r1,[r0,#0x28]
	pop {r0-r1,pc}

.global ledoff
ledoff:
	push {r0-r1,lr}
	ldr r0,=0x3f200000
	mov r1,#001
	lsl r1,#26
	str r1,[r0,#0x1c]
	pop {r0-r1,pc}

.global blink
blink:
	push {r3-r4,lr}
loopblink:
	bl ledon
	ldr r4,=2000000
looponblink:
	subs r4,#1
	bne looponblink
	bl ledoff
	ldr r4,=2000000
loopoffblink:
	subs r4,#1
	bne loopoffblink
	subs r3,#1
	bne loopblink
	ldr r4,=9000000
loopafterblink:
	subs r4,#1
	bne loopafterblink
	pop {r3-r4,pc}

Tahina
Posts: 4
Joined: Fri Feb 09, 2018 3:38 pm

Re: Multicore tries... work not everytime

Mon Feb 12, 2018 10:18 am

Hello Mr Shnoogle
Sorry I have missed your answer before as (I suppose) you certainly posted it at the same time I posted my last message.
I didn't know about this SEV instruction (there are not a lot info about it, I just found a previous post from Mr LdB). Even on examples I used as reference, I didn't find info about that.
But now it works!
My cores are not sleeping any more.
Thanks to both of you.
Tahina

Return to “Bare metal, Assembly language”

Who is online

Users browsing this forum: No registered users and 8 guests