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

Subversion Repositories mmu180

[/] [mmu180/] [trunk/] [vsourc/] [mmu180.v] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 beattidp
/** @package zGlue
2
 
3
    @file mmu180.v
4
 
5
    @brief Memory Management Unit, mimics classic Z180;
6
            for eZ80 Family host processor with 24-bit address bus.
7
 
8
<BR>Simplified (2-clause) BSD License
9
 
10
Copyright (c) 2012, Douglas Beattie Jr.
11
All rights reserved.
12
 
13
Redistribution and use in source and hardware/binary forms, with or without
14
modification, are permitted provided that the following conditions are met:
15
 
16
1. Redistributions of source code must retain the above copyright notice,
17
   this list of conditions and the following disclaimer.
18
 
19
2. Redistributions in hardware/binary form must reproduce the above
20
   copyright notice, this list of conditions and the following disclaimer in
21
   the documentation and/or other materials provided with the distribution.
22
 
23
THIS RTL SOURCE IS PROVIDED BY DOUGLAS BEATTIE JR. "AS IS" AND ANY
24
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26
DISCLAIMED. IN NO EVENT SHALL DOUGLAS BEATTIE JR. BE LIABLE FOR ANY
27
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
30
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
32
THIS RTL SOURCE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33
 
34
    Author: Douglas Beattie
35
    Created on: 4/12/2012 8:50:12 PM
36
        Last change: DBJR 4/27/2012 7:55:01 PM
37
*/
38
`timescale 1ns / 100ps
39
 
40
// User-defined I/O addresses from eZ80 address bus;
41
// these match the original Z180 MMU defaults at reset.
42
// These must not be defined within eZ80 on-chip i/o space (7F..FF)
43
`define CBR_IO_ADDR     16'h0038  // Common Bank Register
44
`define BBR_IO_ADDR     16'h0039  // Bank Base Register
45
`define CBAR_IO_ADDR    16'h003A  // Common/Bank Address Register
46
 
47
module mmu180(reset_n, en, iorq_n, mreq_n, rd_n, wr_n, phi, addr_in, dq, addr_out,
48
        cbar_hinyb, cbar_lonyb);
49
 
50
input           reset_n, en, iorq_n, mreq_n, rd_n, wr_n, phi;
51
input   [23:0]  addr_in; //processor address bus
52
inout   [7:0]   dq;     // processor data bus
53
output  [19:12]  addr_out; // memory address bus
54
 
55
 
56
reg [7:0]  cpu_data_buf;
57
 
58
wire cbar_hinyb_gteq;   // for CBR valid address match
59
wire cbar_lonyb_gteq;   // for BBR valid address match
60
 
61
// These are for verification only
62
output cbar_hinyb, cbar_lonyb;
63
// These are for verification only
64
assign cbar_hinyb = cbar_hinyb_gteq;
65
assign cbar_lonyb = cbar_lonyb_gteq;
66
 
67
/** *************************************************************** */
68
/** define 3 I/O Ports, 1 each for CBR, BBR, and CBAR               */
69
 
70
wire [7:0] iolatched_oup_CBR;
71
wire [7:0] iolatched_oup_BBR;
72
wire [7:0] iolatched_oup_CBAR;
73
 
74
 
75
/**************
76
wire addr16_msb_zero;
77
assign addr16_msb_zero = (addr_in[15:8] == 8'b0);
78
 
79
wire iosel_CBR, iosel_BBR, iosel_CBAR;
80
assign iosel_CBR = (addr16_msb_zero && (addr_in[7:0] == `CBR_IO_ADDR) && ! iorq_n && ! phi);
81
assign iosel_BBR = (addr16_msb_zero && (addr_in[7:0] == `BBR_IO_ADDR) && ! iorq_n && ! phi);
82
assign iosel_CBAR = (addr16_msb_zero && (addr_in[7:0] == `CBAR_IO_ADDR) && ! iorq_n && ! phi);
83
********************/
84
wire iosel_CBR, iosel_BBR, iosel_CBAR;
85
assign iosel_CBR = ((addr_in[15:0] == `CBR_IO_ADDR) && ! iorq_n && ! phi);
86
assign iosel_BBR = ((addr_in[15:0] == `BBR_IO_ADDR) && ! iorq_n && ! phi);
87
assign iosel_CBAR = ((addr_in[15:0] == `CBAR_IO_ADDR) && ! iorq_n && ! phi);
88
 
89
 
90
wire iosel_CBR_wr, iosel_BBR_wr, iosel_CBAR_wr;
91
assign iosel_CBR_wr = ! (iosel_CBR & ! wr_n);
92
assign iosel_BBR_wr = ! (iosel_BBR & ! wr_n);
93
assign iosel_CBAR_wr = ! (iosel_CBAR & ! wr_n);
94
 
95
assign dq = ( (iosel_CBR | iosel_BBR | iosel_CBAR) & (! rd_n)) ? cpu_data_buf : 8'bz;
96
 
97
wire iosel;
98
assign iosel = (! iorq_n && ! phi);
99
always  @ (posedge iosel)
100
    if (! rd_n) begin
101
        case (addr_in[15:0])
102
            `CBR_IO_ADDR: begin
103
                cpu_data_buf <= iolatched_oup_CBR;
104
            end
105
            `BBR_IO_ADDR: begin
106
                cpu_data_buf <= iolatched_oup_BBR;
107
            end
108
            `CBAR_IO_ADDR: begin
109
                cpu_data_buf <= iolatched_oup_CBAR;
110
            end
111
        endcase
112
    end
113
 
114
/// define I/O port to read/write CBR
115
ioport_a16_d8_wo   ioport_CBR(
116
    .reset_n   (reset_n),
117
//    .rd_n   (iosel_CBR_rd),
118
    .wr_n   (iosel_CBR_wr),
119
    .data_in   (dq),
120
    .ouplatched_bus (iolatched_oup_CBR)
121
);
122
 
123
/// define I/O port to read/write BBR
124
ioport_a16_d8_wo  ioport_BBR(
125
    .reset_n   (reset_n),
126
//    .rd_n   (iosel_BBR_rd),
127
    .wr_n   (iosel_BBR_wr),
128
    .data_in   (dq),
129
    .ouplatched_bus (iolatched_oup_BBR)
130
);
131
 
132
/// define I/O port to read/write CBAR
133
ioport_a16_d8_wo  #(.INIT_VAL(8'hF0)) ioport_CBAR(
134
    .reset_n   (reset_n),
135
//    .rd_n   (iosel_CBAR_rd),
136
    .wr_n   (iosel_CBAR_wr),
137
    .data_in   (dq),
138
    .ouplatched_bus (iolatched_oup_CBAR)
139
);
140
 
141
/** **************************************************************** */
142
/** define MMU compare and adder logic                               */
143
 
144
 
145
// Compare CBAR high nybble for Common Area 1 address ("use CBR?")
146
assign cbar_hinyb_gteq = (addr_in[15:12] >= iolatched_oup_CBAR[7:4]);
147
 
148
// Compare CBAR low nybble for Bank Area address  ("use BBR?")
149
assign cbar_lonyb_gteq = (addr_in[15:12] >= iolatched_oup_CBAR[3:0]);
150
 
151
wire cbar_is_valid;
152
assign cbar_is_valid = (iolatched_oup_CBAR[7:4] >= iolatched_oup_CBAR[3:0]);
153
 
154
wire    [7:0]   bbr_cbr_mux;
155
assign bbr_cbr_mux =
156
        (cbar_is_valid & cbar_hinyb_gteq) ? iolatched_oup_CBR :
157
        (cbar_is_valid & cbar_lonyb_gteq) ? iolatched_oup_BBR : 8'b0;
158
 
159
wire    [7:0]   hiaddr_1meg;
160
assign hiaddr_1meg = bbr_cbr_mux + {4'b0,addr_in[15:12]};
161
 
162
//define when hiaddr_1meg is to be used instead of normal a[19..12]
163
assign addr_out = (/*en &&*/ (addr_in[23:16] != 0)) ?
164
                    addr_in[19:12] : (en && (! mreq_n) && (cbar_hinyb_gteq | cbar_lonyb_gteq)) ?
165
                    hiaddr_1meg : addr_in[19:12];// : 8'bz;
166
 
167
/**
168
                    addr_in[19:12] : (en_mmu && (! mreq_n) && (cbar_hinyb_gteq | cbar_lonyb_gteq)) ?
169
                    hiaddr_1meg : (en_mod4 && (! mreq_n)) ? {addr_in[19:17], adj_a16, adj_a15, addr_in[14:12] }
170
                        : addr_in[19:12];// : 8'bz;
171
 
172
*/
173
 
174
endmodule
175
 

powered by: WebSVN 2.1.0

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