@ -26,6 +26,13 @@ entity core_debug is
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
					terminate       : in std_ulogic;
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
					core_stopped    : in std_ulogic;
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
					nia             : in std_ulogic_vector(63 downto 0);
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				        msr             : in std_ulogic_vector(63 downto 0);
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				        -- GSPR register read port
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				        dbg_gpr_req     : out std_ulogic;
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				        dbg_gpr_ack     : in std_ulogic;
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				        dbg_gpr_addr    : out gspr_index_t;
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				        dbg_gpr_data    : in std_ulogic_vector(63 downto 0);
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
					-- Misc
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
					terminated_out  : out std_ulogic
 
			
		 
		
	
	
		
			
				
					
						
							
								 
							 
						
						
							
								 
							 
						
						
					 
				
			
			 
			 
			
				@ -61,6 +68,15 @@ architecture behave of core_debug is
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				    -- NIA register (read only for now)
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				    constant DBG_CORE_NIA	     : std_ulogic_vector(3 downto 0) := "0010";
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				    -- MSR (read only)
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				    constant DBG_CORE_MSR            : std_ulogic_vector(3 downto 0) := "0011";
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				    -- GSPR register index
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				    constant DBG_CORE_GSPR_INDEX     : std_ulogic_vector(3 downto 0) := "0100";
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				    -- GSPR register data
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				    constant DBG_CORE_GSPR_DATA      : std_ulogic_vector(3 downto 0) := "0101";
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				    -- Some internal wires
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				    signal stat_reg : std_ulogic_vector(63 downto 0);
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				
 
			
		 
		
	
	
		
			
				
					
						
						
						
							
								 
							 
						
					 
				
			
			 
			 
			
				@ -70,10 +86,15 @@ architecture behave of core_debug is
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				    signal do_reset     : std_ulogic;
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				    signal do_icreset   : std_ulogic;
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				    signal terminated   : std_ulogic;
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				    signal do_gspr_rd   : std_ulogic;
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				    signal gspr_index   : gspr_index_t;
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				begin
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				       -- Single cycle register accesses on DMI
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				    dmi_ack <= dmi_req;
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				       -- Single cycle register accesses on DMI except for GSPR data
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				    dmi_ack <= dmi_req when dmi_addr /= DBG_CORE_GSPR_DATA
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				               else dbg_gpr_ack;
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				    dbg_gpr_req <= dmi_req when dmi_addr = DBG_CORE_GSPR_DATA
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				                   else '0';
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				    -- Status register read composition
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				    stat_reg <= (2 => terminated,
 
			
		 
		
	
	
		
			
				
					
						
						
						
							
								 
							 
						
					 
				
			
			 
			 
			
				@ -85,6 +106,8 @@ begin
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				    with dmi_addr select dmi_dout <=
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
					stat_reg        when DBG_CORE_STAT,
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
					nia             when DBG_CORE_NIA,
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				        msr             when DBG_CORE_MSR,
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				        dbg_gpr_data    when DBG_CORE_GSPR_DATA,
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
					(others => '0') when others;
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				    -- DMI writes
 
			
		 
		
	
	
		
			
				
					
						
							
								 
							 
						
						
							
								 
							 
						
						
					 
				
			
			 
			 
			
				@ -126,6 +149,8 @@ begin
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
								stopping <= '0';
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
								terminated <= '0';
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
							    end if;
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				                        elsif dmi_addr = DBG_CORE_GSPR_INDEX then
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				                            gspr_index <= dmi_din(gspr_index_t'left downto 0);
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
							end if;
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
						    else
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
							report("DMI read from " & to_string(dmi_addr));
 
			
		 
		
	
	
		
			
				
					
						
						
						
							
								 
							 
						
					 
				
			
			 
			 
			
				@ -143,6 +168,8 @@ begin
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
					end if;
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				    end process;
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				    dbg_gpr_addr <= gspr_index;
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				    -- Core control signals generated by the debug module
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				    core_stop <= stopping and not do_step;
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				    core_rst <= do_reset;