Skip to content

Commit be5eccd

Browse files
Flavio Ceolincarlescufi
authored andcommitted
tests: userspace: Add xtensa support
This test requires architecture specific code to work. Signed-off-by: Flavio Ceolin <[email protected]> Signed-off-by: Daniel Leung <[email protected]>
1 parent 7a5d2a2 commit be5eccd

File tree

1 file changed

+33
-2
lines changed
  • tests/kernel/mem_protect/userspace/src

1 file changed

+33
-2
lines changed

tests/kernel/mem_protect/userspace/src/main.c

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@
2020
#include "test_syscall.h"
2121
#include <zephyr/sys/libc-hooks.h> /* for z_libc_partition */
2222

23+
#if defined(CONFIG_XTENSA)
24+
#include <zephyr/arch/xtensa/cache.h>
25+
#include <zephyr/arch/xtensa/xtensa_mmu.h>
26+
#endif
27+
2328
#if defined(CONFIG_ARC)
2429
#include <zephyr/arch/arc/v2/mpu/arc_core_mpu.h>
2530
#endif
@@ -178,6 +183,12 @@ ZTEST_USER(userspace, test_write_control)
178183
set_fault(K_ERR_CPU_EXCEPTION);
179184

180185
__asm__ volatile("csrr %0, mstatus" : "=r" (status));
186+
#elif defined(CONFIG_XTENSA)
187+
unsigned int ps;
188+
189+
set_fault(K_ERR_CPU_EXCEPTION);
190+
191+
__asm__ volatile("rsr.ps %0" : "=r" (ps));
181192
#else
182193
#error "Not implemented for this architecture"
183194
zassert_unreachable("Write to control register did not fault");
@@ -245,6 +256,24 @@ ZTEST_USER(userspace, test_disable_mmu_mpu)
245256
*/
246257
csr_write(pmpaddr3, LLONG_MAX);
247258
csr_write(pmpcfg0, (PMP_R|PMP_W|PMP_X|PMP_NAPOT) << 24);
259+
#elif defined(CONFIG_XTENSA)
260+
set_fault(K_ERR_CPU_EXCEPTION);
261+
262+
/* Reset way 6 to do identity mapping.
263+
* Complier would complain addr going out of range if we
264+
* simply do addr = i * 0x20000000 inside the loop. So
265+
* we do increment instead.
266+
*/
267+
uint32_t addr = 0U;
268+
269+
for (int i = 0; i < 8; i++) {
270+
uint32_t attr = addr | Z_XTENSA_MMU_XW;
271+
272+
__asm__ volatile("wdtlb %0, %1; witlb %0, %1"
273+
:: "r"(attr), "r"(addr));
274+
275+
addr += 0x20000000;
276+
}
248277
#else
249278
#error "Not implemented for this architecture"
250279
#endif
@@ -381,7 +410,8 @@ ZTEST_USER(userspace, test_read_priv_stack)
381410

382411
s[0] = 0;
383412
priv_stack_ptr = (char *)&s[0] - size;
384-
#elif defined(CONFIG_ARM) || defined(CONFIG_X86) || defined(CONFIG_RISCV) || defined(CONFIG_ARM64)
413+
#elif defined(CONFIG_ARM) || defined(CONFIG_X86) || defined(CONFIG_RISCV) || \
414+
defined(CONFIG_ARM64) || defined(CONFIG_XTENSA)
385415
/* priv_stack_ptr set by test_main() */
386416
#else
387417
#error "Not implemented for this architecture"
@@ -405,7 +435,8 @@ ZTEST_USER(userspace, test_write_priv_stack)
405435

406436
s[0] = 0;
407437
priv_stack_ptr = (char *)&s[0] - size;
408-
#elif defined(CONFIG_ARM) || defined(CONFIG_X86) || defined(CONFIG_RISCV) || defined(CONFIG_ARM64)
438+
#elif defined(CONFIG_ARM) || defined(CONFIG_X86) || defined(CONFIG_RISCV) || \
439+
defined(CONFIG_ARM64) || defined(CONFIG_XTENSA)
409440
/* priv_stack_ptr set by test_main() */
410441
#else
411442
#error "Not implemented for this architecture"

0 commit comments

Comments
 (0)