libgloss/aarch64: Add support for Armv8-R AArch64

Message ID 20200918144327.7qgh64f57myg6njs@arm.com
State New
Headers show
Series
  • libgloss/aarch64: Add support for Armv8-R AArch64
Related show

Commit Message

Alex Coplan Sept. 18, 2020, 2:43 p.m.
Hello,

This patch adds support for Armv8-R AArch64. We update the AArch64 CPU
boot code to work on Armv8-R if __ARM_ARCH_PROFILE is set to 'R'.
Armv8-R AArch64 has no EL3, so we don't set vbar_el3, and adjust the
code to set up the MPU for Armv8-R.

We also add a specs file for use with Armv8-R AArch64 models.

Testing:
 * Ran AArch64 GCC testsuite using --with-arch=armv8-r together with the
   new specs file and boot code in an Armv8-R AArch64 model.
 * Ran newlib testsuite, no regressions.

OK for master?

Thanks,
Alex

---

2020-09-18  Alex Coplan  <alex.coplan@arm.com>

libgloss/ChangeLog:

	* aarch64/Makefile.in: Install new specs file.
	* aarch64/cpu-init/Makefile.in: Also build boot code for Armv8-R.
	* aarch64/cpu-init/rdimon-aem-el3.S: Add support for Armv8-R.
	* aarch64/elf-aem-v8-r.specs: New.

Comments

Kyrylo Tkachov Sept. 22, 2020, 12:42 p.m. | #1
> -----Original Message-----

> From: Newlib <newlib-bounces@sourceware.org> On Behalf Of Alex Coplan

> Sent: 18 September 2020 15:43

> To: newlib@sourceware.org

> Cc: Richard Earnshaw <Richard.Earnshaw@arm.com>

> Subject: [PATCH] libgloss/aarch64: Add support for Armv8-R AArch64

> 

> Hello,

> 

> This patch adds support for Armv8-R AArch64. We update the AArch64 CPU

> boot code to work on Armv8-R if __ARM_ARCH_PROFILE is set to 'R'.

> Armv8-R AArch64 has no EL3, so we don't set vbar_el3, and adjust the

> code to set up the MPU for Armv8-R.

> 

> We also add a specs file for use with Armv8-R AArch64 models.

> 

> Testing:

>  * Ran AArch64 GCC testsuite using --with-arch=armv8-r together with the

>    new specs file and boot code in an Armv8-R AArch64 model.

>  * Ran newlib testsuite, no regressions.

> 

> OK for master?

> 


FWIW this looks good to me but I'm not a maintainer.
Thanks,
Kyrill

> Thanks,

> Alex

> 

> ---

> 

> 2020-09-18  Alex Coplan  <alex.coplan@arm.com>

> 

> libgloss/ChangeLog:

> 

> 	* aarch64/Makefile.in: Install new specs file.

> 	* aarch64/cpu-init/Makefile.in: Also build boot code for Armv8-R.

> 	* aarch64/cpu-init/rdimon-aem-el3.S: Add support for Armv8-R.

> 	* aarch64/elf-aem-v8-r.specs: New.
Richard Earnshaw (lists) Sept. 29, 2020, 2:06 p.m. | #2
On 18/09/2020 15:43, Alex Coplan wrote:
> Hello,

> 

> This patch adds support for Armv8-R AArch64. We update the AArch64 CPU

> boot code to work on Armv8-R if __ARM_ARCH_PROFILE is set to 'R'.

> Armv8-R AArch64 has no EL3, so we don't set vbar_el3, and adjust the

> code to set up the MPU for Armv8-R.

> 

> We also add a specs file for use with Armv8-R AArch64 models.

> 

> Testing:

>  * Ran AArch64 GCC testsuite using --with-arch=armv8-r together with the

>    new specs file and boot code in an Armv8-R AArch64 model.

>  * Ran newlib testsuite, no regressions.

> 

> OK for master?

> 

> Thanks,

> Alex

> 

> ---

> 

> 2020-09-18  Alex Coplan  <alex.coplan@arm.com>

> 

> libgloss/ChangeLog:

> 

> 	* aarch64/Makefile.in: Install new specs file.

> 	* aarch64/cpu-init/Makefile.in: Also build boot code for Armv8-R.

> 	* aarch64/cpu-init/rdimon-aem-el3.S: Add support for Armv8-R.

> 	* aarch64/elf-aem-v8-r.specs: New.

> 


The main problem I see with this is that it assumes that the compiler
being used is *not* configured for a default CPU architecture of
ARMv8-r.  If it is, then the normal rdimon-aem-el3.o file will in fact
become the same as the v8-r version, which is not really what we want.

Perhaps, rather than hacking around the __ARM_ARCH_PROFILE setting you
should just set things up to build the file twice, but with a different
conventional pre-define set each time.

R.
Corinna Vinschen via Newlib Sept. 29, 2020, 4:27 p.m. | #3
Hi Richard,

On 29/09/2020 15:06, Richard Earnshaw (lists) wrote:
> On 18/09/2020 15:43, Alex Coplan wrote:

> > Hello,

> > 

> > This patch adds support for Armv8-R AArch64. We update the AArch64 CPU

> > boot code to work on Armv8-R if __ARM_ARCH_PROFILE is set to 'R'.

> > Armv8-R AArch64 has no EL3, so we don't set vbar_el3, and adjust the

> > code to set up the MPU for Armv8-R.

> > 

> > We also add a specs file for use with Armv8-R AArch64 models.

> > 

> > Testing:

> >  * Ran AArch64 GCC testsuite using --with-arch=armv8-r together with the

> >    new specs file and boot code in an Armv8-R AArch64 model.

> >  * Ran newlib testsuite, no regressions.

> > 

> > OK for master?

> > 

> > Thanks,

> > Alex

> > 

> > ---

> > 

> > 2020-09-18  Alex Coplan  <alex.coplan@arm.com>

> > 

> > libgloss/ChangeLog:

> > 

> > 	* aarch64/Makefile.in: Install new specs file.

> > 	* aarch64/cpu-init/Makefile.in: Also build boot code for Armv8-R.

> > 	* aarch64/cpu-init/rdimon-aem-el3.S: Add support for Armv8-R.

> > 	* aarch64/elf-aem-v8-r.specs: New.

> > 

> 

> The main problem I see with this is that it assumes that the compiler

> being used is *not* configured for a default CPU architecture of

> ARMv8-r.  If it is, then the normal rdimon-aem-el3.o file will in fact

> become the same as the v8-r version, which is not really what we want.


Good catch. Thanks for the review.

> 

> Perhaps, rather than hacking around the __ARM_ARCH_PROFILE setting you

> should just set things up to build the file twice, but with a different

> conventional pre-define set each time.

> 

> R.


Sounds sensible. Is the revised patch (attached) OK?

Thanks,
Alex
diff --git a/libgloss/aarch64/Makefile.in b/libgloss/aarch64/Makefile.in
index 546557e3c..b8c2ca43c 100644
--- a/libgloss/aarch64/Makefile.in
+++ b/libgloss/aarch64/Makefile.in
@@ -85,7 +85,8 @@ RDIMON_BSP	= librdimon${${MULTILIBNAME}}.a
 RDIMON_OBJS	= $(patsubst %,rdimon-%,$(OBJS))
 RDIMON_SCRIPTS	= rdimon${${MULTILIBNAME}}.specs \
 		  aem-ve${${MULTILIBNAME}}.specs \
-		  aem-validation${${MULTILIBNAME}}.specs
+		  aem-validation${${MULTILIBNAME}}.specs \
+		  aem-v8-r${${MULTILIBNAME}}.specs
 RDIMON_INSTALL	= install-rdimon
 
 CFLAGS		= -g
diff --git a/libgloss/aarch64/cpu-init/Makefile.in b/libgloss/aarch64/cpu-init/Makefile.in
index 08aa1760f..c96f4ee0e 100644
--- a/libgloss/aarch64/cpu-init/Makefile.in
+++ b/libgloss/aarch64/cpu-init/Makefile.in
@@ -62,7 +62,7 @@ AR = @AR@
 LD = @LD@
 RANLIB = @RANLIB@
 
-CPU_INIT_OBJS = rdimon-aem-el3.o
+CPU_INIT_OBJS = rdimon-aem-el3.o rdimon-aem-v8-r.o
 CPU_INIT_INSTALL = install-cpu-init
 
 CFLAGS		= -g
@@ -79,10 +79,12 @@ all: ${CPU_INIT_OBJS}
 .PHONY: test
 test:
 
-# Static pattern rule for assembling cpu init files to object files.
-${CPU_INIT_OBJS}: %.o: %.S
+rdimon-aem-el3.o : rdimon-aem-el3.S
 	$(CC) $(CFLAGS_FOR_TARGET) $(CFLAGS) $(INCLUDES) -DARM_RDI_MONITOR -o $@ -c $<
 
+rdimon-aem-v8-r.o : rdimon-aem-el3.S
+	$(CC) $(CFLAGS_FOR_TARGET) $(CFLAGS) $(INCLUDES) -DARM_RDI_MONITOR -DBUILD_FOR_R_PROFILE -o $@ -c $<
+
 clean mostlyclean:
 	rm -f a.out core *.i *.o *-test *.srec *.dis *.x
 
diff --git a/libgloss/aarch64/cpu-init/rdimon-aem-el3.S b/libgloss/aarch64/cpu-init/rdimon-aem-el3.S
index e00f0b2c8..0296a8054 100644
--- a/libgloss/aarch64/cpu-init/rdimon-aem-el3.S
+++ b/libgloss/aarch64/cpu-init/rdimon-aem-el3.S
@@ -43,7 +43,9 @@ _init_vectors:
         /* Installs a table of exception vectors to catch and handle all
            exceptions by terminating the process with a diagnostic.  */
 	adr	x0, vectors
+#ifndef BUILD_FOR_R_PROFILE
 	msr	vbar_el3, x0
+#endif
 	msr	vbar_el2, x0
 	msr	vbar_el1, x0
 	ret
@@ -110,6 +112,14 @@ vectors:
 	.text
 	.align 2
 _flat_map:
+#ifdef BUILD_FOR_R_PROFILE
+	mrs	x0, sctlr_el2
+	orr	x0, x0, #1         // SCTLR_EL2.M (enable MPU)
+	orr	x0, x0, #(1 << 17) // SCTLR_EL2.BR (background regions)
+	msr	sctlr_el2, x0
+	isb
+	ret
+#else
 	/* Page table setup (identity mapping).  */
 	adrp	x0, ttb
 	add	x0, x0, :lo12:ttb
@@ -173,6 +183,7 @@ _flat_map:
        isb
 .Lnosve:
 	ret
+#endif
 
 	.data
 	.align	12
diff --git a/libgloss/aarch64/elf-aem-v8-r.specs b/libgloss/aarch64/elf-aem-v8-r.specs
new file mode 100644
index 000000000..4daeffd11
--- /dev/null
+++ b/libgloss/aarch64/elf-aem-v8-r.specs
@@ -0,0 +1,20 @@
+# elf-aem-v8-r.specs
+#
+# Spec file for AArch64 baremetal newlib, libgloss on Armv8-R with version 2 of
+# AngelAPI semi-hosting.
+
+%rename link old_link
+
+*link:
+-Ttext-segment 0x10000 %(old_link)
+
+%rename lib libc
+
+*libgloss:
+-lrdimon
+
+*lib:
+cpu-init/rdimon-aem-v8-r.o%s --start-group %(libc) %(libgloss) --end-group
+
+*startfile:
+crti%O%s crtbegin%O%s %{!pg:rdimon-crt0%O%s} %{pg:rdimon-crt0%O%s}
Corinna Vinschen via Newlib Sept. 30, 2020, 10:25 a.m. | #4
On 29/09/2020 17:27, Alex Coplan via Newlib wrote:
> Hi Richard,

> 

> On 29/09/2020 15:06, Richard Earnshaw (lists) wrote:

>> On 18/09/2020 15:43, Alex Coplan wrote:

>>> Hello,

>>>

>>> This patch adds support for Armv8-R AArch64. We update the AArch64 CPU

>>> boot code to work on Armv8-R if __ARM_ARCH_PROFILE is set to 'R'.

>>> Armv8-R AArch64 has no EL3, so we don't set vbar_el3, and adjust the

>>> code to set up the MPU for Armv8-R.

>>>

>>> We also add a specs file for use with Armv8-R AArch64 models.

>>>

>>> Testing:

>>>  * Ran AArch64 GCC testsuite using --with-arch=armv8-r together with the

>>>    new specs file and boot code in an Armv8-R AArch64 model.

>>>  * Ran newlib testsuite, no regressions.

>>>

>>> OK for master?

>>>

>>> Thanks,

>>> Alex

>>>

>>> ---

>>>

>>> 2020-09-18  Alex Coplan  <alex.coplan@arm.com>

>>>

>>> libgloss/ChangeLog:

>>>

>>> 	* aarch64/Makefile.in: Install new specs file.

>>> 	* aarch64/cpu-init/Makefile.in: Also build boot code for Armv8-R.

>>> 	* aarch64/cpu-init/rdimon-aem-el3.S: Add support for Armv8-R.

>>> 	* aarch64/elf-aem-v8-r.specs: New.

>>>

>>

>> The main problem I see with this is that it assumes that the compiler

>> being used is *not* configured for a default CPU architecture of

>> ARMv8-r.  If it is, then the normal rdimon-aem-el3.o file will in fact

>> become the same as the v8-r version, which is not really what we want.

> 

> Good catch. Thanks for the review.

> 

>>

>> Perhaps, rather than hacking around the __ARM_ARCH_PROFILE setting you

>> should just set things up to build the file twice, but with a different

>> conventional pre-define set each time.

>>

>> R.

> 

> Sounds sensible. Is the revised patch (attached) OK?

> 

> Thanks,

> Alex

> 


Pushed.  I've used the following as the commit message (note that newlib
doesn't use ChangeLog files anymore).

    libgloss: aarch64: Add support for Armv8-R AArch64

    This patch adds support for Armv8-R AArch64.

    Armv8-R AArch64 has no EL3, so we don't set vbar_el3, and adjust the
    code to set up the MPU for Armv8-R.  So build a different flavour of the
    startup code to support that.

    We also add a specs file that uses this alternative startup code which
    can be used with Armv8-R AArch64 models.

R.
Brian Hawley Sept. 30, 2020, 1:25 p.m. | #5
Brian Hawley
Luminex Software, Inc.
1-951-781-4100 x112
www.luminex.com



	  Original Message  	


From: newlib@sourceware.org
Sent: September 30, 2020 3:46 AM
To: alex.coplan@arm.com
Reply-to: Richard.Earnshaw@arm.com
Cc: newlib@sourceware.org
Subject: Re: [PATCH] libgloss/aarch64: Add support for Armv8-R AArch64


On 29/09/2020 17:27, Alex Coplan via Newlib wrote:
> Hi Richard,
>
> On 29/09/2020 15:06, Richard Earnshaw (lists) wrote:
>> On 18/09/2020 15:43, Alex Coplan wrote:
>>> Hello,
>>>
>>> This patch adds support for Armv8-R AArch64. We update the AArch64 CPU
>>> boot code to work on Armv8-R if __ARM_ARCH_PROFILE is set to 'R'.
>>> Armv8-R AArch64 has no EL3, so we don't set vbar_el3, and adjust the
>>> code to set up the MPU for Armv8-R.
>>>
>>> We also add a specs file for use with Armv8-R AArch64 models.
>>>
>>> Testing:
>>>  * Ran AArch64 GCC testsuite using --with-arch=armv8-r together with the
>>>    new specs file and boot code in an Armv8-R AArch64 model.
>>>  * Ran newlib testsuite, no regressions.
>>>
>>> OK for master?
>>>
>>> Thanks,
>>> Alex
>>>
>>> ---
>>>
>>> 2020-09-18  Alex Coplan  <alex.coplan@arm.com>
>>>
>>> libgloss/ChangeLog:
>>>
>>> * aarch64/Makefile.in: Install new specs file.
>>> * aarch64/cpu-init/Makefile.in: Also build boot code for Armv8-R.
>>> * aarch64/cpu-init/rdimon-aem-el3.S: Add support for Armv8-R.
>>> * aarch64/elf-aem-v8-r.specs: New.
>>>
>>
>> The main problem I see with this is that it assumes that the compiler
>> being used is *not* configured for a default CPU architecture of
>> ARMv8-r.  If it is, then the normal rdimon-aem-el3.o file will in fact
>> become the same as the v8-r version, which is not really what we want.
>
> Good catch. Thanks for the review.
>
>>
>> Perhaps, rather than hacking around the __ARM_ARCH_PROFILE setting you
>> should just set things up to build the file twice, but with a different
>> conventional pre-define set each time.
>>
>> R.
>
> Sounds sensible. Is the revised patch (attached) OK?
>
> Thanks,
> Alex
>

Pushed.  I've used the following as the commit message (note that newlib
doesn't use ChangeLog files anymore).

    libgloss: aarch64: Add support for Armv8-R AArch64

    This patch adds support for Armv8-R AArch64.

    Armv8-R AArch64 has no EL3, so we don't set vbar_el3, and adjust the
    code to set up the MPU for Armv8-R.  So build a different flavour of the
    startup code to support that.

    We also add a specs file that uses this alternative startup code which
    can be used with Armv8-R AArch64 models.

R.

Patch

diff --git a/libgloss/aarch64/Makefile.in b/libgloss/aarch64/Makefile.in
index 546557e3c..b8c2ca43c 100644
--- a/libgloss/aarch64/Makefile.in
+++ b/libgloss/aarch64/Makefile.in
@@ -85,7 +85,8 @@  RDIMON_BSP	= librdimon${${MULTILIBNAME}}.a
 RDIMON_OBJS	= $(patsubst %,rdimon-%,$(OBJS))
 RDIMON_SCRIPTS	= rdimon${${MULTILIBNAME}}.specs \
 		  aem-ve${${MULTILIBNAME}}.specs \
-		  aem-validation${${MULTILIBNAME}}.specs
+		  aem-validation${${MULTILIBNAME}}.specs \
+		  aem-v8-r${${MULTILIBNAME}}.specs
 RDIMON_INSTALL	= install-rdimon
 
 CFLAGS		= -g
diff --git a/libgloss/aarch64/cpu-init/Makefile.in b/libgloss/aarch64/cpu-init/Makefile.in
index 08aa1760f..3ada50d64 100644
--- a/libgloss/aarch64/cpu-init/Makefile.in
+++ b/libgloss/aarch64/cpu-init/Makefile.in
@@ -62,7 +62,7 @@  AR = @AR@
 LD = @LD@
 RANLIB = @RANLIB@
 
-CPU_INIT_OBJS = rdimon-aem-el3.o
+CPU_INIT_OBJS = rdimon-aem-el3.o rdimon-aem-v8-r.o
 CPU_INIT_INSTALL = install-cpu-init
 
 CFLAGS		= -g
@@ -79,10 +79,15 @@  all: ${CPU_INIT_OBJS}
 .PHONY: test
 test:
 
-# Static pattern rule for assembling cpu init files to object files.
-${CPU_INIT_OBJS}: %.o: %.S
+rdimon-aem-el3.o : rdimon-aem-el3.S
 	$(CC) $(CFLAGS_FOR_TARGET) $(CFLAGS) $(INCLUDES) -DARM_RDI_MONITOR -o $@ -c $<
 
+rdimon-aem-v8-r.o : rdimon-aem-el3.S
+	# Force the ACLE macro __ARM_ARCH_PROFILE='R'. This should be defined by
+	# the compiler for compilers supporting -march=armv8-r on AArch64 but we
+	# want to be able to build this code with older compilers.
+	$(CC) $(CFLAGS_FOR_TARGET) $(CFLAGS) $(INCLUDES) -DARM_RDI_MONITOR -D__ARM_ARCH_PROFILE=82 -o $@ -c $<
+
 clean mostlyclean:
 	rm -f a.out core *.i *.o *-test *.srec *.dis *.x
 
diff --git a/libgloss/aarch64/cpu-init/rdimon-aem-el3.S b/libgloss/aarch64/cpu-init/rdimon-aem-el3.S
index e00f0b2c8..93dcdb353 100644
--- a/libgloss/aarch64/cpu-init/rdimon-aem-el3.S
+++ b/libgloss/aarch64/cpu-init/rdimon-aem-el3.S
@@ -43,7 +43,9 @@  _init_vectors:
         /* Installs a table of exception vectors to catch and handle all
            exceptions by terminating the process with a diagnostic.  */
 	adr	x0, vectors
+#if __ARM_ARCH_PROFILE != 'R'
 	msr	vbar_el3, x0
+#endif
 	msr	vbar_el2, x0
 	msr	vbar_el1, x0
 	ret
@@ -110,6 +112,14 @@  vectors:
 	.text
 	.align 2
 _flat_map:
+#if __ARM_ARCH_PROFILE == 'R'
+	mrs	x0, sctlr_el2
+	orr	x0, x0, #1         // SCTLR_EL2.M (enable MPU)
+	orr	x0, x0, #(1 << 17) // SCTLR_EL2.BR (background regions)
+	msr	sctlr_el2, x0
+	isb
+	ret
+#else
 	/* Page table setup (identity mapping).  */
 	adrp	x0, ttb
 	add	x0, x0, :lo12:ttb
@@ -173,6 +183,7 @@  _flat_map:
        isb
 .Lnosve:
 	ret
+#endif
 
 	.data
 	.align	12
diff --git a/libgloss/aarch64/elf-aem-v8-r.specs b/libgloss/aarch64/elf-aem-v8-r.specs
new file mode 100644
index 000000000..4daeffd11
--- /dev/null
+++ b/libgloss/aarch64/elf-aem-v8-r.specs
@@ -0,0 +1,20 @@ 
+# elf-aem-v8-r.specs
+#
+# Spec file for AArch64 baremetal newlib, libgloss on Armv8-R with version 2 of
+# AngelAPI semi-hosting.
+
+%rename link old_link
+
+*link:
+-Ttext-segment 0x10000 %(old_link)
+
+%rename lib libc
+
+*libgloss:
+-lrdimon
+
+*lib:
+cpu-init/rdimon-aem-v8-r.o%s --start-group %(libc) %(libgloss) --end-group
+
+*startfile:
+crti%O%s crtbegin%O%s %{!pg:rdimon-crt0%O%s} %{pg:rdimon-crt0%O%s}