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

Subversion Repositories s80186

[/] [s80186/] [trunk/] [rtl/] [LoadStore.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 LoadStore(input logic clk,
19
                 input logic reset,
20
                 // Memory Address Register
21
                 input logic write_mar,
22
                 input logic [15:0] segment,
23
                 input [15:0] mar_in,
24
                 // Memory Data Register
25
                 output [15:0] mar_out,
26
                 output [15:0] mdr_out,
27
                 input logic write_mdr,
28
                 input [15:0] mdr_in,
29
                 // Memory bus
30
                 output logic [19:1] m_addr,
31
                 input logic [15:0] m_data_in,
32
                 output logic [15:0] m_data_out,
33
                 output logic m_access,
34
                 input logic m_ack,
35
                 output logic m_wr_en,
36
                 output logic [1:0] m_bytesel,
37
                 // Control
38
                 input logic io,
39
                 input logic start,
40
                 input logic is_8bit,
41
                 input logic wr_en,
42
                 output logic busy,
43
                 output logic complete);
44
 
45
reg [15:0] mar;
46
reg [15:0] mdr;
47
 
48
assign busy = (start | fetching | second_byte) & ~complete;
49
assign m_access = (start | fetching | second_byte) & ~complete & ~m_ack;
50
assign m_addr = !io ?
51
    {segment, 3'b0} + {3'b0, mar[15:1]} + {18'b0, second_byte} :
52
    {3'b0, mar[15:1]} + {18'b0, second_byte};
53
assign m_wr_en = wr_en;
54
assign mdr_out = mdr;
55
assign mar_out = mar;
56
 
57
always_comb begin
58
    if (unaligned && !second_byte)
59
        m_data_out = {mdr[7:0], 8'b0};
60
    else if (unaligned && second_byte)
61
        m_data_out = {8'b0, mdr[15:8]};
62
    else
63
        m_data_out = mdr;
64
end
65
 
66
always_comb begin
67
    if (!is_8bit && !unaligned)
68
        m_bytesel = 2'b11;
69
    else if (unaligned && !second_byte)
70
        m_bytesel = 2'b10;
71
    else
72
        m_bytesel = 2'b01;
73
end
74
 
75
wire unaligned = mar[0];
76
reg fetching;
77
reg second_byte;
78
 
79
always_ff @(posedge clk or posedge reset)
80
    if (reset)
81
        fetching <= 1'b0;
82
    else
83
        fetching <= start ? 1'b1 : complete ? 1'b0 : fetching;
84
 
85
always_ff @(posedge clk or posedge reset)
86
    if (reset)
87
        mar <= 16'b0;
88
    else
89
        mar <= write_mar ? mar_in : mar;
90
 
91
always_ff @(posedge clk)
92
    complete <= m_ack && (is_8bit || (unaligned && second_byte) || !unaligned);
93
 
94
always_ff @(posedge clk or posedge reset)
95
    if (reset) begin
96
        second_byte <= 1'b0;
97
    end else begin
98
        if (m_ack && unaligned && !second_byte && !is_8bit)
99
            second_byte <= 1'b1;
100
        else if ((start && !fetching) || complete)
101
            second_byte <= 1'b0;
102
    end
103
 
104
always_ff @(posedge clk or posedge reset) begin
105
    if (reset)
106
        mdr <= 16'b0;
107
    else if (start && !fetching && !wr_en)
108
        mdr <= 16'b0;
109
    else if (write_mdr)
110
        mdr <= mdr_in;
111
    else if (!wr_en && m_ack && !unaligned)
112
        mdr <= is_8bit ? {8'b0, m_data_in[7:0]} : m_data_in;
113
    else if (!wr_en && m_ack && unaligned && !second_byte)
114
        mdr[7:0] <= unaligned ? m_data_in[15:8] : m_data_in[7:0];
115
    else if (!wr_en && m_ack && unaligned && second_byte)
116
        mdr[15:8] <= unaligned ? m_data_in[7:0] : m_data_in[15:8];
117
end
118
 
119
endmodule

powered by: WebSVN 2.1.0

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