Skip to contentSkip to conversation

ARM Cortex-R4 support ?

Qemu-devel In review Giancarlo ASNAGHI 5 participants 11 messages Sep 21, 2012 – Sep 25, 2012

lore
Share & tools
lore
#0 lore raw

Hello,

Do you know which is the status of the support for Cortex-R4 support? I've seen an initial set of patches from Andreas Farber one years ago, but into the qemu-system-arm the Cortex-R4 ins't available yet.

Thanks a lot
Best Regards
Giancarlo

#1 lore raw

Hello Giancarlo,

Am 21.09.2012 17:15, schrieb Giancarlo ASNAGHI:

Quoted 1 line

Do you know which is the status of the support for Cortex-R4 support? I've seen an initial set of patches from Andreas Farber one years ago, but into the qemu-system-arm the Cortex-R4 ins't available yet.

That's true. As a consequence of my patches we redesigned several parts of ARM CPU modelling to facilitate this. My patches were not yet rebased onto that. A new QOM type derived from TYPE_ARM_CPU would need to be created now, to initialize the registers imperatively rather than declaratively. I might manage that quickly.

Note that my published patches only took care of CPUID, FPU and a few others to instantiate the -cpu cortex-r4 at all.

Where I got stuck was reading through the ARMv7 TRM differences between VMSA and PMSA (chapters B3 and B4 respectively) to implement PMSA, pointed out by Peter. And there were also some floating point width differences to ARMv7-A (VFPv3-D16 vs. VFPv3-S32 or so). Neither is a small patch that I can supply short-term, maybe your colleagues can help with those parts once I've refreshed my patches? Cédric has worked on the FPU before, cc'ing.

Regards,
Andreas

Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
#2 lore raw

RFC v2 1/2 target-arm: Prepare support for Cortex-R4

Glue "cortex-r4" to r1p4, the latest available TRM. Set MPU and Thumb division feature bit.

---
 target-arm/cpu.c |   24 ++++++++++++++++++++++++

1 Datei geändert, 24 Zeilen hinzugefügt(+)

target-arm/cpu.c +24 -0
index b00f5fa..6726498 100644
@@ -382,6 +382,29 @@ static void cortex_m3_initfn(Object *obj)
     cpu->midr = 0x410fc231;
 }
 
+static void cortex_r4_initfn(Object *obj)
+{
+    ARMCPU *cpu = ARM_CPU(obj);
+    set_feature(&cpu->env, ARM_FEATURE_V7);
+    set_feature(&cpu->env, ARM_FEATURE_THUMB_DIV);
+    set_feature(&cpu->env, ARM_FEATURE_MPU);
+    cpu->midr = 0x411FC144; /* r1p4 */
+    cpu->id_pfr0 = 0x0131;
+    cpu->id_pfr1 = 0x001;
+    cpu->id_dfr0 = 0x010400;
+    cpu->id_afr0 = 0x0;
+    cpu->id_mmfr0 = 0x0210030;
+    cpu->id_mmfr1 = 0x00000000;
+    cpu->id_mmfr2 = 0x01200000;
+    cpu->id_mmfr3 = 0x0211;
+    cpu->id_isar0 = 0x1101111;
+    cpu->id_isar1 = 0x13112111;
+    cpu->id_isar2 = 0x21232131;
+    cpu->id_isar3 = 0x01112131;
+    cpu->id_isar4 = 0x0010142;
+    cpu->id_isar5 = 0x0;
+}
+
 static const ARMCPRegInfo cortexa8_cp_reginfo[] = {
     { .name = "L2LOCKDOWN", .cp = 15, .crn = 9, .crm = 0, .opc1 = 1, .opc2 = 0,
       .access = PL1_RW, .type = ARM_CP_CONST, .resetvalue = 0 },
@@ -737,6 +760,7 @@ static const ARMCPUInfo arm_cpus[] = {
     { .name = "arm1176",     .initfn = arm1176_initfn },
     { .name = "arm11mpcore", .initfn = arm11mpcore_initfn },
     { .name = "cortex-m3",   .initfn = cortex_m3_initfn },
+    { .name = "cortex-r4",   .initfn = cortex_r4_initfn },
     { .name = "cortex-a8",   .initfn = cortex_a8_initfn },
     { .name = "cortex-a9",   .initfn = cortex_a9_initfn },
     { .name = "cortex-a15",  .initfn = cortex_a15_initfn },
Signature · 1 line
1.7.10.4
#3 lore raw

RFC v2 2/2 target-arm: Add support for Cortex-R4F

With QOM ARMCPU we can now distinguish between -cpu cortex-r4 and -cpu cortex-r4f despite identical MIDR.

---
 target-arm/cpu.c |   47 +++++++++++++++++++++++++++++++++++++++++++++++

1 Datei geändert, 47 Zeilen hinzugefügt(+)

target-arm/cpu.c +47 -0
index 6726498..e176559 100644
@@ -405,6 +405,52 @@ static void cortex_r4_initfn(Object *obj)
     cpu->id_isar5 = 0x0;
 }
 
+static const struct {
+    uint8_t r;
+    uint8_t p;
+    uint8_t value;
+} cortexr4_fpsid_revs[] = {
+    { 1, 0, 0x3 },
+    { 1, 1, 0x4 },
+    { 1, 2, 0x6 },
+    { 1, 3, 0x7 },
+    { 1, 4, 0x8 },
+    {}
+};
+
+static void cortex_r4f_initfn(Object *obj)
+{
+    ARMCPU *cpu = ARM_CPU(obj);
+
+    /* Cortex-R4F = Cortex-R4 + FPU */
+    cortex_r4_initfn(obj);
+
+    set_feature(&cpu->env, ARM_FEATURE_VFP3);
+    /* TODO VFPv3-D16 */
+    {
+        /* PMM didn't like this dynamic revision lookup... */
+        /* TODO: maybe weave cross-checks into QOM properties instead? */
+        uint8_t r = (cpu->midr >> 20) & 0xf;
+        uint8_t p = cpu->midr & 0xf;
+        uint8_t rev = 0;
+        int i;
+        /* Calculate FPSID value matching to MIDR */
+        for (i = 0; cortexr4_fpsid_revs[i].r != 0; i++) {
+            if (cortexr4_fpsid_revs[i].r == r &&
+                cortexr4_fpsid_revs[i].p == p) {
+                rev = cortexr4_fpsid_revs[i].value;
+                break;
+            }
+        }
+        if (rev == 0) {
+            cpu_abort(&cpu->env,
+                      "Cortex-R4F r%" PRIu8 "p%" PRIu8 " unsupported",
+                      r, p);
+        }
+        cpu->reset_fpsid = 0x41023140 | (rev & 0xf);
+    }
+}
+
 static const ARMCPRegInfo cortexa8_cp_reginfo[] = {
     { .name = "L2LOCKDOWN", .cp = 15, .crn = 9, .crm = 0, .opc1 = 1, .opc2 = 0,
       .access = PL1_RW, .type = ARM_CP_CONST, .resetvalue = 0 },
@@ -761,6 +807,7 @@ static const ARMCPUInfo arm_cpus[] = {
     { .name = "arm11mpcore", .initfn = arm11mpcore_initfn },
     { .name = "cortex-m3",   .initfn = cortex_m3_initfn },
     { .name = "cortex-r4",   .initfn = cortex_r4_initfn },
+    { .name = "cortex-r4f",  .initfn = cortex_r4f_initfn },
     { .name = "cortex-a8",   .initfn = cortex_a8_initfn },
     { .name = "cortex-a9",   .initfn = cortex_a9_initfn },
     { .name = "cortex-a15",  .initfn = cortex_a15_initfn },
Signature · 1 line
1.7.10.4
#4 lore raw

Re: [Qemu-devel] [RFC v2 2/2] target-arm: Add support for Cortex-R4F

Quoted 37 lines · Andreas Färber

With QOM ARMCPU we can now distinguish between -cpu cortex-r4 and -cpu cortex-r4f despite identical MIDR.

---
 target-arm/cpu.c |   47 +++++++++++++++++++++++++++++++++++++++++++++++

1 Datei geändert, 47 Zeilen hinzugefügt(+)

target-arm/cpu.c +21 -0
index 6726498..e176559 100644
@@ -405,6 +405,52 @@ static void cortex_r4_initfn(Object *obj)
     cpu->id_isar5 = 0x0;
 }
 
+static const struct {
+    uint8_t r;
+    uint8_t p;
+    uint8_t value;
+} cortexr4_fpsid_revs[] = {
+    { 1, 0, 0x3 },
+    { 1, 1, 0x4 },
+    { 1, 2, 0x6 },
+    { 1, 3, 0x7 },
+    { 1, 4, 0x8 },
+    {}
+};
+
+static void cortex_r4f_initfn(Object *obj)
+{
+    ARMCPU *cpu = ARM_CPU(obj);
+
+    /* Cortex-R4F = Cortex-R4 + FPU */
+    cortex_r4_initfn(obj);
+
+    set_feature(&cpu->env, ARM_FEATURE_VFP3);

target-arm/cpu.c static void cortex_r4_initfn(Object *obj) · line 438

Quoted 10 lines
target-arm/cpu.c +10 -0
+    /* TODO VFPv3-D16 */
+    {
+        /* PMM didn't like this dynamic revision lookup... */
+        /* TODO: maybe weave cross-checks into QOM properties instead? */
+        uint8_t r = (cpu->midr >> 20) & 0xf;
+        uint8_t p = cpu->midr & 0xf;
+        uint8_t rev = 0;
+        int i;
+        /* Calculate FPSID value matching to MIDR */
+        for (i = 0; cortexr4_fpsid_revs[i].r != 0; i++) {

You could use ARRAY_SIZE() to determine max index without the zero entry. That way the number of entries would be known by the compiler too.

Quoted 30 lines
target-arm/cpu.c +16 -1
+            if (cortexr4_fpsid_revs[i].r == r &&
+                cortexr4_fpsid_revs[i].p == p) {
+                rev = cortexr4_fpsid_revs[i].value;
+                break;
+            }
+        }
+        if (rev == 0) {
+            cpu_abort(&cpu->env,
+                      "Cortex-R4F r%" PRIu8 "p%" PRIu8 " unsupported",
+                      r, p);
+        }
+        cpu->reset_fpsid = 0x41023140 | (rev & 0xf);
+    }
+}
+
 static const ARMCPRegInfo cortexa8_cp_reginfo[] = {
     { .name = "L2LOCKDOWN", .cp = 15, .crn = 9, .crm = 0, .opc1 = 1, .opc2 = 0,
       .access = PL1_RW, .type = ARM_CP_CONST, .resetvalue = 0 },
@@ -761,6 +807,7 @@ static const ARMCPUInfo arm_cpus[] = {
     { .name = "arm11mpcore", .initfn = arm11mpcore_initfn },
     { .name = "cortex-m3",   .initfn = cortex_m3_initfn },
     { .name = "cortex-r4",   .initfn = cortex_r4_initfn },
+    { .name = "cortex-r4f",  .initfn = cortex_r4f_initfn },
     { .name = "cortex-a8",   .initfn = cortex_a8_initfn },
     { .name = "cortex-a9",   .initfn = cortex_a9_initfn },
     { .name = "cortex-a15",  .initfn = cortex_a15_initfn },
--

1.7.10.4

#5 lore raw

Re: [Qemu-devel] [RFC v2 2/2] target-arm: Add support for Cortex-R4F

In reply to Andreas Färber
Quoted 2 lines · Andreas Färber

With QOM ARMCPU we can now distinguish between -cpu cortex-r4 and -cpu cortex-r4f despite identical MIDR.

I'm not convinced that we should treat the R4 any differently to any of the other CPUs which we model which might or might not have an FPU. For the others we basically model the "all options enabled" version of the CPU. It might be nice to have the ability to separately toggle options on and off in general. Basically if we add 'cortex-r4f' then we're stuck with supporting that name forever for backwards compatibility.

(I have a feeling we've had this conversation before but I forget the outcome.)

-- PMM

#6 lore raw

Re: [Qemu-devel] [RFC v2 1/2] target-arm: Prepare support for Cortex-R4

In reply to Andreas Färber

target-arm/cpu.c static void cortex_m3_initfn(Object *obj) · line 390

Quoted 6 lines · Andreas Färber
target-arm/cpu.c +6 -0
+static void cortex_r4_initfn(Object *obj)
+{
+    ARMCPU *cpu = ARM_CPU(obj);
+    set_feature(&cpu->env, ARM_FEATURE_V7);
+    set_feature(&cpu->env, ARM_FEATURE_THUMB_DIV);
+    set_feature(&cpu->env, ARM_FEATURE_MPU);

This will trip the assert in register_cp_regs_for_features():

    if (arm_feature(env, ARM_FEATURE_MPU)) {
        /* These are the MPU registers prior to PMSAv6. Any new
         * PMSA core later than the ARM946 will require that we
         * implement the PMSAv6 or PMSAv7 registers, which are
         * completely different.
         */
        assert(!arm_feature(env, ARM_FEATURE_V6));

...indicating that R4 support is more work than is contained in this patch :-)

-- PMM

#7 lore raw

Re: [Qemu-devel] [RFC v2 1/2] target-arm: Prepare support for Cortex-R4

Am 22.09.2012 15:05, schrieb Peter Maydell:

Quoted 9 lines · Andreas Färber

target-arm/cpu.c static void cortex_m3_initfn(Object *obj) · line 390

Quoted 6 lines
target-arm/cpu.c +6 -0
+static void cortex_r4_initfn(Object *obj)
+{
+    ARMCPU *cpu = ARM_CPU(obj);
+    set_feature(&cpu->env, ARM_FEATURE_V7);
+    set_feature(&cpu->env, ARM_FEATURE_THUMB_DIV);
+    set_feature(&cpu->env, ARM_FEATURE_MPU);

This will trip the assert in register_cp_regs_for_features():

Thanks for the pointer. This rebased version is only compile-tested and is provided mainly for the ST guys to build upon, during my absence.

Quoted 10 lines
    if (arm_feature(env, ARM_FEATURE_MPU)) {
        /* These are the MPU registers prior to PMSAv6. Any new
         * PMSA core later than the ARM946 will require that we
         * implement the PMSAv6 or PMSAv7 registers, which are
         * completely different.
         */
        assert(!arm_feature(env, ARM_FEATURE_V6));

...indicating that R4 support is more work than is contained in this patch :-)

...which confirms what I stated in the message this is threaded to, and is reflected by "prepare". :)

Same for VFPv3-D16 in the second RFC patch (which used to "add" to cortex-r4, now should've been updated to "prepare" as well).

And of course the Cortex-R4's lock-step mode that seems to make it so interesting for automotive customers.

/-F

#8 lore raw

Re: [Qemu-devel] [RFC v2 1/2] target-arm: Prepare support for Cortex-R4

Quoted 2 lines · Andreas Färber

And of course the Cortex-R4's lock-step mode that seems to make it so interesting for automotive customers.

Lock-step is trivial to emulate: just do nothing and never raise a "cores out of sync" error :-)

-- PMM

#9 lore raw
In reply to Andreas Färber

Hi Andreas,

thanks to share the status. I've doubts that some of my collegues may helps here, because we are focusing on the uclinux kernel and user side. Anyway I check and I let you know.

Best Regards
Giancarlo

Quoted 37 lines

-----Original Message-----
From: Andreas Färber [mailto:[email protected]]
Sent: venerdì 21 settembre 2012 19:05
To: Giancarlo ASNAGHI
Cc: [email protected]; Peter Maydell; Cedric VINCENT
Subject: Re: [Qemu-devel] ARM Cortex-R4 support ?

Hello Giancarlo,

Am 21.09.2012 17:15, schrieb Giancarlo ASNAGHI:

Quoted 1 line

Do you know which is the status of the support for Cortex-R4 support? I've

seen an initial set of patches from Andreas Farber one years ago, but into the qemu-system-arm the Cortex-R4 ins't available yet.

That's true. As a consequence of my patches we redesigned several parts of ARM CPU modelling to facilitate this. My patches were not yet rebased onto that. A new QOM type derived from TYPE_ARM_CPU would need to be created now, to initialize the registers imperatively rather than declaratively. I might manage that quickly.

Note that my published patches only took care of CPUID, FPU and a few others to instantiate the -cpu cortex-r4 at all.

Where I got stuck was reading through the ARMv7 TRM differences between VMSA and PMSA (chapters B3 and B4 respectively) to implement PMSA, pointed out by Peter. And there were also some floating point width differences to ARMv7-A (VFPv3-D16 vs. VFPv3-S32 or so).
Neither is a small patch that I can supply short-term, maybe your colleagues can help with those parts once I've refreshed my patches?
Cédric has worked on the FPU before, cc'ing.

Regards,
Andreas

--
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg

#10 lore raw
In reply to Andreas Färber

Hi Andreas,

just a question.
Due to the fact that we don't have the FPU on our Cortex-R4 and that we don't plan using floating point do you mind that we may use it even with the VFPv3-D16 vs. VFPv3-S32 issue?

Thanks and Best Regads

Giancarlo

Quoted 37 lines

-----Original Message-----
From: Andreas Färber [mailto:[email protected]]
Sent: venerdì 21 settembre 2012 19:05
To: Giancarlo ASNAGHI
Cc: [email protected]; Peter Maydell; Cedric VINCENT
Subject: Re: [Qemu-devel] ARM Cortex-R4 support ?

Hello Giancarlo,

Am 21.09.2012 17:15, schrieb Giancarlo ASNAGHI:

Quoted 1 line

Do you know which is the status of the support for Cortex-R4 support? I've

seen an initial set of patches from Andreas Farber one years ago, but into the qemu-system-arm the Cortex-R4 ins't available yet.

That's true. As a consequence of my patches we redesigned several parts of ARM CPU modelling to facilitate this. My patches were not yet rebased onto that. A new QOM type derived from TYPE_ARM_CPU would need to be created now, to initialize the registers imperatively rather than declaratively. I might manage that quickly.

Note that my published patches only took care of CPUID, FPU and a few others to instantiate the -cpu cortex-r4 at all.

Where I got stuck was reading through the ARMv7 TRM differences between VMSA and PMSA (chapters B3 and B4 respectively) to implement PMSA, pointed out by Peter. And there were also some floating point width differences to ARMv7-A (VFPv3-D16 vs. VFPv3-S32 or so).
Neither is a small patch that I can supply short-term, maybe your colleagues can help with those parts once I've refreshed my patches?
Cédric has worked on the FPU before, cc'ing.

Regards,
Andreas

--
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg