modified: first approach to pointers. not finished, alu missing etc.
authorMarkus Hofstätter <markus.hofstaetter@gmx.net>
Thu, 2 Dec 2010 16:11:09 +0000 (17:11 +0100)
committerMarkus Hofstätter <markus.hofstaetter@gmx.net>
Thu, 2 Dec 2010 16:11:09 +0000 (17:11 +0100)
cpu/src/alu_pkg.vhd
cpu/src/common_pkg.vhd
cpu/src/extension.vhd
cpu/src/extension_b.vhd
cpu/src/extension_pkg.vhd

index bb15c6a27324f08d92721a6f1479fd863aa971e0..7a9564e913149c6f0b4c25a407f75234b3d5c5df 100755 (executable)
@@ -15,6 +15,10 @@ package alu_pkg is
                sign : std_logic;
                carry : std_logic;
        end record;
+
+       constant PADDR_WIDTH : integer := 2; 
+       type pointers_t is array(0 to 2**PADDR_WIDTH-1) of gp_register_t;
+       subtype paddr_t is std_logic_vector(PADDR_WIDTH-1 downto 0);
        
        subtype status_t is byte_t;
        --type alu_interal_rec is record
@@ -26,14 +30,12 @@ package alu_pkg is
                result_addr : gp_addr_t;
                
                status : status_rec;
-               --stackpointer : gp_register_t;
 
                alu_jump : std_logic;
                brpr : std_logic;
                reg_op : std_logic;
                mem_op  : std_logic;
                
-               --new_val : std_logic;
                mem_en : std_logic;
                
                hw_op   : std_logic;
index 23791653dacc5a17bebf2f18faf9ae34a4bdfcd3..3790d0f7b2268bb85379289508bc0057ff1160cb 100755 (executable)
@@ -30,6 +30,7 @@ package common_pkg is
        
        constant NUM_OP_OPT_WIDTH       : INTEGER := 6;
        constant COND_WIDTH : INTEGER := 4;
+       constant DATA_END_ADDR          : integer := ((2**DATA_ADDR_WIDTH)-1);
 
        
        subtype instruction_word_t is std_logic_vector(WORD_WIDTH-1 downto 0);
index ab53a3c6ef02e778ec5f04e690b60b6739833352..aa19e9d95f3fd5cc6df443d2c603039c31d7797a 100644 (file)
@@ -17,14 +17,17 @@ entity extension_gpm is
                --System inputs
                        clk :   in std_logic;
                        reset : in std_logic;
-               -- Standartinterface                    
+               -- general extension interface                  
                        ext_reg  : in extmod_rec;
                        data_out : out gp_register_t;
                -- Input
                        alu_nxt : in alu_result_rec;
+                       paddr   : in paddr_t;
+                       pinc    : in std_logic;
+                       pwr_en  : in std_logic;
                -- Ouput
-                        psw     : out status_rec
-
+                        psw     : out status_rec;
+                        pval    : out gp_register_t
                        
                );
                
index a035511b1284e489e2d14ee37d95175ace76c738..0c18a7de2da98d6ab9b8a0348d769442436130f1 100644 (file)
@@ -11,26 +11,105 @@ use work.extension_pkg.all;
 architecture behav of extension_gpm is
 type gpm_internal is record
         status : status_rec;
+       preg : pointers_t;
 end record gpm_internal;
 
 signal reg, reg_nxt : gpm_internal;
 
+
 begin
 syn : process (clk, reset)
 begin
         if (reset = RESET_VALUE) then
                 reg.status <= ('0','0','0','0');
+               reg.pointers <= (others => (std_logic_vector(to_unsigned(DATA_END_ADDR,DATA_ADDR_WIDTH)));
         elsif rising_edge(clk) then
                 reg <= reg_nxt;
         end if;
 end process syn;
 
-asyn : process (clk, reset, alu_nxt)
+asyn : process (clk, reset, reg, alu_nxt, ext_reg, pval, pwr_en, pinc, paddr)
+       variable reg_nxt_v : gpm_internal;
+       variable incb : gp_register_t;
+       variable sel_pval : gp_register_t;
 begin
-        reg_nxt.status <= alu_nxt.status;
-end process asyn;
+       reg_nxt_v := reg;
+
+       psw <= reg.status;
+       data_out <= (others => '0');
+
+       incb := (others => '0');
+       incb(0) := '1';
+       if pinc = '1' then
+               incb := (others => '1');
+       end if;
+
+       if (ext_reg.sel = '1') and ext_reg.wr_en = '1' then
+               case ext_reg.addr(1 downto 0) is
+               when "00" => 
+                       if ext_reg.byte_en(0) = '1' then
+                               reg_nxt_v.psw := (ext_reg.data(0),ext_reg.data(1),ext_reg.data(3),ext_reg.data(2));
+                               psw <= reg_nxt_v.psw;
+                       end if;
+               when "01" =>
+                       --STACK_POINTER
+                       if ext_reg.byte_en(0) = '1' then
+                               reg_next_v.preg(0)(byte_t'range) := ext_reg.data(byte_t'range);
+                       end if;
+                       if ext_reg.byte_en(1) = '1' then
+                               reg_next_v.preg(0)((byte_t'length*2)-1 downto byte_t'length) :=
+                                       ext_reg.data((byte_t'length*2)-1 downto byte_t'length) ;
+                       end if;
+                       if ext_reg.byte_en(2) = '1' then
+                               reg_next_v.preg(0)((byte_t'length*3)-1 downto byte_t'length*2) :=
+                                       ext_reg.data((byte_t'length*3)-1 downto byte_t'length*2) ;
+                       end if;
+                       if ext_reg.byte_en(3) = '1' then
+                               reg_next_v.preg(0)((byte_t'length*4)-1 downto byte_t'length*3) :=
+                                       ext_reg.data((byte_t'length*4)-1 downto byte_t'length*3) ;
+                       end if;
+               when others => null;
+               end case;
+       end if;
 
-psw <= reg.status;
+       if (ext_reg.sel = '1') and wr_en = '0' then
+               case ext_reg.addr(1 downto 0) is
+               when "00" => 
+                       if ext_reg.byte_en(0) = '1' then
+                               data_out(3 downto 0) <= (reg.status.sign, reg.status.carry, reg.status.oflo, reg.status.zero);
+                       end if;
+               when "01" =>
+                       --STACK_POINTER
+                       if ext_reg.byte_en(0) = '1' then
+                               data_out(byte_t'range) <= reg.preg(0)(byte_t'range);
+                       end if;
+                       if ext_reg.byte_en(1) = '1' then
+                               data_out((byte_t'length*2)-1 downto byte_t'length) <=
+                                       reg_preg(0)((byte_t'length*2)-1 downto byte_t'length) ;
+                       end if;
+                       if ext_reg.byte_en(2) = '1' then
+                               data_out((byte_t'length*3)-1 downto 2*byte_t'length) <=
+                                       reg_preg(0)((byte_t'length*3)-1 downto 2*byte_t'length) ;
+                       end if;
+                       if ext_reg.byte_en(3) = '1' then
+                               data_out((byte_t'length*4)-1 downto 3*byte_t'length) <=
+                                       reg_preg(0)((byte_t'length*4)-1 downto 3*byte_t'length) ;
+                       end if;
+               when others => null;
+               end case;
+       end if;
+
+
+       sel_pval := reg_nxt_v.preg(unsigned(paddr));
+       pval <= sel_pval;
+       if pwr_en = '1' then
+               reg_nxt_v.preg(to_integer(unsigned(paddr))) := std_logic_vector(unsigned(sel_pval)+unsigned(incb));
+       end if;
+
+       reg_nxt_v.status := alu_nxt.status;
+       
+       reg_nxt <= reg_nxt_v;
+end process asyn;
 
 end behav;
 
index 14253d6d3b1d58f42f14d4989a070a74ce95f22d..daa23061e03396faad20922c138bcb5e33e2a1ce 100644 (file)
@@ -46,13 +46,17 @@ constant EXT_GPMP_ADDR:    ext_addrid_t := x"FFFFFFF";
                --System inputs
                        clk :   in std_logic;
                        reset : in std_logic;
-               -- Standartinterface                    
+               -- general extension interface                  
                        ext_reg  : in extmod_rec;
                        data_out : out gp_register_t;
                -- Input
                        alu_nxt : in alu_result_rec;
+                       paddr   : in paddr_t;
+                       pinc    : in std_logic;
+                       pwr_en  : in std_logic;
                -- Ouput
-                        psw     : out status_rec
+                        psw     : out status_rec;
+                        pval    : out gp_register_t
 
                        
                );