1 |
3 |
JonasDC |
----------------------------------------------------------------------
|
2 |
|
|
---- mont_ctrl ----
|
3 |
|
|
---- ----
|
4 |
|
|
---- This file is part of the ----
|
5 |
|
|
---- Modular Simultaneous Exponentiation Core project ----
|
6 |
|
|
---- http://www.opencores.org/cores/mod_sim_exp/ ----
|
7 |
|
|
---- ----
|
8 |
|
|
---- Description ----
|
9 |
|
|
---- control unit for a pipelined montgomery multiplier, with ----
|
10 |
|
|
---- split pipeline operation and "auto-run" support ----
|
11 |
|
|
---- ----
|
12 |
|
|
---- Dependencies: ----
|
13 |
|
|
---- - autorun_cntrl ----
|
14 |
|
|
---- ----
|
15 |
|
|
---- Authors: ----
|
16 |
|
|
---- - Geoffrey Ottoy, DraMCo research group ----
|
17 |
|
|
---- - Jonas De Craene, JonasDC@opencores.org ----
|
18 |
|
|
---- ----
|
19 |
|
|
----------------------------------------------------------------------
|
20 |
|
|
---- ----
|
21 |
|
|
---- Copyright (C) 2011 DraMCo research group and OPENCORES.ORG ----
|
22 |
|
|
---- ----
|
23 |
|
|
---- This source file may be used and distributed without ----
|
24 |
|
|
---- restriction provided that this copyright statement is not ----
|
25 |
|
|
---- removed from the file and that any derivative work contains ----
|
26 |
|
|
---- the original copyright notice and the associated disclaimer. ----
|
27 |
|
|
---- ----
|
28 |
|
|
---- This source file is free software; you can redistribute it ----
|
29 |
|
|
---- and/or modify it under the terms of the GNU Lesser General ----
|
30 |
|
|
---- Public License as published by the Free Software Foundation; ----
|
31 |
|
|
---- either version 2.1 of the License, or (at your option) any ----
|
32 |
|
|
---- later version. ----
|
33 |
|
|
---- ----
|
34 |
|
|
---- This source is distributed in the hope that it will be ----
|
35 |
|
|
---- useful, but WITHOUT ANY WARRANTY; without even the implied ----
|
36 |
|
|
---- warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR ----
|
37 |
|
|
---- PURPOSE. See the GNU Lesser General Public License for more ----
|
38 |
|
|
---- details. ----
|
39 |
|
|
---- ----
|
40 |
|
|
---- You should have received a copy of the GNU Lesser General ----
|
41 |
|
|
---- Public License along with this source; if not, download it ----
|
42 |
|
|
---- from http://www.opencores.org/lgpl.shtml ----
|
43 |
|
|
---- ----
|
44 |
|
|
----------------------------------------------------------------------
|
45 |
2 |
JonasDC |
|
46 |
3 |
JonasDC |
library ieee;
|
47 |
|
|
use ieee.std_logic_1164.all;
|
48 |
|
|
use ieee.std_logic_arith.all;
|
49 |
|
|
use ieee.std_logic_unsigned.all;
|
50 |
2 |
JonasDC |
|
51 |
3 |
JonasDC |
library mod_sim_exp;
|
52 |
|
|
use mod_sim_exp.mod_sim_exp_pkg.all;
|
53 |
|
|
|
54 |
|
|
|
55 |
24 |
JonasDC |
-- This module controls the montgommery mutliplier and controls traffic between
|
56 |
|
|
-- RAM and multiplier. Also contains the autorun logic for exponentiations.
|
57 |
2 |
JonasDC |
entity mont_ctrl is
|
58 |
3 |
JonasDC |
port (
|
59 |
|
|
clk : in std_logic;
|
60 |
|
|
reset : in std_logic;
|
61 |
|
|
-- bus side
|
62 |
|
|
start : in std_logic;
|
63 |
|
|
x_sel_single : in std_logic_vector(1 downto 0);
|
64 |
|
|
y_sel_single : in std_logic_vector(1 downto 0);
|
65 |
|
|
run_auto : in std_logic;
|
66 |
|
|
op_buffer_empty : in std_logic;
|
67 |
|
|
op_sel_buffer : in std_logic_vector(31 downto 0);
|
68 |
|
|
read_buffer : out std_logic;
|
69 |
|
|
done : out std_logic;
|
70 |
|
|
calc_time : out std_logic;
|
71 |
|
|
-- multiplier side
|
72 |
|
|
op_sel : out std_logic_vector(1 downto 0);
|
73 |
|
|
load_x : out std_logic;
|
74 |
|
|
load_result : out std_logic;
|
75 |
|
|
start_multiplier : out std_logic;
|
76 |
|
|
multiplier_ready : in std_logic
|
77 |
2 |
JonasDC |
);
|
78 |
|
|
end mont_ctrl;
|
79 |
|
|
|
80 |
3 |
JonasDC |
|
81 |
2 |
JonasDC |
architecture Behavioral of mont_ctrl is
|
82 |
24 |
JonasDC |
signal start_d : std_logic; -- delayed version of start input
|
83 |
|
|
signal start_pulse : std_logic;
|
84 |
|
|
signal auto_start_pulse : std_logic;
|
85 |
3 |
JonasDC |
signal start_multiplier_i : std_logic;
|
86 |
24 |
JonasDC |
signal start_up_counter : std_logic_vector(2 downto 0) := "100"; -- used in op_sel at multiplier start
|
87 |
2 |
JonasDC |
|
88 |
3 |
JonasDC |
signal calc_time_i : std_logic; -- high ('1') during multiplication
|
89 |
|
|
|
90 |
24 |
JonasDC |
signal x_sel : std_logic_vector(1 downto 0); -- the operand used as x input
|
91 |
|
|
signal y_sel : std_logic_vector(1 downto 0); -- the operand used as y input
|
92 |
|
|
signal x_sel_buffer : std_logic_vector(1 downto 0); -- x operand as specified by fifo buffer (autorun)
|
93 |
3 |
JonasDC |
|
94 |
24 |
JonasDC |
signal auto_done : std_logic;
|
95 |
|
|
signal start_auto : std_logic;
|
96 |
3 |
JonasDC |
signal auto_multiplier_done_i : std_logic;
|
97 |
2 |
JonasDC |
|
98 |
|
|
begin
|
99 |
|
|
|
100 |
|
|
-----------------------------------------------------------------------------------
|
101 |
|
|
-- Processes related to starting and stopping the multiplier
|
102 |
|
|
-----------------------------------------------------------------------------------
|
103 |
|
|
-- generate a start pulse (duration 1 clock cycle) based on ext. start sig
|
104 |
|
|
START_PULSE_PROC: process(clk)
|
105 |
|
|
begin
|
106 |
|
|
if rising_edge(clk) then
|
107 |
24 |
JonasDC |
start_d <= start;
|
108 |
2 |
JonasDC |
end if;
|
109 |
|
|
end process START_PULSE_PROC;
|
110 |
24 |
JonasDC |
start_pulse <= start and (not start_d);
|
111 |
|
|
start_auto <= start_pulse and run_auto;
|
112 |
2 |
JonasDC |
|
113 |
24 |
JonasDC |
-- to start the multiplier we first need to select the x_operand and
|
114 |
|
|
-- clock it in the x shift register
|
115 |
|
|
-- the we select the y_operand and start the multiplier
|
116 |
|
|
|
117 |
|
|
-- start_up_counter
|
118 |
|
|
-- default state : "100"
|
119 |
|
|
-- at start pulse counter resets to 0 and counts up to "100"
|
120 |
2 |
JonasDC |
START_MULT_PROC: process(clk, reset)
|
121 |
|
|
begin
|
122 |
|
|
if reset = '1' then
|
123 |
24 |
JonasDC |
start_up_counter <= "100";
|
124 |
2 |
JonasDC |
elsif rising_edge(clk) then
|
125 |
24 |
JonasDC |
if start_pulse = '1' or auto_start_pulse = '1' then
|
126 |
|
|
start_up_counter <= "000";
|
127 |
|
|
elsif start_up_counter(2) /= '1' then
|
128 |
|
|
start_up_counter <= start_up_counter + '1';
|
129 |
2 |
JonasDC |
else
|
130 |
24 |
JonasDC |
start_up_counter <= "100";
|
131 |
2 |
JonasDC |
end if;
|
132 |
|
|
end if;
|
133 |
|
|
end process;
|
134 |
|
|
|
135 |
|
|
-- select operands (autorun/single run)
|
136 |
24 |
JonasDC |
x_sel <= x_sel_buffer when (run_auto = '1') else x_sel_single;
|
137 |
|
|
y_sel <= "11" when (run_auto = '1') else y_sel_single; -- y is operand3 in auto mode
|
138 |
2 |
JonasDC |
|
139 |
24 |
JonasDC |
-- clock operands to operand_mem output (first x, then y)
|
140 |
|
|
with start_up_counter(2 downto 1) select
|
141 |
|
|
op_sel <= x_sel when "00", -- start_up_counter="00x" (first 2 cycles)
|
142 |
|
|
y_sel when others; --
|
143 |
|
|
load_x <= start_up_counter(0) and (not start_up_counter(1)); -- latch x operand if start_up_counter="x01"
|
144 |
|
|
|
145 |
|
|
-- start multiplier when start_up_counter="x11"
|
146 |
|
|
start_multiplier_i <= start_up_counter(1) and start_up_counter(0);
|
147 |
2 |
JonasDC |
start_multiplier <= start_multiplier_i;
|
148 |
|
|
|
149 |
|
|
-- signal calc time is high during multiplication
|
150 |
|
|
CALC_TIME_PROC: process(clk, reset)
|
151 |
|
|
begin
|
152 |
|
|
if reset = '1' then
|
153 |
|
|
calc_time_i <= '0';
|
154 |
|
|
elsif rising_edge(clk) then
|
155 |
|
|
if start_multiplier_i = '1' then
|
156 |
|
|
calc_time_i <= '1';
|
157 |
|
|
elsif multiplier_ready = '1' then
|
158 |
|
|
calc_time_i <= '0';
|
159 |
|
|
else
|
160 |
|
|
calc_time_i <= calc_time_i;
|
161 |
|
|
end if;
|
162 |
|
|
end if;
|
163 |
|
|
end process CALC_TIME_PROC;
|
164 |
|
|
calc_time <= calc_time_i;
|
165 |
|
|
|
166 |
|
|
-- what happens when a multiplication has finished
|
167 |
|
|
load_result <= multiplier_ready;
|
168 |
24 |
JonasDC |
-- ignore multiplier_ready when in automode, the logic will assert auto_done when finished
|
169 |
|
|
done <= ((not run_auto) and multiplier_ready) or auto_done;
|
170 |
2 |
JonasDC |
|
171 |
|
|
-----------------------------------------------------------------------------------
|
172 |
|
|
-- Processes related to op_buffer cntrl and auto_run mode
|
173 |
24 |
JonasDC |
-- start_auto -> start autorun mode operation
|
174 |
2 |
JonasDC |
-- auto_start_pulse <- autorun logic starts the multiplier
|
175 |
|
|
-- auto_done <- autorun logic signals when autorun operation has finished
|
176 |
24 |
JonasDC |
-- x_sel_buffer <- autorun logic determines which operand is used as x
|
177 |
2 |
JonasDC |
|
178 |
|
|
-- check buffer empty signal
|
179 |
|
|
-----------------------------------------------------------------------------------
|
180 |
24 |
JonasDC |
|
181 |
2 |
JonasDC |
-- multiplier_ready is only passed to autorun control when in autorun mode
|
182 |
24 |
JonasDC |
auto_multiplier_done_i <= (multiplier_ready and run_auto);
|
183 |
3 |
JonasDC |
|
184 |
|
|
autorun_control_logic : autorun_cntrl port map(
|
185 |
|
|
clk => clk,
|
186 |
|
|
reset => reset,
|
187 |
24 |
JonasDC |
start => start_auto,
|
188 |
|
|
done => auto_done,
|
189 |
|
|
op_sel => x_sel_buffer,
|
190 |
|
|
start_multiplier => auto_start_pulse,
|
191 |
3 |
JonasDC |
multiplier_done => auto_multiplier_done_i,
|
192 |
|
|
read_buffer => read_buffer,
|
193 |
|
|
buffer_din => op_sel_buffer,
|
194 |
|
|
buffer_empty => op_buffer_empty
|
195 |
|
|
);
|
196 |
|
|
|
197 |
2 |
JonasDC |
end Behavioral;
|