Skip to contentSkip to conversation

target/xtensa: provide configuration with MPU

PATCH New Max Filippov 1 participant 5 messages Jan 12, 2024

lore
Share & tools
lore
#1 lore raw

PATCH 1/4 target/xtensa: add translation for wsr.mpucfg

In reply to Max Filippov

Although MPUCFG is not writable, the opcode wsr.mpucfg is defined and it just does nothing. Define wsr.mpucfg as nop.

---
 target/xtensa/translate.c | 9 +++++++++
 1 file changed, 9 insertions(+)
target/xtensa/translate.c +9 -0
index de899405994e..6a2f5d308e6a 100644
@@ -5332,6 +5332,15 @@ static const XtensaOpcodeOps core_ops[] = {
             XTENSA_OPTION_TRACE_PORT,
         },
         .op_flags = XTENSA_OP_PRIVILEGED,
+    }, {
+        .name = "wsr.mpucfg",
+        .translate = translate_nop,
+        .test_exceptions = test_exceptions_sr,
+        .par = (const uint32_t[]){
+            MPUCFG,
+            XTENSA_OPTION_MPU,
+        },
+        .op_flags = XTENSA_OP_PRIVILEGED,
     }, {
         .name = "wsr.mpuenb",
         .translate = translate_wsr_mpuenb,
Signature · 1 line
2.39.2
#0 lore raw

cover target/xtensa: provide configuration with MPU

Hello,

this series adds xtensa core 'sample_controller32' with 32 foreground entry MPU, adds missing translation for the 'wsr.mpucfg' opcode and makes xtensa/tcg/tests work with the new core.

Max Filippov (4):
target/xtensa: add translation for wsr.mpucfg target/xtensa: import sample_controller32 core tests/tcg/xtensa: tidy test linker script tests/tcg/xtensa: fix SR test for configs with MPU

 target/xtensa/core-sample_controller32.c      |    52 +
 .../core-sample_controller32/core-isa.h       |   739 +
 .../core-sample_controller32/core-matmap.h    |   106 +
 .../core-sample_controller32/gdb-config.c.inc |   144 +
 .../xtensa-modules.c.inc                      | 11845 ++++++++++++++++
 target/xtensa/cores.list                      |     1 +
 target/xtensa/translate.c                     |     9 +
 tests/tcg/xtensa/linker.ld.S                  |    34 +-
 tests/tcg/xtensa/test_sr.S                    |    16 +-
 9 files changed, 12921 insertions(+), 25 deletions(-)
 create mode 100644 target/xtensa/core-sample_controller32.c
 create mode 100644 target/xtensa/core-sample_controller32/core-isa.h
 create mode 100644 target/xtensa/core-sample_controller32/core-matmap.h
 create mode 100644 target/xtensa/core-sample_controller32/gdb-config.c.inc
 create mode 100644 target/xtensa/core-sample_controller32/xtensa-modules.c.inc
Signature · 1 line
2.39.2
#2 lore raw

PATCH 2/4 target/xtensa: import sample_controller32 core

This is an LX core with MPU and exclusive access options.

---
 target/xtensa/core-sample_controller32.c      |    52 +
 .../core-sample_controller32/core-isa.h       |   739 +
 .../core-sample_controller32/core-matmap.h    |   106 +
 .../core-sample_controller32/gdb-config.c.inc |   144 +
 .../xtensa-modules.c.inc                      | 11845 ++++++++++++++++
 target/xtensa/cores.list                      |     1 +
 6 files changed, 12887 insertions(+)
 create mode 100644 target/xtensa/core-sample_controller32.c
 create mode 100644 target/xtensa/core-sample_controller32/core-isa.h
 create mode 100644 target/xtensa/core-sample_controller32/core-matmap.h
 create mode 100644 target/xtensa/core-sample_controller32/gdb-config.c.inc
 create mode 100644 target/xtensa/core-sample_controller32/xtensa-modules.c.inc
target/xtensa/core-sample_controller32.c new file +52 -0
new file mode 100644
index 000000000000..56c60f936f34
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2024, Max Filippov, Open Source and Linux Lab.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in the
+ *       documentation and/or other materials provided with the distribution.
+ *     * Neither the name of the Open Source and Linux Lab nor the
+ *       names of its contributors may be used to endorse or promote products
+ *       derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "qemu/osdep.h"
+#include "cpu.h"
+#include "gdbstub/helpers.h"
+#include "qemu/host-utils.h"
+
+#include "core-sample_controller32/core-isa.h"
+#include "core-sample_controller32/core-matmap.h"
+#include "overlay_tool.h"
+
+#define xtensa_modules xtensa_modules_sample_controller32
+#include "core-sample_controller32/xtensa-modules.c.inc"
+
+static XtensaConfig sample_controller32 __attribute__((unused)) = {
+    .name = "sample_controller32",
+    .gdb_regmap = {
+        .reg = {
+#include "core-sample_controller32/gdb-config.c.inc"
+        }
+    },
+    .isa_internal = &xtensa_modules,
+    .clock_freq_khz = 10000,
+    DEFAULT_SECTIONS
+};
+
+REGISTER_CORE(sample_controller32)
target/xtensa/core-sample_controller32/core-isa.h new file +739 -0

739 lines not on this page · raw message

target/xtensa/core-sample_controller32/core-matmap.h new file +106 -0

106 lines not on this page · raw message

target/xtensa/core-sample_controller32/gdb-config.c.inc new file +144 -0

144 lines not on this page · raw message

target/xtensa/core-sample_controller32/xtensa-modules.c.inc new file +11845 -0

1,959 lines not on this page · raw message

target/xtensa/cores.list +1 -0
index a526a71cfd98..be689275acb3 100644

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Signature · 1 line
2.39.2

Part of the diff is not shown here. View the raw message.

#4 lore raw

PATCH 4/4 tests/tcg/xtensa: fix SR test for configs with MPU

In reply to Max Filippov

- atomctl is available not only in the presence of s32c1i, but also with the exclusive access option
- cacheadrdis SR has the same number as cacheattr, mpuenb SR has the same number as rasid and mpucfg SR has the same number as dtlbcfg, add MPU case to the tests of these SR numbers

---
 tests/tcg/xtensa/test_sr.S | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)
tests/tcg/xtensa/test_sr.S +14 -2
index 34441c7afff7..661ef6c66ed1 100644
@@ -62,7 +62,7 @@ test_sr_mask /*acchi*/17, 0, 0
 test_sr_mask /*acclo*/16, 0, 0
 #endif
 
-#if XCHAL_HAVE_S32C1I && XCHAL_HW_VERSION >= 230000
+#if XCHAL_HAVE_S32C1I && XCHAL_HW_VERSION >= 230000 || XCHAL_HAVE_EXCLUSIVE
 test_sr atomctl, 1
 #else
 test_sr_mask /*atomctl*/99, 0, 0
@@ -74,7 +74,11 @@ test_sr br, 1
 test_sr_mask /*br*/4, 0, 0
 #endif
 
+#if XCHAL_HAVE_MPU
+test_sr cacheadrdis, 1
+#else
 test_sr_mask /*cacheattr*/98, 0, 0
+#endif
 
 #if XCHAL_HAVE_CCOUNT
 test_sr ccompare0, 1
@@ -106,6 +110,8 @@ test_sr depc, 1
 
 #if XCHAL_HAVE_PTP_MMU
 test_sr dtlbcfg, 1
+#elif XCHAL_HAVE_MPU
+test_sr_mask /*mpucfg*/92, 0, 3
 #else
 test_sr_mask /*dtlbcfg*/92, 0, 0
 #endif
@@ -205,9 +211,15 @@ test_sr ps, 1
 
 #if XCHAL_HAVE_PTP_MMU
 test_sr ptevaddr, 1
-test_sr rasid, 1
 #else
 test_sr_mask /*ptevaddr*/83, 0, 0
+#endif
+
+#if XCHAL_HAVE_PTP_MMU
+test_sr rasid, 1
+#elif XCHAL_HAVE_MPU
+test_sr mpuenb, 1
+#else
 test_sr_mask /*rasid*/90, 0, 0
 #endif
 
Signature · 1 line
2.39.2
#3 lore raw

PATCH 3/4 tests/tcg/xtensa: tidy test linker script

In reply to Max Filippov

Drop MEMORY clause and related size definitions and output section region specifications. Drop .rodata output section as the tests don't use it. Add DATA_SEGMENT_ALIGN/DATA_SEGMENT_END around .data and .bss to let the linker make an RW segment for data. Reserve 1M for stack instead of almost 128M.

---
 tests/tcg/xtensa/linker.ld.S | 34 +++++++++++-----------------------
 1 file changed, 11 insertions(+), 23 deletions(-)
tests/tcg/xtensa/linker.ld.S +11 -23
index ac89b0054ee4..0e21eee31ccc 100644
@@ -10,9 +10,8 @@
 #define XCHAL_WINDOW_UF12_VECOFS  0x00000140
 #endif
 
-#define RAM_SIZE 0x08000000  /* 128M */
-#define ROM_SIZE 0x00001000  /* 4k */
 #define VECTORS_RESERVED_SIZE 0x1000
+#define STACK_SIZE 0x00100000
 
 #if XCHAL_HAVE_BE
 OUTPUT_FORMAT("elf32-xtensa-be")
@@ -21,18 +20,13 @@ OUTPUT_FORMAT("elf32-xtensa-le")
 #endif
 ENTRY(_start)
 
-MEMORY {
-    ram : ORIGIN = XCHAL_VECBASE_RESET_VADDR, LENGTH = RAM_SIZE
-    rom : ORIGIN = XCHAL_RESET_VECTOR_VADDR, LENGTH = ROM_SIZE
-}
-
 SECTIONS
 {
-    .init :
+    .init XCHAL_RESET_VECTOR_VADDR :
     {
         *(.init)
         *(.init.*)
-    } > rom
+    }
 
 #if XCHAL_HAVE_WINDOWED
     .vector.window XCHAL_WINDOW_VECTORS_VADDR :
@@ -119,23 +113,16 @@ SECTIONS
         *(.vector.kernel.*)
         *(.vector.user.*)
         *(.vector.double.*)
-    } > ram
+    }
 
     .text :
     {
         _ftext = .;
         *(.text .stub .text.* .gnu.linkonce.t.* .literal .literal.*)
         _etext = .;
-    } > ram
+    }
 
-    .rodata :
-    {
-        . = ALIGN(4);
-        _frodata = .;
-        *(.rodata .rodata.* .gnu.linkonce.r.*)
-        *(.rodata1)
-        _erodata = .;
-    } > ram
+    . = DATA_SEGMENT_ALIGN(0x1000, 0x1000);
 
     .data :
     {
@@ -146,7 +133,7 @@ SECTIONS
         _gp = ALIGN(16);
         *(.sdata .sdata.* .gnu.linkonce.s.*)
         _edata = .;
-    } > ram
+    }
 
     .bss :
     {
@@ -160,7 +147,8 @@ SECTIONS
         *(COMMON)
         _ebss = .;
         _end = .;
-    } > ram
-}
+    }
 
-PROVIDE(_fstack = (ORIGIN(ram) & 0xf0000000) + LENGTH(ram) - 16);
+    . = DATA_SEGMENT_END(.);
+    _fstack = ALIGN(. + STACK_SIZE, 16);
+}
Signature · 1 line
2.39.2