1
|
|
2
|
-- Copyright (C) 1996 Morgan Kaufmann Publishers, Inc
|
3
|
|
4
|
-- This file is part of VESTs (Vhdl tESTs).
|
5
|
|
6
|
-- VESTs is free software; you can redistribute it and/or modify it
|
7
|
-- under the terms of the GNU General Public License as published by the
|
8
|
-- Free Software Foundation; either version 2 of the License, or (at
|
9
|
-- your option) any later version.
|
10
|
|
11
|
-- VESTs is distributed in the hope that it will be useful, but WITHOUT
|
12
|
-- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
13
|
-- FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
14
|
-- for more details.
|
15
|
|
16
|
-- You should have received a copy of the GNU General Public License
|
17
|
-- along with VESTs; if not, write to the Free Software Foundation,
|
18
|
-- Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
19
|
|
20
|
-- ---------------------------------------------------------------------
|
21
|
--
|
22
|
-- $Id: ch_04_fg_04_06.vhd,v 1.2 2001-10-26 16:29:33 paw Exp $
|
23
|
-- $Revision: 1.2 $
|
24
|
--
|
25
|
-- ---------------------------------------------------------------------
|
26
|
|
27
|
architecture system_level of computer is
|
28
|
|
29
|
type opcodes is (add, sub, addu, subu, jmp, breq, brne, ld, st, -- . . .);
|
30
|
-- not in book:
|
31
|
nop);
|
32
|
-- end not in book
|
33
|
type reg_number is range 0 to 31;
|
34
|
constant r0 : reg_number := 0; constant r1 : reg_number := 1; -- . . .
|
35
|
-- not in book:
|
36
|
constant r2 : reg_number := 2;
|
37
|
-- end not in book
|
38
|
|
39
|
type instruction is record
|
40
|
opcode : opcodes;
|
41
|
source_reg1, source_reg2, dest_reg : reg_number;
|
42
|
displacement : integer;
|
43
|
end record instruction;
|
44
|
|
45
|
type word is record
|
46
|
instr : instruction;
|
47
|
data : bit_vector(31 downto 0);
|
48
|
end record word;
|
49
|
|
50
|
signal address : natural;
|
51
|
signal read_word, write_word : word;
|
52
|
signal mem_read, mem_write : bit := '0';
|
53
|
signal mem_ready : bit := '0';
|
54
|
|
55
|
begin
|
56
|
|
57
|
cpu : process is
|
58
|
variable instr_reg : instruction;
|
59
|
variable PC : natural;
|
60
|
-- . . . -- other declarations for register file, etc.
|
61
|
begin
|
62
|
address <= PC;
|
63
|
mem_read <= '1';
|
64
|
wait until mem_ready = '1';
|
65
|
instr_reg := read_word.instr;
|
66
|
mem_read <= '0';
|
67
|
-- not in book:
|
68
|
wait until mem_ready = '0';
|
69
|
-- end not in book
|
70
|
PC := PC + 4;
|
71
|
case instr_reg.opcode is -- execute the instruction
|
72
|
-- . . .
|
73
|
-- not in book:
|
74
|
when others => null;
|
75
|
-- end not in book
|
76
|
end case;
|
77
|
end process cpu;
|
78
|
|
79
|
memory : process is
|
80
|
type memory_array is array (0 to 2**14 - 1) of word;
|
81
|
variable store : memory_array :=
|
82
|
( 0 => ( ( ld, r0, r0, r2, 40 ), X"00000000" ),
|
83
|
1 => ( ( breq, r2, r0, r0, 5 ), X"00000000" ),
|
84
|
-- . . .
|
85
|
40 => ( ( nop, r0, r0, r0, 0 ), X"FFFFFFFE"),
|
86
|
others => ( ( nop, r0, r0, r0, 0 ), X"00000000") );
|
87
|
begin
|
88
|
-- . . .
|
89
|
-- not in book:
|
90
|
wait until mem_read = '1';
|
91
|
read_word <= store(address);
|
92
|
mem_ready <= '1';
|
93
|
wait until mem_read = '0';
|
94
|
mem_ready <= '0';
|
95
|
-- end not in book
|
96
|
end process memory;
|
97
|
|
98
|
end architecture system_level;
|