OpenCores
URL https://opencores.org/ocsvn/s80186/s80186/trunk

Subversion Repositories s80186

[/] [s80186/] [trunk/] [rtl/] [RegisterFile.sv] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 jamieiles
// Copyright Jamie Iles, 2017
2
//
3
// This file is part of s80x86.
4
//
5
// s80x86 is free software: you can redistribute it and/or modify
6
// it under the terms of the GNU General Public License as published by
7
// the Free Software Foundation, either version 3 of the License, or
8
// (at your option) any later version.
9
//
10
// s80x86 is distributed in the hope that it will be useful,
11
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
// GNU General Public License for more details.
14
//
15
// You should have received a copy of the GNU General Public License
16
// along with s80x86.  If not, see .
17
 
18
module RegisterFile(input logic clk,
19
                    input logic reset,
20
                    input logic is_8_bit,
21
                    // Read port.
22
                    input logic [2:0] rd_sel[2],
23
                    output logic [15:0] rd_val[2],
24
                    // Write port.
25
                    input logic [2:0] wr_sel,
26
                    input logic [15:0] wr_val,
27
                    input logic wr_en);
28
 
29
reg [15:0] gprs[8];
30
 
31
wire wr_sel_low_byte = ~wr_sel[2];
32
wire [2:0] wr_8_bit_sel = {1'b0, wr_sel[1:0]};
33
 
34
always_ff @(posedge reset)
35
    ; // Reset is handled by the microcode.
36
 
37
always_ff @(posedge clk) begin
38
    if (wr_en) begin
39
        if (is_8_bit) begin
40
            if (wr_sel_low_byte)
41
                gprs[wr_8_bit_sel][7:0] <= wr_val[7:0];
42
            else
43
                gprs[wr_8_bit_sel][15:8] <= wr_val[7:0];
44
        end else begin
45
            gprs[wr_sel] <= wr_val;
46
        end
47
    end
48
end
49
 
50
genvar rd_port;
51
 
52
generate
53
for (rd_port = 0; rd_port < 2; ++rd_port) begin: read_port
54
    wire rd_sel_low_byte = ~rd_sel[rd_port][2];
55
    wire [2:0] rd_8_bit_sel = {1'b0, rd_sel[rd_port][1:0]};
56
    wire bypass = wr_en && wr_sel == rd_sel[rd_port];
57
 
58
    always_ff @(posedge clk) begin
59
        if (is_8_bit)
60
            rd_val[rd_port] <= bypass ? {8'b0, wr_val[7:0]} :
61
                {8'b0, rd_sel_low_byte ?
62
                    gprs[rd_8_bit_sel][7:0] : gprs[rd_8_bit_sel][15:8]};
63
        else
64
            rd_val[rd_port] <= bypass ? wr_val :
65
                gprs[rd_sel[rd_port]];
66
    end
67
end
68
endgenerate
69
 
70
endmodule

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.