initial commit
[riscv-tests.git] / env / v / riscv_test.h
1 #ifndef _ENV_VIRTUAL_SINGLE_CORE_H
2 #define _ENV_VIRTUAL_SINGLE_CORE_H
3
4 //-----------------------------------------------------------------------
5 // Begin Macro
6 //-----------------------------------------------------------------------
7
8 #define RVTEST_RV64U \
9
10 #define RVTEST_RV64S \
11
12 #define RVTEST_FP_ENABLE \
13 mfpcr t0, cr0; \
14 or t0, t0, 2; \
15 mtpcr t0, cr0; \
16 mtfsr x0; \
17
18 #define RVTEST_VEC_ENABLE \
19 mfpcr t0, cr0; \
20 ori t0, t0, 4; \
21 mtpcr t0, cr0; \
22 li t0, 0xff; \
23 mtpcr t0, cr11; \
24
25 #define RVTEST_CODE_BEGIN \
26 .text; \
27 .align 13; \
28 .global userstart; \
29 userstart: \
30
31 //-----------------------------------------------------------------------
32 // End Macro
33 //-----------------------------------------------------------------------
34
35 #define RVTEST_CODE_END \
36
37 //-----------------------------------------------------------------------
38 // Pass/Fail Macro
39 //-----------------------------------------------------------------------
40
41 #define RVTEST_PASS li a0, 1; syscall;
42 #define RVTEST_FAIL sll a0, x28, 1; 1:beqz a0, 1b; or a0, a0, 1; syscall;
43
44 #define RVTEST_PASS_NOFP li a0, 1234; syscall;
45
46 //-----------------------------------------------------------------------
47 // Data Section Macro
48 //-----------------------------------------------------------------------
49
50 #define RVTEST_DATA_BEGIN
51 #define RVTEST_DATA_END
52
53 //#define RVTEST_DATA_BEGIN .align 4; .global begin_signature; begin_signature:
54 //#define RVTEST_DATA_END .align 4; .global end_signature; end_signature:
55
56 //-----------------------------------------------------------------------
57 // Supervisor mode definitions and macros
58 //-----------------------------------------------------------------------
59
60 #include "pcr.h"
61
62 #define vvcfg(nxregs, nfregs) ({ \
63 asm volatile ("vvcfg %0,%1" : : "r"(nxregs), "r"(nfregs)); })
64
65 #define vsetvl(vl) ({ long __tmp; \
66 asm volatile ("vsetvl %0,%1" : "=r"(__tmp) : "r"(vl)); })
67
68 #define vcfg(word) ({ vvcfg((word)>>12, (word)>>18); vsetvl((word)); })
69
70 #define dword_bit_cmd(dw) ((dw >> 32) & 0x1)
71 #define dword_bit_cnt(dw) (!dword_bit_cmd(dw))
72 #define dword_bit_imm1(dw) ((dw >> 35) & 0x1)
73 #define dword_bit_imm2(dw) ((dw >> 34) & 0x1)
74 #define dword_bit_pf(dw) ((dw >> 36) & 0x1)
75
76 #define fencevl() ({ \
77 asm volatile ("fence.v.l" ::: "memory"); })
78
79 #define vxcptkill() ({ \
80 asm volatile ("vxcptkill"); })
81
82 #define vxcpthold() ({ \
83 asm volatile ("vxcpthold"); })
84
85 #define venqcmd(bits, pf) ({ \
86 asm volatile ("venqcmd %0,%1" : : "r"(bits), "r"(pf)); })
87
88 #define venqimm1(bits, pf) ({ \
89 asm volatile ("venqimm1 %0,%1" : : "r"(bits), "r"(pf)); })
90
91 #define venqimm2(bits, pf) ({ \
92 asm volatile ("venqimm2 %0,%1" : : "r"(bits), "r"(pf)); })
93
94 #define venqcnt(bits, pf) ({ \
95 asm volatile ("venqcnt %0,%1" :: "r"(bits), "r"(pf)); })
96
97 #define MAX_TEST_PAGES 63 // this must be the period of the LFSR below
98 #define LFSR_NEXT(x) (((((x)^((x)>>1)) & 1) << 5) | ((x) >> 1))
99
100 #define PGSHIFT 13
101 #define PGSIZE (1 << PGSHIFT)
102
103 #define SIZEOF_TRAPFRAME_T 1336
104
105 #ifndef __ASSEMBLER__
106
107
108 typedef unsigned long pte_t;
109 #define LEVELS (sizeof(pte_t) == sizeof(uint64_t) ? 3 : 2)
110 #define PTIDXBITS (PGSHIFT - (sizeof(pte_t) == 8 ? 3 : 2))
111 #define VPN_BITS (PTIDXBITS * LEVELS)
112 #define VA_BITS (VPN_BITS + PGSHIFT)
113 #define PTES_PER_PT (PGSIZE/sizeof(pte_t))
114
115 typedef struct
116 {
117 long gpr[32];
118 long sr;
119 long epc;
120 long badvaddr;
121 long cause;
122 long insn;
123 long vecbank;
124 long veccfg;
125 long evac[128];
126 } trapframe_t;
127 #endif
128
129 #endif