copyleft: gplv3 added and set repo to public
[calu.git] / cpu / src / extension_pkg.vhd
1 --   `Deep Thought', a softcore CPU implemented on a FPGA
2 --
3 --  Copyright (C) 2010 Markus Hofstaetter <markus.manrow@gmx.at>
4 --  Copyright (C) 2010 Martin Perner <e0725782@student.tuwien.ac.at>
5 --  Copyright (C) 2010 Stefan Rebernig <stefan.rebernig@gmail.com>
6 --  Copyright (C) 2010 Manfred Schwarz <e0725898@student.tuwien.ac.at>
7 --  Copyright (C) 2010 Bernhard Urban <lewurm@gmail.com>
8 --
9 --  This program is free software: you can redistribute it and/or modify
10 --  it under the terms of the GNU General Public License as published by
11 --  the Free Software Foundation, either version 3 of the License, or
12 --  (at your option) any later version.
13 --
14 --  This program is distributed in the hope that it will be useful,
15 --  but WITHOUT ANY WARRANTY; without even the implied warranty of
16 --  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 --  GNU General Public License for more details.
18 --
19 --  You should have received a copy of the GNU General Public License
20 --  along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
22 library IEEE;
23
24 use IEEE.std_logic_1164.all;
25 use IEEE.numeric_std.all;
26
27 use work.common_pkg.all;
28 --use work.alu_pkg.all;
29 --use work.gpm_pkg.all;
30
31 package extension_pkg is
32
33 constant EXTWORDL : integer := log2c(4);
34 constant BYTEADDR : integer := log2c(4);
35 constant PCOUNT   : integer := 3;
36 constant EXTWORDS : integer := EXTWORDL + BYTEADDR;
37
38 subtype ext_addrid_t  is std_logic_vector(gp_register_t'high - EXTWORDS downto 0);
39 subtype ext_addr_t    is std_logic_vector((gp_register_t'high-BYTEADDR) downto 0);    
40 subtype paddr_t is std_logic_vector(log2c(PCOUNT)-1 downto 0);   
41
42         type extmod_rec is record
43                 sel   : std_logic;
44                 wr_en : std_logic;
45                 byte_en : byte_en_t;
46                 data : gp_register_t;
47                 addr : ext_addr_t;     
48         end record; 
49
50
51 type status_rec is record
52                 zero : std_logic;
53                 oflo : std_logic;
54                 sign : std_logic;
55                 carry : std_logic;
56 end record;
57
58 procedure put_word_be (tmp : out gp_register_t; signal reg : in gp_register_t; signal byte_en : byte_en_t);
59
60 -- Addressen der bis jetzt vorhanden extensions
61 constant EXT_UART_ADDR:   ext_addrid_t := x"0000200";
62 constant EXT_7SEG_ADDR:   ext_addrid_t := x"0000201";
63 constant EXT_INT_ADDR:    ext_addrid_t := x"0000202";
64 constant EXT_IMP_ADDR:    ext_addrid_t := x"0000203";
65 constant EXT_TIMER_ADDR:  ext_addrid_t := x"0000204";
66 -- dummy addressen
67 constant EXT_EXTMEM_ADDR: ext_addrid_t := x"FFFFFFB";
68 constant EXT_AC97_ADDR:   ext_addrid_t := x"FFFFFFD";
69 constant EXT_GPMP_ADDR:    ext_addrid_t := x"FFFFFFF";
70
71 component extension_gpm is
72         --some modules won't need all inputs/outputs
73         generic (
74                         -- active reset value
75                         RESET_VALUE : std_logic
76                         );
77         port(
78                 --System inputs
79                         clk :   in std_logic;
80                         reset : in std_logic;
81                 -- general extension interface                  
82                         ext_reg  : in extmod_rec;
83                          data_out : out gp_register_t;
84                 -- Input
85                         psw_nxt : in status_rec;
86                         paddr   : in paddr_t;
87                         pinc    : in std_logic;
88                         pwr_en  : in std_logic;
89                 -- Ouput
90                          psw     : out status_rec;
91                          pval    : out gp_register_t;
92                          pval_nxt : out gp_register_t
93                 );
94  end component extension_gpm;
95
96 component extension_interrupt is
97         --some modules won't need all inputs/outputs
98         generic (
99                         -- active reset value
100                         RESET_VALUE : std_logic
101                         );
102         port(
103                 --System inputs
104                         clk :   in std_logic;
105                         reset : in std_logic;
106                 -- general extension interface                  
107                         ext_reg  : in extmod_rec;
108                         data_out : out gp_register_t;
109                 -- Input
110                         uart_int : in std_logic;
111                 -- Ouput
112                         int_req : out interrupt_t
113                 );
114  end component extension_interrupt;
115
116
117 end package extension_pkg;
118
119 package body extension_pkg is
120         procedure put_word_be (tmp : out gp_register_t; signal reg : in gp_register_t; signal byte_en : byte_en_t) is
121         begin
122                 for i in 0 to 3 loop
123                         if byte_en(i) = '1' then
124                                 tmp(((i+1)*byte_t'length-1) downto i*byte_t'length) := reg(((i+1)*byte_t'length-1) downto i*byte_t'length);
125                         end if;
126                 end loop;
127         end;
128 end package body extension_pkg;