| 1 |
2 |
trurl |
-----------------------------------------------------------------
|
| 2 |
|
|
--!
|
| 3 |
|
|
--! PDP-8 Processor
|
| 4 |
|
|
--!
|
| 5 |
|
|
--! \brief
|
| 6 |
|
|
--! CPU Program Counter (PC) Register
|
| 7 |
|
|
--!
|
| 8 |
|
|
--! \details
|
| 9 |
|
|
--! The Program Counter (PC) Register contains the address
|
| 10 |
|
|
--! of the next instruction to be executed.
|
| 11 |
|
|
--!
|
| 12 |
|
|
--! A block diagram of the PC block is illustrated below.
|
| 13 |
|
|
--!
|
| 14 |
|
|
--! \image
|
| 15 |
|
|
--! html pc.png "Program Counter Block Diagram"
|
| 16 |
|
|
--!
|
| 17 |
|
|
--! Of note, the PC contains it's own adder which really
|
| 18 |
|
|
--! only adds by 0 or 1. Similarly the PC contains a
|
| 19 |
|
|
--! couple of constants that are used for PDP8 interrupts,
|
| 20 |
|
|
--! HD-6120 Panel Traps, etc.
|
| 21 |
|
|
--!
|
| 22 |
|
|
--! \file
|
| 23 |
|
|
--! pc.vhd
|
| 24 |
|
|
--!
|
| 25 |
|
|
--! \author
|
| 26 |
|
|
--! Rob Doyle - doyle (at) cox (dot) net
|
| 27 |
|
|
--!
|
| 28 |
|
|
--------------------------------------------------------------------
|
| 29 |
|
|
--
|
| 30 |
|
|
-- Copyright (C) 2009, 2010, 2011, 2012 Rob Doyle
|
| 31 |
|
|
--
|
| 32 |
|
|
-- This source file may be used and distributed without
|
| 33 |
|
|
-- restriction provided that this copyright statement is not
|
| 34 |
|
|
-- removed from the file and that any derivative work contains
|
| 35 |
|
|
-- the original copyright notice and the associated disclaimer.
|
| 36 |
|
|
--
|
| 37 |
|
|
-- This source file is free software; you can redistribute it
|
| 38 |
|
|
-- and/or modify it under the terms of the GNU Lesser General
|
| 39 |
|
|
-- Public License as published by the Free Software Foundation;
|
| 40 |
|
|
-- version 2.1 of the License.
|
| 41 |
|
|
--
|
| 42 |
|
|
-- This source is distributed in the hope that it will be
|
| 43 |
|
|
-- useful, but WITHOUT ANY WARRANTY; without even the implied
|
| 44 |
|
|
-- warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
| 45 |
|
|
-- PURPOSE. See the GNU Lesser General Public License for more
|
| 46 |
|
|
-- details.
|
| 47 |
|
|
--
|
| 48 |
|
|
-- You should have received a copy of the GNU Lesser General
|
| 49 |
|
|
-- Public License along with this source; if not, download it
|
| 50 |
|
|
-- from http://www.gnu.org/licenses/lgpl.txt
|
| 51 |
|
|
--
|
| 52 |
|
|
--------------------------------------------------------------------
|
| 53 |
|
|
--
|
| 54 |
|
|
-- Comments are formatted for doxygen
|
| 55 |
|
|
--
|
| 56 |
|
|
|
| 57 |
|
|
library ieee; --! IEEE Library
|
| 58 |
|
|
use ieee.std_logic_1164.all; --! IEEE 1164
|
| 59 |
|
|
use ieee.numeric_std.all; --! IEEE Numeric Standard
|
| 60 |
|
|
use work.cpu_types.all; --! CPU Types
|
| 61 |
|
|
|
| 62 |
|
|
--
|
| 63 |
|
|
--! CPU Program Counter (PC) Register Entity
|
| 64 |
|
|
--
|
| 65 |
|
|
|
| 66 |
|
|
entity ePC is port (
|
| 67 |
|
|
sys : in sys_t; --! Clock/Reset
|
| 68 |
|
|
pcOP : in pcOP_t; --! PC Operation
|
| 69 |
|
|
IR : in data_t; --! Instruction Register
|
| 70 |
|
|
MA : in addr_t; --! Memory Address Register
|
| 71 |
|
|
MB : in data_t; --! Memory Data Register
|
| 72 |
|
|
MD : in data_t; --! Memory Data
|
| 73 |
|
|
SR : in data_t; --! Switch Register
|
| 74 |
|
|
PC : out addr_t --! PC Output
|
| 75 |
|
|
);
|
| 76 |
|
|
end ePC;
|
| 77 |
|
|
|
| 78 |
|
|
--
|
| 79 |
|
|
--! CPU Program Counter (PC) Register RTL
|
| 80 |
|
|
--
|
| 81 |
|
|
|
| 82 |
|
|
architecture rtl of ePC is
|
| 83 |
|
|
|
| 84 |
|
|
signal pcREG : addr_t; --! Program Counter
|
| 85 |
|
|
signal addMUX1 : addr_t; --! Adder Mux #1
|
| 86 |
|
|
signal addMUX2 : addr_t; --! Adder Mux #2
|
| 87 |
|
|
signal CP : addr_t; --! Current Page Addr
|
| 88 |
|
|
signal ZP : addr_t; --! Zero Page Addr
|
| 89 |
|
|
|
| 90 |
|
|
begin
|
| 91 |
|
|
|
| 92 |
|
|
--
|
| 93 |
|
|
-- Current Page and Zero Page addresses
|
| 94 |
|
|
--
|
| 95 |
|
|
|
| 96 |
|
|
CP <= MA(0 to 4) & IR(5 to 11); -- Current Page Addr
|
| 97 |
|
|
ZP <= "00000" & IR(5 to 11); -- Zero Page Addr
|
| 98 |
|
|
|
| 99 |
|
|
--
|
| 100 |
|
|
-- Adder input #1 mux.
|
| 101 |
|
|
-- This will synthesize into a 16x12 ROM
|
| 102 |
|
|
--
|
| 103 |
|
|
|
| 104 |
|
|
with pcOP select
|
| 105 |
|
|
addMUX1 <= o"0000" when pcopNOP, -- PC <- PC
|
| 106 |
|
|
o"0000" when pcop0000, -- PC <- "0000"
|
| 107 |
|
|
o"0001" when pcop0001, -- PC <- "0001"
|
| 108 |
|
|
o"0000" when pcop7777, -- PC <- "7777"
|
| 109 |
|
|
o"0000" when pcopMA, -- PC <- MA
|
| 110 |
|
|
o"0000" when pcopMB, -- PC <- MB
|
| 111 |
|
|
o"0000" when pcopMD, -- PC <- MD
|
| 112 |
|
|
o"0000" when pcopSR, -- PC <- SR
|
| 113 |
|
|
o"0000" when pcopZP, -- PC <- "00000" & IR(5 to 11)
|
| 114 |
|
|
o"0000" when pcopCP, -- PC <- MA(0 to 4) & IR(5 to 11)
|
| 115 |
|
|
o"0001" when pcopINC, -- PC <- PC + 1
|
| 116 |
|
|
o"0001" when pcopMAP1, -- PC <- MA + 1
|
| 117 |
|
|
o"0001" when pcopMBP1, -- PC <- MB + 1
|
| 118 |
|
|
o"0001" when pcopMDP1, -- PC <- MD + 1
|
| 119 |
|
|
o"0001" when pcopZPP1, -- PC <- ("00000" & IR(5 to 11)) + "1"
|
| 120 |
|
|
o"0001" when pcopCPP1; -- PC <- (MA(0 to 4) & IR(5 to 11)) + "1"
|
| 121 |
|
|
|
| 122 |
|
|
--
|
| 123 |
|
|
-- Adder input #2 mux.
|
| 124 |
|
|
--
|
| 125 |
|
|
|
| 126 |
|
|
with pcOP select
|
| 127 |
|
|
addMUX2 <= pcREG when pcopNOP, -- PC <- PC
|
| 128 |
|
|
o"0000" when pcop0000, -- PC <- "0000"
|
| 129 |
|
|
o"0000" when pcop0001, -- PC <- "0001"
|
| 130 |
|
|
o"7777" when pcop7777, -- PC <- "7777"
|
| 131 |
|
|
MA when pcopMA, -- PC <- MA
|
| 132 |
|
|
MB when pcopMB, -- PC <- MB
|
| 133 |
|
|
MD when pcopMD, -- PC <- MD
|
| 134 |
|
|
SR when pcopSR, -- PC <- SR
|
| 135 |
|
|
ZP when pcopZP, -- PC <- "00000" & IR(5 to 11
|
| 136 |
|
|
CP when pcopCP, -- PC <- MA(0 to 4) & IR(5 to 11)
|
| 137 |
|
|
pcREG when pcopINC, -- PC <- PC + 1
|
| 138 |
|
|
MA when pcopMAP1, -- PC <- MA + 1
|
| 139 |
|
|
MB when pcopMBP1, -- PC <- MB + 1
|
| 140 |
|
|
MD when pcopMDP1, -- PC <- MD + 1
|
| 141 |
|
|
ZP when pcopZPP1, -- PC <- ("00000" & IR(5 to 11)) + "1"
|
| 142 |
|
|
CP when pcopCPP1; -- PC <- (MA(0 to 4) & IR(5 to 11)) + "1"
|
| 143 |
|
|
|
| 144 |
|
|
--
|
| 145 |
|
|
--! PC Register
|
| 146 |
|
|
--
|
| 147 |
|
|
|
| 148 |
|
|
REG_PC : process(sys)
|
| 149 |
|
|
begin
|
| 150 |
|
|
if sys.rst = '1' then
|
| 151 |
|
|
pcREG <= o"0000";
|
| 152 |
|
|
elsif rising_edge(sys.clk) then
|
| 153 |
|
|
pcREG <= std_logic_vector(unsigned(addMUX2) + unsigned(addMUX1));
|
| 154 |
|
|
end if;
|
| 155 |
|
|
end process REG_PC;
|
| 156 |
|
|
|
| 157 |
|
|
PC <= pcREG;
|
| 158 |
|
|
|
| 159 |
|
|
end rtl;
|