Skip to content

Commit

Permalink
Merge pull request #2293 from silabs-robin/cv32e40x_dev_merge_2023-11-16
Browse files Browse the repository at this point in the history
Cv32e40x dev merge 2023 11 16
  • Loading branch information
silabs-robin authored Nov 20, 2023
2 parents 08c84fc + b626b26 commit 034b338
Show file tree
Hide file tree
Showing 83 changed files with 18,672 additions and 2,319 deletions.
20 changes: 17 additions & 3 deletions bin/clonetb
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@

usage() {
echo "usage: $0 [-x] [--clone] [--ignore] [--unignore]"
echo " -x clone cv32e40x subtree"
echo " --clone clone subtree based on env vars"
echo " -x clone cv32e40x subtree, known stable hash"
echo " --x-main clone cv32e40x subtree, latest main branch"
echo " --clone clone a subtree based on env vars"
echo " --ignore tell git to ignore the cloned subtree"
echo " --unignore tell git to not ignore the cloned subtree"

Expand Down Expand Up @@ -80,7 +81,17 @@ clone() {
clone_cv32e40x() {
CV_CORE=cv32e40x
VERIF_ENV_REPO=https://github.com/openhwgroup/cv32e40x-dv.git
VERIF_ENV_REF=e7bae19ebc7806021f909d49484c66d302b2f8a8
VERIF_ENV_REF=be17b8902002f91803abde4bfb8caa91088575e1
clone

ignore_cloned_directory
}

clone_cv32e40x_main() {
CV_CORE=cv32e40x
VERIF_ENV_REPO=https://github.com/openhwgroup/cv32e40x-dv.git
VERIF_ENV_REF=main

clone

ignore_cloned_directory
Expand Down Expand Up @@ -114,6 +125,9 @@ main() {
"-x")
clone_cv32e40x
;;
"--x-main")
clone_cv32e40x_main
;;
"--clone")
clone
;;
Expand Down
9 changes: 7 additions & 2 deletions bin/csv2json
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,16 @@ csv_reader = csv.DictReader(csv_file)
csv_rows = []
csv_row_previous = None

def should_fill_cell(cell_value, previous_row, row_key):
cell_is_empty = not cell_value
previous_row_exists = previous_row
column_should_repeat = row_key in ['Feature', 'Verification Goal']
return cell_is_empty and previous_row_exists and column_should_repeat

for row in csv_reader:
for key, value in row.items():
if not value and csv_row_previous:
if should_fill_cell(value, csv_row_previous, key):
row[key] = csv_row_previous[key]
# TODO not for "link-to-cov" etc

csv_rows.append(row)
csv_row_previous = row
Expand Down
64 changes: 42 additions & 22 deletions bin/merge.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ usage() {
echo "--x-dv_into_s Do a merge of cv32e40x-dv main into core-v-verif cv32e40s/dev cv32e40s (not yet developed)"
echo "--sdev_into_xdev Do a merge of core-v-verif cv32e40s/dev into core-v-verif cv32e40x/dev"
echo "--xdev_into_sdev Do a merge of core-v-verif cv32e40x/dev into core-v-verif cv32e40s/dev"
echo "--rejection-diff Merge s/dev to x-dv, using 'theirs'"

exit 1

}


Expand Down Expand Up @@ -64,12 +66,12 @@ merge_cv32e40s_into_cv32e40x-dv () {

move_files_40s_into_40x () {

echo "=== Exchange 40x/X with 40s/S in file names ==="
echo "=== Replace 40s/S with 40x/X in file names ==="

find . -type d | egrep -iv '\/\.|40sx|40xs' | grep -i 40s | xargs -n1 dirname | awk '{gsub(/40s/, "40x"); gsub(/40S/, "40X"); print}' | xargs -n2 mkdir -p
find . -type d | egrep -iv '\/\.|40sx|40xs' | grep -i 40s | awk '{printf $1; printf " "; gsub(/40s/, "40x"); gsub(/40S/, "40X"); print}' | xargs -n2 git mv
find . -type d | egrep -iv '\/\.|40sx|40xs' | grep -i 40s | awk '{printf $1; printf " "; gsub(/40s/, "40x"); gsub(/40S/, "40X"); print}' | xargs -n2 git mv -f
find . -type f | egrep -iv '\/\.|40sx|40xs' | grep -i 40s | xargs -n1 dirname | awk '{gsub(/40s/, "40x"); gsub(/40S/, "40X"); print}' | xargs -n2 mkdir -p
find . -type f | egrep -iv '\/\.|40sx|40xs' | grep -i 40s | awk '{printf $1; printf " "; gsub(/40s/, "40x"); gsub(/40S/, "40X"); print}' | xargs -n2 git mv
find . -type f | egrep -iv '\/\.|40sx|40xs' | grep -i 40s | awk '{printf $1; printf " "; gsub(/40s/, "40x"); gsub(/40S/, "40X"); print}' | xargs -n2 git mv -f

}

Expand Down Expand Up @@ -124,38 +126,53 @@ merge_xdev_into_sdev () {
}


check_cv32e40x_repo() {
clone_x_dv() {

echo "=== Cloning x-dv ==="

echo "=== Check if cv32e40x exist ==="
if [ ! -d "./cv32e40x/" ]; then
echo "Directory cv32e40x does not exists."
echo "Run: ./bin/clonetb -x"
echo "before running: ./bin/merge_script --s_into_x-dv"
exit 1
fi
printf "OK\n\n"
read -p "This overwrites 'cv32e40x/'. Continue? y/n " yn
case $yn in
[Yy]* ) ;;
* ) echo "aborting"; exit;;
esac

echo "=== Check if cv32e40x is the core-v-verif repo ==="
if [ ! -d "./cv32e40x/.git/" ]; then
echo "Directory cv32e40x is a 'core-v-verif' repo and not a 'cv32e40x-dv' repo."
echo "Run: ./bin/clonetb -x"
echo "before running: ./bin/merge_script --s_into_x-dv"
exit 1
fi
printf "OK\n\n"
./bin/clonetb --x-main

}


check_merge_status() {

git status

}


rejection_diff() {

echo "=== Merging s/dev to x-dv, using 'theirs' ==="
echo "WARNING, this function is crude and makes assumptions."

cd cv32e40x
branch_name_40s_subtree=$(git branch | grep ' cv32e40s')
branch_name_merge_normal=$(git branch | grep 'merge')
branch_name_merge_theirs=$(echo $branch_name_merge_normal | sed 's/merge/theirs/')

git checkout main
git checkout -B $branch_name_merge_theirs
git merge -X theirs $branch_name_40s_subtree

move_files_40s_into_40x
substitute_file_content_40s_into_40x

}


main() {

case $1 in
"--s_into_x-dv")
check_cv32e40x_repo
clone_x_dv
merge_cv32e40s_into_cv32e40x-dv
move_files_40s_into_40x
substitute_file_content_40s_into_40x
Expand All @@ -172,11 +189,14 @@ main() {
merge_xdev_into_sdev
check_merge_status
;;
"--rejection-diff")
rejection_diff
;;
*)
usage
;;
esac

}

main "$@"

165 changes: 165 additions & 0 deletions cv32e40s/bsp/bsp.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
// Copyright 2022 Silicon Laboratories Inc.
//
// SPDX-License-Identifier: Apache-2.0 WITH SHL-2.1
//
// Licensed under the Solderpad Hardware License v 2.1 (the "License"); you
// may not use this file except in compliance with the License, or, at your
// option, the Apache License version 2.0.
//
// You may obtain a copy of the License at
// https://solderpad.org/licenses/SHL-2.1/
//
// Unless required by applicable law or agreed to in writing, any work
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//
// See the License for the specific language governing permissions and
// limitations under the License.


enum {
EXC_CAUSE_INSTR_ACC_FAULT = 1,
EXC_CAUSE_ILLEGAL_INSTR = 2,
EXC_CAUSE_BREAKPOINT = 3,
EXC_CAUSE_LOAD_ACC_FAULT = 5,
EXC_CAUSE_STORE_ACC_FAULT = 7,
EXC_CAUSE_ENV_CALL_U = 8,
EXC_CAUSE_ENV_CALL_M = 11,
EXC_CAUSE_INSTR_BUS_FAULT = 24,
EXC_CAUSE_INSTR_INTEGRITY_FAULT = 25,
};

typedef enum {
PMPMODE_OFF = 0,
PMPMODE_TOR = 1,
PMPMODE_NA4 = 2,
PMPMODE_NAPOT = 3
} pmp_mode_t;

// Verbosity levels (Akin to the uvm verbosity concept)
typedef enum {
V_OFF = 0,
V_LOW = 1,
V_MEDIUM = 2,
V_HIGH = 3,
V_DEBUG = 4
} verbosity_t;

// Matches funct3 values for CSR instructions
typedef enum {
CSRRW = 1,
CSRRS = 2,
CSRRC = 3,
CSRRWI = 5,
CSRRSI = 6,
CSRRCI = 7
} csr_instr_access_t;

typedef union {
struct {
volatile uint32_t opcode : 7;
volatile uint32_t rd : 5;
volatile uint32_t funct3 : 3;
volatile uint32_t rs1_uimm : 5;
volatile uint32_t csr : 12;
} volatile fields;
volatile uint32_t raw;
} __attribute__((packed)) csr_instr_t;

typedef union {
struct {
volatile uint32_t load : 1;
volatile uint32_t store : 1;
volatile uint32_t execute : 1;
volatile uint32_t u : 1;
volatile uint32_t s : 1;
volatile uint32_t res_5_5 : 1;
volatile uint32_t m : 1;
volatile uint32_t match : 4;
volatile uint32_t chain : 1;
volatile uint32_t action : 4;
volatile uint32_t size : 4;
volatile uint32_t timing : 1;
volatile uint32_t select : 1;
volatile uint32_t hit : 1;
volatile uint32_t vu : 1;
volatile uint32_t vs : 1;
volatile uint32_t res_26_25: 2;
volatile uint32_t dmode : 1;
volatile uint32_t type : 4;
} __attribute__((packed)) volatile fields;
volatile uint32_t raw;
} __attribute__((packed)) mcontrol6_t;

typedef union {
struct {
volatile uint32_t uie : 1; // 0
volatile uint32_t sie : 1; // 1
volatile uint32_t wpri : 1; // 2
volatile uint32_t mie : 1; // 3
volatile uint32_t upie : 1; // 4
volatile uint32_t spie : 1; // 5
volatile uint32_t wpri0 : 1; // 6
volatile uint32_t mpie : 1; // 7
volatile uint32_t spp : 1; // 8
volatile uint32_t wpri1 : 2; // 10: 9
volatile uint32_t mpp : 2; // 12:11
volatile uint32_t fs : 2; // 14:13
volatile uint32_t xs : 2; // 16:15
volatile uint32_t mprv : 1; // 17
volatile uint32_t sum : 1; // 18
volatile uint32_t mxr : 1; // 19
volatile uint32_t tvm : 1; // 20
volatile uint32_t tw : 1; // 21
volatile uint32_t tsr : 1; // 22
volatile uint32_t wpri3 : 8; // 30:23
volatile uint32_t sd : 1; // 31
} volatile fields;
volatile uint32_t raw;
} __attribute__((packed)) mstatus_t;

typedef union {
struct {
volatile uint32_t mml : 1;
volatile uint32_t mmwp : 1;
volatile uint32_t rlb : 1;
volatile uint32_t reserved_31_3 : 29;
} __attribute__((packed)) volatile fields;
volatile uint32_t raw : 32;
} __attribute__((packed)) mseccfg_t;

typedef union {
struct {
volatile uint32_t reserved_1_0 : 2;
volatile uint32_t jvt_access : 1;
volatile uint32_t reserved_31_3 : 29;
} __attribute__((packed)) volatile fields;
volatile uint32_t raw : 32;
} __attribute__((packed)) mstateen0_t;

typedef union {
struct {
volatile uint32_t r : 1;
volatile uint32_t w : 1;
volatile uint32_t x : 1;
volatile uint32_t a : 1;
volatile uint32_t reserved_6_5 : 2;
volatile uint32_t l : 1;
} __attribute__((packed)) volatile fields;
volatile uint32_t raw : 8;
} __attribute__((packed)) pmpsubcfg_t;

typedef union {
struct {
volatile uint32_t cfg : 8;
} __attribute__((packed)) volatile reg_idx[4];
volatile uint32_t raw : 32;
} __attribute__((packed)) pmpcfg_t;

typedef union {
struct {
volatile uint32_t mode : 6;
volatile uint32_t base : 26;
} __attribute__((packed)) volatile fields;
volatile uint32_t raw : 32;
} __attribute__((packed)) jvt_t;
3 changes: 2 additions & 1 deletion cv32e40s/bsp/corev_uvmt.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,13 @@
#define CV_VP_OBI_SLV_RESP_D_EXOKAY_ADDR_MAX ((volatile uint32_t*) (CV_VP_OBI_SLV_RESP_BASE + 6*4 + 4*4))
#define CV_VP_OBI_SLV_RESP_D_EXOKAY_VALID ((volatile uint32_t*) (CV_VP_OBI_SLV_RESP_BASE + 6*4 + 4*5))

// Bitfields for Debug Control VP register
// API for Debug Control VP register
#define CV_VP_DEBUG_CONTROL_DBG_REQ(i) ((i) << 31)
#define CV_VP_DEBUG_CONTROL_REQ_MODE(i) ((i) << 30)
#define CV_VP_DEBUG_CONTROL_RAND_PULSE_DURATION(i) ((i) << 29)
#define CV_VP_DEBUG_CONTROL_PULSE_DURATION(i) ((i) << 16)
#define CV_VP_DEBUG_CONTROL_RAND_START_DELAY(i) ((i) << 15)
#define CV_VP_DEBUG_CONTROL_START_DELAY(i) ((i) << 0)
#define CV_VP_DEBUG_CONTROL *((volatile uint32_t * volatile) (CV_VP_DEBUG_CONTROL_BASE))

#endif
9 changes: 9 additions & 0 deletions cv32e40s/bsp/handlers.S
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#define EXCEPTION_LOAD_ACCESS_FAULT 5
#define EXCEPTION_STORE_ACCESS_FAULT 7
#define EXCEPTION_ECALL_M 11
#define EXCEPTION_ECALL_U 8
#define EXCEPTION_INSN_BUS_FAULT 24

/* NMI interrupt codes */
Expand Down Expand Up @@ -77,6 +78,8 @@
.weak handle_illegal_insn
.weak handle_insn_access_fault
.weak handle_insn_bus_fault
.weak handle_ecall
.weak handle_ecall_u

/* exception handling */
__no_irq_handler:
Expand Down Expand Up @@ -181,6 +184,8 @@ u_sw_irq_handler:
beq t0, t1, handle_illegal_insn
li t1, EXCEPTION_ECALL_M
beq t0, t1, handle_ecall
li t1, EXCEPTION_ECALL_U
beq t0, t1, handle_ecall_u
li t1, EXCEPTION_BREAKPOINT
beq t0, t1, handle_ebreak
li t1, EXCEPTION_INSN_BUS_FAULT
Expand All @@ -191,6 +196,10 @@ handle_ecall:
jal ra, handle_syscall
j end_handler_incr_mepc

handle_ecall_u:
jal ra, handle_syscall
j end_handler_incr_mepc

handle_ebreak:
/* TODO support debug handling requirements. */
la a0, ebreak_msg
Expand Down
Loading

0 comments on commit 034b338

Please sign in to comment.