From: Richard Henderson <richard.henderson@linaro.org>
To: qemu-devel@nongnu.org
Cc: "Alex Bennée" <alex.bennee@linaro.org>
Subject: [PATCH v7 63/64] tests/tcg/nios2: Add semihosting multiarch tests
Date: Thu, 21 Apr 2022 08:17:34 -0700 [thread overview]
Message-ID: <20220421151735.31996-64-richard.henderson@linaro.org> (raw)
In-Reply-To: <20220421151735.31996-1-richard.henderson@linaro.org>
Add runtime supporting the nios2-semi.c interface.
Execute the hello and memory multiarch tests.
Cc: Alex Bennée <alex.bennee@linaro.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
tests/tcg/nios2/semicall.h | 25 +++
tests/tcg/nios2/10m50-ghrd.ld | 59 +++++++
tests/tcg/nios2/Makefile.softmmu-target | 29 ++++
tests/tcg/nios2/boot.S | 218 ++++++++++++++++++++++++
tests/tcg/nios2/intr.S | 31 ++++
5 files changed, 362 insertions(+)
create mode 100644 tests/tcg/nios2/semicall.h
create mode 100644 tests/tcg/nios2/10m50-ghrd.ld
create mode 100644 tests/tcg/nios2/Makefile.softmmu-target
create mode 100644 tests/tcg/nios2/boot.S
create mode 100644 tests/tcg/nios2/intr.S
diff --git a/tests/tcg/nios2/semicall.h b/tests/tcg/nios2/semicall.h
new file mode 100644
index 0000000000..d7acf665e1
--- /dev/null
+++ b/tests/tcg/nios2/semicall.h
@@ -0,0 +1,25 @@
+/*
+ * Nios2 semihosting interface.
+ */
+
+#ifndef SEMICALL_H
+#define SEMICALL_H
+
+#define HOSTED_EXIT 0
+#define HOSTED_INIT_SIM 1
+#define HOSTED_OPEN 2
+#define HOSTED_CLOSE 3
+#define HOSTED_READ 4
+#define HOSTED_WRITE 5
+#define HOSTED_LSEEK 6
+#define HOSTED_RENAME 7
+#define HOSTED_UNLINK 8
+#define HOSTED_STAT 9
+#define HOSTED_FSTAT 10
+#define HOSTED_GETTIMEOFDAY 11
+#define HOSTED_ISATTY 12
+#define HOSTED_SYSTEM 13
+
+#define semihosting_call break 1
+
+#endif /* SEMICALL_H */
diff --git a/tests/tcg/nios2/10m50-ghrd.ld b/tests/tcg/nios2/10m50-ghrd.ld
new file mode 100644
index 0000000000..d83e136267
--- /dev/null
+++ b/tests/tcg/nios2/10m50-ghrd.ld
@@ -0,0 +1,59 @@
+MEMORY
+{
+ tpf (rx) : ORIGIN = 0xc0000000, LENGTH = 1K
+ ram (rwx) : ORIGIN = 0xc8000000, LENGTH = 128M
+}
+
+PHDRS
+{
+ RAM PT_LOAD;
+}
+
+ENTRY(_start)
+EXTERN(_start)
+EXTERN(_interrupt)
+EXTERN(_fast_tlb_miss)
+
+SECTIONS
+{
+ /* Begin at the (hardcoded) _interrupt entry point. */
+ .text 0xc8000120 : {
+ *(.text.intr)
+ *(.text .text.* .gnu.linkonce.t.*)
+ } >ram :RAM
+
+ .rodata : ALIGN(4) {
+ *(.rodata .rodata.* .gnu.linkonce.r.*)
+ } > ram :RAM
+
+ .eh_frame_hdr : ALIGN (4) {
+ KEEP (*(.eh_frame_hdr))
+ *(.eh_frame_entry .eh_frame_entry.*)
+ } >ram :RAM
+ .eh_frame : ALIGN (4) {
+ KEEP (*(.eh_frame)) *(.eh_frame.*)
+ } >ram :RAM
+
+ .data : ALIGN(4) {
+ *(.shdata)
+ *(.data .data.* .gnu.linkonce.d.*)
+ . = ALIGN(4);
+ _gp = ABSOLUTE(. + 0x8000);
+ *(.got.plt) *(.got)
+ *(.lit8)
+ *(.lit4)
+ *(.sdata .sdata.* .gnu.linkonce.s.*)
+ } >ram :RAM
+
+ .bss : ALIGN(4) {
+ __bss_start = ABSOLUTE(.);
+ *(.sbss .sbss.* .gnu.linkonce.sb.*)
+ *(.scommon)
+ *(.bss .bss.* .gnu.linkonce.b.*)
+ *(COMMON)
+ . = ALIGN(4);
+ __bss_end = ABSOLUTE(.);
+ } >ram :RAM
+
+ __stack = ORIGIN(ram) + LENGTH(ram);
+}
diff --git a/tests/tcg/nios2/Makefile.softmmu-target b/tests/tcg/nios2/Makefile.softmmu-target
new file mode 100644
index 0000000000..70664db81c
--- /dev/null
+++ b/tests/tcg/nios2/Makefile.softmmu-target
@@ -0,0 +1,29 @@
+#
+# Nios2 system tests
+#
+
+NIOS2_SYSTEM_SRC = $(SRC_PATH)/tests/tcg/nios2
+VPATH += $(NIOS2_SYSTEM_SRC)
+
+# These objects provide the basic boot code and helper functions for all tests
+CRT_OBJS = boot.o intr.o $(MINILIB_OBJS)
+LINK_SCRIPT = $(NIOS2_SYSTEM_SRC)/10m50-ghrd.ld
+
+CFLAGS += -nostdlib -g -O0 $(MINILIB_INC)
+LDFLAGS += -Wl,-T$(LINK_SCRIPT) -static -nostdlib $(CRT_OBJS) -lgcc
+
+%.o: %.S
+ $(call quiet-command, $(CC) $(CFLAGS) $(EXTRA_CFLAGS) -x assembler-with-cpp -c $< -o $@, AS, $@)
+
+%.o: %.c
+ $(call quiet-command, $(CC) $(CFLAGS) $(EXTRA_CFLAGS) -c $< -o $@, CC, $@)
+
+# Build and link the tests
+%: %.o $(LINK_SCRIPT) $(CRT_OBJS)
+ $(call quiet-command, $(CC) $(CFLAGS) $(EXTRA_CFLAGS) $< -o $@ $(LDFLAGS), LD, $@)
+
+# FIXME: nios2 semihosting writes to stdout, not a chardev
+QEMU_OPTS = -M 10m50-ghrd,vic=on -semihosting >$@.out -kernel
+
+memory: CFLAGS+=-DCHECK_UNALIGNED=0
+TESTS += $(MULTIARCH_TESTS)
diff --git a/tests/tcg/nios2/boot.S b/tests/tcg/nios2/boot.S
new file mode 100644
index 0000000000..f6771cbc81
--- /dev/null
+++ b/tests/tcg/nios2/boot.S
@@ -0,0 +1,218 @@
+/*
+ * Minimal Nios2 system boot code.
+ *
+ * Copyright Linaro Ltd 2022
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "semicall.h"
+
+ .text
+ .set noat
+
+_start:
+ /* Linker script defines stack at end of ram. */
+ movia sp, __stack
+
+ /* Install trampoline to _fast_tlb_miss at hardcoded vector. */
+ movia r4, 0xc0000100
+ movia r5, _ftm_tramp
+ movi r6, .L__ftm_end - _ftm_tramp
+ call memcpy
+
+ /* Zero the bss to satisfy C. */
+ movia r4, __bss_start
+ movia r6, __bss_end
+ sub r6, r6, r4
+ movi r5, 0
+ call memset
+
+ /* Test! */
+ call main
+
+ /* Exit with main's return value. */
+ movi r4, HOSTED_EXIT
+ mov r5, r2
+ semihosting_call
+
+ .globl _start
+ .type _start, @function
+ .size _start, . - _start
+
+_ftm_tramp:
+ movia et, _fast_tlb_miss
+ jmp et
+.L__ftm_end:
+
+ .type _ftm_tramp, @function
+ .size _ftm_tramp, . - _ftm_tramp
+
+#define dst r4
+#define src r5
+#define len r6
+
+memcpy:
+ /* Store return value right away, per API */
+ mov r2, dst
+
+ /* Check for both dst and src aligned. */
+ or at, dst, src
+ andi at, at, 3
+ bne at, zero, .L_mc_test1
+
+ /* Copy blocks of 8. */
+
+ movi at, 8
+ bltu len, at, .L_mc_test4
+
+.L_mc_loop8:
+ ldw r8, 0(src)
+ ldw r9, 4(src)
+ addi src, src, 8
+ addi dst, dst, 8
+ subi len, len, 8
+ stw r8, -8(dst)
+ stw r9, -4(dst)
+ bgeu len, at, .L_mc_loop8
+
+ /* Copy final aligned block of 4. */
+
+.L_mc_test4:
+ movi at, 4
+ bltu len, at, .L_mc_test1
+
+ ldw r8, 0(src)
+ addi src, src, 4
+ addi dst, dst, 4
+ subi len, len, 4
+ stw r8, -4(dst)
+
+ /* Copy single bytes to finish. */
+
+.L_mc_test1:
+ beq len, zero, .L_mc_done
+
+.L_mc_loop1:
+ ldb r8, 0(src)
+ addi src, src, 1
+ addi dst, dst, 1
+ subi len, len, 1
+ stb r8, -1(dst)
+ bne len, zero, .L_mc_loop1
+
+.L_mc_done:
+ ret
+
+#undef dst
+#undef src
+#undef len
+
+ .global memcpy
+ .type memcpy, @function
+ .size memcpy, . - memcpy
+
+#define dst r4
+#define val r5
+#define len r6
+
+memset:
+ /* Store return value right away, per API */
+ mov r2, dst
+
+ /* Check for small blocks; fall back to bytewise. */
+ movi r3, 8
+ bltu len, r3, .L_ms_test1
+
+ /* Replicate the byte across the word. */
+ andi val, val, 0xff
+ slli at, val, 8
+ or val, val, at
+ slli at, val, 16
+ or val, val, at
+
+ /* Check for destination alignment; realign if needed. */
+ andi at, dst, 3
+ bne at, zero, .L_ms_align
+
+ /* Set blocks of 8. */
+
+.L_ms_loop8:
+ stw val, 0(dst)
+ stw val, 4(dst)
+ addi dst, dst, 8
+ subi len, len, 8
+ bgeu len, r3, .L_ms_loop8
+
+ /* Set final aligned block of 4. */
+
+.L_ms_test4:
+ movi at, 4
+ bltu len, at, .L_ms_test1
+
+ stw r8, 0(dst)
+ addi dst, dst, 4
+ subi len, len, 4
+ stw r8, -4(dst)
+
+ /* Set single bytes to finish. */
+
+.L_ms_test1:
+ beq len, zero, .L_ms_done
+
+.L_ms_loop1:
+ stb r8, 0(dst)
+ addi dst, dst, 1
+ subi len, len, 1
+ bne len, zero, .L_ms_loop1
+
+.L_ms_done:
+ ret
+
+ /* Realign for a large block, len >= 8. */
+.L_ms_align:
+ andi at, dst, 1
+ beq at, zero, 2f
+
+ stb val, 0(dst)
+ addi dst, dst, 1
+ subi len, len, 1
+
+2: andi at, dst, 2
+ beq at, zero, 4f
+
+ sth val, 0(dst)
+ addi dst, dst, 2
+ subi len, len, 2
+
+4: bgeu len, r3, .L_ms_loop8
+ br .L_ms_test4
+
+#undef dst
+#undef val
+#undef len
+
+ .global memset
+ .type memset, @function
+ .size memset, . - memset
+
+/*
+ * void __sys_outc(char c);
+ */
+__sys_outc:
+ subi sp, sp, 16
+ stb r4, 0(sp) /* buffer[0] = c */
+ movi at, 1
+ stw at, 4(sp) /* STDOUT_FILENO */
+ stw sp, 8(sp) /* buffer */
+ stw at, 12(sp) /* len */
+
+ movi r4, HOSTED_WRITE
+ addi r5, sp, 4
+ semihosting_call
+
+ addi sp, sp, 16
+ ret
+
+ .global __sys_outc
+ .type __sys_outc, @function
+ .size __sys_outc, . - __sys_outc
diff --git a/tests/tcg/nios2/intr.S b/tests/tcg/nios2/intr.S
new file mode 100644
index 0000000000..c1730692ba
--- /dev/null
+++ b/tests/tcg/nios2/intr.S
@@ -0,0 +1,31 @@
+/*
+ * Minimal Nios2 system boot code -- exit on interrupt.
+ *
+ * Copyright Linaro Ltd 2022
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "semicall.h"
+
+ .section .text.intr, "ax"
+ .global _interrupt
+ .type _interrupt, @function
+
+_interrupt:
+ rdctl r5, exception /* extract exception.CAUSE */
+ srli r5, r5, 2
+ movi r4, HOSTED_EXIT
+ semihosting_call
+
+ .size _interrupt, . - _interrupt
+
+ .text
+ .global _fast_tlb_miss
+ .type _fast_tlb_miss, @function
+
+_fast_tlb_miss:
+ movi r5, 32
+ movi r4, HOSTED_EXIT
+ semihosting_call
+
+ .size _fast_tlb_miss, . - _fast_tlb_miss
--
2.34.1
next prev parent reply other threads:[~2022-04-21 16:15 UTC|newest]
Thread overview: 78+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-21 15:16 [PATCH v7 00/64] nios2 fixes, cleanups, shadow reg sets Richard Henderson
2022-04-21 15:16 ` [PATCH v7 01/64] linux-user/nios2: Hoist pc advance to the top of EXCP_TRAP Richard Henderson
2022-04-21 15:16 ` [PATCH v7 02/64] linux-user/nios2: Fix clone child return Richard Henderson
2022-04-21 15:16 ` [PATCH v7 03/64] linux-user/nios2: Drop syscall 0 "workaround" Richard Henderson
2022-04-21 15:16 ` [PATCH v7 04/64] linux-user/nios2: Adjust error return Richard Henderson
2022-04-21 15:16 ` [PATCH v7 05/64] linux-user/nios2: Handle special qemu syscall return values Richard Henderson
2022-04-21 15:16 ` [PATCH v7 06/64] linux-user/nios2: Remove do_sigreturn Richard Henderson
2022-04-21 15:16 ` [PATCH v7 07/64] linux-user/nios2: Use QEMU_ESIGRETURN from do_rt_sigreturn Richard Henderson
2022-04-21 15:16 ` [PATCH v7 08/64] tests/tcg/nios2: Re-enable linux-user tests Richard Henderson
2022-04-21 15:16 ` [PATCH v7 09/64] target/nios2: Remove user-only nios2_cpu_do_interrupt Richard Henderson
2022-04-22 12:51 ` Peter Maydell
2022-04-21 15:16 ` [PATCH v7 10/64] target/nios2: Remove nios2_cpu_record_sigsegv Richard Henderson
2022-04-22 12:53 ` Peter Maydell
2022-04-21 15:16 ` [PATCH v7 11/64] target/nios2: Build helper.c for system only Richard Henderson
2022-04-22 12:54 ` Peter Maydell
2022-04-21 15:16 ` [PATCH v7 12/64] linux-user/nios2: Use force_sig_fault for EXCP_DEBUG Richard Henderson
2022-04-22 12:54 ` Peter Maydell
2022-04-21 15:16 ` [PATCH v7 13/64] target/nios2: Check supervisor on eret Richard Henderson
2022-04-21 15:16 ` [PATCH v7 14/64] target/nios2: Stop generating code if gen_check_supervisor fails Richard Henderson
2022-04-21 15:16 ` [PATCH v7 15/64] target/nios2: Add NUM_GP_REGS and NUM_CP_REGS Richard Henderson
2022-04-21 15:16 ` [PATCH v7 16/64] target/nios2: Split PC out of env->regs[] Richard Henderson
2022-04-21 15:16 ` [PATCH v7 17/64] target/nios2: Split out helper for eret instruction Richard Henderson
2022-04-21 15:16 ` [PATCH v7 18/64] target/nios2: Fix BRET instruction Richard Henderson
2022-04-21 15:16 ` [PATCH v7 19/64] target/nios2: Do not create TCGv for control registers Richard Henderson
2022-04-21 15:16 ` [PATCH v7 20/64] linux-user/nios2: Only initialize SP and PC in target_cpu_copy_regs Richard Henderson
2022-04-21 15:16 ` [PATCH v7 21/64] target/nios2: Remove cpu_interrupts_enabled Richard Henderson
2022-04-21 15:16 ` [PATCH v7 22/64] target/nios2: Split control registers away from general registers Richard Henderson
2022-04-21 15:16 ` [PATCH v7 23/64] target/nios2: Clean up nios2_cpu_dump_state Richard Henderson
2022-04-21 15:16 ` [PATCH v7 24/64] target/nios2: Use hw/registerfields.h for CR_STATUS fields Richard Henderson
2022-04-21 15:16 ` [PATCH v7 25/64] target/nios2: Use hw/registerfields.h for CR_EXCEPTION fields Richard Henderson
2022-04-21 15:16 ` [PATCH v7 26/64] target/nios2: Use hw/registerfields.h for CR_TLBADDR fields Richard Henderson
2022-04-21 15:16 ` [PATCH v7 27/64] target/nios2: Use hw/registerfields.h for CR_TLBACC fields Richard Henderson
2022-04-21 15:16 ` [PATCH v7 28/64] target/nios2: Rename CR_TLBMISC_WR to CR_TLBMISC_WE Richard Henderson
2022-04-21 15:17 ` [PATCH v7 29/64] target/nios2: Use hw/registerfields.h for CR_TLBMISC fields Richard Henderson
2022-04-21 15:17 ` [PATCH v7 30/64] target/nios2: Move R_FOO and CR_BAR into enumerations Richard Henderson
2022-04-21 15:17 ` [PATCH v7 31/64] target/nios2: Create EXCP_SEMIHOST for semi-hosting Richard Henderson
2022-04-21 15:17 ` [PATCH v7 32/64] target/nios2: Clean up nios2_cpu_do_interrupt Richard Henderson
2022-04-21 15:17 ` [PATCH v7 33/64] target/nios2: Hoist CPU_LOG_INT logging Richard Henderson
2022-04-21 15:17 ` [PATCH v7 34/64] target/nios2: Handle EXCP_UNALIGN and EXCP_UALIGND Richard Henderson
2022-04-22 12:56 ` Peter Maydell
2022-04-21 15:17 ` [PATCH v7 35/64] target/nios2: Cleanup set of CR_EXCEPTION for do_interrupt Richard Henderson
2022-04-21 15:17 ` [PATCH v7 36/64] target/nios2: Clean up handling of tlbmisc in do_exception Richard Henderson
2022-04-21 15:17 ` [PATCH v7 37/64] target/nios2: Prevent writes to read-only or reserved control fields Richard Henderson
2022-04-22 12:56 ` Peter Maydell
2022-04-21 15:17 ` [PATCH v7 38/64] target/nios2: Implement cpuid Richard Henderson
2022-04-21 15:17 ` [PATCH v7 39/64] target/nios2: Implement CR_STATUS.RSIE Richard Henderson
2022-04-21 15:17 ` [PATCH v7 40/64] target/nios2: Remove CPU_INTERRUPT_NMI Richard Henderson
2022-04-21 15:17 ` [PATCH v7 41/64] target/nios2: Support division error exception Richard Henderson
2022-04-21 15:17 ` [PATCH v7 42/64] target/nios2: Use tcg_constant_tl Richard Henderson
2022-04-21 15:17 ` [PATCH v7 43/64] target/nios2: Split out named structs for [IRJ]_TYPE Richard Henderson
2022-04-22 12:57 ` Peter Maydell
2022-04-21 15:17 ` [PATCH v7 44/64] target/nios2: Split out helpers for gen_* translate macros Richard Henderson
2022-04-22 13:16 ` Peter Maydell
2022-04-21 15:17 ` [PATCH v7 45/64] target/nios2: Introduce dest_gpr Richard Henderson
2022-04-21 15:17 ` [PATCH v7 46/64] target/nios2: Drop CR_STATUS_EH from tb->flags Richard Henderson
2022-04-21 15:17 ` [PATCH v7 47/64] target/nios2: Enable unaligned traps for system mode Richard Henderson
2022-04-21 15:17 ` [PATCH v7 48/64] target/nios2: Create gen_jumpr Richard Henderson
2022-04-21 15:17 ` [PATCH v7 49/64] target/nios2: Hoist set of is_jmp into gen_goto_tb Richard Henderson
2022-04-21 15:17 ` [PATCH v7 50/64] target/nios2: Use gen_goto_tb for DISAS_TOO_MANY Richard Henderson
2022-04-21 15:17 ` [PATCH v7 51/64] target/nios2: Use tcg_gen_lookup_and_goto_ptr Richard Henderson
2022-04-21 15:17 ` [PATCH v7 52/64] target/nios2: Implement Misaligned destination exception Richard Henderson
2022-04-21 15:17 ` [PATCH v7 53/64] target/nios2: Introduce shadow register sets Richard Henderson
2022-04-22 13:21 ` Peter Maydell
2022-04-21 15:17 ` [PATCH v7 54/64] target/nios2: Implement rdprs, wrprs Richard Henderson
2022-04-21 15:17 ` [PATCH v7 55/64] target/nios2: Update helper_eret for shadow registers Richard Henderson
2022-04-21 15:17 ` [PATCH v7 56/64] target/nios2: Implement EIC interrupt processing Richard Henderson
2022-04-22 13:24 ` Peter Maydell
2022-04-21 15:17 ` [PATCH v7 57/64] target/nios2: Advance pc when raising exceptions Richard Henderson
2022-04-22 13:00 ` Peter Maydell
2022-04-21 15:17 ` [PATCH v7 58/64] linux-user/nios2: Handle various SIGILL exceptions Richard Henderson
2022-04-21 15:17 ` [PATCH v7 59/64] hw/intc: Vectored Interrupt Controller (VIC) Richard Henderson
2022-04-21 15:17 ` [PATCH v7 60/64] hw/nios2: Introduce Nios2MachineState Richard Henderson
2022-04-21 15:17 ` [PATCH v7 61/64] hw/nios2: Move memory regions into Nios2Machine Richard Henderson
2022-04-21 15:17 ` [PATCH v7 62/64] hw/nios2: Machine with a Vectored Interrupt Controller Richard Henderson
2022-04-21 15:17 ` Richard Henderson [this message]
2022-04-22 13:26 ` [PATCH v7 63/64] tests/tcg/nios2: Add semihosting multiarch tests Peter Maydell
2022-04-21 15:17 ` [PATCH v7 64/64] tests/tcg/nios2: Add test-shadow-1 Richard Henderson
2022-04-22 13:26 ` Peter Maydell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220421151735.31996-64-richard.henderson@linaro.org \
--to=richard.henderson@linaro.org \
--cc=alex.bennee@linaro.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.