subtype instruction_word_t is std_logic_vector(WORD_WIDTH-1 downto 0);
subtype instruction_addr_t is std_logic_vector(INSTR_ADDR_WIDTH-1 downto 0);
- subtype gp_addr_t is unsigned(REG_ADDR_WIDTH-1 downto 0);
+ subtype gp_addr_t is std_logic_vector(REG_ADDR_WIDTH-1 downto 0);
subtype data_ram_word_t is std_logic_vector(WORD_WIDTH-1 downto 0);
subtype data_ram_addr_t is std_logic_vector(DATA_ADDR_WIDTH-1 downto 0);
carry, sreg_update, high_low, fill, signext, bp, arith, left_right : std_logic;
+ op_detail : op_pot_t;
+
end record;
rtw_reg : gp_register_t;
rtw_reg1 : std_logic;
rtw_reg2 : std_logic;
+ immediate : gp_register_t;
end record;
use work.common_pkg.all;
-
architecture behav of decode_stage is
signal instr_spl : instruction_rec;
end process;
+-- type dec_op is record
+-- condition : condition_t;
+-- op_group : op_info_t;
+-- op_detail : op_opt_t;
+-- brpr : std_logic;
+--
+-- src1 : gp_register_t;
+-- src2 : gp_register_t;
+--
+-- saddr1 : gp_addr_t;
+-- saddr2 : gp_addr_t;
+--
+-- daddr : gp_addr_t;
+--
+-- end record;
+
+to_alu: process(instr_spl)
+
+begin
+
+
+end process;
+
-- async process: decides between memory and read-through-write buffer on output
output: process(rtw_rec, reg1_mem_data, reg2_mem_data)
rtw_rec_nxt.rtw_reg1 <= '0';
rtw_rec_nxt.rtw_reg2 <= '0';
+ rtw_rec_nxt.immediate <= instr_spl.immediate;
+
if (reg_w_addr = instr_spl.reg_src1_addr) then
rtw_rec_nxt.rtw_reg1 <= '1';
end if;
instr_s.signext := '0';
instr_s.bp := '0';
instr_s.arith := '0';
+ instr_s.op_detail := (others => '0');
-- special function register operations missing
instr_s.reg_src2_addr := instruction(14 downto 11);
instr_s.carry := instruction(1);
instr_s.sreg_update := instruction(0);
+
+ instr_s.op_detail(NO_PSW_OPT) := instruction(0); --instr_s.sreg_update;
+
+ if (instr_s.opcode = "00000") then
+ instr_s.op_detail(CARRY_OPT) := instruction(1); --instr_s.carry;
+ end if;
+
+ if (instr_s.opcode = "00001") then
+ instr_s.op_detail(SUB_OPT) := '1';
+ instr_s.op_detail(CARRY_OPT) := instruction(1); --instr_s.carry;
+ end if;
end if;
-- when "00001" => --sub
-- instr_s.reg_dest_addr := instruction(22 downto 19);
if (instr_s.signext = '1' and instr_s.immediate(11) = '1') then
instr_s.immediate(31 downto 12) := (others => '1');
end if;
- end if;
+ instr_s.op_detail(IMM_OPT) := '1';
+ instr_s.op_detail(CARRY_OPT) := instruction(1);
+ instr_s.op_detail(NO_PSW_OPT) := instruction(0);
+
+ if (instr_s.opcode = "00011") then
+ instr_s.op_detail(SUB_OPT) := '1';
+ end if;
+ end if;
-- when "00011" => --subi
-- instr_s.reg_dest_addr := instruction(22 downto 19);
instr_s.high_low := instruction(2);
instr_s.fill := instruction(1);
instr_s.sreg_update := instruction(0);
+
+ if (instr_s.fill = '1') then
+ instr_s.immediate(31 downto 16) := (others => '1');
+ end if;
+
+ instr_s.op_detail(IMM_OPT) := '1';
+ instr_s.op_detail(NO_PSW_OPT) := instruction(0);
end if;
-- when "00111" => --orx
instr_s.arith := instruction(2);
instr_s.carry := instruction(1);
instr_s.sreg_update := instruction(0);
+
+ instr_s.op_detail(RIGHT_OPT) := instruction(3);
+ instr_s.op_detail(NO_PSW_OPT) := instruction(0);
+ instr_s.op_detail(CARRY_OPT) := instruction(1);
+ instr_s.op_detail(ARITH_OPT) := instruction(2);
end if;
-- when "01011" => --stackop
instr_s.signext := instruction(2);
instr_s.high_low := instruction(1);
- if (instr_s.signext = '1' and instr_s.immediate(11) = '1') then
- instr_s.immediate(31 downto 16) := (others => '1');
+ if (instr_s.opcode = "11010") then
+ if (instr_s.signext = '1' and instr_s.immediate(11) = '1') then
+ instr_s.immediate(31 downto 16) := (others => '1');
+ end if;
+ instr_s.op_detail(IMM_OPT) := '1';
end if;
end if;
-- when "11000" => --cmp
instr_s.reg_src1_addr := instruction(22 downto 19);
instr_s.reg_src2_addr := instruction(18 downto 15);
- instr_s.immediate(15 downto 0) := instruction(18 downto 3);
+
+ if (instr_s.opcode = "11001") then
+ instr_s.immediate(15 downto 0) := instruction(18 downto 3);
+ instr_s.signext := instruction(2);
+
+ if (instr_s.signext = '1' and instr_s.immediate(15) = '1') then
+ instr_s.immediate(31 downto 16) := (others => '1');
+ end if;
+
+ instr_s.op_detail(IMM_OPT) := '1';
+ end if;
+
end if;
-- when "11001" => --cmpi
-library IEEE;\r
-use IEEE.std_logic_1164.all;\r
-use IEEE.numeric_std.all;\r
-\r
-use work.common_pkg.all;\r
-use work.alu_pkg.all;\r
-\r
-architecture add_op of exec_op is\r
-\r
-signal sub, addc : std_logic;\r
-\r
-begin\r
-\r
-sub <= op_detail(SUB_OPT);\r
-addc <= op_detail(CARRY_OPT);\r
-\r
-calc: process(left_operand, right_operand, alu_state, sub, addc)\r
- variable alu_result_v : alu_result_rec;\r
- variable complement : gp_register_t;\r
- variable carry_res : unsigned(gp_register_t'length downto 0);\r
- variable tmp_right_operand : unsigned(gp_register_t'length downto 0);\r
- variable oflo1, oflo2, l_neg, r_neg : std_logic;\r
- variable addcarry : unsigned(carry_res'range);\r
-begin\r
- alu_result_v := alu_state;\r
- \r
- addcarry := (others =>'0');\r
- addcarry(0) := alu_state.status.carry and addc;\r
- \r
- complement := inc(not(right_operand));\r
- l_neg := left_operand(gp_register_t'high);\r
- \r
- carry_res := unsigned('0' & left_operand)+addcarry;\r
- oflo1 := add_oflo(l_neg,'0',std_logic_vector(carry_res)(gp_register_t'high));\r
- \r
- if sub = '1' then\r
- tmp_right_operand := unsigned('0' & complement);\r
- else\r
- tmp_right_operand := unsigned('0' & right_operand);\r
- end if;\r
- \r
- l_neg := std_logic_vector(carry_res)(gp_register_t'high);\r
- r_neg := std_logic_vector(tmp_right_operand)(gp_register_t'high);\r
- \r
- carry_res := carry_res + tmp_right_operand;\r
- oflo2 := add_oflo(l_neg,r_neg,std_logic_vector(carry_res)(gp_register_t'high));\r
- \r
-\r
- alu_result_v.result := std_logic_vector(carry_res)(gp_register_t'range);\r
- alu_result_v.status.carry := std_logic_vector(carry_res)(carry_res'high);\r
- \r
- \r
- alu_result_v.status.carry := oflo1 or oflo2;\r
- \r
- --sign will be set globally.\r
- --zero will be set globally.\r
- \r
- alu_result <= alu_result_v;\r
-end process; \r
-\r
-end architecture add_op;\r
+library IEEE;
+use IEEE.std_logic_1164.all;
+use IEEE.numeric_std.all;
+
+use work.common_pkg.all;
+use work.alu_pkg.all;
+
+architecture add_op of exec_op is
+
+signal sub, addc : std_logic;
+
+begin
+
+sub <= op_detail(SUB_OPT);
+addc <= op_detail(CARRY_OPT);
+
+calc: process(left_operand, right_operand, alu_state, sub, addc)
+ variable alu_result_v : alu_result_rec;
+ variable complement : gp_register_t;
+ variable carry_res : unsigned(gp_register_t'length downto 0);
+ variable tmp_right_operand : unsigned(gp_register_t'length downto 0);
+ variable oflo1, oflo2, l_neg, r_neg : std_logic;
+ variable addcarry : unsigned(carry_res'range);
+begin
+ alu_result_v := alu_state;
+
+ addcarry := (others =>'0');
+ addcarry(0) := alu_state.status.carry and addc;
+
+ complement := inc(not(right_operand));
+ l_neg := left_operand(gp_register_t'high);
+
+ carry_res := unsigned('0' & left_operand)+addcarry;
+ oflo1 := add_oflo(l_neg,'0',std_logic_vector(carry_res)(gp_register_t'high));
+
+ if sub = '1' then
+ tmp_right_operand := unsigned('0' & complement);
+ else
+ tmp_right_operand := unsigned('0' & right_operand);
+ end if;
+
+ l_neg := std_logic_vector(carry_res)(gp_register_t'high);
+ r_neg := std_logic_vector(tmp_right_operand)(gp_register_t'high);
+
+ carry_res := carry_res + tmp_right_operand;
+ oflo2 := add_oflo(l_neg,r_neg,std_logic_vector(carry_res)(gp_register_t'high));
+
+
+ alu_result_v.result := std_logic_vector(carry_res)(gp_register_t'range);
+ alu_result_v.status.carry := std_logic_vector(carry_res)(carry_res'high);
+
+
+ alu_result_v.status.carry := oflo1 or oflo2;
+
+ --sign will be set globally.
+ --zero will be set globally.
+
+ alu_result <= alu_result_v;
+end process;
+
+end architecture add_op;
-library IEEE;\r
-use IEEE.std_logic_1164.all;\r
-use IEEE.numeric_std.all;\r
-\r
-use work.common_pkg.all;\r
-use work.alu_pkg.all;\r
-\r
-architecture and_op of exec_op is\r
-begin\r
-\r
-calc: process(left_operand, right_operand, alu_state)\r
- variable alu_result_v : alu_result_rec;\r
- \r
-begin\r
- alu_result_v := alu_state;\r
- \r
- alu_result_v.result := left_operand and right_operand;\r
- \r
- alu_result <= alu_result_v;\r
-end process; \r
-\r
-end architecture and_op;\r
+library IEEE;
+use IEEE.std_logic_1164.all;
+use IEEE.numeric_std.all;
+
+use work.common_pkg.all;
+use work.alu_pkg.all;
+
+architecture and_op of exec_op is
+begin
+
+calc: process(left_operand, right_operand, alu_state)
+ variable alu_result_v : alu_result_rec;
+
+begin
+ alu_result_v := alu_state;
+
+ alu_result_v.result := left_operand and right_operand;
+
+ alu_result <= alu_result_v;
+end process;
+
+end architecture and_op;
-library IEEE;\r
-use IEEE.std_logic_1164.all;\r
-use IEEE.numeric_std.all;\r
-\r
-use work.common_pkg.all;\r
-use work.alu_pkg.all;\r
-\r
-architecture or_op of exec_op is\r
-begin\r
-\r
-calc: process(left_operand, right_operand, alu_state)\r
- variable alu_result_v : alu_result_rec;\r
- \r
-begin\r
- alu_result_v := alu_state;\r
- \r
- alu_result_v.result := left_operand or right_operand;\r
- \r
- alu_result <= alu_result_v;\r
-end process; \r
-\r
-end architecture or_op;\r
+library IEEE;
+use IEEE.std_logic_1164.all;
+use IEEE.numeric_std.all;
+
+use work.common_pkg.all;
+use work.alu_pkg.all;
+
+architecture or_op of exec_op is
+begin
+
+calc: process(left_operand, right_operand, alu_state)
+ variable alu_result_v : alu_result_rec;
+
+begin
+ alu_result_v := alu_state;
+
+ alu_result_v.result := left_operand or right_operand;
+
+ alu_result <= alu_result_v;
+end process;
+
+end architecture or_op;
-library IEEE;\r
-use IEEE.std_logic_1164.all;\r
-use IEEE.numeric_std.all;\r
-\r
-use work.common_pkg.all;\r
-use work.alu_pkg.all;\r
-\r
-architecture shift_op of exec_op is\r
-\r
- signal logic, ls, carry : std_logic;\r
-\r
-begin\r
-\r
- logic <= op_detail(LOG_OPT);\r
- ls <= op_detail(LEFT_OPT);\r
- carry <= op_detail(CARRY_OPT);\r
-\r
-calc: process(left_operand, right_operand, logic,ls, carry, alu_state)\r
- variable alu_result_v : alu_result_rec;\r
- variable tmp_shift : bit_vector(gp_register_t'length+1 downto 0);\r
- variable tmp_sb : std_logic;\r
- begin\r
- alu_result_v := alu_state;\r
- \r
- if ls = '1' then\r
- tmp_sb := (carry and alu_state.status.carry and logic);\r
- tmp_shift := to_bitvector(alu_state.status.carry & left_operand & tmp_sb);\r
- tmp_shift := tmp_shift sla to_integer(unsigned(right_operand)(SHIFT_WIDTH-1 downto 0));\r
- \r
- alu_result_v.status.carry := to_stdlogicvector(tmp_shift)(tmp_shift'high);\r
- \r
- else\r
- tmp_sb := (carry and alu_state.status.carry and logic) or (not(logic) and left_operand(gp_register_t'high));\r
- tmp_shift := to_bitvector(tmp_sb & left_operand & alu_state.status.carry);\r
- tmp_shift := tmp_shift sra to_integer(unsigned(right_operand)(SHIFT_WIDTH-1 downto 0));\r
- \r
- alu_result_v.status.carry := to_stdlogicvector(tmp_shift)(0);\r
- end if;\r
- \r
- alu_result_v.result := to_stdlogicvector(tmp_shift)(gp_register_t'length downto 1);\r
- \r
- alu_result <= alu_result_v;\r
- \r
-end process;\r
-\r
-end architecture shift_op;\r
+library IEEE;
+use IEEE.std_logic_1164.all;
+use IEEE.numeric_std.all;
+
+use work.common_pkg.all;
+use work.alu_pkg.all;
+
+architecture shift_op of exec_op is
+
+ signal logic, ls, carry : std_logic;
+
+begin
+
+ logic <= op_detail(LOG_OPT);
+ ls <= op_detail(LEFT_OPT);
+ carry <= op_detail(CARRY_OPT);
+
+calc: process(left_operand, right_operand, logic,ls, carry, alu_state)
+ variable alu_result_v : alu_result_rec;
+ variable tmp_shift : bit_vector(gp_register_t'length+1 downto 0);
+ variable tmp_sb : std_logic;
+ begin
+ alu_result_v := alu_state;
+
+ if ls = '1' then
+ tmp_sb := (carry and alu_state.status.carry and logic);
+ tmp_shift := to_bitvector(alu_state.status.carry & left_operand & tmp_sb);
+ tmp_shift := tmp_shift sla to_integer(unsigned(right_operand)(SHIFT_WIDTH-1 downto 0));
+
+ alu_result_v.status.carry := to_stdlogicvector(tmp_shift)(tmp_shift'high);
+
+ else
+ tmp_sb := (carry and alu_state.status.carry and logic) or (not(logic) and left_operand(gp_register_t'high));
+ tmp_shift := to_bitvector(tmp_sb & left_operand & alu_state.status.carry);
+ tmp_shift := tmp_shift sra to_integer(unsigned(right_operand)(SHIFT_WIDTH-1 downto 0));
+
+ alu_result_v.status.carry := to_stdlogicvector(tmp_shift)(0);
+ end if;
+
+ alu_result_v.result := to_stdlogicvector(tmp_shift)(gp_register_t'length downto 1);
+
+ alu_result <= alu_result_v;
+
+end process;
+
+end architecture shift_op;
-library IEEE;\r
-use IEEE.std_logic_1164.all;\r
-use IEEE.numeric_std.all;\r
-\r
-use work.common_pkg.all;\r
-use work.alu_pkg.all;\r
-\r
-architecture xor_op of exec_op is\r
-begin\r
-\r
-calc: process(left_operand, right_operand, alu_state)\r
- variable alu_result_v : alu_result_rec;\r
- \r
-begin\r
- alu_result_v := alu_state;\r
- \r
- alu_result_v.result := left_operand xor right_operand;\r
- \r
- alu_result <= alu_result_v;\r
-end process; \r
-\r
-end architecture xor_op;\r
+library IEEE;
+use IEEE.std_logic_1164.all;
+use IEEE.numeric_std.all;
+
+use work.common_pkg.all;
+use work.alu_pkg.all;
+
+architecture xor_op of exec_op is
+begin
+
+calc: process(left_operand, right_operand, alu_state)
+ variable alu_result_v : alu_result_rec;
+
+begin
+ alu_result_v := alu_state;
+
+ alu_result_v.result := left_operand xor right_operand;
+
+ alu_result <= alu_result_v;
+end process;
+
+end architecture xor_op;