From 8148bbb8db0703b0ba86d91747227b6ee566bfba Mon Sep 17 00:00:00 2001 From: Ayoub Jalali Date: Thu, 27 Jul 2023 14:25:00 +0200 Subject: [PATCH] CVXIF:Add directed test in supervisor and user mode --- cva6/tests/custom/cv_xif/cvxif_macros.h | 12 ++-- cva6/tests/custom/cv_xif/cvxif_s_mode.S | 73 +++++++++++++++++++++++++ cva6/tests/custom/cv_xif/cvxif_u_mode.S | 73 +++++++++++++++++++++++++ cva6/tests/testlist_cvxif.yaml | 26 ++++++--- 4 files changed, 170 insertions(+), 14 deletions(-) create mode 100644 cva6/tests/custom/cv_xif/cvxif_s_mode.S create mode 100644 cva6/tests/custom/cv_xif/cvxif_u_mode.S diff --git a/cva6/tests/custom/cv_xif/cvxif_macros.h b/cva6/tests/custom/cv_xif/cvxif_macros.h index 75aa131d13..f7e4448ce8 100644 --- a/cva6/tests/custom/cv_xif/cvxif_macros.h +++ b/cva6/tests/custom/cv_xif/cvxif_macros.h @@ -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 diff --git a/cva6/tests/custom/cv_xif/cvxif_s_mode.S b/cva6/tests/custom/cv_xif/cvxif_s_mode.S new file mode 100644 index 0000000000..2da7522374 --- /dev/null +++ b/cva6/tests/custom/cv_xif/cvxif_s_mode.S @@ -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 (ayoub.jalali@external.thalesgroup.com) + +#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; diff --git a/cva6/tests/custom/cv_xif/cvxif_u_mode.S b/cva6/tests/custom/cv_xif/cvxif_u_mode.S new file mode 100644 index 0000000000..fd03ebe8b4 --- /dev/null +++ b/cva6/tests/custom/cv_xif/cvxif_u_mode.S @@ -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 (ayoub.jalali@external.thalesgroup.com) + +#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; diff --git a/cva6/tests/testlist_cvxif.yaml b/cva6/tests/testlist_cvxif.yaml index 45d08d3336..f8861a1025 100644 --- a/cva6/tests/testlist_cvxif.yaml +++ b/cva6/tests/testlist_cvxif.yaml @@ -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: /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: /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: /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: /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: /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: /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: /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: /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: /custom/cv_xif/cvxif_u_mode.S