Skip to content

Commit

Permalink
CVXIF:Add directed test in supervisor and user mode
Browse files Browse the repository at this point in the history
  • Loading branch information
AyoubJalali committed Aug 10, 2023
1 parent 1ddf160 commit 8148bbb
Show file tree
Hide file tree
Showing 4 changed files with 170 additions and 14 deletions.
12 changes: 5 additions & 7 deletions cva6/tests/custom/cv_xif/cvxif_macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,10 @@

#define LOAD_RS(rs,value) li rs, value
#define COMP_RS(rs1,rs2,rd) xor rd, rs1, rs2
#define CUS_ADD(rs1,rs2,rs3,rd) .word 0b##0000000##rs2####rs1##001##rd##1111011
#define CUS_NOP(rs1,rs2,rs3,rd) .word 0b##0000000##00000####00000##000##00000##1111011
#define CUS_NOP_EXC(rs1,rs2,rs3,rd) .word 0b##0100000##00000####00000##000##00000##1111011
#define CUS_ISS_EXC(rs1,rs2,rs3,rd) .word 0b##1100000##00000####00000##010##00000##1111011
#define CUS_ADD(rs1,rs2,rd) .word 0b##0000000##rs2####rs1##001##rd##1111011
#define CUS_NOP(rs1,rs2,rd) .word 0b##0000000##00000####00000##000##00000##1111011
#define CUS_ADD_RS3(rs1,rs2,rs3,rd) .word 0b##rs3##01##rs2####rs1##000##rd##1111011
#define CUS_ADD_MULTI(rs1,rs2,rs3,rd) .word 0b##0001000##rs2####rs1##000##rd##1111011
#define CUS_ADD_MULTI(rs1,rs2,rd) .word 0b##0001000##rs2####rs1##000##rd##1111011
#define CUS_EXC(rs1,rs2,rs3,rd) .word 0b####1100000##rs2####rs1##010##rd##1111011
#define CUS_M_ADD(rs1,rs2,rs3,rd) .word 0b####0000010##rs2####rs1##011##rd##1111011
#define CUS_S_ADD(rs1,rs2,rs3,rd) .word 0b####0000110##rs2####rs1##001##rd##1111011
#define CUS_U_ADD(rs1,rs2,rd) .word 0b####0000010##rs2####rs1##000##rd##1111011
#define CUS_S_ADD(rs1,rs2,rd) .word 0b####0000110##rs2####rs1##000##rd##1111011
73 changes: 73 additions & 0 deletions cva6/tests/custom/cv_xif/cvxif_s_mode.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# Copyright 2023 Thales DIS
#
# Licensed under the Solderpad Hardware Licence, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# SPDX-License-Identifier: Apache-2.0 WITH SHL-2.0
# You may obtain a copy of the License at https://solderpad.org/licenses/
#
# Original Author: Ayoub JALALI ([email protected])

#include "cvxif_macros.h"

#*****************************************************************************
# cvxif_s_mode.S
#-----------------------------------------------------------------------------
#

.globl main
main:
## set start address range t0 x7
la x7, supervisor_code
li x28, 0x10000
add x7, x7, x28
# Enable R,W,X,TOR IN PMPCFG CSR t0 x8
li x8, 0x0F
#set PMPADDR0 CSR with x7
csrw 0x3B0, x7
# set PMPCFG0 CSR with x8
csrw 0x3A0, x8

# Set the MPP field to supervisor mode (1)
li x29, 0b01
slli x29, x29, 11
or x28, x28, x29

# Write the modified MSTATUS value back to the CSR
csrw 0x300, x28

# Load address of supervisor code
la x28, supervisor_code
#set MEPC register to address of supervisor code
csrw 0x341, x28

csrr x31, 0x300
mret
supervisor_code:

CUS_S_ADD(01010,01010,01011);
CUS_S_ADD(01010,11111,11010);
CUS_ADD_MULTI(01010,01010,01011);
CUS_ADD(11010,11001,11011);
CUS_ADD(01010,01010,01011);
CUS_S_ADD(10000,00010,00000);
CUS_S_ADD(11111,11110,11111);
CUS_S_ADD(00000,01010,01011);
CUS_S_ADD(01010,01010,01011);
CUS_ADD_MULTI(01010,00000,01011);
CUS_S_ADD(11111,11111,01011);

# (example of) final self-check test
li a0, 0xCAFE;
li a1, 0xCAFE;
xor a2, a0, a1;
beqz a2, pass;

fail:
# Failure post-processing (messages, ecall setup etc.)
li a0, 0x0;
jal exit;

pass:
# Success post-processing (messages, ecall setup etc.)
li a0, 0x0;
jal exit;
73 changes: 73 additions & 0 deletions cva6/tests/custom/cv_xif/cvxif_u_mode.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# Copyright 2023 Thales DIS
#
# Licensed under the Solderpad Hardware Licence, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# SPDX-License-Identifier: Apache-2.0 WITH SHL-2.0
# You may obtain a copy of the License at https://solderpad.org/licenses/
#
# Original Author: Ayoub JALALI ([email protected])

#include "cvxif_macros.h"

#*****************************************************************************
# cvxif_s_mode.S
#-----------------------------------------------------------------------------
#

.globl main
main:
## set start address range t0 x7
la x7, user_code
li x28, 0x10000
add x7, x7, x28
# Enable R,W,X,TOR IN PMPCFG CSR t0 x8
li x8, 0x0F
#set PMPADDR0 CSR with x7
csrw 0x3B0, x7
# set PMPCFG0 CSR with x8
csrw 0x3A0, x8

# Set the MPP field to user mode (0)
li x29, 0b00
slli x29, x29, 11
or x28, x28, x29

# Write the modified MSTATUS value back to the CSR
csrw 0x300, x28

# Load address of user code
la x28, user_code
#set MEPC register to address of user code
csrw 0x341, x28

csrr x31, 0x300
mret
user_code:

CUS_U_ADD(01010,01010,01011);
CUS_U_ADD(01010,11111,11010);
CUS_ADD_MULTI(01010,01010,01011);
CUS_ADD(11010,11001,11011);
CUS_ADD(01010,01010,01011);
CUS_U_ADD(10000,00010,00000);
CUS_U_ADD(11111,11110,11111);
CUS_U_ADD(00000,01010,01011);
CUS_U_ADD(01010,01010,01011);
CUS_ADD_MULTI(01010,00000,01011);
CUS_U_ADD(11111,11111,01011);

# (example of) final self-check test
li a0, 0xCAFE;
li a1, 0xCAFE;
xor a2, a0, a1;
beqz a2, pass;

fail:
# Failure post-processing (messages, ecall setup etc.)
li a0, 0x0;
jal exit;

pass:
# Success post-processing (messages, ecall setup etc.)
li a0, 0x0;
jal exit;
26 changes: 19 additions & 7 deletions cva6/tests/testlist_cvxif.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,43 +26,55 @@
# --------------------------------------------------------------------------------

- test: cvxif_add_nop
iterations: 1
iterations: 0
path_var: TESTS_PATH
gcc_opts: "-static -mcmodel=medany -fvisibility=hidden -nostdlib -nostartfiles ../tests/custom/common/syscalls.c ../tests/custom/common/crt.S -I../tests/custom/env -I../tests/custom/common -T ../tests/custom/common/test.ld"
asm_tests: <path_var>/custom/cv_xif/cvxif_add_nop.S

- test: cvxif_multi
iterations: 1
iterations: 0
path_var: TESTS_PATH
gcc_opts: "-static -mcmodel=medany -fvisibility=hidden -nostdlib -nostartfiles ../tests/custom/common/syscalls.c ../tests/custom/common/crt.S -I../tests/custom/env -I../tests/custom/common -T ../tests/custom/common/test.ld"
asm_tests: <path_var>/custom/cv_xif/cvxif_multi.S

- test: cvxif_rs3
iterations: 1
iterations: 0
path_var: TESTS_PATH
gcc_opts: "-static -mcmodel=medany -fvisibility=hidden -nostdlib -nostartfiles ../tests/custom/common/syscalls.c ../tests/custom/common/crt.S -I../tests/custom/env -I../tests/custom/common -T ../tests/custom/common/test.ld"
asm_tests: <path_var>/custom/cv_xif/cvxif_rs3.S

- test: cvxif_exc
iterations: 1
iterations: 0
path_var: TESTS_PATH
gcc_opts: "-static -mcmodel=medany -fvisibility=hidden -nostdlib -nostartfiles ../tests/custom/common/syscalls.c ../tests/custom/common/crt.S -I../tests/custom/env -I../tests/custom/common -T ../tests/custom/common/test.ld"
asm_tests: <path_var>/custom/cv_xif/cvxif_exc.S

- test: cvxif_illegal
iterations: 1
iterations: 0
path_var: TESTS_PATH
gcc_opts: "-static -mcmodel=medany -fvisibility=hidden -nostdlib -nostartfiles ../tests/custom/common/syscalls.c ../tests/custom/common/crt.S -I../tests/custom/env -I../tests/custom/common -T ../tests/custom/common/test.ld"
asm_tests: <path_var>/custom/cv_xif/cvxif_illegal.S

- test: cvxif_nopexc
iterations: 1
iterations: 0
path_var: TESTS_PATH
gcc_opts: "-static -mcmodel=medany -fvisibility=hidden -nostdlib -nostartfiles ../tests/custom/common/syscalls.c ../tests/custom/common/crt.S -I../tests/custom/env -I../tests/custom/common -T ../tests/custom/common/test.ld"
asm_tests: <path_var>/custom/cv_xif/cvxif_nopexc.S

- test: cvxif_issexc
iterations: 1
iterations: 0
path_var: TESTS_PATH
gcc_opts: "-static -mcmodel=medany -fvisibility=hidden -nostdlib -nostartfiles ../tests/custom/common/syscalls.c ../tests/custom/common/crt.S -I../tests/custom/env -I../tests/custom/common -T ../tests/custom/common/test.ld"
asm_tests: <path_var>/custom/cv_xif/cvxif_issexc.S

- test: cvxif_s_mode
iterations: 1
path_var: TESTS_PATH
gcc_opts: "-static -mcmodel=medany -fvisibility=hidden -nostdlib -nostartfiles ../tests/custom/common/syscalls.c ../tests/custom/common/crt.S -I../tests/custom/env -I../tests/custom/common -T ../tests/custom/common/test.ld -lgcc"
asm_tests: <path_var>/custom/cv_xif/cvxif_s_mode.S

- test: cvxif_u_mode
iterations: 1
path_var: TESTS_PATH
gcc_opts: "-static -mcmodel=medany -fvisibility=hidden -nostdlib -nostartfiles ../tests/custom/common/syscalls.c ../tests/custom/common/crt.S -I../tests/custom/env -I../tests/custom/common -T ../tests/custom/common/test.ld -lgcc"
asm_tests: <path_var>/custom/cv_xif/cvxif_u_mode.S

0 comments on commit 8148bbb

Please sign in to comment.