mirror of
https://github.com/openhwgroup/cvw
synced 2025-02-03 10:15:19 +00:00
Merge branch 'main' of github.com:openhwgroup/cvw into boot
This commit is contained in:
commit
3e5b082e66
21
README.md
21
README.md
@ -56,7 +56,7 @@ Run a regression simulation with Questa to prove everything is installed.
|
||||
$ cd pipelined/regression
|
||||
$ ./regression-wally (depends on having Questa installed)
|
||||
|
||||
# Tool-chain Installation (Sys Admin)
|
||||
# Toolchain Installation (Sys Admin)
|
||||
|
||||
This section describes the open source toolchain installation. These steps should only be done once by the system admin.
|
||||
|
||||
@ -67,9 +67,9 @@ The script installs the open source tools to /opt/riscv by default. This can be
|
||||
|
||||
$ sudo wally-tool-chain-install.sh <optional, install directory, defaults to /opt/riscv>
|
||||
|
||||
## Detailed Tool-chain Install Guide
|
||||
## Detailed Toolchain Install Guide
|
||||
|
||||
Section 2.1 described Wally platform requirements and Section 2.2 describes how a user gets started using Wally on a Linux server. This appendix describes how the system administrator installs RISC-V tools. Superuser privileges are necessary for many of the tools. Setting up all of the tools can be time-consuming and fussy, so this appendix also describes a fallback flow with Docker and Podman.
|
||||
This section describes how to install the tools needed for CORE-V-Wally. Superuser privileges are necessary for many of the tools. Setting up all of the tools can be time-consuming and fussy, so Appendix D also describes an option with a Docker container.
|
||||
|
||||
### Open Source Software Installation
|
||||
|
||||
@ -102,11 +102,11 @@ First, set up a directory for riscv software in some place such as /opt/riscv.
|
||||
|
||||
### Update Tools
|
||||
|
||||
Ubuntu users may need to install and update various tools.
|
||||
Ubuntu users may need to install and update various tools. Beware when cutting and pasting that some lines are long!
|
||||
|
||||
$ sudo apt update
|
||||
$ sudo apt upgrade
|
||||
$ sudo apt install git gawk make texinfo bison flex build-essential python libz-dev libexpat-dev autoconf device-tree-compiler ninja-build libglib2.56-dev libpixman-1-dev build-essential ncurses-base ncurses-bin libncurses5-dev dialog
|
||||
$ sudo apt install git gawk make texinfo bison flex build-essential python3 zlib1g-dev libexpat-dev autoconf device-tree-compiler ninja-build libglib2.0-dev libpixman-1-dev build-essential ncurses-base ncurses-bin libncurses5-dev dialog
|
||||
|
||||
### Install RISC-V GCC Cross-Compiler
|
||||
|
||||
@ -265,6 +265,17 @@ For logic synthesis, we need a synthesis tool (see Section 3.XREF) and a cell li
|
||||
$ cd cad/lib
|
||||
$ git clone https://foss-eda-tools.googlesource.com/skywater-pdk/libs/sky130_osu_sc_t12
|
||||
|
||||
### Install github cli
|
||||
|
||||
The github cli allows users to directly issue pull requests from their fork back to openhwgroup/cvw using the command line.
|
||||
|
||||
$ type -p curl >/dev/null || sudo apt install curl -y
|
||||
$ curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg \ && sudo chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg \
|
||||
&& echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null \
|
||||
&& sudo apt update \
|
||||
&& sudo apt install gh -y
|
||||
|
||||
|
||||
## Installing EDA Tools
|
||||
|
||||
Electronic Design Automation (EDA) tools are vital to implementations of System on Chip architectures as well as validating different designs. Open-source and commercial tools exist for multiple strategies and although the one can spend a lifetime using combinations of different tools, only a small subset of tools is utilized for this text. The tools are chosen because of their ease in access as well as their repeatability for accomplishing many of the tasks utilized to design Wally. It is anticipated that additional tools may be documented later after this is text is published to improve use and access.
|
||||
|
107
addins/docker/Dockerfile
Executable file
107
addins/docker/Dockerfile
Executable file
@ -0,0 +1,107 @@
|
||||
# Compliance Development Environment Image
|
||||
FROM debian
|
||||
|
||||
# UPDATE / UPGRADE
|
||||
RUN apt update
|
||||
|
||||
# INSTALL
|
||||
RUN apt install -y git gawk make texinfo bison flex build-essential python libz-dev libexpat-dev autoconf device-tree-compiler ninja-build libpixman-1-dev build-essential ncurses-base ncurses-bin libncurses5-dev dialog curl wget ftp libgmp-dev python3-pip pkg-config libglib2.0-dev opam build-essential z3 pkg-config zlib1g-dev verilator cpio bc vim emacs gedit nano
|
||||
|
||||
RUN pip3 install chardet==3.0.4
|
||||
RUN pip3 install urllib3==1.22
|
||||
RUN pip3 install testresources
|
||||
RUN pip3 install riscof --ignore-installed PyYAML
|
||||
RUN echo "root:wally" | chpasswd
|
||||
|
||||
# ADD RISCV
|
||||
WORKDIR /opt/riscv
|
||||
|
||||
# Create a user group 'xyzgroup'
|
||||
ARG USERNAME=cad
|
||||
ARG USER_UID=1000
|
||||
ARG USER_GID=$USER_UID
|
||||
|
||||
# Create the user
|
||||
RUN groupadd --gid $USER_GID $USERNAME \
|
||||
&& useradd --uid $USER_UID --gid $USER_GID -m $USERNAME \
|
||||
# [Optional] Add sudo support. Omit if you don't need to install software after connecting.
|
||||
&& apt-get update \
|
||||
&& apt-get install -y sudo \
|
||||
&& echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \
|
||||
&& chmod 0440 /etc/sudoers.d/$USERNAME
|
||||
|
||||
# Change RISCV user
|
||||
run chown -Rf cad:cad /opt
|
||||
|
||||
# Add cad user
|
||||
USER $USERNAME
|
||||
|
||||
# SET ENVIRONMENT VARIABLES
|
||||
ENV RISCV=/opt/riscv
|
||||
ENV PATH=$PATH:$RISCV/bin
|
||||
|
||||
# TOOLCHAIN
|
||||
RUN git clone https://github.com/riscv/riscv-gnu-toolchain && \
|
||||
cd riscv-gnu-toolchain && \
|
||||
./configure --prefix=${RISCV} --enable-multilib --with-multilib-generator="rv32e-ilp32e--;rv32i-ilp32--;rv32im-ilp32--;rv32iac-ilp32--;rv32imac-ilp32--;rv32imafc-ilp32f--;rv32imafdc-ilp32d--;rv64i-lp64--;rv64ic-lp64--;rv64iac-lp64--;rv64imac-lp64--;rv64imafdc-lp64d--;rv64im-lp64--;" && \
|
||||
make --jobs && \
|
||||
make install
|
||||
|
||||
# elf2hex
|
||||
ENV PATH=$RISCV/riscv-gnu-toolchain/bin:$PATH
|
||||
WORKDIR /opt/riscv
|
||||
RUN git clone https://github.com/sifive/elf2hex.git && \
|
||||
cd elf2hex && \
|
||||
autoreconf -i && \
|
||||
./configure --target=riscv64-unknown-elf --prefix=$RISCV && \
|
||||
make && \
|
||||
make install
|
||||
|
||||
# QEMU
|
||||
WORKDIR /opt/riscv
|
||||
RUN git clone --recurse-submodules https://github.com/qemu/qemu && \
|
||||
cd qemu && \
|
||||
./configure --target-list=riscv64-softmmu --prefix=$RISCV && \
|
||||
make --jobs && \
|
||||
make install
|
||||
|
||||
# Spike
|
||||
WORKDIR /opt/riscv
|
||||
RUN git clone https://github.com/riscv-software-src/riscv-isa-sim && \
|
||||
mkdir riscv-isa-sim/build && \
|
||||
cd riscv-isa-sim/build && \
|
||||
../configure --prefix=$RISCV --enable-commitlog && \
|
||||
make --jobs && \
|
||||
make install && \
|
||||
cd ../arch_test_target/spike/device && \
|
||||
sed -i 's/--isa=rv32ic/--isa=rv32iac/' rv32i_m/privilege/Makefile.include && \
|
||||
sed -i 's/--isa=rv64ic/--isa=rv64iac/' rv64i_m/privilege/Makefile.include
|
||||
|
||||
# SAIL
|
||||
WORKDIR /opt/riscv
|
||||
RUN opam init -y --disable-sandboxing
|
||||
RUN opam switch create ocaml-base-compiler.4.06.1
|
||||
RUN opam install sail -y
|
||||
RUN eval $(opam config env) && \
|
||||
cd $RISCV && \
|
||||
git clone https://github.com/riscv/sail-riscv.git && \
|
||||
cd sail-riscv && \
|
||||
make && \
|
||||
ARCH=RV32 make && \
|
||||
ARCH=RV64 make && \
|
||||
ln -s $RISCV/sail-riscv/c_emulator/riscv_sim_RV64 $RISCV/bin/riscv_sim_RV64 && \
|
||||
ln -s $RISCV/sail-riscv/c_emulator/riscv_sim_RV32 $RISCV/bin/riscv_sim_RV32
|
||||
|
||||
# Buildroot
|
||||
WORKDIR /opt/riscv
|
||||
RUN git clone --recurse-submodules https://github.com/openhwgroup/cvw.git
|
||||
ENV export WALLY=/opt/riscv/riscv-wally
|
||||
RUN git clone https://github.com/buildroot/buildroot.git && \
|
||||
cd buildroot && \
|
||||
git checkout 2021.05 && \
|
||||
cp -r /opt/riscv/riscv-wally/linux/buildroot-config-src/wally ./board && \
|
||||
cp ./board/wally/main.config .config && \
|
||||
make --jobs
|
||||
|
||||
# change to cad's hometown
|
||||
WORKDIR /home/cad
|
48
addins/docker/README.md
Normal file
48
addins/docker/README.md
Normal file
@ -0,0 +1,48 @@
|
||||
Installing Wally, RISC-V tools, and Imperas tests from source gives you maximum control, but has several disadvantages:
|
||||
|
||||
-Building the executables takes several hours.
|
||||
-Linux is poorly standardized, and the build steps might not work on your version
|
||||
-The source files are constantly changing, and the versions you download might not be compatible with this textbook flow.
|
||||
|
||||
Docker is a tools to run applications in a prepackaged container
|
||||
including all of the operating system support required. Wally offers
|
||||
a ~30GB container image with the open-source tools pre-installed from
|
||||
Section D.1. In particular, using the container solves the long build
|
||||
time for gcc and the fussy installation of sail. The container runs on
|
||||
any platform supporting Docker, including Windows and Mac as well as
|
||||
Linux. It can access files outside the container, including local
|
||||
installation of CAD tools such as Questa, and a local clone of the
|
||||
core-v-wally repository.
|
||||
|
||||
Docker can be run on most operating systems, including Linux, Windows,
|
||||
and Mac. The Wally Docker container is hosted at DockerHub
|
||||
(http://docker.io).
|
||||
|
||||
Podman is a more secure and easier-to-use variation of Docker for
|
||||
Linux developed by RedHat. Both Docker and Podman run the same
|
||||
containers.
|
||||
|
||||
This directory has a copy of the file utilized to create the Docker
|
||||
for the toolchain discussed in the text. To build this docker, you can
|
||||
type the following where the last argument is the name where you want
|
||||
to store your docker.
|
||||
|
||||
docker build -t docker.io/wallysoc/wally-docker:latest .
|
||||
|
||||
This can also be changed if you make a mistake by using the tag
|
||||
command. For example, if I wanted to change my docker from
|
||||
wally-docker to wally-docker2, I would type:
|
||||
|
||||
docker tag wallysoc/wally-docker:latest docker.io/wallysoc/wally-docker2:latest
|
||||
|
||||
Once you build your docker, you can run it as given in the Readme.
|
||||
However, you can also push it to DockerHub with the following command.
|
||||
|
||||
docker push docker.io/wallysoc/wally-docker:latest
|
||||
|
||||
To run your docker, you can type the following at a command prompt or
|
||||
terminal.
|
||||
|
||||
docker run -it -p 8080:8080 docker.io/wallysoc/wally-docker
|
||||
|
||||
|
53
gitflow.txt
Normal file
53
gitflow.txt
Normal file
@ -0,0 +1,53 @@
|
||||
###########################################
|
||||
## A component of the CORE-V-WALLY configurable RISC-V project.
|
||||
##
|
||||
## Copyright (C) 2021-23 Harvey Mudd College & Oklahoma State University
|
||||
##
|
||||
## 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.
|
||||
################################################################################################
|
||||
|
||||
Setup
|
||||
1. goto github and fork openhwgroup/cvw.git
|
||||
2. clone: git clone --recurse-submodules git@ross144/cvw.git
|
||||
3. git remote add upstream https://github.com/openhwgroup/cvw.git
|
||||
4. install gh (github command line interface)
|
||||
type -p curl >/dev/null || sudo apt install curl -y
|
||||
curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg \
|
||||
&& sudo chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg \
|
||||
&& echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null \
|
||||
&& sudo apt update \
|
||||
&& sudo apt install gh -y
|
||||
|
||||
Once per session (This authorizes gh to use your github account)
|
||||
1. gh auth login
|
||||
2. Use ssh and point to your public key
|
||||
3. Copy one-time code from terminal to browser
|
||||
|
||||
Fetch upstream and sync fork
|
||||
1. git fetch upstream # fetch the upstream openhwgroup/cvw into your local clone
|
||||
2. git merge upstream/main # merge the upstream openhwgroup/cvw into your local clone
|
||||
3. git push # pushes changes back to your fork. Now all three should be in sync
|
||||
|
||||
Create pull request
|
||||
1. git fetch upstream # fetch the upstream openhwgroup/cvw into your local clone
|
||||
2. git merge upstream/main # merge the upstream openhwgroup/cvw into your local clone
|
||||
3. git push # pushes changes back to your fork. Now all three should be in sync
|
||||
4. gh pr create # Create a pull request.
|
||||
5. Must include a title and strongly encourage a body message explaining your changes.
|
||||
6. Wait for pull request to be approved, rejected, or needs changes.
|
||||
7. Finish by fetching the upstream and pushing back to your fork.
|
||||
1. git fetch upstream
|
||||
2. git merge upstream/main # sync your clone with the upstream
|
||||
3. git push # sync your fork with the upstream and clone
|
||||
|
@ -66,8 +66,6 @@ module ebu (
|
||||
output logic HMASTLOCK // AHB master lock. Wally does not use
|
||||
);
|
||||
|
||||
typedef enum logic [1:0] {IDLE, ARBITRATE} statetype;
|
||||
statetype CurrState, NextState;
|
||||
|
||||
logic LSUDisable;
|
||||
logic LSUSelect;
|
||||
@ -75,7 +73,6 @@ module ebu (
|
||||
logic IFURestore;
|
||||
logic IFUDisable;
|
||||
logic IFUSelect;
|
||||
logic both; // Both the LSU and IFU request at the same time
|
||||
|
||||
logic [`PA_BITS-1:0] IFUHADDROut;
|
||||
logic [1:0] IFUHTRANSOut;
|
||||
@ -92,12 +89,6 @@ module ebu (
|
||||
logic IFUReq;
|
||||
logic LSUReq;
|
||||
|
||||
logic BeatCntEn;
|
||||
logic [4-1:0] NextBeatCount, BeatCount; // Position within a burst transfer
|
||||
logic FinalBeat, FinalBeatD; // Indicates the last beat of a burst
|
||||
logic CntReset;
|
||||
logic [3:0] Threshold; // Number of beats derived from HBURST
|
||||
logic IFUReqD; // 1 cycle delayed IFU request. Part of arbitration
|
||||
|
||||
|
||||
assign HCLK = clk;
|
||||
@ -137,66 +128,9 @@ module ebu (
|
||||
assign HWSTRB = LSUHWSTRB;
|
||||
// HRDATA is sent to all controllers at the core level.
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Aribtration scheme
|
||||
// FSM decides if arbitration needed. Arbitration is held until the last beat of
|
||||
// a burst is completed.
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
assign both = LSUReq & IFUReq;
|
||||
flopenl #(.TYPE(statetype)) busreg(HCLK, ~HRESETn, 1'b1, NextState, IDLE, CurrState);
|
||||
always_comb
|
||||
case (CurrState)
|
||||
IDLE: if (both) NextState = ARBITRATE;
|
||||
else NextState = IDLE;
|
||||
ARBITRATE: if (HREADY & FinalBeatD & ~(LSUReq & IFUReq)) NextState = IDLE;
|
||||
else NextState = ARBITRATE;
|
||||
default: NextState = IDLE;
|
||||
endcase
|
||||
|
||||
// basic arb always selects LSU when both
|
||||
// replace this block for more sophisticated arbitration as needed.
|
||||
// Controller 0 (IFU)
|
||||
assign IFUSave = CurrState == IDLE & both;
|
||||
assign IFURestore = CurrState == ARBITRATE;
|
||||
assign IFUDisable = CurrState == ARBITRATE;
|
||||
assign IFUSelect = (NextState == ARBITRATE) ? 1'b0 : IFUReq;
|
||||
// Controller 1 (LSU)
|
||||
// When both the IFU and LSU request at the same time, the FSM will go into the arbitrate state.
|
||||
// Once the LSU request is done the fsm returns to IDLE. To prevent the LSU from regaining
|
||||
// priority and re issuing the same memroy operation, the delayed IFUReqD squashes the LSU request.
|
||||
// This is necessary because the pipeline is stalled for the entire duration of both transactions,
|
||||
// and the LSU memory request will stil be active.
|
||||
flopr #(1) ifureqreg(clk, ~HRESETn, IFUReq, IFUReqD);
|
||||
assign LSUDisable = CurrState == ARBITRATE ? 1'b0 : (IFUReqD & ~(HREADY & FinalBeatD));
|
||||
assign LSUSelect = NextState == ARBITRATE ? 1'b1: LSUReq;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Burst mode logic
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
flopenr #(4) BeatCountReg(HCLK, ~HRESETn | CntReset | FinalBeat, BeatCntEn, NextBeatCount, BeatCount);
|
||||
assign NextBeatCount = BeatCount + 1'b1;
|
||||
|
||||
assign CntReset = NextState == IDLE;
|
||||
assign FinalBeat = (BeatCount == Threshold); // Detect when we are waiting on the final access.
|
||||
assign BeatCntEn = (NextState == ARBITRATE & HREADY);
|
||||
|
||||
// Used to store data from data phase of AHB.
|
||||
flopenr #(1) FinalBeatReg(HCLK, ~HRESETn | CntReset, BeatCntEn, FinalBeat, FinalBeatD);
|
||||
|
||||
// unlike the bus fsm in lsu/ifu, we need to derive the number of beats from HBURST.
|
||||
always_comb begin
|
||||
case(HBURST)
|
||||
0: Threshold = 4'b0000;
|
||||
3: Threshold = 4'b0011; // INCR4
|
||||
5: Threshold = 4'b0111; // INCR8
|
||||
7: Threshold = 4'b1111; // INCR16
|
||||
default: Threshold = 4'b0000; // INCR without end.
|
||||
endcase
|
||||
end
|
||||
|
||||
|
||||
ebufsmarb ebufsmarb(.HCLK, .HRESETn, .HBURST, .HREADY, .LSUReq, .IFUReq, .IFUSave,
|
||||
.IFURestore, .IFUDisable, .IFUSelect, .LSUDisable, .LSUSelect);
|
||||
|
||||
endmodule
|
||||
|
||||
|
||||
|
121
pipelined/src/ebu/ebuarbfsm.sv
Normal file
121
pipelined/src/ebu/ebuarbfsm.sv
Normal file
@ -0,0 +1,121 @@
|
||||
///////////////////////////////////////////
|
||||
// ebufsmarb
|
||||
//
|
||||
// Written: Ross Thompson ross1728@gmail.com
|
||||
// Created: 23 January 2023
|
||||
// Modified: 23 January 2023
|
||||
//
|
||||
// Purpose: Arbitrates requests from instruction and data streams
|
||||
// LSU has priority.
|
||||
//
|
||||
// Documentation: RISC-V System on Chip Design Chapter 6 (Figures 6.25 and 6.26)
|
||||
//
|
||||
// A component of the CORE-V-WALLY configurable RISC-V project.
|
||||
//
|
||||
// Copyright (C) 2021-23 Harvey Mudd College & Oklahoma State University
|
||||
//
|
||||
// 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.
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
`include "wally-config.vh"
|
||||
|
||||
module ebufsmarb (
|
||||
input logic HCLK,
|
||||
input logic HRESETn,
|
||||
input logic [2:0] HBURST,
|
||||
// AHB burst length
|
||||
|
||||
input logic HREADY,
|
||||
|
||||
input logic LSUReq,
|
||||
input logic IFUReq,
|
||||
|
||||
|
||||
output logic IFUSave,
|
||||
output logic IFURestore,
|
||||
output logic IFUDisable,
|
||||
output logic IFUSelect,
|
||||
output logic LSUDisable,
|
||||
output logic LSUSelect);
|
||||
|
||||
typedef enum logic [1:0] {IDLE, ARBITRATE} statetype;
|
||||
statetype CurrState, NextState;
|
||||
|
||||
logic both; // Both the LSU and IFU request at the same time
|
||||
logic IFUReqD; // 1 cycle delayed IFU request. Part of arbitration
|
||||
logic FinalBeat, FinalBeatD; // Indicates the last beat of a burst
|
||||
logic BeatCntEn;
|
||||
logic [4-1:0] NextBeatCount, BeatCount; // Position within a burst transfer
|
||||
logic CntReset;
|
||||
logic [3:0] Threshold; // Number of beats derived from HBURST
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Aribtration scheme
|
||||
// FSM decides if arbitration needed. Arbitration is held until the last beat of
|
||||
// a burst is completed.
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
assign both = LSUReq & IFUReq;
|
||||
flopenl #(.TYPE(statetype)) busreg(HCLK, ~HRESETn, 1'b1, NextState, IDLE, CurrState);
|
||||
always_comb
|
||||
case (CurrState)
|
||||
IDLE: if (both) NextState = ARBITRATE;
|
||||
else NextState = IDLE;
|
||||
ARBITRATE: if (HREADY & FinalBeatD & ~(LSUReq & IFUReq)) NextState = IDLE;
|
||||
else NextState = ARBITRATE;
|
||||
default: NextState = IDLE;
|
||||
endcase
|
||||
|
||||
// basic arb always selects LSU when both
|
||||
// replace this block for more sophisticated arbitration as needed.
|
||||
// Controller 0 (IFU)
|
||||
assign IFUSave = CurrState == IDLE & both;
|
||||
assign IFURestore = CurrState == ARBITRATE;
|
||||
assign IFUDisable = CurrState == ARBITRATE;
|
||||
assign IFUSelect = (NextState == ARBITRATE) ? 1'b0 : IFUReq;
|
||||
// Controller 1 (LSU)
|
||||
// When both the IFU and LSU request at the same time, the FSM will go into the arbitrate state.
|
||||
// Once the LSU request is done the fsm returns to IDLE. To prevent the LSU from regaining
|
||||
// priority and re issuing the same memroy operation, the delayed IFUReqD squashes the LSU request.
|
||||
// This is necessary because the pipeline is stalled for the entire duration of both transactions,
|
||||
// and the LSU memory request will stil be active.
|
||||
flopr #(1) ifureqreg(HCLK, ~HRESETn, IFUReq, IFUReqD);
|
||||
assign LSUDisable = CurrState == ARBITRATE ? 1'b0 : (IFUReqD & ~(HREADY & FinalBeatD));
|
||||
assign LSUSelect = NextState == ARBITRATE ? 1'b1: LSUReq;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Burst mode logic
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
flopenr #(4) BeatCountReg(HCLK, ~HRESETn | CntReset | FinalBeat, BeatCntEn, NextBeatCount, BeatCount);
|
||||
assign NextBeatCount = BeatCount + 1'b1;
|
||||
|
||||
assign CntReset = NextState == IDLE;
|
||||
assign FinalBeat = (BeatCount == Threshold); // Detect when we are waiting on the final access.
|
||||
assign BeatCntEn = (NextState == ARBITRATE & HREADY);
|
||||
|
||||
// Used to store data from data phase of AHB.
|
||||
flopenr #(1) FinalBeatReg(HCLK, ~HRESETn | CntReset, BeatCntEn, FinalBeat, FinalBeatD);
|
||||
|
||||
// unlike the bus fsm in lsu/ifu, we need to derive the number of beats from HBURST.
|
||||
always_comb begin
|
||||
case(HBURST)
|
||||
0: Threshold = 4'b0000;
|
||||
3: Threshold = 4'b0011; // INCR4
|
||||
5: Threshold = 4'b0111; // INCR8
|
||||
7: Threshold = 4'b1111; // INCR16
|
||||
default: Threshold = 4'b0000; // INCR without end.
|
||||
endcase
|
||||
end
|
||||
endmodule
|
@ -31,21 +31,23 @@
|
||||
`include "wally-config.vh"
|
||||
|
||||
module lrsc(
|
||||
input logic clk, reset,
|
||||
input logic clk,
|
||||
input logic reset,
|
||||
input logic StallW,
|
||||
input logic MemReadM,
|
||||
input logic [1:0] PreLSURWM,
|
||||
output logic [1:0] LSURWM,
|
||||
input logic [1:0] LSUAtomicM,
|
||||
input logic [`PA_BITS-1:0] PAdrM, // from mmu to dcache
|
||||
output logic SquashSCW
|
||||
input logic MemReadM, // Memory read
|
||||
input logic [1:0] PreLSURWM, // Memory operation from the HPTW or IEU [1]: read, [0]: write
|
||||
output logic [1:0] LSURWM, // Memory operation after potential squash of SC
|
||||
input logic [1:0] LSUAtomicM, // Atomic memory operaiton
|
||||
input logic [`PA_BITS-1:0] PAdrM, // Physical memory address
|
||||
output logic SquashSCW // Squash the store conditional by not allowing rf write
|
||||
);
|
||||
|
||||
// possible bug: *** double check if PreLSURWM needs to be flushed by ignorerequest.
|
||||
// Handle atomic load reserved / store conditional
|
||||
logic [`PA_BITS-1:2] ReservationPAdrW;
|
||||
logic ReservationValidM, ReservationValidW;
|
||||
logic lrM, scM, WriteAdrMatchM;
|
||||
logic SquashSCM;
|
||||
logic [`PA_BITS-1:2] ReservationPAdrW;
|
||||
logic ReservationValidM, ReservationValidW;
|
||||
logic lrM, scM, WriteAdrMatchM;
|
||||
logic SquashSCM;
|
||||
|
||||
assign lrM = MemReadM & LSUAtomicM[0];
|
||||
assign scM = PreLSURWM[0] & LSUAtomicM[0];
|
||||
|
@ -32,107 +32,107 @@
|
||||
`include "wally-config.vh"
|
||||
|
||||
module lsu (
|
||||
input logic clk, reset,
|
||||
input logic StallM, FlushM, StallW, FlushW,
|
||||
output logic LSUStallM, // LSU stalls pipeline during a multicycle operation
|
||||
input logic clk, reset,
|
||||
input logic StallM, FlushM, StallW, FlushW,
|
||||
output logic LSUStallM, // LSU stalls pipeline during a multicycle operation
|
||||
// connected to cpu (controls)
|
||||
input logic [1:0] MemRWM, // Read/Write control
|
||||
input logic [2:0] Funct3M, // Size of memory operation
|
||||
input logic [6:0] Funct7M, // Atomic memory operation function
|
||||
input logic [1:0] AtomicM, // Atomic memory operation
|
||||
input logic FlushDCacheM, // Flush D cache to next level of memory
|
||||
output logic CommittedM, // Delay interrupts while memory operation in flight
|
||||
output logic SquashSCW, // Store conditional failed disable write to GPR
|
||||
output logic DCacheMiss, // D cache miss for performance counters
|
||||
output logic DCacheAccess, // D cache memory access for performance counters
|
||||
input logic [1:0] MemRWM, // Read/Write control
|
||||
input logic [2:0] Funct3M, // Size of memory operation
|
||||
input logic [6:0] Funct7M, // Atomic memory operation function
|
||||
input logic [1:0] AtomicM, // Atomic memory operation
|
||||
input logic FlushDCacheM, // Flush D cache to next level of memory
|
||||
output logic CommittedM, // Delay interrupts while memory operation in flight
|
||||
output logic SquashSCW, // Store conditional failed disable write to GPR
|
||||
output logic DCacheMiss, // D cache miss for performance counters
|
||||
output logic DCacheAccess, // D cache memory access for performance counters
|
||||
// address and write data
|
||||
input logic [`XLEN-1:0] IEUAdrE, // Execution stage memory address
|
||||
output logic [`XLEN-1:0] IEUAdrM, // Memory stage memory address
|
||||
input logic [`XLEN-1:0] WriteDataM, // Write data from IEU
|
||||
output logic [`LLEN-1:0] ReadDataW, // Read data to IEU or FPU
|
||||
input logic [`XLEN-1:0] IEUAdrE, // Execution stage memory address
|
||||
output logic [`XLEN-1:0] IEUAdrM, // Memory stage memory address
|
||||
input logic [`XLEN-1:0] WriteDataM, // Write data from IEU
|
||||
output logic [`LLEN-1:0] ReadDataW, // Read data to IEU or FPU
|
||||
// cpu privilege
|
||||
input logic [1:0] PrivilegeModeW, // Current privilege mode
|
||||
input logic BigEndianM, // Swap byte order to big endian
|
||||
input logic sfencevmaM, // Virtual memory address fence, invalidate TLB entries
|
||||
input logic [1:0] PrivilegeModeW, // Current privilege mode
|
||||
input logic BigEndianM, // Swap byte order to big endian
|
||||
input logic sfencevmaM, // Virtual memory address fence, invalidate TLB entries
|
||||
// fpu
|
||||
input logic [`FLEN-1:0] FWriteDataM, // Write data from FPU
|
||||
input logic FpLoadStoreM, // Selects FPU as store for write data
|
||||
input logic [`FLEN-1:0] FWriteDataM, // Write data from FPU
|
||||
input logic FpLoadStoreM, // Selects FPU as store for write data
|
||||
// faults
|
||||
output logic LoadPageFaultM, StoreAmoPageFaultM, // Page fault exceptions
|
||||
output logic LoadMisalignedFaultM, // Load address misaligned fault
|
||||
output logic LoadAccessFaultM, // Load access fault (PMA)
|
||||
output logic HPTWInstrAccessFaultM, // HPTW generated access fault during instruction fetch
|
||||
output logic LoadPageFaultM, StoreAmoPageFaultM, // Page fault exceptions
|
||||
output logic LoadMisalignedFaultM, // Load address misaligned fault
|
||||
output logic LoadAccessFaultM, // Load access fault (PMA)
|
||||
output logic HPTWInstrAccessFaultM, // HPTW generated access fault during instruction fetch
|
||||
// cpu hazard unit (trap)
|
||||
output logic StoreAmoMisalignedFaultM, // Store or AMO address misaligned fault
|
||||
output logic StoreAmoAccessFaultM, // Store or AMO access fault
|
||||
// connect to ahb
|
||||
output logic [`PA_BITS-1:0] LSUHADDR, // Bus address from LSU to EBU
|
||||
input logic [`XLEN-1:0] HRDATA, // Bus read data from LSU to EBU
|
||||
output logic [`XLEN-1:0] LSUHWDATA, // Bus write data from LSU to EBU
|
||||
input logic LSUHREADY, // Bus ready from LSU to EBU
|
||||
output logic LSUHWRITE, // Bus write operation from LSU to EBU
|
||||
output logic [2:0] LSUHSIZE, // Bus operation size from LSU to EBU
|
||||
output logic [2:0] LSUHBURST, // Bus burst from LSU to EBU
|
||||
output logic [1:0] LSUHTRANS, // Bus transaction type from LSU to EBU
|
||||
output logic [`XLEN/8-1:0] LSUHWSTRB, // Bus byte write enables from LSU to EBU
|
||||
// page table walker
|
||||
input logic [`XLEN-1:0] SATP_REGW, // SATP (supervisor address translation and protection) CSR
|
||||
input logic STATUS_MXR, STATUS_SUM, STATUS_MPRV, // STATUS CSR bits: make executable readable, supervisor user memory, machine privilege
|
||||
input logic [1:0] STATUS_MPP, // Machine previous privilege mode
|
||||
input logic [`XLEN-1:0] PCF, // Fetch PC
|
||||
input logic ITLBMissF, // ITLB miss causes HPTW (hardware pagetable walker) walk
|
||||
input logic InstrDAPageFaultF, // ITLB hit needs to update dirty or access bits
|
||||
output logic [`XLEN-1:0] PTE, // Page table entry write to ITLB
|
||||
output logic [1:0] PageType, // Type of page table entry to write to ITLB
|
||||
output logic ITLBWriteF, // Write PTE to ITLB
|
||||
output logic SelHPTW, // During a HPTW walk the effective privilege mode becomes S_MODE
|
||||
input var logic [7:0] PMPCFG_ARRAY_REGW[`PMP_ENTRIES-1:0], // PMP configuration from privileged unit
|
||||
output logic StoreAmoMisalignedFaultM, // Store or AMO address misaligned fault
|
||||
output logic StoreAmoAccessFaultM, // Store or AMO access fault
|
||||
// connect to ahb
|
||||
output logic [`PA_BITS-1:0] LSUHADDR, // Bus address from LSU to EBU
|
||||
input logic [`XLEN-1:0] HRDATA, // Bus read data from LSU to EBU
|
||||
output logic [`XLEN-1:0] LSUHWDATA, // Bus write data from LSU to EBU
|
||||
input logic LSUHREADY, // Bus ready from LSU to EBU
|
||||
output logic LSUHWRITE, // Bus write operation from LSU to EBU
|
||||
output logic [2:0] LSUHSIZE, // Bus operation size from LSU to EBU
|
||||
output logic [2:0] LSUHBURST, // Bus burst from LSU to EBU
|
||||
output logic [1:0] LSUHTRANS, // Bus transaction type from LSU to EBU
|
||||
output logic [`XLEN/8-1:0] LSUHWSTRB, // Bus byte write enables from LSU to EBU
|
||||
// page table walker
|
||||
input logic [`XLEN-1:0] SATP_REGW, // SATP (supervisor address translation and protection) CSR
|
||||
input logic STATUS_MXR, STATUS_SUM, STATUS_MPRV, // STATUS CSR bits: make executable readable, supervisor user memory, machine privilege
|
||||
input logic [1:0] STATUS_MPP, // Machine previous privilege mode
|
||||
input logic [`XLEN-1:0] PCF, // Fetch PC
|
||||
input logic ITLBMissF, // ITLB miss causes HPTW (hardware pagetable walker) walk
|
||||
input logic InstrDAPageFaultF, // ITLB hit needs to update dirty or access bits
|
||||
output logic [`XLEN-1:0] PTE, // Page table entry write to ITLB
|
||||
output logic [1:0] PageType, // Type of page table entry to write to ITLB
|
||||
output logic ITLBWriteF, // Write PTE to ITLB
|
||||
output logic SelHPTW, // During a HPTW walk the effective privilege mode becomes S_MODE
|
||||
input var logic [7:0] PMPCFG_ARRAY_REGW[`PMP_ENTRIES-1:0], // PMP configuration from privileged unit
|
||||
input var logic [`XLEN-1:0] PMPADDR_ARRAY_REGW[`PMP_ENTRIES-1:0] // PMP address from privileged unit
|
||||
);
|
||||
|
||||
logic [`XLEN+1:0] IEUAdrExtM; // Memory stage address zero-extended to PA_BITS or XLEN whichever is longer
|
||||
logic [`XLEN+1:0] IEUAdrExtE; // Execution stage address zero-extended to PA_BITS or XLEN whichever is longer
|
||||
logic [`PA_BITS-1:0] PAdrM; // Physical memory address
|
||||
logic [`XLEN+1:0] IHAdrM; // Either IEU or HPTW memory address
|
||||
logic [`XLEN+1:0] IEUAdrExtM; // Memory stage address zero-extended to PA_BITS or XLEN whichever is longer
|
||||
logic [`XLEN+1:0] IEUAdrExtE; // Execution stage address zero-extended to PA_BITS or XLEN whichever is longer
|
||||
logic [`PA_BITS-1:0] PAdrM; // Physical memory address
|
||||
logic [`XLEN+1:0] IHAdrM; // Either IEU or HPTW memory address
|
||||
|
||||
logic [1:0] PreLSURWM; // IEU or HPTW Read/Write signal
|
||||
logic [1:0] LSURWM; // IEU or HPTW Read/Write signal gated by LR/SC
|
||||
logic [2:0] LSUFunct3M; // IEU or HPTW memory operation size
|
||||
logic [6:0] LSUFunct7M; // AMO function gated by HPTW
|
||||
logic [1:0] LSUAtomicM; // AMO signal gated by HPTW
|
||||
logic [1:0] PreLSURWM; // IEU or HPTW Read/Write signal
|
||||
logic [1:0] LSURWM; // IEU or HPTW Read/Write signal gated by LR/SC
|
||||
logic [2:0] LSUFunct3M; // IEU or HPTW memory operation size
|
||||
logic [6:0] LSUFunct7M; // AMO function gated by HPTW
|
||||
logic [1:0] LSUAtomicM; // AMO signal gated by HPTW
|
||||
|
||||
logic GatedStallW; // Hazard unit StallW gated when SelHPTW = 1
|
||||
logic GatedStallW; // Hazard unit StallW gated when SelHPTW = 1
|
||||
|
||||
logic DCacheStallM; // D$ busy with multicycle operation
|
||||
logic BusStall; // Bus interface busy with multicycle operation
|
||||
logic HPTWStall; // HPTW busy with multicycle operation
|
||||
logic DCacheStallM; // D$ busy with multicycle operation
|
||||
logic BusStall; // Bus interface busy with multicycle operation
|
||||
logic HPTWStall; // HPTW busy with multicycle operation
|
||||
|
||||
logic CacheableM; // PMA indicates memory address is cacheable
|
||||
logic BusCommittedM; // Bus memory operation in flight, delay interrupts
|
||||
logic DCacheCommittedM; // D$ memory operation started, delay interrupts
|
||||
logic CacheableM; // PMA indicates memory address is cacheable
|
||||
logic BusCommittedM; // Bus memory operation in flight, delay interrupts
|
||||
logic DCacheCommittedM; // D$ memory operation started, delay interrupts
|
||||
|
||||
logic [`LLEN-1:0] DTIMReadDataWordM; // DTIM read data
|
||||
logic [`LLEN-1:0] DCacheReadDataWordM; // D$ read data
|
||||
logic [`LLEN-1:0] ReadDataWordMuxM; // DTIM or D$ read data
|
||||
logic [`LLEN-1:0] LittleEndianReadDataWordM; // Endian-swapped read data
|
||||
logic [`LLEN-1:0] ReadDataWordM; // Read data before subword selection
|
||||
logic [`LLEN-1:0] ReadDataM; // Final read data
|
||||
logic [`LLEN-1:0] DTIMReadDataWordM; // DTIM read data
|
||||
logic [`LLEN-1:0] DCacheReadDataWordM; // D$ read data
|
||||
logic [`LLEN-1:0] ReadDataWordMuxM; // DTIM or D$ read data
|
||||
logic [`LLEN-1:0] LittleEndianReadDataWordM; // Endian-swapped read data
|
||||
logic [`LLEN-1:0] ReadDataWordM; // Read data before subword selection
|
||||
logic [`LLEN-1:0] ReadDataM; // Final read data
|
||||
|
||||
logic [`XLEN-1:0] IHWriteDataM; // IEU or HPTW write data
|
||||
logic [`XLEN-1:0] IMAWriteDataM; // IEU, HPTW, or AMO write data
|
||||
logic [`LLEN-1:0] IMAFWriteDataM; // IEU, HPTW, AMO, or FPU write data
|
||||
logic [`LLEN-1:0] LittleEndianWriteDataM; // Ending-swapped write data
|
||||
logic [`LLEN-1:0] LSUWriteDataM; // Final write data
|
||||
logic [(`LLEN-1)/8:0] ByteMaskM; // Selects which bytes within a word to write
|
||||
logic [`XLEN-1:0] IHWriteDataM; // IEU or HPTW write data
|
||||
logic [`XLEN-1:0] IMAWriteDataM; // IEU, HPTW, or AMO write data
|
||||
logic [`LLEN-1:0] IMAFWriteDataM; // IEU, HPTW, AMO, or FPU write data
|
||||
logic [`LLEN-1:0] LittleEndianWriteDataM; // Ending-swapped write data
|
||||
logic [`LLEN-1:0] LSUWriteDataM; // Final write data
|
||||
logic [(`LLEN-1)/8:0] ByteMaskM; // Selects which bytes within a word to write
|
||||
|
||||
logic DTLBMissM; // DTLB miss causes HPTW walk
|
||||
logic DTLBWriteM; // Writes PTE and PageType to DTLB
|
||||
logic DataDAPageFaultM; // DTLB hit needs to update dirty or access bits
|
||||
logic LSULoadAccessFaultM; // Load acces fault
|
||||
logic LSUStoreAmoAccessFaultM; // Store access fault
|
||||
logic IgnoreRequestTLB; // On either ITLB or DTLB miss, ignore miss so HPTW can handle
|
||||
logic IgnoreRequest; // On FlushM or TLB miss ignore memory operation
|
||||
logic SelDTIM; // Select DTIM rather than bus or D$
|
||||
logic DTLBMissM; // DTLB miss causes HPTW walk
|
||||
logic DTLBWriteM; // Writes PTE and PageType to DTLB
|
||||
logic DataDAPageFaultM; // DTLB hit needs to update dirty or access bits
|
||||
logic LSULoadAccessFaultM; // Load acces fault
|
||||
logic LSUStoreAmoAccessFaultM; // Store access fault
|
||||
logic IgnoreRequestTLB; // On either ITLB or DTLB miss, ignore miss so HPTW can handle
|
||||
logic IgnoreRequest; // On FlushM or TLB miss ignore memory operation
|
||||
logic SelDTIM; // Select DTIM rather than bus or D$
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
Loading…
Reference in New Issue
Block a user