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

Re: Bare Metal - Blinking an LED

Mon Feb 11, 2019 2:34 am

I am on same windows so that can't be problem.

You don't need to download FreeRTos it is on the repository :-)
https://github.com/LdB-ECM/Raspberry-Pi ... TOSv10.1.1
You just needed to change directory and do make Pi3-64

However given I have already made the new makefile for myBlinker try that first.

Tony201800
Posts: 26
Joined: Sun Sep 09, 2018 9:57 am

Re: Bare Metal - Blinking an LED

Mon Feb 11, 2019 2:50 am

ok got it to work :).

line 27 in the make file had an extra '-gcc' in its directory path.

trillions of thanks again!!

if i were to just compile the 2 lines of code you mentioned in your post yesterday about MPIDR and get a result could you please advise how i can do that.

my process would be to:
create another e.g., a test.s file with the 2 lines it
change the file name in the make file to test.s (line 29)
do a make clean
then finally make Pi3-64
convert the .elf file to .img
copy the .img to SD card and boot from it

If the above procedure is correct I can compile and run any aarch64.s file and get to see an output? I use qemu as well as a physical monitor attached by hdmi.

cheers

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

Re: Bare Metal - Blinking an LED

Mon Feb 11, 2019 3:05 am

Woot .. good news you are away.

Just set the EL2 register straight after the label _start:

After you do the drop to EL1 do the second part read EL1 and see what you have.

Tony201800
Posts: 26
Joined: Sun Sep 09, 2018 9:57 am

Re: Bare Metal - Blinking an LED

Mon Feb 11, 2019 4:22 am

treading very cautiously here since i want to understand what is going on intimately.

_start: .global _start
.global main

main:
mrs x0, VMPIDR_EL2
.end

is the above what you meant by saying set el2

thx

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

Re: Bare Metal - Blinking an LED

Mon Feb 11, 2019 5:44 am

You must have a section descriptor first then the global declaration which has a strange spelling ... I think correct spelling works these days but I am old school.

mrs is read from a register, msr is write to a register ... second letter r = read s = store is way to remember

you might want to read thru at least chapter 1-8 of this
https://thinkingeek.com/2016/10/08/expl ... -chapter1/
https://thinkingeek.com/2016/10/08/expl ... chapter-2/
https://thinkingeek.com/2016/10/23/expl ... chapter-3/
https://thinkingeek.com/2016/10/23/expl ... chapter-4/
https://thinkingeek.com/2016/11/13/expl ... chapter-5/
https://thinkingeek.com/2016/11/27/expl ... chapter-6/
https://thinkingeek.com/2017/03/19/expl ... chapter-7/
https://thinkingeek.com/2017/05/29/expl ... chapter-8/

anyhow code should be something like

Code: Select all

.section ".init", "ax", %progbits
.globl _start
_start:	
mov	x0, #7
msr VMPIDR_EL2, x0

Tony201800
Posts: 26
Joined: Sun Sep 09, 2018 9:57 am

Re: Bare Metal - Blinking an LED

Mon Feb 11, 2019 6:26 am

ok maybe the last questions for today...

ofcourse it's MSR not MRS... for write..sorry my bad
why was there an mov instruction to mov 7 to x0

are the below lines standard for gcc assembler

.section ".init", "ax", %progbits
.globl _start
_start:

cheers

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

Re: Bare Metal - Blinking an LED

Mon Feb 11, 2019 7:30 am

I thought that is what you wanted to write some virtual core id (I chose 7 as an example) into the EL2 level and check you got it back at EL1?

The only reason to write to that register is that :-)

Those lines are standard to both GCC and any aarch64 assembler
In the section line the name may vary that is up to the programmer

some just call the section .text
some will call it .boot
some will call it .init

It does not matter what you call the section so long as it matches the linker file

In my linker file we nominated it as being .init that starts at 0x80000
https://github.com/LdB-ECM/Raspberry-Pi ... r/rpi64.ld

Code: Select all

.init 0x80000 : {
		KEEP(*(.init))
	}

Tony201800
Posts: 26
Joined: Sun Sep 09, 2018 9:57 am

Re: Bare Metal - Blinking an LED

Mon Feb 11, 2019 9:56 pm

Good Morning Mate,

Could you please advise how I can run the above code via command line. Do I have to run it from a linux pc or can I do it from Windows

This is what I did from command prompt...

aarch64-elf-as D:\RPi\Tests\test.s -o D:\RPi\Tests\test.o

test.s had your mpidr code in it. This command produced the .o file but what do I do with it or is this not the way to do it.

cheers

Tony201800
Posts: 26
Joined: Sun Sep 09, 2018 9:57 am

Re: Bare Metal - Blinking an LED

Mon Feb 11, 2019 10:05 pm

ofcourse i need to link the file with rpi64.ld?

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

Re: Bare Metal - Blinking an LED

Tue Feb 12, 2019 3:20 am

You do :-)

The easy cheat is just copy the makefile and linker file (rpi64.ld) from myblinker and edit the makefile to reflect your start.S.

For now just make an minimal main.c with

Code: Select all

int main(void)
{
    return 0;
}
You can also use qemu for the Raspberry Pi on Windows if you wish to debug and play with code on the PC.
https://www.codepool.biz/raspberry-pi-e ... ndows.html

Tony201800
Posts: 26
Joined: Sun Sep 09, 2018 9:57 am

Re: Bare Metal - Blinking an LED

Tue Feb 12, 2019 3:55 am

do i need to have the c code? do i need to edit the .ld file to not include any c file?

i tried to use qemu but kept getting a message about not specifying block size. I will send you the message shortly after I redo the simulation.

thx.

Tony201800
Posts: 26
Joined: Sun Sep 09, 2018 9:57 am

Re: Bare Metal - Blinking an LED

Wed Feb 13, 2019 9:19 pm

Good morning mate

Still working on getting an output from the aarch64 code to display in qemu.

I get a GTK warning at the command prompt but don’t see an output on the qemu console.

Any tips.

Cheers

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

Re: Bare Metal - Blinking an LED

Thu Feb 14, 2019 1:37 am

Open a github account or similar and throw your work directory up .. be much easier if I could see everything to advise you.

Return to “Bare metal, Assembly language”