From: gilles grimaud <[email protected]>

Signed-off-by: gilles grimaud <[email protected]>
---
 tests/tcg/arm/Makefile.softmmu-target |   7 +-
 tests/tcg/arm/system/rp2040-timer.S   | 116 ++++++++++++++++++++++++++
 tests/tcg/arm/system/rp2040-timer.ref |   2 +
 3 files changed, 122 insertions(+), 3 deletions(-)
 create mode 100644 tests/tcg/arm/system/rp2040-timer.S
 create mode 100644 tests/tcg/arm/system/rp2040-timer.ref

diff --git a/tests/tcg/arm/Makefile.softmmu-target 
b/tests/tcg/arm/Makefile.softmmu-target
index 28e4c5774a..f3efe619d1 100644
--- a/tests/tcg/arm/Makefile.softmmu-target
+++ b/tests/tcg/arm/Makefile.softmmu-target
@@ -22,7 +22,7 @@ ARM_TESTS+=test-armv6m-undef
 
 RP2040_TESTS=rp2040-boot rp2040-uart rp2040-mpu \
        rp2040-sio-fifo rp2040-sio-divider rp2040-psm-proc1 \
-       rp2040-core1-launch
+       rp2040-core1-launch rp2040-timer
 
 $(RP2040_TESTS): %: %.S rp2040-minimal.ld
        $(CC) -mcpu=cortex-m0plus -mthumb -mfloat-abi=soft \
@@ -35,14 +35,15 @@ run-rp2040-boot: QEMU_OPTS=-M raspi-pico \
 
 run-rp2040-uart run-rp2040-mpu \
 run-rp2040-sio-fifo run-rp2040-sio-divider \
-run-rp2040-psm-proc1 run-rp2040-core1-launch: \
+run-rp2040-psm-proc1 run-rp2040-core1-launch run-rp2040-timer: \
        QEMU_OPTS=-M raspi-pico,strict-uart-pins=off \
        -serial chardev:output \
        -semihosting-config enable=on,target=native -kernel
 
 run-rp2040-uart run-rp2040-mpu \
 run-rp2040-sio-fifo run-rp2040-sio-divider \
-run-rp2040-psm-proc1 run-rp2040-core1-launch: run-rp2040-%: rp2040-%
+run-rp2040-psm-proc1 run-rp2040-core1-launch \
+run-rp2040-timer: run-rp2040-%: rp2040-%
        $(call run-test, $<, \
          $(QEMU) -monitor none -display none \
                  -chardev file$(COMMA)path=$<.out$(COMMA)id=output \
diff --git a/tests/tcg/arm/system/rp2040-timer.S 
b/tests/tcg/arm/system/rp2040-timer.S
new file mode 100644
index 0000000000..249df6433a
--- /dev/null
+++ b/tests/tcg/arm/system/rp2040-timer.S
@@ -0,0 +1,116 @@
+/*
+ * Raspberry Pi Pico timer alarm interrupt test.
+ *
+ * Copyright 2026 Gilles Grimaud
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+.syntax unified
+.cpu cortex-m0plus
+.thumb
+
+#define SRAM_END               0x20042000
+#define TEST_FLAG              0x20000000
+#define UART0_DR               0x40034000
+#define TIMER_BASE             0x40054000
+#define TIMER_ALARM0           0x10
+#define TIMER_RAWL             0x28
+#define TIMER_INTR             0x34
+#define TIMER_INTE             0x38
+#define NVIC_ISER              0xe000e100
+#define SYS_EXIT               0x18
+#define ADP_STOPPED_APPLICATION_EXIT 0x20026
+#define ADP_STOPPED_RUNTIME_ERROR    0x20023
+
+.section .vectors, "a", %progbits
+.global vector_table
+vector_table:
+    .word SRAM_END
+    .word reset_handler + 1
+    .word default_handler + 1
+    .word default_handler + 1
+    .rept 12
+    .word default_handler + 1
+    .endr
+    .word timer_irq + 1
+
+.section .text, "ax", %progbits
+.thumb_func
+.global reset_handler
+reset_handler:
+    ldr r0, =start_message
+    bl puts
+
+    ldr r0, =TEST_FLAG
+    movs r1, 0
+    str r1, [r0]
+
+    ldr r0, =NVIC_ISER
+    movs r1, 1
+    str r1, [r0]
+
+    ldr r4, =TIMER_BASE
+    str r1, [r4, TIMER_INTR]
+    str r1, [r4, TIMER_INTE]
+    ldr r2, [r4, TIMER_RAWL]
+    ldr r3, =1000
+    adds r2, r2, r3
+    str r2, [r4, TIMER_ALARM0]
+
+1:
+    ldr r0, =TEST_FLAG
+    ldr r1, [r0]
+    cmp r1, 0
+    beq 1b
+
+    ldr r0, =ok_message
+    bl puts
+    movs r0, SYS_EXIT
+    ldr r1, =ADP_STOPPED_APPLICATION_EXIT
+    bkpt 0xab
+
+2:
+    b 2b
+
+.thumb_func
+timer_irq:
+    ldr r0, =TIMER_BASE
+    movs r1, 1
+    str r1, [r0, TIMER_INTR]
+    ldr r0, =TEST_FLAG
+    str r1, [r0]
+    bx lr
+
+.thumb_func
+default_handler:
+    ldr r0, =fail_message
+    bl puts
+    movs r0, SYS_EXIT
+    ldr r1, =ADP_STOPPED_RUNTIME_ERROR
+    bkpt 0xab
+
+3:
+    b 3b
+
+.thumb_func
+puts:
+    ldr r2, =UART0_DR
+
+4:
+    ldrb r1, [r0]
+    cmp r1, 0
+    beq 5f
+    str r1, [r2]
+    adds r0, 1
+    b 4b
+
+5:
+    bx lr
+
+.section .rodata, "a", %progbits
+start_message:
+    .asciz "PICO TCG TIMER START\n"
+ok_message:
+    .asciz "PICO TCG TIMER OK\n"
+fail_message:
+    .asciz "PICO TCG TIMER FAIL\n"
diff --git a/tests/tcg/arm/system/rp2040-timer.ref 
b/tests/tcg/arm/system/rp2040-timer.ref
new file mode 100644
index 0000000000..32e6e169b6
--- /dev/null
+++ b/tests/tcg/arm/system/rp2040-timer.ref
@@ -0,0 +1,2 @@
+PICO TCG TIMER START
+PICO TCG TIMER OK
-- 
2.55.0


Reply via email to