master
s 55 lines 834 Bytes
Raw
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2
3 .option norvc
4
5 .text
6 .global _start
7 _start:
8 lla t0, trap
9 csrw mtvec, t0
10
11 /*
12 * The first CSR read retires after obtaining s0. The ecall does not
13 * retire, so the trap handler must observe a difference of one.
14 */
15 csrr s0, minstret
16 ecall
17 sub t0, s1, s0
18 li t1, 1
19 bne t0, t1, fail
20
21 li a0, 0
22 j _exit
23
24 trap:
25 csrr s1, minstret
26 csrr t0, mcause
27 li t1, 11 /* Environment call from M-mode */
28 bne t0, t1, fail
29
30 csrr t0, mepc
31 addi t0, t0, 4
32 csrw mepc, t0
33 mret
34
35 fail:
36 li a0, 1
37
38 _exit:
39 lla a1, semiargs
40 li t0, 0x20026 /* ADP_Stopped_ApplicationExit */
41 sd t0, 0(a1)
42 sd a0, 8(a1)
43 li a0, 0x20 /* TARGET_SYS_EXIT_EXTENDED */
44
45 /* Semihosting call sequence */
46 .balign 16
47 slli zero, zero, 0x1f
48 ebreak
49 srai zero, zero, 0x7
50 j .
51
52 .data
53 .balign 16
54 semiargs:
55 .space 16