Added FreeRTOS to RISC-V demonstration example code
This commit is contained in:
parent
ff90a94be9
commit
e5dd8a951c
30 changed files with 586 additions and 456 deletions
|
|
@ -35,7 +35,7 @@
|
|||
#include <pthread.h>
|
||||
#include <semaphore.h>
|
||||
|
||||
#define VERSION_STRING "VProc version 1.7.3.2. Copyright (c) 2004-2024 Simon Southwell."
|
||||
#define VERSION_STRING "VProc version 1.7.4. Copyright (c) 2004-2024 Simon Southwell."
|
||||
|
||||
#ifndef VP_MAX_NODES
|
||||
#define VP_MAX_NODES 64
|
||||
|
|
|
|||
39
examples/riscv/README.md
Normal file
39
examples/riscv/README.md
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
# RISC-V ISS model demonstration example
|
||||
|
||||
This directory contains an example of co-simulating a RISC-V instruction set simulator C++ model on VProc
|
||||
|
||||
## Simple assembly code test
|
||||
|
||||
To run the simple assembly code test to generate an interrupt and invoke an ISR, <tt>vusermain.cfg</tt> should be configured as follows:
|
||||
|
||||
vusermain0 -rbH -D disassem.log -t ./interrupt/test.exe
|
||||
|
||||
The <tt>-r</tt> option enables run-time disassembler output, with the <tt>-D</tt> option directing this to the file <tt>disassem.log</tt>. The <tt>-b</tt> option specifies to halt at a specific address (defaulting to <tt>0x00000040</tt>) and the <tt>-H</tt> option specifies to halt on decoding an unimplemented instruction. The <tt>-t</tt> option selects the compiled RISC-V test executable to be loaded and run.
|
||||
|
||||
To run the test, use the make command:
|
||||
|
||||
make [-f makefile.verilator] run
|
||||
|
||||
## FreeRTOS test (verilator only)
|
||||
|
||||
This example uses the demo code fro the rv32 RISC-V ISS repository found on github: https://github.com/wyvernSemi/riscV/tree/main/freertos. An executable is provided in this directory (<tt>main.exe</tt>), but to compile the code from the ISS repository use the folllowing make command:
|
||||
|
||||
make USRFLAGS="-DCOSIM"
|
||||
|
||||
This compiles the demo program (<tt>demo/main.c</tt>), support functions and FreeRTOS configuration (<tt>rv32/*.[ch]</tt>) and FreeRTOS operating system. The resultant executable's text and read-only data is compiled at offset <tt>0x00000000</tt>, data and BSS at <tt>0x00080000</tt>, and with heap above and stack top at <tt>0x00082000</tt>. The mtime timer registers are configured in FreeRTOS to start from <tt>0xaffffffe0</tt>, and the UART driver code expects the terminal to start at <tt>0x80000000</tt>.
|
||||
|
||||
To run FreeRTOS demo, vusermain.cfg must be set as follows:
|
||||
|
||||
vusermain0 -T -t ./main.exe
|
||||
|
||||
The <tt>-T</tt> option specifies to use an external model for the mtime/mtimecmp timer, rather than the internal ISS model for the timer. This directs accesses to the timer to the memory mapped bus, and the HDL timer model is then accessed.
|
||||
|
||||
### Run FreeRTOS demo forever
|
||||
To run the simulation without a timeout, and without generating waveform data, use the make command:
|
||||
|
||||
make -f makefile.verilator USRSIMFLAGS="-GTIMEOUTCOUNT=0 -GRISCVTEST=1" run
|
||||
|
||||
### Run FreeRTOS demo for 20ms in GUI mode
|
||||
To run the demo for a given time (20ms in example), generating waveform data to be displayed in gtkwave, use the make command:
|
||||
|
||||
make -f makefile.verilator USRSIMFLAGS="-GVCD_DUMP=1 -GTIMEOUTCOUNT=2000000 -GRISCVTEST=1" gui
|
||||
|
|
@ -1,3 +1,5 @@
|
|||
../../f_VProc.sv
|
||||
mtimer.v
|
||||
uart.v
|
||||
riscVsim.v
|
||||
test.v
|
||||
|
|
@ -1,42 +1,28 @@
|
|||
// =========================================================================
|
||||
//=============================================================
|
||||
//
|
||||
// Copyright (c) 2021 Simon Southwell. All rights reserved.
|
||||
//
|
||||
// File Name: rv32.h
|
||||
// Design Unit Name:
|
||||
// Revision: OSVVM MODELS STANDARD VERSION
|
||||
// Date: 12th July 2021
|
||||
//
|
||||
// Maintainer: Simon Southwell email: simon.southwell@gmail.com
|
||||
// Contributor(s):
|
||||
// Simon Southwell simon.southwell@gmail.com
|
||||
// Contains the class definition for the top level derived class
|
||||
//
|
||||
// Description:
|
||||
// Contains the class definition for the top level derived class
|
||||
// This file is part of the Zicsr extended RISC-V instruction
|
||||
// set simulator (rv32).
|
||||
//
|
||||
// This file is part of the Zicsr extended RISC-V instruction
|
||||
// set simulator (rv32).
|
||||
// This code is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Revision History:
|
||||
// Date Version Description
|
||||
// 07/2023 2023.?? Updates for supporting FreeRTOS
|
||||
// 01/2023 2023.01 Released with OSVVM CoSim
|
||||
// 12th July 2021 Earlier version
|
||||
// This code is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// This file is part of OSVVM.
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this code. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
// Copyright (c) 2021 Simon Southwell.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// 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.
|
||||
//
|
||||
// =========================================================================
|
||||
//=============================================================
|
||||
|
||||
#ifndef _RV32_H_
|
||||
#define _RV32_H_
|
||||
|
|
@ -52,7 +38,7 @@ class rv32 : public RV32_TARGET_INHERITANCE_CLASS
|
|||
public:
|
||||
|
||||
static const int major_ver = 0;
|
||||
static const int minor_ver = 28;
|
||||
static const int minor_ver = 29;
|
||||
|
||||
LIBRISCV32_API rv32(FILE* dbg_fp = stdout) : RV32_TARGET_INHERITANCE_CLASS(dbg_fp)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,38 +1,25 @@
|
|||
// =========================================================================
|
||||
//=============================================================
|
||||
//
|
||||
// Copyright (c) 2021 Simon Southwell. All rights reserved.
|
||||
//
|
||||
// File Name: rv32_cpu_gdb.h
|
||||
// Design Unit Name:
|
||||
// Revision: OSVVM MODELS STANDARD VERSION
|
||||
// Date: 5th August 2021
|
||||
//
|
||||
// Maintainer: Simon Southwell email: simon.southwell@gmail.com
|
||||
// Contributor(s):
|
||||
// Simon Southwell simon.southwell@gmail.com
|
||||
// This file is part of the rv32_cpu instruction set simulator.
|
||||
//
|
||||
// Description:
|
||||
// This file is part of the rv32_cpu instruction set simulator.
|
||||
// This code is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Revision History:
|
||||
// Date Version Description
|
||||
// 01/2023 2023.01 Released with OSVVM CoSim
|
||||
// 5th August 2021 Earlier version
|
||||
// The code is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// This file is part of OSVVM.
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this code. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
// Copyright (c) 2021 Simon Southwell.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// 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.
|
||||
//
|
||||
// =========================================================================
|
||||
//=============================================================
|
||||
|
||||
#ifndef _RV32_CPU_GDB_H_
|
||||
#define _RV32_CPU_GDB_H_
|
||||
|
|
@ -64,7 +51,7 @@
|
|||
// TYPEDEFS (windows)
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
// Map the socket type for windows
|
||||
// Map the socket type for windows
|
||||
#include <Winsock2.h>
|
||||
typedef SOCKET rv32gdb_skt_t;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,38 +1,3 @@
|
|||
// =========================================================================
|
||||
//
|
||||
// File Name: rv32_extensions.h
|
||||
// Design Unit Name:
|
||||
// Revision: OSVVM MODELS STANDARD VERSION
|
||||
//
|
||||
// Maintainer: Simon Southwell email: simon.southwell@gmail.com
|
||||
// Contributor(s):
|
||||
// Simon Southwell simon.southwell@gmail.com
|
||||
//
|
||||
// Description:
|
||||
// Autogenerated
|
||||
//
|
||||
// Revision History:
|
||||
// Date Version Description
|
||||
// 01/2023 2023.01 Released with OSVVM CoSim
|
||||
// Autogenerated ...
|
||||
//
|
||||
// This file is part of OSVVM.
|
||||
//
|
||||
// Copyright (c) 2021 Simon Southwell.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// 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.
|
||||
//
|
||||
// =========================================================================
|
||||
|
||||
// *** AUTOMATICALLY GENERATED FILE. DO NOT EDIT! ***
|
||||
|
||||
|
|
|
|||
|
|
@ -1,42 +1,28 @@
|
|||
// =========================================================================
|
||||
//=============================================================
|
||||
//
|
||||
// Copyright (c) 2021 Simon Southwell. All rights reserved.
|
||||
//
|
||||
// File Name: rv32a_cpu.h
|
||||
// Design Unit Name:
|
||||
// Revision: OSVVM MODELS STANDARD VERSION
|
||||
// Date: 26th July 2021
|
||||
//
|
||||
// Maintainer: Simon Southwell email: simon.southwell@gmail.com
|
||||
// Contributor(s):
|
||||
// Simon Southwell simon.southwell@gmail.com
|
||||
// Contains the class definition for the rv32a_cpu derived class
|
||||
//
|
||||
// Description:
|
||||
// Contains the definitions for the rv32csr_cpu derived class
|
||||
// This file is part of the M extended RISC-V instruction
|
||||
// set simulator (rv32a_cpu).
|
||||
//
|
||||
// This file is part of the A extended RISC-V instruction
|
||||
// set simulator (rv32a_cpu).
|
||||
// This code is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Revision History:
|
||||
// Date Version Description
|
||||
// 07/2023 2023.?? Updates for supporting FreeRTOS
|
||||
// 01/2023 2023.01 Released with OSVVM CoSim
|
||||
// 26th July 2021 Earlier version
|
||||
// This code is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// This file is part of OSVVM.
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this code. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
// Copyright (c) 2021 Simon Southwell.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// 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.
|
||||
//
|
||||
// =========================================================================
|
||||
//=============================================================
|
||||
|
||||
#ifndef _RV32A_CPU_H_
|
||||
#define _RV32A_CPU_H_
|
||||
|
|
|
|||
|
|
@ -1,41 +1,28 @@
|
|||
// =========================================================================
|
||||
//=============================================================
|
||||
//
|
||||
// Copyright (c) 2021 Simon Southwell. All rights reserved.
|
||||
//
|
||||
// File Name: rv32c_cpu.h
|
||||
// Design Unit Name:
|
||||
// Revision: OSVVM MODELS STANDARD VERSION
|
||||
// Date: 6th September 2021
|
||||
//
|
||||
// Maintainer: Simon Southwell email: simon.southwell@gmail.com
|
||||
// Contributor(s):
|
||||
// Simon Southwell simon.southwell@gmail.com
|
||||
// Contains the header for the rv32c_cpu class
|
||||
//
|
||||
// Description:
|
||||
// Contains the definitions for the rv32c_cpu derived class
|
||||
// This file is part of the base RISC-V instruction set simulator
|
||||
// (rv32i_cpu).
|
||||
//
|
||||
// This file is part of the base RISC-V instruction set simulator
|
||||
// This code is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Revision History:
|
||||
// Date Version Description
|
||||
// 01/2023 2023.01 Released with OSVVM CoSim
|
||||
// 6th September 2021 Earlier version
|
||||
// This code is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this code. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
// This file is part of OSVVM.
|
||||
//
|
||||
// Copyright (c) 2021 Simon Southwell. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// 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.
|
||||
//
|
||||
// =========================================================================
|
||||
//=============================================================
|
||||
|
||||
#ifndef _RV32C_CPU_H_
|
||||
#define _RV32C_CPU_H_
|
||||
|
|
|
|||
|
|
@ -1,42 +1,28 @@
|
|||
// =========================================================================
|
||||
//=============================================================
|
||||
//
|
||||
// Copyright (c) 2021 Simon Southwell. All rights reserved.
|
||||
//
|
||||
// File Name: rv32csr_cpu.h
|
||||
// Design Unit Name:
|
||||
// Revision: OSVVM MODELS STANDARD VERSION
|
||||
// Date: 12th July 2021
|
||||
//
|
||||
// Maintainer: Simon Southwell email: simon.southwell@gmail.com
|
||||
// Contributor(s):
|
||||
// Simon Southwell simon.southwell@gmail.com
|
||||
// Contains the class definition for the rv32csr_cpu derived class
|
||||
//
|
||||
// Description:
|
||||
// Contains the definitions for the rv32csr_cpu derived class
|
||||
// This file is part of the Zicsr extended RISC-V instruction
|
||||
// set simulator (rv32csr_cpu).
|
||||
//
|
||||
// This file is part of the Zicsr extended RISC-V instruction
|
||||
// set simulator (rv32csr_cpu).
|
||||
// This code is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Revision History:
|
||||
// Date Version Description
|
||||
// 07/2023 2023.?? Updates for supporting FreeRTOS
|
||||
// 01/2023 2023.01 Released with OSVVM CoSim
|
||||
// 12th July 2021 Earlier version
|
||||
// This code is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// This file is part of OSVVM.
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this code. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
// Copyright (c) 2021 Simon Southwell.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// 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.
|
||||
//
|
||||
// =========================================================================
|
||||
//=============================================================
|
||||
|
||||
#ifndef _RV32CSR_CPU_H_
|
||||
#define _RV32CSR_CPU_H_
|
||||
|
|
|
|||
|
|
@ -1,42 +1,28 @@
|
|||
// =========================================================================
|
||||
//=============================================================
|
||||
//
|
||||
// Copyright (c) 2021 Simon Southwell. All rights reserved.
|
||||
//
|
||||
// File Name: rv32csr_cpu_hdr.h
|
||||
// Design Unit Name:
|
||||
// Revision: OSVVM MODELS STANDARD VERSION
|
||||
// Date: 12th July 2021
|
||||
//
|
||||
// Maintainer: Simon Southwell email: simon.southwell@gmail.com
|
||||
// Contributor(s):
|
||||
// Simon Southwell simon.southwell@gmail.com
|
||||
// Contains the definitions for the rv32csr_cpu derived class
|
||||
//
|
||||
// Description:
|
||||
// Contains the definitions for the rv32csr_cpu derived class
|
||||
// This file is part of the Zicsr extended RISC-V instruction
|
||||
// set simulator (rv32csr_cpu).
|
||||
//
|
||||
// This file is part of the Zicsr extended RISC-V instruction
|
||||
// set simulator (rv32csr_cpu).
|
||||
// This code is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Revision History:
|
||||
// Date Version Description
|
||||
// 07/2023 2023.?? Updates for supporting FreeRTOS
|
||||
// 01/2023 2023.01 Released with OSVVM CoSim
|
||||
// Date: 12th July 2021 Earlier version
|
||||
// This code is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// This file is part of OSVVM.
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this code. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
// Copyright (c) 2021 Simon Southwell.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// 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.
|
||||
//
|
||||
// =========================================================================
|
||||
//=============================================================
|
||||
|
||||
#ifndef _RV32CSR_CPU_HDR_H_
|
||||
#define _RV32CSR_CPU_HDR_H_
|
||||
|
|
|
|||
|
|
@ -1,42 +1,28 @@
|
|||
// =========================================================================
|
||||
//=============================================================
|
||||
//
|
||||
// File Name: rv32d_cpu.h
|
||||
// Design Unit Name:
|
||||
// Revision: OSVVM MODELS STANDARD VERSION
|
||||
// Copyright (c) 2021 Simon Southwell. All rights reserved.
|
||||
//
|
||||
// Maintainer: Simon Southwell email: simon.southwell@gmail.com
|
||||
// Contributor(s):
|
||||
// Simon Southwell simon.southwell@gmail.com
|
||||
// Date: 30th July 2021
|
||||
//
|
||||
// Description:
|
||||
// Contains the class definition for the rv32d_cpu derived class
|
||||
//
|
||||
// This file is part of the D extended RISC-V instruction
|
||||
// set simulator (rv32d_cpu).
|
||||
// Contains the class definition for the rv32d_cpu derived class
|
||||
//
|
||||
// Revision History:
|
||||
// Date Version Description
|
||||
// 07/2023 2023.?? Updates for supporting FreeRTOS
|
||||
// 01/2023 2023.01 Released with OSVVM CoSim
|
||||
// 30th July 2021 Earlier version
|
||||
// This file is part of the M extended RISC-V instruction
|
||||
// set simulator (rv32d_cpu).
|
||||
//
|
||||
// This file is part of OSVVM.
|
||||
// This code is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Copyright (c) 2021 Simon Southwell.
|
||||
// This code is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this code. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// 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.
|
||||
//
|
||||
// =========================================================================
|
||||
//=============================================================
|
||||
|
||||
#ifndef _RV32D_CPU_H_
|
||||
#define _RV32D_CPU_H_
|
||||
|
|
|
|||
|
|
@ -1,42 +1,28 @@
|
|||
// =========================================================================
|
||||
//=============================================================
|
||||
//
|
||||
// Copyright (c) 2021 Simon Southwell. All rights reserved.
|
||||
//
|
||||
// File Name: rv32f_cpu.h
|
||||
// Design Unit Name:
|
||||
// Revision: OSVVM MODELS STANDARD VERSION
|
||||
// Date: 26th July 2021
|
||||
//
|
||||
// Maintainer: Simon Southwell email: simon.southwell@gmail.com
|
||||
// Contributor(s):
|
||||
// Simon Southwell simon.southwell@gmail.com
|
||||
// Contains the class definition for the rv32f_cpu derived class
|
||||
//
|
||||
// Description:
|
||||
// Contains the class definition for the rv32f_cpu derived class
|
||||
//
|
||||
// This file is part of the F extended RISC-V instruction
|
||||
// set simulator (rv32f_cpu).
|
||||
// This file is part of the M extended RISC-V instruction
|
||||
// set simulator (rv32f_cpu).
|
||||
//
|
||||
// Revision History:
|
||||
// Date Version Description
|
||||
// 07/2023 2023.?? Updates for supporting FreeRTOS
|
||||
// 01/2023 2023.01 Released with OSVVM CoSim
|
||||
// 26th July 2021 Earlier version
|
||||
// This code is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This file is part of OSVVM.
|
||||
// This code is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// Copyright (c) 2021 Simon Southwell.
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this code. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// 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.
|
||||
//
|
||||
// =========================================================================
|
||||
//=============================================================
|
||||
|
||||
#ifndef _RV32F_CPU_H_
|
||||
#define _RV32F_CPU_H_
|
||||
|
|
|
|||
|
|
@ -1,42 +1,28 @@
|
|||
// =========================================================================
|
||||
//=============================================================
|
||||
//
|
||||
// Copyright (c) 2021 Simon Southwell. All rights reserved.
|
||||
//
|
||||
// File Name: rv32i_cpu.h
|
||||
// Design Unit Name:
|
||||
// Revision: OSVVM MODELS STANDARD VERSION
|
||||
// Date: 28th June 2021
|
||||
//
|
||||
// Maintainer: Simon Southwell email: simon.southwell@gmail.com
|
||||
// Contributor(s):
|
||||
// Simon Southwell simon.southwell@gmail.com
|
||||
// Contains the header for the rv32i_cpu class
|
||||
//
|
||||
// Description:
|
||||
// Contains the header for the rv32i_cpu class
|
||||
//
|
||||
// This file is part of the base RISC-V instruction set simulator
|
||||
// (rv32i_cpu).
|
||||
// This file is part of the base RISC-V instruction set simulator
|
||||
// (rv32i_cpu).
|
||||
//
|
||||
// Revision History:
|
||||
// Date Version Description
|
||||
// 07/2023 2023.?? Updates for supporting FreeRTOS
|
||||
// 01/2023 2023.01 Released with OSVVM CoSim
|
||||
// 28th June 2021 Earlier version
|
||||
// This code is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This file is part of OSVVM.
|
||||
// This code is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// Copyright (c) 2021 Simon Southwell.
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this code. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// 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.
|
||||
//
|
||||
// =========================================================================
|
||||
//=============================================================
|
||||
|
||||
#ifndef _RV32I_CPU_H_
|
||||
#define _RV32I_CPU_H_
|
||||
|
|
@ -264,8 +250,12 @@ protected:
|
|||
// Debug ABI register names enable flag
|
||||
bool abi_en;
|
||||
|
||||
// Flag to select using cycle count for internal mtime timer model
|
||||
bool use_cycles_for_mtime;
|
||||
|
||||
// Flag to select using external memory mapped mtime timer model (user provided via external memory access callback)
|
||||
bool use_external_timer;
|
||||
|
||||
// Holds CSR and HART (pc and regs) state
|
||||
rv32i_state state;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,42 +1,28 @@
|
|||
// =========================================================================
|
||||
//=============================================================
|
||||
//
|
||||
// Copyright (c) 2021 Simon Southwell. All rights reserved.
|
||||
//
|
||||
// File Name: rv32i_cpu_hdr.h
|
||||
// Design Unit Name:
|
||||
// Revision: OSVVM MODELS STANDARD VERSION
|
||||
// Date: 28th June 2021
|
||||
//
|
||||
// Maintainer: Simon Southwell email: simon.southwell@gmail.com
|
||||
// Contributor(s):
|
||||
// Simon Southwell simon.southwell@gmail.com
|
||||
// Contains the header for local definitions for the rv32i_cpu class
|
||||
//
|
||||
// Description:
|
||||
// Contains the header for local definitions for the rv32i_cpu class
|
||||
// This file is part of the base RISC-V instruction set simulator
|
||||
// (rv32i_cpu).
|
||||
//
|
||||
// This file is part of the Zicsr extended RISC-V instruction
|
||||
// set simulator (rv32i_cpu).
|
||||
// This code is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Revision History:
|
||||
// Date Version Description
|
||||
// 07/2023 2023.?? Updates for supporting FreeRTOS
|
||||
// 01/2023 2023.01 Released with OSVVM CoSim
|
||||
// 28th June 2021 Earlier version
|
||||
// This code is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// This file is part of OSVVM.
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this code. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
// Copyright (c) 2021 Simon Southwell.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// 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.
|
||||
//
|
||||
// =========================================================================
|
||||
//=============================================================
|
||||
|
||||
#ifndef _RV32I_CPU_HDR_H_
|
||||
#define _RV32I_CPU_HDR_H_
|
||||
|
|
@ -559,6 +545,7 @@ struct rv32i_cfg_s {
|
|||
bool dump_regs;
|
||||
bool dump_csrs;
|
||||
bool use_cycles_for_mtime;
|
||||
bool use_external_timer;
|
||||
uint32_t num_mem_dump_words;
|
||||
uint32_t mem_dump_start;
|
||||
bool gdb_mode;
|
||||
|
|
@ -570,27 +557,28 @@ struct rv32i_cfg_s {
|
|||
|
||||
rv32i_cfg_s()
|
||||
{
|
||||
exec_fname = "test.exe";
|
||||
user_fname = false;
|
||||
num_instr = 0;
|
||||
rt_dis = false;
|
||||
dis_en = false;
|
||||
abi_en = false;
|
||||
hlt_on_inst_err = false;
|
||||
hlt_on_ecall = false;
|
||||
hlt_on_ebreak = false;
|
||||
en_brk_on_addr = false;
|
||||
use_cycles_for_mtime = false;
|
||||
dump_regs = false;
|
||||
dump_csrs = false;
|
||||
num_mem_dump_words = 0;
|
||||
mem_dump_start = 0x1000;
|
||||
gdb_mode = false;
|
||||
gdb_ip_portnum = RV32_DEFAULT_TCP_PORT;
|
||||
brk_addr = RISCV_TEST_ENV_TERMINATE_ADDR;
|
||||
update_rst_vec = false;
|
||||
new_rst_vec = RV32I_RESET_VECTOR;
|
||||
dbg_fp = stdout;
|
||||
exec_fname = "test.exe";
|
||||
user_fname = false;
|
||||
num_instr = 0;
|
||||
rt_dis = false;
|
||||
dis_en = false;
|
||||
abi_en = false;
|
||||
hlt_on_inst_err = false;
|
||||
hlt_on_ecall = false;
|
||||
hlt_on_ebreak = false;
|
||||
en_brk_on_addr = false;
|
||||
use_cycles_for_mtime = false;
|
||||
use_external_timer = false;
|
||||
dump_regs = false;
|
||||
dump_csrs = false;
|
||||
num_mem_dump_words = 0;
|
||||
mem_dump_start = 0x1000;
|
||||
gdb_mode = false;
|
||||
gdb_ip_portnum = RV32_DEFAULT_TCP_PORT;
|
||||
brk_addr = RISCV_TEST_ENV_TERMINATE_ADDR;
|
||||
update_rst_vec = false;
|
||||
new_rst_vec = RV32I_RESET_VECTOR;
|
||||
dbg_fp = stdout;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -1,42 +1,28 @@
|
|||
// =========================================================================
|
||||
//=============================================================
|
||||
//
|
||||
// Copyright (c) 2021 Simon Southwell. All rights reserved.
|
||||
//
|
||||
// File Name: rv32m_cpu.h
|
||||
// Design Unit Name:
|
||||
// Revision: OSVVM MODELS STANDARD VERSION
|
||||
// Date: 24th July 2021
|
||||
//
|
||||
// Maintainer: Simon Southwell email: simon.southwell@gmail.com
|
||||
// Contributor(s):
|
||||
// Simon Southwell simon.southwell@gmail.com
|
||||
// Contains the class definition for the rv32m_cpu derived class
|
||||
//
|
||||
// Description:
|
||||
// Contains the definitions for the rv32m_cpu derived class
|
||||
// This file is part of the M extended RISC-V instruction
|
||||
// set simulator (rv32m_cpu).
|
||||
//
|
||||
// This file is part of the M extended RISC-V instruction
|
||||
// set simulator (rv32m_cpu).
|
||||
// This code is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Revision History:
|
||||
// Date Version Description
|
||||
// 07/2023 2023.?? Updates for supporting FreeRTOS
|
||||
// 01/2023 2023.01 Released with OSVVM CoSim
|
||||
// 24th July 2021 Earlier version
|
||||
// This code is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// This file is part of OSVVM.
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this code. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
// Copyright (c) 2021 Simon Southwell.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// 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.
|
||||
//
|
||||
// =========================================================================
|
||||
//=============================================================
|
||||
|
||||
#ifndef _RV32M_CPU_H_
|
||||
#define _RV32M_CPU_H_
|
||||
|
|
|
|||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
examples/riscv/main.exe
Normal file
BIN
examples/riscv/main.exe
Normal file
Binary file not shown.
|
|
@ -110,7 +110,7 @@ CPPSTD = -std=c++20
|
|||
SIMFLAGS = --binary -sv --trace \
|
||||
$(FINISHFLAG) \
|
||||
$(TIMINGFLAG) \
|
||||
$(VCDFLAG) $(BURSTDEF) \
|
||||
$(BURSTDEF) \
|
||||
$(INCLFLAG) \
|
||||
$(USRSIMFLAGS) \
|
||||
$(WARNCONTROL) \
|
||||
|
|
|
|||
97
examples/riscv/mtimer.v
Normal file
97
examples/riscv/mtimer.v
Normal file
|
|
@ -0,0 +1,97 @@
|
|||
// ====================================================================
|
||||
//
|
||||
// RISC-V mtime timer to return (and compare) time in units of
|
||||
// 1 microsecond.
|
||||
//
|
||||
// Copyright (c) 2024 Simon Southwell.
|
||||
//
|
||||
// This file is part of VProc.
|
||||
//
|
||||
// VProc is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// VProc is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with VProc. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
// ====================================================================
|
||||
module mtimer
|
||||
#(parameter MTIME_INIT = 64'h0,
|
||||
MTIMECMP_INIT = 64'hffffffffffffffff,
|
||||
CLKFREQMHZ = 100 // must be an integer between 1 and 1023
|
||||
)
|
||||
(
|
||||
input clk,
|
||||
input nreset,
|
||||
|
||||
input cs,
|
||||
input [1:0] addr,
|
||||
input wr,
|
||||
input [31:0] wdata,
|
||||
input rd,
|
||||
output reg [31:0] rdata,
|
||||
output reg rvalid,
|
||||
|
||||
output reg irq
|
||||
);
|
||||
|
||||
localparam TICKCOUNTUS = CLKFREQMHZ;
|
||||
|
||||
reg [63:0] mtime;
|
||||
reg [63:0] mtimecmp;
|
||||
reg [9:0] count;
|
||||
|
||||
always @(posedge clk or negedge nreset)
|
||||
begin
|
||||
if (nreset == 1'b0)
|
||||
begin
|
||||
rvalid <= 1'b0;
|
||||
irq <= 1'b0;
|
||||
mtime <= MTIME_INIT;
|
||||
mtimecmp <= MTIMECMP_INIT;
|
||||
count <= 0;
|
||||
end
|
||||
else
|
||||
begin
|
||||
// Generate IRQ output
|
||||
irq <= (mtime > mtimecmp) ? 1'b1 : 1'b0;
|
||||
|
||||
// Update registers
|
||||
if (cs && wr)
|
||||
begin
|
||||
case(addr)
|
||||
2'b00 : mtime[31:0] <= wdata;
|
||||
2'b01 : mtime[63:32] <= wdata;
|
||||
2'b10 : mtimecmp[31:0] <= wdata;
|
||||
2'b11 : mtimecmp[63:32] <= wdata;
|
||||
endcase
|
||||
end
|
||||
|
||||
// Read registers
|
||||
case (addr)
|
||||
2'b00 : rdata <= mtime[31:0];
|
||||
2'b01 : rdata <= mtime[63:32];
|
||||
2'b10 : rdata <= mtimecmp[31:0];
|
||||
2'b11 : rdata <= mtimecmp[63:32];
|
||||
endcase
|
||||
|
||||
rvalid <= (rd & ~rvalid);
|
||||
|
||||
// Increment counters
|
||||
count <= count + 10'd1;
|
||||
|
||||
if (count == TICKCOUNTUS-1)
|
||||
begin
|
||||
count <= 10'd0;
|
||||
mtime <= mtime + 64'd1;
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
endmodule
|
||||
|
|
@ -34,7 +34,8 @@
|
|||
module riscVsim
|
||||
#(parameter NODE = 0,
|
||||
USE_HARVARD = 1,
|
||||
DISABLE_DELTA = 0)
|
||||
DISABLE_DELTA = 0,
|
||||
RISCVTEST = 0)
|
||||
(
|
||||
input clk,
|
||||
|
||||
|
|
@ -53,7 +54,7 @@ module riscVsim
|
|||
input [31:0] ireaddata,
|
||||
input iwaitrequest,
|
||||
|
||||
input irq
|
||||
input [2:0] irq
|
||||
);
|
||||
|
||||
wire instr_access;
|
||||
|
|
@ -63,7 +64,7 @@ wire read_int;
|
|||
wire [31:0] nodenum = NODE;
|
||||
wire [31:0] rd_data;
|
||||
|
||||
assign instr_access = daddress[31];
|
||||
assign instr_access = (RISCVTEST == 0) ? daddress[31] : daddress < (64*1024);
|
||||
assign iaddress = {1'b0, daddress[30:0]};
|
||||
assign iread = read_int && instr_access && USE_HARVARD;
|
||||
assign dread = read_int && (instr_access == 1'b0 || USE_HARVARD == 0);
|
||||
|
|
@ -82,7 +83,7 @@ assign RDAck = ((dread & ~dwaitrequest) == 1'b1 || (iread & ~iwaitre
|
|||
.DataIn (rd_data),
|
||||
.WRAck (dwrite),
|
||||
.RDAck (RDAck),
|
||||
.Interrupt ({2'b00, irq}),
|
||||
.Interrupt (irq),
|
||||
.Update (Update),
|
||||
.UpdateResponse (Update),
|
||||
.Node (nodenum[3:0])
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ extern "C" {
|
|||
// I'm node 0
|
||||
int node = 0;
|
||||
|
||||
static bool irq = false;
|
||||
static uint32_t irq = 0;
|
||||
static uint32_t irq_state = 0;
|
||||
|
||||
static const int strbufsize = 256;
|
||||
|
|
@ -177,6 +177,9 @@ int parseArgs(int argcIn, char** argvIn, rv32i_cfg_s &cfg, const int node)
|
|||
case 'H':
|
||||
cfg.hlt_on_inst_err = true;
|
||||
break;
|
||||
case 'T':
|
||||
cfg.use_external_timer = true;
|
||||
break;
|
||||
case 'e':
|
||||
cfg.hlt_on_ecall = true;
|
||||
break;
|
||||
|
|
@ -204,6 +207,7 @@ int parseArgs(int argcIn, char** argvIn, rv32i_cfg_s &cfg, const int node)
|
|||
fprintf(stderr, " -n specify number of instructions to run (default 0, i.e. run until unimp)\n");
|
||||
fprintf(stderr, " -d Enable disassemble mode (default off)\n");
|
||||
fprintf(stderr, " -r Enable run-time disassemble mode (default off. Overridden by -d)\n");
|
||||
fprintf(stderr, " -T Use external memory mapped timer model (default internal)\n");
|
||||
fprintf(stderr, " -H Halt on unimplemented instructions (default trap)\n");
|
||||
fprintf(stderr, " -e Halt on ecall/ebreak instruction (default trap)\n");
|
||||
fprintf(stderr, " -b Halt at a specific address (default off)\n");
|
||||
|
|
@ -232,19 +236,19 @@ int parseArgs(int argcIn, char** argvIn, rv32i_cfg_s &cfg, const int node)
|
|||
// in the main program flow.
|
||||
int vproc_irq_callback(int val)
|
||||
{
|
||||
irq = val ? true : false;
|
||||
irq = val;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// The ISS interrupt callback will return an interrupt when irq
|
||||
// is true, else it returns 0. The wakeup time in this model is always the next
|
||||
// is non-zero, else it returns 0. The wakeup time in this model is always the next
|
||||
// cycle.
|
||||
uint32_t iss_int_callback(const rv32i_time_t time, rv32i_time_t *wakeup_time)
|
||||
{
|
||||
*wakeup_time = time + 1;
|
||||
|
||||
return irq ? 1 : 0;
|
||||
return irq;
|
||||
}
|
||||
|
||||
// ---------------------------------------------
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ extern "C" {
|
|||
}
|
||||
|
||||
#define CFGFILENAME "vusermain.cfg"
|
||||
#define RV32I_GETOPT_ARG_STR "hHdbrget:n:D:A:p:S:"
|
||||
#define RV32I_GETOPT_ARG_STR "ThHdbrget:n:D:A:p:S:"
|
||||
#define MAXARGS 100
|
||||
#define MEM_SIZE (1024*1024)
|
||||
#define MEM_OFFSET 0
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ uint32_t read_instr(uint32_t addr)
|
|||
{
|
||||
uint32_t word;
|
||||
|
||||
VRead(addr & ~0x3 | 0x80000000, &word, NORMAL_UPDATE, node);
|
||||
VRead(addr & ~0x3, &word, NORMAL_UPDATE, node);
|
||||
|
||||
VTick(ACCESS_LEN, node);
|
||||
|
||||
|
|
@ -59,7 +59,7 @@ uint32_t read_hword(uint32_t addr)
|
|||
|
||||
VTick(ACCESS_LEN, node);
|
||||
|
||||
return word >> ((addr & 0x2UL) * 8);
|
||||
return (word >> ((addr & 0x2UL) * 8)) & 0xffff;
|
||||
}
|
||||
|
||||
uint32_t read_byte(uint32_t addr)
|
||||
|
|
@ -70,5 +70,5 @@ uint32_t read_byte(uint32_t addr)
|
|||
|
||||
VTick(ACCESS_LEN, node);
|
||||
|
||||
return word >> ((addr & 0x3UL) * 8);
|
||||
return (word >> ((addr & 0x3UL) * 8)) & 0xff;
|
||||
}
|
||||
|
|
@ -33,10 +33,15 @@
|
|||
`timescale 1ns/1ps
|
||||
|
||||
`define RESET_PERIOD 10
|
||||
`define TIMEOUT_COUNT 4000
|
||||
|
||||
`define DMEM_SEGMENT 4'h0
|
||||
`define IMEM_SEGMENT 4'h8
|
||||
`define MEMSEG 4'h0
|
||||
`define UARTSEG 4'h8
|
||||
|
||||
`define IMEM_SUBSEGMENT 4'h0
|
||||
`define DMEM_SUBSEGMENT 4'h8
|
||||
|
||||
`define TIMERSTARTADDR 32'hAFFFFFE0
|
||||
`define TIMERENDADDR 32'hAFFFFFEC
|
||||
|
||||
`define HALT_ADDR 32'hAFFFFFF8
|
||||
`define INT_ADDR 32'hAFFFFFFC
|
||||
|
|
@ -46,7 +51,9 @@ module test
|
|||
CLK_FREQ_MHZ = 100,
|
||||
USE_HARVARD = 1,
|
||||
VCD_DUMP = 0,
|
||||
DISABLE_DELTA = 0);
|
||||
DISABLE_DELTA = 0,
|
||||
TIMEOUTCOUNT = 4000,
|
||||
RISCVTEST = 0);
|
||||
|
||||
// Clock, reset and simulation control state
|
||||
reg clk;
|
||||
|
|
@ -60,6 +67,10 @@ wire [31:0] writedata;
|
|||
wire [3:0] byteenable;
|
||||
wire read;
|
||||
wire [31:0] readdata;
|
||||
wire [31:0] memreaddata;
|
||||
wire [31:0] romreaddata;
|
||||
wire [31:0] timreaddata;
|
||||
wire [31:0] uartreaddata;
|
||||
wire [31:0] ireaddata;
|
||||
|
||||
wire iread;
|
||||
|
|
@ -67,7 +78,10 @@ wire [31:0] iaddress;
|
|||
|
||||
reg readdatavalid;
|
||||
reg ireaddatavalid;
|
||||
reg irq;
|
||||
reg swirq;
|
||||
|
||||
wire timirq;
|
||||
wire [2:0] irq = {swirq, timirq, 1'b0};
|
||||
|
||||
// -----------------------------------------------
|
||||
// Initialisation, clock and reset
|
||||
|
|
@ -84,7 +98,7 @@ begin
|
|||
|
||||
count = -1;
|
||||
clk = 1'b1;
|
||||
irq = 1'b0;
|
||||
swirq = 1'b0;
|
||||
readdatavalid = 1'b0;
|
||||
ireaddatavalid = 1'b0;
|
||||
end
|
||||
|
|
@ -95,21 +109,43 @@ always #(500/CLK_FREQ_MHZ) clk = ~clk;
|
|||
// Generate a reset signal using count
|
||||
assign reset_n = (count >= `RESET_PERIOD) ? 1'b1 : 1'b0;
|
||||
|
||||
// -----------------------------------------------
|
||||
// Address decode
|
||||
// -----------------------------------------------
|
||||
|
||||
// Generate memory chip selects
|
||||
wire cs0 = iaddress[31:28] == `IMEM_SEGMENT ? 1'b1 : 1'b0;
|
||||
wire cs1 = address[31:28] == `DMEM_SEGMENT ? 1'b1 : 1'b0;
|
||||
wire cs0 = iaddress[31:28] == `MEMSEG && iaddress[19:16] == `IMEM_SUBSEGMENT && iread == 1'b1 ? 1'b1 : 1'b0;
|
||||
wire cs1 = address[31:28] == `MEMSEG && address[19:16] == `IMEM_SUBSEGMENT && (read == 1'b1 || write == 1'b1) ? 1'b1 : 1'b0;
|
||||
wire cs4 = address[31:28] == `MEMSEG && address[19:16] == `DMEM_SUBSEGMENT && (read == 1'b1 || write == 1'b1) ? 1'b1 : 1'b0;
|
||||
|
||||
// Generate peripheral chip selects
|
||||
wire cs2 = (read == 1'b1 || write ==1'b1) && address >= `TIMERSTARTADDR && address <= `TIMERENDADDR;
|
||||
wire cs3 = (read == 1'b1 || write ==1'b1) && address[31:28] == `UARTSEG;
|
||||
|
||||
// Software interrupt
|
||||
wire cs5 = write == 1'b1 && address == `INT_ADDR;
|
||||
|
||||
// Simulation control
|
||||
wire cs6 = write == 1'b1 && address == `HALT_ADDR;
|
||||
|
||||
// Amalgamate read data
|
||||
assign readdata = cs2 ? timreaddata :
|
||||
cs3 ? uartreaddata :
|
||||
cs4 ? memreaddata :
|
||||
romreaddata;
|
||||
|
||||
// -----------------------------------------------
|
||||
// Simulation control process
|
||||
// -----------------------------------------------
|
||||
|
||||
always @(posedge clk)
|
||||
begin
|
||||
count <= count + 1;
|
||||
|
||||
// Stop/finish the simulations of timeout or a write to the halt address
|
||||
if (count == `TIMEOUT_COUNT || (write == 1'b1 && address == `HALT_ADDR && writedata[0]))
|
||||
if ((TIMEOUTCOUNT && count == TIMEOUTCOUNT) || (cs6 == 1'b1 && writedata[0]))
|
||||
begin
|
||||
if (count >= `TIMEOUT_COUNT)
|
||||
if (count >= TIMEOUTCOUNT)
|
||||
begin
|
||||
$display("***ERROR: simulation timed out!");
|
||||
end
|
||||
|
|
@ -131,9 +167,9 @@ end
|
|||
|
||||
always @(posedge clk)
|
||||
begin
|
||||
if (write == 1'b1 && address == `INT_ADDR && byteenable[0] == 1'b1)
|
||||
if (cs5 == 1'b1 && byteenable[0] == 1'b1)
|
||||
begin
|
||||
irq <= writedata[0];
|
||||
swirq <= writedata[0];
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -149,32 +185,32 @@ end
|
|||
// Virtual CPU
|
||||
// -----------------------------------------------
|
||||
|
||||
riscVsim #(.USE_HARVARD(USE_HARVARD),
|
||||
.DISABLE_DELTA(DISABLE_DELTA)) cpu
|
||||
(
|
||||
.clk (clk),
|
||||
|
||||
.daddress (address),
|
||||
.dwrite (write),
|
||||
.dwritedata (writedata),
|
||||
.dbyteenable (byteenable),
|
||||
.dread (read),
|
||||
.dreaddata (readdata),
|
||||
.dwaitrequest (read & ~readdatavalid),
|
||||
|
||||
.iaddress (iaddress),
|
||||
.iread (iread),
|
||||
.ireaddata (ireaddata),
|
||||
.iwaitrequest (iread & ~ireaddatavalid),
|
||||
|
||||
.irq (irq)
|
||||
);
|
||||
riscVsim #(.USE_HARVARD (USE_HARVARD),
|
||||
.DISABLE_DELTA (DISABLE_DELTA),
|
||||
.RISCVTEST (RISCVTEST)) cpu
|
||||
(.clk (clk),
|
||||
|
||||
.daddress (address),
|
||||
.dwrite (write),
|
||||
.dwritedata (writedata),
|
||||
.dbyteenable (byteenable),
|
||||
.dread (read),
|
||||
.dreaddata (readdata),
|
||||
.dwaitrequest (read & ~readdatavalid),
|
||||
|
||||
.iaddress (iaddress),
|
||||
.iread (iread),
|
||||
.ireaddata (ireaddata),
|
||||
.iwaitrequest (iread & ~ireaddatavalid),
|
||||
|
||||
.irq (irq)
|
||||
);
|
||||
|
||||
// ---------------------------------------------------------
|
||||
// Memory
|
||||
// ROM
|
||||
// ---------------------------------------------------------
|
||||
|
||||
Mem m (.clk (clk),
|
||||
Mem r (.clk (clk),
|
||||
|
||||
.CS0 (cs0),
|
||||
.A0 (iaddress[15:2]),
|
||||
|
|
@ -188,7 +224,66 @@ end
|
|||
.BE1 (byteenable),
|
||||
.WE1 (write),
|
||||
.DI1 (writedata),
|
||||
.DO1 (readdata)
|
||||
.DO1 (romreaddata)
|
||||
);
|
||||
|
||||
// ---------------------------------------------------------
|
||||
// Memory
|
||||
// ---------------------------------------------------------
|
||||
|
||||
Mem m (.clk (clk),
|
||||
|
||||
.CS0 (1'b0),
|
||||
.A0 (14'h0),
|
||||
.BE0 (4'hf),
|
||||
.WE0 (1'b0),
|
||||
.DI0 (32'h0),
|
||||
.DO0 (),
|
||||
|
||||
.CS1 (cs4),
|
||||
.A1 (address[15:2]),
|
||||
.BE1 (byteenable),
|
||||
.WE1 (write),
|
||||
.DI1 (writedata),
|
||||
.DO1 (memreaddata)
|
||||
);
|
||||
|
||||
// ---------------------------------------------------------
|
||||
// Timer
|
||||
// ---------------------------------------------------------
|
||||
|
||||
mtimer #(.CLKFREQMHZ (CLK_FREQ_MHZ)) timer
|
||||
(
|
||||
.clk (clk),
|
||||
.nreset (reset_n),
|
||||
|
||||
.cs (cs2),
|
||||
.addr (address[3:2]),
|
||||
.wr (write),
|
||||
.wdata (writedata),
|
||||
.rd (read),
|
||||
.rdata (timreaddata),
|
||||
.rvalid (),
|
||||
|
||||
.irq (timirq)
|
||||
);
|
||||
|
||||
// ---------------------------------------------------------
|
||||
// UART
|
||||
// ---------------------------------------------------------
|
||||
|
||||
uart_model console
|
||||
(
|
||||
.clk (clk),
|
||||
.nreset (reset_n),
|
||||
|
||||
.cs (cs3),
|
||||
.addr (address[4:0]),
|
||||
.wr (write),
|
||||
.wdata (writedata),
|
||||
.rd (read),
|
||||
.rdata (uartreaddata),
|
||||
.rvalid ()
|
||||
);
|
||||
|
||||
endmodule
|
||||
|
|
@ -197,7 +292,10 @@ endmodule
|
|||
// Simple dual-port 64K byte memory model with byte enables
|
||||
// =========================================================
|
||||
|
||||
module Mem (
|
||||
module Mem
|
||||
#(parameter MEMWORDS = 16384
|
||||
)
|
||||
(
|
||||
input clk,
|
||||
input WE0,
|
||||
input CS0,
|
||||
|
|
@ -214,7 +312,7 @@ module Mem (
|
|||
output [31:0] DO1
|
||||
);
|
||||
|
||||
reg [31:0] Mem [0:16383];
|
||||
reg [31:0] Mem [0:MEMWORDS-1];
|
||||
|
||||
assign #1 DO0 = Mem[A0];
|
||||
assign #1 DO1 = Mem[A1];
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
../../f_VProc.v
|
||||
mtimer.v
|
||||
uart.v
|
||||
riscVsim.v
|
||||
test.v
|
||||
|
|
|
|||
67
examples/riscv/uart.v
Normal file
67
examples/riscv/uart.v
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
// ====================================================================
|
||||
//
|
||||
// Model to display written data as ASCII characters to console,
|
||||
// as if to a terminal via a UART
|
||||
//
|
||||
// Copyright (c) 2024 Simon Southwell.
|
||||
//
|
||||
// This file is part of VProc.
|
||||
//
|
||||
// VProc is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// VProc is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with VProc. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
// ====================================================================
|
||||
|
||||
module uart_model
|
||||
(
|
||||
input clk,
|
||||
input nreset,
|
||||
|
||||
input cs,
|
||||
input [4:0] addr,
|
||||
input wr,
|
||||
input [31:0] wdata,
|
||||
input rd,
|
||||
output reg [31:0] rdata,
|
||||
output reg rvalid
|
||||
);
|
||||
|
||||
always @(posedge clk or negedge nreset)
|
||||
begin
|
||||
if (nreset == 1'b0)
|
||||
begin
|
||||
rvalid <= 1'b0;
|
||||
end
|
||||
else
|
||||
begin
|
||||
// Update registers
|
||||
if (cs && wr)
|
||||
begin
|
||||
case(addr)
|
||||
5'h00 : $write("%c", wdata[7:0]);
|
||||
default:;
|
||||
endcase
|
||||
end
|
||||
|
||||
// Read registers
|
||||
case (addr)
|
||||
5'h00 : rdata <= 32'hcc;
|
||||
5'h14 : rdata <= 32'h20;
|
||||
default: rdata <= 32'h0;
|
||||
endcase
|
||||
|
||||
rvalid <= (rd & ~rvalid);
|
||||
end
|
||||
end
|
||||
|
||||
endmodule
|
||||
|
|
@ -1 +1,2 @@
|
|||
vusermain0 -rbH -D disassem.log -t ./interrupt/test.exe
|
||||
#vusermain0 -T -t ./main.exe
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue