2 ----------------------------------------
3 --- program counter register declaration
4 ----------------------------------------
7 use ieee.std_logic_1164.all;
8 use ieee.std_logic_unsigned.all;
9 use ieee.std_logic_arith.conv_std_logic_vector;
14 reset_addr : integer := 0
17 trig_clk : in std_logic;
19 dbus_we_n : in std_logic;
20 abus_we_n : in std_logic;
21 dbus_oe_n : in std_logic;
22 abus_oe_n : in std_logic;
23 addr_inc_n : in std_logic;
24 add_carry : in std_logic;
25 inc_carry : out std_logic;
26 int_d_bus : inout std_logic_vector (dsize - 1 downto 0);
27 int_a_bus : inout std_logic_vector (dsize - 1 downto 0)
31 architecture rtl of pc is
33 signal val : std_logic_vector (dsize - 1 downto 0);
36 int_a_bus <= (val + add_carry) when
37 (abus_oe_n = '0' and add_carry = '1') else
39 (abus_oe_n = '0' and add_carry /= '1') else
41 int_d_bus <= (val + add_carry) when
42 (dbus_oe_n = '0' and add_carry = '1') else
44 (dbus_oe_n = '0' and add_carry /= '1') else
47 set_p : process (trig_clk, res_n)
48 variable add_val : std_logic_vector(dsize downto 0);
50 if ( trig_clk'event and trig_clk = '1') then
51 if (addr_inc_n = '0') then
52 add_val := ('0' & val) + 1;
53 inc_carry <= add_val(dsize);
54 val <= add_val(dsize - 1 downto 0);
56 if (dbus_we_n = '0') then
59 if (abus_we_n = '0') then
62 elsif (res_n'event and res_n = '0') then
63 val <= conv_std_logic_vector(reset_addr, dsize);
68 ----------------------------------------
69 --- normal d-flipflop declaration
70 ----------------------------------------
73 use ieee.std_logic_1164.all;
83 d : in std_logic_vector (dsize - 1 downto 0);
84 q : out std_logic_vector (dsize - 1 downto 0)
88 architecture rtl of dff is
89 signal val : std_logic_vector (dsize - 1 downto 0);
94 if ( clk'event and clk = '1'and we_n = '0') then
99 q <= val when oe_n = '0' else
103 ----------------------------------------
104 --- normal data latch declaration
105 ----------------------------------------
108 use ieee.std_logic_1164.all;
117 d : in std_logic_vector (dsize - 1 downto 0);
118 q : out std_logic_vector (dsize - 1 downto 0)
122 architecture rtl of latch is
123 signal val : std_logic_vector (dsize - 1 downto 0);
128 if ( we_n = '0') then
133 q <= val when oe_n = '0' else
137 ----------------------------------------
138 --- data bus buffer register
139 ----------------------------------------
142 use ieee.std_logic_1164.all;
151 int_oe_n : in std_logic;
152 int_dbus : inout std_logic_vector (dsize - 1 downto 0);
153 ext_dbus : inout std_logic_vector (dsize - 1 downto 0)
157 architecture rtl of dbus_buf is
166 d : in std_logic_vector (dsize - 1 downto 0);
167 q : out std_logic_vector (dsize - 1 downto 0)
178 d : in std_logic_vector (dsize - 1 downto 0);
179 q : out std_logic_vector (dsize - 1 downto 0)
183 signal not_r_nw : std_logic;
187 not_r_nw <= not r_nw;
188 --read from i/o to cpu
189 dff_r : dff generic map (dsize)
190 port map(clk, not_r_nw, int_oe_n, ext_dbus, int_dbus);
191 --write from cpu to io
192 latch_w : latch generic map (dsize)
193 port map(r_nw, r_nw, int_dbus, ext_dbus);
196 ----------------------------------------
197 --- input data latch register
198 ----------------------------------------
201 use ieee.std_logic_1164.all;
209 int_d_oe_n : in std_logic;
210 int_al_oe_n : in std_logic;
211 int_ah_oe_n : in std_logic;
212 int_dbus : inout std_logic_vector (dsize - 1 downto 0);
213 int_abus_l : out std_logic_vector (dsize - 1 downto 0);
214 int_abus_h : out std_logic_vector (dsize - 1 downto 0)
218 architecture rtl of input_dl is
226 d : in std_logic_vector (dsize - 1 downto 0);
227 q : out std_logic_vector (dsize - 1 downto 0)
230 signal oe_n : std_logic;
231 signal q : std_logic_vector (dsize - 1 downto 0);
233 oe_n <= (int_d_oe_n and int_al_oe_n and int_ah_oe_n);
234 int_dbus <= q when int_d_oe_n = '0' else
236 int_abus_l <= q when int_al_oe_n = '0' else
238 int_abus_h <= q when int_ah_oe_n = '0' else
240 latch_inst : latch generic map (dsize)
241 port map(we_n, oe_n, int_dbus, q);
244 ----------------------------------------
245 --- stack pointer register
246 ----------------------------------------
249 use ieee.std_logic_1164.all;
250 use ieee.std_logic_unsigned.all;
259 push_n : in std_logic;
260 pop_n : in std_logic;
261 int_d_oe_n : in std_logic;
262 int_a_oe_n : in std_logic;
263 int_dbus : inout std_logic_vector (dsize - 1 downto 0);
264 int_abus_l : out std_logic_vector (dsize - 1 downto 0);
265 int_abus_h : out std_logic_vector (dsize - 1 downto 0)
269 architecture rtl of sp is
278 d : in std_logic_vector (dsize - 1 downto 0);
279 q : out std_logic_vector (dsize - 1 downto 0)
282 signal oe_n : std_logic;
283 signal dff_we_n : std_logic;
284 signal q : std_logic_vector (dsize - 1 downto 0);
285 signal d : std_logic_vector (dsize - 1 downto 0);
286 signal q_buf : std_logic_vector (dsize - 1 downto 0);
289 oe_n <= (int_d_oe_n and int_a_oe_n);
290 dff_we_n <= (we_n and push_n and pop_n);
291 int_dbus <= q when int_d_oe_n = '0' else
293 -- int_abus_l <= q when int_a_oe_n = '0' else
296 ---push: address decrement after push is done.
297 ---pop: address increment before pop is done.
298 al_p : process (int_a_oe_n, push_n, clk, q_buf, q)
300 if (int_a_oe_n = '0') then
301 if (push_n = '0') then
307 elsif (pop_n = '0') then
317 int_abus_l <= (others => 'Z');
321 int_abus_h <= "00000001" when int_a_oe_n = '0' else
323 d <= int_dbus when we_n = '0' else
324 (q - 1) when push_n = '0' else
325 (q + 1) when pop_n = '0' else
328 dff_inst : dff generic map (dsize)
329 port map(clk, dff_we_n, oe_n, d, q);
330 buf : dff generic map (dsize)
331 port map(clk, dff_we_n, '0', q, q_buf);
335 ----------------------------------------
337 ----------------------------------------
340 use ieee.std_logic_1164.all;
348 res_n : in std_logic;
349 set_n : in std_logic;
352 d : in std_logic_vector (dsize - 1 downto 0);
353 q : out std_logic_vector (dsize - 1 downto 0)
357 architecture rtl of srff is
358 signal val : std_logic_vector (dsize - 1 downto 0);
361 q <= val when oe_n = '0' else
364 main_p : process (clk, res_n, set_n, d)
366 if ( clk'event and clk = '1'and we_n = '0') then
369 if (res_n'event and res_n = '0') then
370 val <= (others => '0');
372 if (set_n = '0') then
378 ----------------------------------------
379 --- status register component
380 --- status register is subtype of SR FF.
381 ----------------------------------------
384 use ieee.std_logic_1164.all;
386 entity processor_status is
392 res_n : in std_logic;
393 dec_we_n : in std_logic;
394 bus_we_n : in std_logic;
395 dec_oe_n : in std_logic;
396 bus_oe_n : in std_logic;
397 alu_c : in std_logic;
398 alu_v : in std_logic;
399 decoder : inout std_logic_vector (dsize - 1 downto 0);
400 int_dbus : inout std_logic_vector (dsize - 1 downto 0)
402 end processor_status;
404 architecture rtl of processor_status is
405 signal val : std_logic_vector (dsize - 1 downto 0);
407 decoder <= val when dec_oe_n = '0' else
409 int_dbus <= val when bus_oe_n = '0' else
413 main_p : process (clk, res_n, decoder, int_dbus, bus_we_n)
414 variable tmp : std_logic_vector (dsize - 1 downto 0);
416 -- SR Flags (bit 7 to bit 0):
422 -- D .... Decimal (use BCD for arithmetics)
423 -- I .... Interrupt (IRQ disable)
427 ---only interrupt flag is set on reset.
428 if (res_n'event and res_n = '0') then
432 if ( clk'event and clk = '1'and dec_we_n = '0') then
435 -- if ( clk'event and clk = '1'and bus_we_n = '0') then
439 ---status flag set from the internal data bus.
440 ---interpret the input data by the decoder input.
441 if ( clk'event and clk = '1'and bus_we_n = '0') then
442 if ((decoder(0) and decoder(1) and decoder(2) and decoder(3) and
443 decoder(4) and decoder(5) and decoder(6) and decoder(7)) = '1' )
445 ---only plp (pull status) sets the data bus data as they are.
448 ---other case: n/z/c/v data must be interpreted.
450 val (5 downto 2) <= tmp (5 downto 2);
453 if (decoder(7) = '1') then
454 val (7) <= int_dbus(7);
459 if (decoder(6) = '1') then
465 if (decoder(1) = '1') then
466 ---nor outputs 1 when all inputs are 0.
467 val (1) <= not (int_dbus(7) or int_dbus(6) or
468 int_dbus(5) or int_dbus(4) or int_dbus(3) or
469 int_dbus(2) or int_dbus(1) or int_dbus(0));
474 if (decoder(0) = '1') then
485 ----------------------------------------
487 ----------------------------------------
490 use ieee.std_logic_1164.all;
498 d : in std_logic_vector (dsize - 1 downto 0);
499 q : out std_logic_vector (dsize - 1 downto 0)
503 architecture rtl of tsb is
504 signal val : std_logic_vector (dsize - 1 downto 0);
506 q <= d when oe_n = '0' else