| 1 |
3 |
yannv |
----------------------------------------------------------------------------------
|
| 2 |
|
|
-- Company:
|
| 3 |
|
|
-- Engineer:
|
| 4 |
|
|
--
|
| 5 |
|
|
-- Create Date: 12:27:16 02/09/2009
|
| 6 |
|
|
-- Design Name:
|
| 7 |
|
|
-- Module Name: coremem - Behavioral
|
| 8 |
|
|
-- Project Name:
|
| 9 |
|
|
-- Target Devices:
|
| 10 |
|
|
-- Tool versions:
|
| 11 |
|
|
-- Description:
|
| 12 |
|
|
--
|
| 13 |
|
|
-- Dependencies:
|
| 14 |
|
|
--
|
| 15 |
|
|
-- Revision:
|
| 16 |
|
|
-- Revision 0.01 - File Created
|
| 17 |
|
|
-- Additional Comments:
|
| 18 |
|
|
-- TODO: Convert to use Xilinx instantiation, because the 18-bit wide memory
|
| 19 |
|
|
-- gets converted to 4 1k*16 and 1 4k*2, wasting a block ram.
|
| 20 |
|
|
-- This is because Xilinx tools do not automatically use the parity bits.
|
| 21 |
|
|
--
|
| 22 |
|
|
----------------------------------------------------------------------------------
|
| 23 |
|
|
library IEEE;
|
| 24 |
|
|
use IEEE.STD_LOGIC_1164.ALL;
|
| 25 |
|
|
use IEEE.STD_LOGIC_ARITH.ALL;
|
| 26 |
|
|
use IEEE.STD_LOGIC_UNSIGNED.ALL;
|
| 27 |
|
|
use IEEE.STD_LOGIC_TEXTIO.ALL;
|
| 28 |
|
|
use STD.TEXTIO.ALL;
|
| 29 |
|
|
|
| 30 |
|
|
---- For instantiating Xilinx block RAMs
|
| 31 |
|
|
--library UNISIM;
|
| 32 |
|
|
--use UNISIM.VComponents.all;
|
| 33 |
|
|
|
| 34 |
|
|
entity coremem is
|
| 35 |
|
|
Port ( A : in STD_LOGIC_VECTOR (0 to 11);
|
| 36 |
|
|
CLK : in STD_LOGIC;
|
| 37 |
|
|
-- The PDP-1 can write to high 6 bits, low 12 bits, or both.
|
| 38 |
|
|
-- To emulate this we need a higher clock to do load-modify-store.
|
| 39 |
|
|
-- TODO: Actually, the PDP-1 rewrites after every read, giving it the
|
| 40 |
|
|
-- opportunity to read-modify-write itself, and does so for Index.
|
| 41 |
|
|
-- So the memory is simpler, runs load/store at double rate,
|
| 42 |
|
|
-- but the CPU needs a matching redesign.
|
| 43 |
|
|
WE : in STD_LOGIC;
|
| 44 |
|
|
ENABLE : in STD_LOGIC := '1';
|
| 45 |
|
|
DI : in STD_LOGIC_VECTOR (0 to 17);
|
| 46 |
|
|
-- DO defaults to jump to 0 instruction
|
| 47 |
|
|
DO : out STD_LOGIC_VECTOR (0 to 17) := o"76_4200" -- match core(0)!
|
| 48 |
|
|
);
|
| 49 |
|
|
end coremem;
|
| 50 |
|
|
|
| 51 |
|
|
architecture Behavioral of coremem is
|
| 52 |
|
|
constant ADDR_WIDTH : integer := 12;
|
| 53 |
|
|
constant DATA_WIDTH : integer := 18;
|
| 54 |
|
|
|
| 55 |
|
|
subtype word is std_logic_vector(0 to DATA_WIDTH-1);
|
| 56 |
|
|
-- important: if downto is used, the code lines must be written backwards!
|
| 57 |
|
|
type coremodule is array (0 to 2**ADDR_WIDTH-1) of word;
|
| 58 |
|
|
|
| 59 |
|
|
-- only works for very small initial programs.
|
| 60 |
|
|
impure function loadcore (filename : in string) return coremodule is
|
| 61 |
|
|
FILE corefile : text is in filename;
|
| 62 |
|
|
variable coreline : line;
|
| 63 |
|
|
variable core : coremodule := (others=>o"00_0000");
|
| 64 |
|
|
variable addr : integer := 0;
|
| 65 |
|
|
begin
|
| 66 |
|
|
--file_open(corefile, filename, READ_MODE);
|
| 67 |
|
|
for addr in coremodule'range loop
|
| 68 |
|
|
--while (not endfile(corefile)) and (addr<2**ADDR_WIDTH) loop
|
| 69 |
|
|
if not endfile(corefile) then
|
| 70 |
|
|
readline (corefile, coreline);
|
| 71 |
|
|
oread (coreline, core(addr));
|
| 72 |
|
|
--addr := addr+1;
|
| 73 |
|
|
end if;
|
| 74 |
|
|
end loop;
|
| 75 |
|
|
-- FIXME this isn't very robust, it breaks if there's an empty line
|
| 76 |
|
|
--file_close(corefile);
|
| 77 |
|
|
return core;
|
| 78 |
|
|
end function;
|
| 79 |
|
|
|
| 80 |
|
|
---- Xilinx IP generator version
|
| 81 |
|
|
--component xilinx_core
|
| 82 |
|
|
--port (
|
| 83 |
|
|
-- clka: IN std_logic;
|
| 84 |
|
|
-- wea: IN std_logic_VECTOR(0 downto 0);
|
| 85 |
|
|
-- addra: IN std_logic_VECTOR(11 downto 0);
|
| 86 |
|
|
-- dina: IN std_logic_VECTOR(17 downto 0);
|
| 87 |
|
|
-- douta: OUT std_logic_VECTOR(17 downto 0));
|
| 88 |
|
|
--end component;
|
| 89 |
|
|
--signal wea: std_logic_vector(0 to 0);
|
| 90 |
|
|
|
| 91 |
|
|
---- Synplicity black box declaration
|
| 92 |
|
|
--attribute syn_black_box : boolean;
|
| 93 |
|
|
--attribute syn_black_box of xilinx_core: component is true;
|
| 94 |
|
|
|
| 95 |
|
|
signal core: coremodule :=
|
| 96 |
|
|
--loadcore("testdpy.octal");
|
| 97 |
|
|
--loadcore("spacewar.octal");
|
| 98 |
|
|
(
|
| 99 |
|
|
-- tape reader test program
|
| 100 |
|
|
--o"73_0001", -- read paper alphanumeric with wait
|
| 101 |
|
|
--o"76_0000", -- NOP
|
| 102 |
|
|
--o"66_6777", -- shift left 9 bits
|
| 103 |
|
|
--o"66_6001", -- and 1 bit, leaving the read byte at
|
| 104 |
|
|
-- -- left edge of IO register
|
| 105 |
|
|
--o"60_0003", -- infinite loop to light AWAKE
|
| 106 |
|
|
|
| 107 |
|
|
-- counter test program (loads result into IO for display)
|
| 108 |
|
|
--o"60_0003", -- jump past constant
|
| 109 |
|
|
--o"00_0001", -- constant one
|
| 110 |
|
|
--o"00_0000", -- variable
|
| 111 |
|
|
--o"40_0001", -- add one to AC
|
| 112 |
|
|
--o"24_0002", -- store in memory
|
| 113 |
|
|
--o"22_0002", -- load into IO
|
| 114 |
|
|
|
| 115 |
|
|
--o"60_0000", -- jump back to start of program
|
| 116 |
|
|
|
| 117 |
|
|
-- tape read in emulation (see readin.mac)
|
| 118 |
|
|
8#0000# => o"60_7700", -- jump to program
|
| 119 |
|
|
8#7700# => o"73_0002", -- read paper binary
|
| 120 |
|
|
8#7701# => o"32_7706", -- deposit instruction just read
|
| 121 |
|
|
8#7702# => o"20_7706", -- read into AC
|
| 122 |
|
|
8#7703# => o"26_7710", -- deposit address into DIO for comparison
|
| 123 |
|
|
8#7704# => o"50_7710", -- skip read if instruction not DIO
|
| 124 |
|
|
8#7705# => o"73_0002", -- read word to be deposited
|
| 125 |
|
|
8#7706# => o"76_0400", -- overwritten instruction; initially halt
|
| 126 |
|
|
8#7707# => o"60_7700", -- repeat the loop
|
| 127 |
|
|
8#7710# => o"32_0000", -- deposit IO for comparison
|
| 128 |
|
|
|
| 129 |
|
|
others => o"60_0000"
|
| 130 |
|
|
);
|
| 131 |
|
|
|
| 132 |
|
|
-- signal unused : coremodule :=
|
| 133 |
|
|
-- (
|
| 134 |
|
|
-- o"60_0010", -- jump past constants and variables
|
| 135 |
|
|
-- o"37_7400", -- value to switch direction on
|
| 136 |
|
|
-- o"00_0000", -- unused
|
| 137 |
|
|
-- o"00_0400", -- step -- addr 0003
|
| 138 |
|
|
--
|
| 139 |
|
|
-- o"00_0000", -- variable
|
| 140 |
|
|
-- o"00_0000", -- padding
|
| 141 |
|
|
-- o"00_0000", -- padding
|
| 142 |
|
|
-- o"00_0000", -- padding
|
| 143 |
|
|
--
|
| 144 |
|
|
-- o"76_4200", -- clear AC and IO -- addr 0010 (start)
|
| 145 |
|
|
-- o"40_0003", -- add step to AC -- addr 0011 (loop)
|
| 146 |
|
|
-- o"24_0004", -- store AC to variable
|
| 147 |
|
|
-- o"22_0004", -- load count to IO
|
| 148 |
|
|
-- o"76_1000", -- complement AC
|
| 149 |
|
|
-- o"73_0007", -- display, with waiting
|
| 150 |
|
|
-- o"76_1000", -- switch AC back
|
| 151 |
|
|
-- o"52_0001", -- skip next instruction if AC=endpoint
|
| 152 |
|
|
-- o"60_0011", -- jump to beginning of loop
|
| 153 |
|
|
-- o"20_0001", -- load endpoint
|
| 154 |
|
|
-- o"76_1000", -- complement it
|
| 155 |
|
|
-- o"24_0001", -- store it back
|
| 156 |
|
|
-- o"20_0003", -- load step
|
| 157 |
|
|
-- o"76_1000", -- complement it
|
| 158 |
|
|
-- o"24_0003", -- store it back
|
| 159 |
|
|
-- o"20_0004", -- load count again
|
| 160 |
|
|
-- o"60_0011", -- jump back to loop
|
| 161 |
|
|
-- others => o"00_0000"
|
| 162 |
|
|
-- );
|
| 163 |
|
|
|
| 164 |
|
|
begin
|
| 165 |
|
|
process (CLK)
|
| 166 |
|
|
begin
|
| 167 |
|
|
if (CLK'event and CLK = '1') then
|
| 168 |
|
|
if (enable = '1') then
|
| 169 |
|
|
if (WE = '1') then
|
| 170 |
|
|
core(conv_integer(A)) <= DI;
|
| 171 |
|
|
end if;
|
| 172 |
|
|
DO <= core(conv_integer(A));
|
| 173 |
|
|
end if;
|
| 174 |
|
|
end if;
|
| 175 |
|
|
end process;
|
| 176 |
|
|
--wea(0)<=we;
|
| 177 |
|
|
--xil_core : xilinx_core
|
| 178 |
|
|
-- port map (
|
| 179 |
|
|
-- clka => clk,
|
| 180 |
|
|
-- wea => wea,
|
| 181 |
|
|
-- addra => a,
|
| 182 |
|
|
-- dina => di,
|
| 183 |
|
|
-- douta => do);
|
| 184 |
|
|
end Behavioral;
|
| 185 |
|
|
|