OpenCores
URL https://opencores.org/ocsvn/risc5x/risc5x/trunk

Subversion Repositories risc5x

[/] [risc5x/] [trunk/] [idec.vhd] - Blame information for rev 3

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 mikej
--
2
-- Risc5x
3
-- www.OpenCores.Org - November 2001
4
--
5
--
6
-- This library is free software; you can distribute it and/or modify it
7
-- under the terms of the GNU Lesser General Public License as published
8
-- by the Free Software Foundation; either version 2.1 of the License, or
9
-- (at your option) any later version.
10
--
11
-- This library is distributed in the hope that it will be useful, but
12
-- WITHOUT ANY WARRANTY; without even the implied warranty of
13
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14
-- See the GNU Lesser General Public License for more details.
15
--
16
-- A RISC CPU core.
17
--
18
-- (c) Mike Johnson 2001. All Rights Reserved.
19
-- mikej@opencores.org for support or any other issues.
20
--
21
-- Revision list
22
--
23
-- version 1.0 initial opencores release
24
--
25
 
26
use work.pkg_risc5x.all;
27
library ieee;
28
  use ieee.std_logic_1164.all;
29
  use ieee.std_logic_arith.all;
30
  use ieee.std_logic_unsigned.all;
31
 
32
entity IDEC is
33
  port (
34
    INST                : in  std_logic_vector(11 downto 0);
35
 
36
    ALU_ASEL            : out std_logic_vector(1 downto 0);
37
    ALU_BSEL            : out std_logic_vector(1 downto 0);
38
    ALU_ADDSUB          : out std_logic_vector(1 downto 0);
39
    ALU_BIT             : out std_logic_vector(1 downto 0);
40
    ALU_SEL             : out std_logic_vector(1 downto 0);
41
 
42
    WWE_OP              : out std_logic;
43
    FWE_OP              : out std_logic;
44
 
45
    ZWE                 : out std_logic;
46
    DCWE                : out std_logic;
47
    CWE                 : out std_logic;
48
    BDPOL               : out std_logic;
49
    OPTION              : out std_logic;
50
    TRIS                : out std_logic
51
    );
52
end;
53
architecture RTL of IDEC is
54
 
55
-- signal definitions
56
  signal alu    : std_logic_vector(9 downto 0) := (others => '0');
57
  signal flags  : std_logic_vector(2 downto 0) := (others => '0');
58
  signal fwe    : std_logic;
59
  signal wwe    : std_logic;
60
  signal we     : std_logic;
61
 
62
begin -- architecture
63
 
64
  -- aluasel,        Select source for ALU A input. 00=W, 01=SBUS, 10=K , 11= SBUS_SWAP
65
  -- alubsel,        Select source for ALU B input. 00=W, 01=SBUS, 10=BD, 11= "1"
66
  -- bit             0 : A and B, 1 : A or B, 2 : A xor B, 3 : not A
67
  -- wwe,            W register Write Enable
68
  -- fwe,            File Register Write Enable
69
  -- zwe,            Status register Z bit update
70
  -- dcwe            Status register DC bit update
71
  -- cwe,            Status register C bit update
72
  -- bdpol,          Polarity on bit decode vector (0=no inversion, 1=invert)
73
  -- tris,           Instruction is an TRIS instruction
74
  -- option          Instruction is an OPTION instruction
75
 
76
  p_inst_decode_comb : process(INST)
77
  begin
78
    BDPOL       <= '0';
79
    OPTION      <= '0';
80
    TRIS        <= '0';
81
 
82
    alu         <= (others => '0');
83
    flags       <= (others => '0');
84
    fwe         <= '0';
85
    wwe         <= '0';
86
    we          <= '0';
87
    case INST(11 downto 8) is
88
      when "0000" =>                                    --asel  bsel    +-    bit    sel
89
          if (INST(7 downto 0) = "00000000") then alu <= "00" & "00" & "00" & "00" & "00"; end if; -- NOP
90
          if (INST(7 downto 0) = "00000010") then alu <= "00" & "00" & "00" & "00" & "00"; fwe <= '1'; OPTION <= '1'; end if; -- OPTION
91
          if (INST(7 downto 0) = "00000011") then alu <= "00" & "00" & "00" & "00" & "00"; end if; -- SLEEP
92
          if (INST(7 downto 0) = "00000100") then alu <= "00" & "00" & "00" & "00" & "00"; end if; -- CLRWDT
93
          if (INST(7 downto 0) = "00000101") then alu <= "00" & "00" & "00" & "00" & "00"; fwe <= '1'; TRIS <= '1'; end if; -- TRIS 5
94
          if (INST(7 downto 0) = "00000110") then alu <= "00" & "00" & "00" & "00" & "00"; fwe <= '1'; TRIS <= '1'; end if; -- TRIS 6
95
          if (INST(7 downto 0) = "00000111") then alu <= "00" & "00" & "00" & "00" & "00"; fwe <= '1'; TRIS <= '1'; end if; -- TRIS 7
96
          if (INST(7 downto 5) = "001"     ) then alu <= "00" & "00" & "00" & "00" & "00"; fwe <= '1'; end if; -- MOVWF
97
 
98
          if (INST(7 downto 0) = "01000000") then alu <= "00" & "00" & "00" & "10" & "01"; wwe <= '1'; flags <= "100"; end if; -- CLRW
99
          if (INST(7 downto 5) = "011"     ) then alu <= "00" & "00" & "00" & "10" & "01"; fwe <= '1'; flags <= "100"; end if; -- CLRF
100
 
101
          if (INST(7 downto 6) = "10"      ) then alu <= "01" & "00" & "11" & "00" & "00";  we <= '1'; flags <= "111"; end if; -- SUBWF
102
          if (INST(7 downto 6) = "11"      ) then alu <= "01" & "11" & "11" & "00" & "00";  we <= '1'; flags <= "100"; end if; -- DECF
103
      when "0001" =>
104
        case INST(7 downto 6) is
105
          when "00" => alu <= "00" & "01" & "00" & "01" & "01"; we <= '1'; flags <= "100"; -- IORWF
106
          when "01" => alu <= "00" & "01" & "00" & "00" & "01"; we <= '1'; flags <= "100"; -- ANDWF
107
          when "10" => alu <= "00" & "01" & "00" & "10" & "01"; we <= '1'; flags <= "100"; -- XORWF
108
          when "11" => alu <= "00" & "01" & "10" & "00" & "00"; we <= '1'; flags <= "111"; -- ADDWF
109
          when others => null;
110
        end case;
111
      when "0010" =>
112
        case INST(7 downto 6) is
113
          when "00" => alu <= "01" & "00" & "00" & "00" & "00"; we <= '1'; flags <= "100"; -- MOVF
114
          when "01" => alu <= "01" & "00" & "00" & "11" & "01"; we <= '1'; flags <= "100"; -- COMF
115
          when "10" => alu <= "01" & "11" & "10" & "00" & "00"; we <= '1'; flags <= "100"; -- INCF
116
          when "11" => alu <= "01" & "11" & "11" & "00" & "00"; we <= '1'; flags <= "000"; -- DECFSZ
117
          when others => null;
118
        end case;
119
      when "0011" =>
120
        case INST(7 downto 6) is
121
          when "00" => alu <= "01" & "00" & "00" & "00" & "10"; we <= '1'; flags <= "001"; -- RRF
122
          when "01" => alu <= "01" & "00" & "00" & "00" & "11"; we <= '1'; flags <= "001"; -- RLF
123
          when "10" => alu <= "11" & "00" & "00" & "00" & "00"; we <= '1'; flags <= "000"; -- SWAPF
124
          when "11" => alu <= "01" & "11" & "10" & "00" & "00"; we <= '1'; flags <= "000"; -- INCFSZ
125
          when others => null;
126
        end case;
127
 
128
      when "0100" => alu <= "01" & "10" & "00" & "00" & "01"; fwe <= '1'; flags <= "000";  BDPOL <= '1'; -- BCF
129
      when "0101" => alu <= "01" & "10" & "00" & "01" & "01"; fwe <= '1'; flags <= "000"; -- BSF
130
      when "0110" => alu <= "01" & "10" & "00" & "00" & "01"; -- BTFSC
131
      when "0111" => alu <= "01" & "10" & "00" & "00" & "01"; -- BTFSS
132
 
133
      when "1000" => alu <= "10" & "00" & "00" & "00" & "00"; wwe <= '1'; -- RETLW
134
      when "1001" => alu <= "10" & "00" & "00" & "00" & "00"; -- CALL
135
      when "1010" => alu <= "10" & "00" & "00" & "00" & "00"; -- GOTO
136
      when "1011" => alu <= "10" & "00" & "00" & "00" & "00"; -- GOTO
137
 
138
      when "1100" => alu <= "10" & "00" & "00" & "00" & "00"; wwe <= '1'; flags <= "000"; -- MOVLW
139
      when "1101" => alu <= "10" & "00" & "00" & "01" & "01"; wwe <= '1'; flags <= "100"; -- IORLW
140
      when "1110" => alu <= "10" & "00" & "00" & "00" & "01"; wwe <= '1'; flags <= "100"; -- ANDLW
141
      when "1111" => alu <= "10" & "00" & "00" & "10" & "01"; wwe <= '1'; flags <= "100"; -- XORLW
142
      when others => null;
143
    end case;
144
  end process;
145
 
146
 
147
  p_we_comb : process(wwe,fwe,we,INST)
148
  begin
149
    WWE_OP <= '0';
150
    FWE_OP <= '0';
151
 
152
    if (wwe = '1') or ((we = '1') and (INST(5) ='0')) then
153
      WWE_OP <= '1';
154
    end if;
155
 
156
    if (fwe = '1') or ((we = '1') and (INST(5) = '1')) then
157
      FWE_OP <= '1';
158
    end if;
159
  end process;
160
 
161
  ALU_ASEL            <= alu(9 downto 8);
162
  ALU_BSEL            <= alu(7 downto 6);
163
  ALU_ADDSUB          <= alu(5 downto 4);
164
  ALU_BIT             <= alu(3 downto 2);
165
  ALU_SEL             <= alu(1 downto 0);
166
 
167
  ZWE                 <= flags(2);
168
  DCWE                <= flags(1);
169
  CWE                 <= flags(0);
170
end rtl;

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.