OpenCores
URL https://opencores.org/ocsvn/fwrisc/fwrisc/trunk

Subversion Repositories fwrisc

[/] [fwrisc/] [trunk/] [ve/] [fwrisc/] [tests/] [riscv-compliance/] [riscv-test-suite/] [rv32mi/] [rv64si/] [csr.S] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 mballance
# See LICENSE for license details.
2
 
3
#*****************************************************************************
4
# csr.S
5
#-----------------------------------------------------------------------------
6
#
7
# Test CSRRx and CSRRxI instructions.
8
#
9
 
10
#include "riscv_test.h"
11
#include "compliance_test.h"
12
#include "compliance_io.h"
13
#include "aw_test_macros.h"
14
 
15
RVTEST_RV64S
16
RVTEST_CODE_BEGIN
17
 
18
#ifdef __MACHINE_MODE
19
  #define sscratch mscratch
20
  #define sstatus mstatus
21
  #define scause mcause
22
  #define sepc mepc
23
  #define sret mret
24
  #define stvec_handler mtvec_handler
25
  #undef SSTATUS_SPP
26
  #define SSTATUS_SPP MSTATUS_MPP
27
#endif
28
 
29
  # For RV64, make sure UXL encodes RV64.  (UXL does not exist for RV32.)
30
#if __riscv_xlen == 64
31
  # If running in M mode, use mstatus.MPP to check existence of U mode.
32
  # Otherwise, if in S mode, then U mode must exist and we don't need to check.
33
#ifdef __MACHINE_MODE
34
  li t0, MSTATUS_MPP
35
  csrc mstatus, t0
36
  csrr t1, mstatus
37
  and t0, t0, t1
38
  bnez t0, 1f
39
#endif
40
  # If U mode is present, UXL should be 2 (XLEN = 64-bit)
41
  TEST_CASE(13, a0, SSTATUS_UXL & (SSTATUS_UXL << 1), csrr a0, sstatus; li a1, SSTATUS_UXL; and a0, a0, a1)
42
#ifdef __MACHINE_MODE
43
  j 2f
44
1:
45
  # If U mode is not present, UXL should be 0
46
  TEST_CASE(14, a0, 0, csrr a0, sstatus; li a1, SSTATUS_UXL; and a0, a0, a1)
47
2:
48
#endif
49
#endif
50
 
51
  csrwi sscratch, 3
52
  TEST_CASE( 2, a0,         3, csrr a0, sscratch);
53
  TEST_CASE( 3, a1,         3, csrrci a1, sscratch, 1);
54
  TEST_CASE( 4, a2,         2, csrrsi a2, sscratch, 4);
55
  TEST_CASE( 5, a3,         6, csrrwi a3, sscratch, 2);
56
  TEST_CASE( 6, a1,         2, li a0, 0xbad1dea; csrrw a1, sscratch, a0);
57
  TEST_CASE( 7, a0, 0xbad1dea, li a0, 0x0001dea; csrrc a0, sscratch, a0);
58
  TEST_CASE( 8, a0, 0xbad0000, li a0, 0x000beef; csrrs a0, sscratch, a0);
59
  TEST_CASE( 9, a0, 0xbadbeef, csrr a0, sscratch);
60
 
61
#ifdef __MACHINE_MODE
62
  # Is F extension present?
63
  csrr a0, misa
64
  andi a0, a0, (1 << ('F' - 'A'))
65
  beqz a0, 1f
66
  # If so, make sure FP stores have no effect when mstatus.FS is off.
67
  li a1, MSTATUS_FS
68
  csrs mstatus, a1
69
#ifdef __riscv_flen
70
  fmv.s.x f0, x0
71
  csrc mstatus, a1
72
  la a1, fsw_data
73
  TEST_CASE(10, a0, 1, fsw f0, (a1); lw a0, (a1));
74
#else
75
  # Fail if this test is compiled without F but executed on a core with F.
76
  TEST_CASE(10, zero, 1)
77
#endif
78
1:
79
 
80
  # Figure out if 'U' is set in misa
81
  csrr a0, misa   # a0 = csr(misa)
82
  srli a0, a0, 20 # a0 = a0 >> 20
83
  andi a0, a0, 1  # a0 = a0 & 1
84
  beqz a0, finish # if no user mode, skip the rest of these checks
85
#endif /* __MACHINE_MODE */
86
 
87
  # jump to user land
88
  li t0, SSTATUS_SPP
89
  csrc sstatus, t0
90
  la t0, 1f
91
  csrw sepc, t0
92
  sret
93
  1:
94
 
95
  # Make sure writing the cycle counter causes an exception.
96
  # Don't run in supervisor, as we don't delegate illegal instruction traps.
97
#ifdef __MACHINE_MODE
98
  TEST_CASE(11, a0, 255, li a0, 255; csrrw a0, cycle, x0);
99
#endif
100
 
101
  # Make sure reading status in user mode causes an exception.
102
  # Don't run in supervisor, as we don't delegate illegal instruction traps.
103
#ifdef __MACHINE_MODE
104
  TEST_CASE(12, a0, 255, li a0, 255; csrr a0, sstatus)
105
#else
106
  TEST_CASE(12, x0, 0, nop)
107
#endif
108
 
109
finish:
110
  RVTEST_PASS
111
 
112
  # We should only fall through to this if scall failed.
113
  TEST_PASSFAIL
114
 
115
  .align 2
116
  .global stvec_handler
117
stvec_handler:
118
  # Trapping on tests 10-12 is good news.
119
  # Note that since the test didn't complete, TESTNUM is smaller by 1.
120
  li t0, 9
121
  bltu TESTNUM, t0, 1f
122
  li t0, 11
123
  bleu TESTNUM, t0, privileged
124
1:
125
 
126
  # catch RVTEST_PASS and kick it up to M-mode
127
  csrr t0, scause
128
  li t1, CAUSE_USER_ECALL
129
  bne t0, t1, fail
130
  RVTEST_PASS
131
 
132
privileged:
133
  # Make sure scause indicates a lack of privilege.
134
  csrr t0, scause
135
  li t1, CAUSE_ILLEGAL_INSTRUCTION
136
  bne t0, t1, fail
137
  # Return to user mode, but skip the trapping instruction.
138
  csrr t0, sepc
139
  addi t0, t0, 4
140
  csrw sepc, t0
141
  sret
142
 
143
RVTEST_CODE_END
144
 
145
  .data
146
fsw_data: .word 1
147
RV_COMPLIANCE_DATA_BEGIN
148
test_res:
149
    .fill 8, 4, -1
150
RV_COMPLIANCE_DATA_END
151
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.