1 |
2 |
trurl |
------------------------------------------------------------------
|
2 |
|
|
--!
|
3 |
|
|
--! PDP-8 Processor
|
4 |
|
|
--!
|
5 |
|
|
--! \brief
|
6 |
|
|
--! CPU Stack Pointer (SP) Register
|
7 |
|
|
--!
|
8 |
|
|
--! \file
|
9 |
|
|
--! sp.vhd
|
10 |
|
|
--!
|
11 |
|
|
--! \details
|
12 |
|
|
--! The HD-6120 implements two stacks. The stacks and be
|
13 |
|
|
--! used to push or pop the Program Counter (PC) and/or to
|
14 |
|
|
--! push or pop the Accumulator. All other processor
|
15 |
|
|
--! state can be pushed or popped using one of these two
|
16 |
|
|
--! stacks.
|
17 |
|
|
--!
|
18 |
|
|
--! The Stack Pointers are named SP1 and SP2. The
|
19 |
|
|
--! stacks grow downward in memory.
|
20 |
|
|
--!
|
21 |
|
|
--! The Stack Pointer can be manipulated as follows:
|
22 |
|
|
--! -# SP1 and SP2 are both cleared when the Front Panel
|
23 |
|
|
--! CLEAR switch is asserted, and
|
24 |
|
|
--! -# SPn is decremented after the PC has been stored
|
25 |
|
|
--! during a PPCn instruction, and
|
26 |
|
|
--! -# SPn is decremented after the AC has been stored
|
27 |
|
|
--! during a PACn instruction, and
|
28 |
|
|
--! -# SPn is loaded with the contents of the AC during
|
29 |
|
|
--! a LSPn instruction, and
|
30 |
|
|
--! -# SPn is incremented before the contents of the
|
31 |
|
|
--! memory location pointed to by SPn is loaded
|
32 |
|
|
--! into the PC during a RTNn instruction, and
|
33 |
|
|
--! -# SPn is incremented before the contents of the
|
34 |
|
|
--! memory location pointed to by SPn is loaded
|
35 |
|
|
--! into the AC during a POPn instruction.
|
36 |
|
|
--!
|
37 |
|
|
--!
|
38 |
|
|
--! \note
|
39 |
|
|
--! SP1 and SP2 are identical. Two instances of this entity
|
40 |
|
|
--! are created to make SP1 and SP2.
|
41 |
|
|
--!
|
42 |
|
|
--! \author
|
43 |
|
|
--! Rob Doyle - doyle (at) cox (dot) net
|
44 |
|
|
--!
|
45 |
|
|
--------------------------------------------------------------------
|
46 |
|
|
--
|
47 |
|
|
-- Copyright (C) 2009, 2010, 2011, 2012 Rob Doyle
|
48 |
|
|
--
|
49 |
|
|
-- This source file may be used and distributed without
|
50 |
|
|
-- restriction provided that this copyright statement is not
|
51 |
|
|
-- removed from the file and that any derivative work contains
|
52 |
|
|
-- the original copyright notice and the associated disclaimer.
|
53 |
|
|
--
|
54 |
|
|
-- This source file is free software; you can redistribute it
|
55 |
|
|
-- and/or modify it under the terms of the GNU Lesser General
|
56 |
|
|
-- Public License as published by the Free Software Foundation;
|
57 |
|
|
-- version 2.1 of the License.
|
58 |
|
|
--
|
59 |
|
|
-- This source is distributed in the hope that it will be
|
60 |
|
|
-- useful, but WITHOUT ANY WARRANTY; without even the implied
|
61 |
|
|
-- warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
62 |
|
|
-- PURPOSE. See the GNU Lesser General Public License for more
|
63 |
|
|
-- details.
|
64 |
|
|
--
|
65 |
|
|
-- You should have received a copy of the GNU Lesser General
|
66 |
|
|
-- Public License along with this source; if not, download it
|
67 |
|
|
-- from http://www.gnu.org/licenses/lgpl.txt
|
68 |
|
|
--
|
69 |
|
|
--------------------------------------------------------------------
|
70 |
|
|
--
|
71 |
|
|
-- Comments are formatted for doxygen
|
72 |
|
|
--
|
73 |
|
|
|
74 |
|
|
library ieee; --! IEEE Library
|
75 |
|
|
use ieee.std_logic_1164.all; --! IEEE 1164
|
76 |
|
|
use ieee.numeric_std.all; --! IEEE Numeric Standard
|
77 |
|
|
use work.cpu_types.all; --! Types
|
78 |
|
|
|
79 |
|
|
--
|
80 |
|
|
--! CPU Stack Pointer (SP) Register Entity
|
81 |
|
|
--
|
82 |
|
|
|
83 |
|
|
entity eSP is port (
|
84 |
|
|
sys : in sys_t; --! Clock/Reset
|
85 |
|
|
spop : in spop_t; --! SP Operation
|
86 |
|
|
AC : in data_t; --! AC register
|
87 |
|
|
SP : out addr_t --! SP Output
|
88 |
|
|
);
|
89 |
|
|
end eSP;
|
90 |
|
|
|
91 |
|
|
--
|
92 |
|
|
--! CPU Stack Pointer (SP) Register RTL
|
93 |
|
|
--
|
94 |
|
|
|
95 |
|
|
architecture rtl of eSP is
|
96 |
|
|
|
97 |
|
|
signal spREG : addr_t; --! Stack Pointer Register
|
98 |
|
|
signal addMUX1 : addr_t; --! Adder Mux #1
|
99 |
|
|
signal addMUX2 : addr_t; --! Adder Mux #2
|
100 |
|
|
|
101 |
|
|
begin
|
102 |
|
|
|
103 |
|
|
--
|
104 |
|
|
-- Adder input #1 mux.
|
105 |
|
|
--
|
106 |
|
|
|
107 |
|
|
with spOP select
|
108 |
|
|
addMUX1 <= o"0000" when spopNOP, -- SP <- SP
|
109 |
|
|
o"0000" when spopCLR, -- SP <- o"0000"
|
110 |
|
|
o"0000" when spopAC, -- SP <- AC
|
111 |
|
|
o"0001" when spopINC, -- SP <- SP + 1
|
112 |
|
|
o"0001" when spopDEC; -- SP <- SP - 1
|
113 |
|
|
|
114 |
|
|
--
|
115 |
|
|
-- Adder input #2 mux.
|
116 |
|
|
--
|
117 |
|
|
|
118 |
|
|
with spOP select
|
119 |
|
|
addMUX2 <= spREG when spopNOP, -- SP <- SP
|
120 |
|
|
o"0000" when spopCLR, -- SP <- o"0000"
|
121 |
|
|
AC when spopAC, -- SP <- AC
|
122 |
|
|
spREG when spopINC, -- SP <- SP + 1
|
123 |
|
|
not(spREG) when spopDEC; -- SP <- SP - 1
|
124 |
|
|
--
|
125 |
|
|
--! SP Register
|
126 |
|
|
--
|
127 |
|
|
|
128 |
|
|
REG_SP : process(sys)
|
129 |
|
|
begin
|
130 |
|
|
if sys.rst = '1' then
|
131 |
|
|
spREG <= o"0000";
|
132 |
|
|
elsif rising_edge(sys.clk) then
|
133 |
|
|
spREG <= std_logic_vector(unsigned(addMUX2) + unsigned(addMUX1));
|
134 |
|
|
end if;
|
135 |
|
|
end process REG_SP;
|
136 |
|
|
|
137 |
|
|
SP <= spREG;
|
138 |
|
|
|
139 |
|
|
end rtl;
|