2021-01-15 04:37:51 +00:00
|
|
|
///////////////////////////////////////////
|
|
|
|
// csru.sv
|
|
|
|
//
|
|
|
|
// Written: David_Harris@hmc.edu 9 January 2021
|
|
|
|
// Modified:
|
|
|
|
//
|
|
|
|
// Purpose: User-Mode Control and Status Registers for Floating Point
|
|
|
|
|
|
|
|
// See RISC-V Privileged Mode Specification 20190608 Table 2.2
|
|
|
|
//
|
2023-01-11 23:15:08 +00:00
|
|
|
// A component of the CORE-V-WALLY configurable RISC-V project.
|
2021-01-15 04:37:51 +00:00
|
|
|
//
|
2023-01-10 19:35:20 +00:00
|
|
|
// Copyright (C) 2021-23 Harvey Mudd College & Oklahoma State University
|
2021-01-15 04:37:51 +00:00
|
|
|
//
|
2023-01-10 19:35:20 +00:00
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH SHL-2.1
|
2021-01-15 04:37:51 +00:00
|
|
|
//
|
2023-01-10 19:35:20 +00:00
|
|
|
// 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
|
2021-01-15 04:37:51 +00:00
|
|
|
//
|
2023-01-10 19:35:20 +00:00
|
|
|
// 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.
|
2022-01-07 12:58:40 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
2021-01-15 04:37:51 +00:00
|
|
|
|
2021-01-23 15:48:12 +00:00
|
|
|
`include "wally-config.vh"
|
2021-01-15 04:37:51 +00:00
|
|
|
|
2021-01-23 15:48:12 +00:00
|
|
|
module csru #(parameter
|
2021-01-15 04:37:51 +00:00
|
|
|
FFLAGS = 12'h001,
|
|
|
|
FRM = 12'h002,
|
|
|
|
FCSR = 12'h003) (
|
2021-02-02 04:44:41 +00:00
|
|
|
input logic clk, reset,
|
2022-12-23 08:21:36 +00:00
|
|
|
input logic InstrValidNotFlushedM,
|
2021-02-02 04:44:41 +00:00
|
|
|
input logic CSRUWriteM,
|
|
|
|
input logic [11:0] CSRAdrM,
|
2021-01-23 15:48:12 +00:00
|
|
|
input logic [`XLEN-1:0] CSRWriteValM,
|
2022-05-03 18:32:01 +00:00
|
|
|
input logic [1:0] STATUS_FS,
|
2021-01-23 15:48:12 +00:00
|
|
|
output logic [`XLEN-1:0] CSRUReadValM,
|
2021-02-02 04:44:41 +00:00
|
|
|
input logic [4:0] SetFflagsM,
|
|
|
|
output logic [2:0] FRM_REGW,
|
2021-07-13 17:20:30 +00:00
|
|
|
output logic WriteFRMM, WriteFFLAGSM,
|
2021-02-02 04:44:41 +00:00
|
|
|
output logic IllegalCSRUAccessM
|
2021-01-15 04:37:51 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
// Floating Point CSRs in User Mode only needed if Floating Point is supported
|
2022-01-05 14:35:25 +00:00
|
|
|
if (`F_SUPPORTED | `D_SUPPORTED) begin:csru
|
|
|
|
logic [4:0] FFLAGS_REGW;
|
|
|
|
logic [2:0] NextFRMM;
|
|
|
|
logic [4:0] NextFFLAGSM;
|
|
|
|
|
|
|
|
// Write enables
|
2022-01-18 23:19:33 +00:00
|
|
|
//assign WriteFCSRM = CSRUWriteM & (CSRAdrM == FCSR) & InstrValidNotFlushedM;
|
2022-05-03 18:32:01 +00:00
|
|
|
assign WriteFRMM = (CSRUWriteM & (STATUS_FS != 2'b00) & (CSRAdrM == FRM | CSRAdrM == FCSR)) & InstrValidNotFlushedM;
|
|
|
|
assign WriteFFLAGSM = (CSRUWriteM & (STATUS_FS != 2'b00) & (CSRAdrM == FFLAGS | CSRAdrM == FCSR)) & InstrValidNotFlushedM;
|
2022-01-05 14:35:25 +00:00
|
|
|
|
|
|
|
// Write Values
|
|
|
|
assign NextFRMM = (CSRAdrM == FCSR) ? CSRWriteValM[7:5] : CSRWriteValM[2:0];
|
|
|
|
assign NextFFLAGSM = WriteFFLAGSM ? CSRWriteValM[4:0] : FFLAGS_REGW | SetFflagsM;
|
2021-01-15 04:37:51 +00:00
|
|
|
|
2022-01-05 14:35:25 +00:00
|
|
|
// CSRs
|
|
|
|
flopenr #(3) FRMreg(clk, reset, WriteFRMM, NextFRMM, FRM_REGW);
|
|
|
|
flopr #(5) FFLAGSreg(clk, reset, NextFFLAGSM, FFLAGS_REGW);
|
2021-01-15 04:37:51 +00:00
|
|
|
|
2022-01-05 14:35:25 +00:00
|
|
|
// CSR Reads
|
|
|
|
always_comb begin
|
2022-05-03 18:32:01 +00:00
|
|
|
if (STATUS_FS == 2'b00) begin // fpu disabled, trap
|
|
|
|
IllegalCSRUAccessM = 1;
|
|
|
|
CSRUReadValM = 0;
|
|
|
|
end else begin
|
|
|
|
IllegalCSRUAccessM = 0;
|
|
|
|
case (CSRAdrM)
|
|
|
|
FFLAGS: CSRUReadValM = {{(`XLEN-5){1'b0}}, FFLAGS_REGW};
|
|
|
|
FRM: CSRUReadValM = {{(`XLEN-3){1'b0}}, FRM_REGW};
|
|
|
|
FCSR: CSRUReadValM = {{(`XLEN-8){1'b0}}, FRM_REGW, FFLAGS_REGW};
|
|
|
|
default: begin
|
|
|
|
CSRUReadValM = 0;
|
|
|
|
IllegalCSRUAccessM = 1;
|
|
|
|
end
|
|
|
|
endcase
|
|
|
|
end
|
2021-01-15 04:37:51 +00:00
|
|
|
end
|
2022-01-05 14:35:25 +00:00
|
|
|
end else begin // if not supported
|
|
|
|
assign FRM_REGW = 0;
|
|
|
|
assign CSRUReadValM = 0;
|
|
|
|
assign IllegalCSRUAccessM = 1;
|
|
|
|
end
|
2021-03-24 20:56:55 +00:00
|
|
|
endmodule
|