data/full_repos/permissive/418753455/E906_RTL_FACTORY/gen_rtl/rtu/rtl/pa_rtu_retire.v
1: b"%Error: data/full_repos/permissive/418753455/E906_RTL_FACTORY/gen_rtl/rtu/rtl/pa_rtu_retire.v:748: Define or directive not defined: '`TDT_HINFO_PENDING_HALT'\n                                   && !cbus_retire_ex2_halt_info[`TDT_HINFO_PENDING_HALT]\n                                                                 ^~~~~~~~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/418753455/E906_RTL_FACTORY/gen_rtl/rtu/rtl/pa_rtu_retire.v:748: syntax error, unexpected ']', expecting TYPE-IDENTIFIER\n                                   && !cbus_retire_ex2_halt_info[`TDT_HINFO_PENDING_HALT]\n                                                                                        ^\n%Error: data/full_repos/permissive/418753455/E906_RTL_FACTORY/gen_rtl/rtu/rtl/pa_rtu_retire.v:751: Define or directive not defined: '`TDT_HINFO_MATCH'\n                                   && cbus_retire_ex2_halt_info[`TDT_HINFO_MATCH]\n                                                                ^~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/418753455/E906_RTL_FACTORY/gen_rtl/rtu/rtl/pa_rtu_retire.v:751: syntax error, unexpected ']', expecting TYPE-IDENTIFIER\n                                   && cbus_retire_ex2_halt_info[`TDT_HINFO_MATCH]\n                                                                                ^\n%Error: data/full_repos/permissive/418753455/E906_RTL_FACTORY/gen_rtl/rtu/rtl/pa_rtu_retire.v:752: Define or directive not defined: '`TDT_HINFO_CHAIN'\n                                   && !cbus_retire_ex2_halt_info[`TDT_HINFO_CHAIN]\n                                                                 ^~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/418753455/E906_RTL_FACTORY/gen_rtl/rtu/rtl/pa_rtu_retire.v:753: Define or directive not defined: '`TDT_HINFO_TIMING'\n                                   && !cbus_retire_ex2_halt_info[`TDT_HINFO_TIMING]\n                                                                 ^~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/418753455/E906_RTL_FACTORY/gen_rtl/rtu/rtl/pa_rtu_retire.v:754: Define or directive not defined: '`TDT_HINFO_ACTION'\n                                   && cbus_retire_ex2_halt_info[`TDT_HINFO_ACTION]\n                                                                ^~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/418753455/E906_RTL_FACTORY/gen_rtl/rtu/rtl/pa_rtu_retire.v:755: Define or directive not defined: '`TDT_HINFO_PENDING_HALT'\n                                   && !cbus_retire_ex2_halt_info[`TDT_HINFO_PENDING_HALT]\n                                                                 ^~~~~~~~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/418753455/E906_RTL_FACTORY/gen_rtl/rtu/rtl/pa_rtu_retire.v:758: Define or directive not defined: '`TDT_HINFO_PENDING_HALT'\n                                   && cbus_retire_ex2_halt_info[`TDT_HINFO_PENDING_HALT]\n                                                                ^~~~~~~~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/418753455/E906_RTL_FACTORY/gen_rtl/rtu/rtl/pa_rtu_retire.v:758: syntax error, unexpected ']', expecting TYPE-IDENTIFIER\n                                   && cbus_retire_ex2_halt_info[`TDT_HINFO_PENDING_HALT]\n                                                                                       ^\n%Error: data/full_repos/permissive/418753455/E906_RTL_FACTORY/gen_rtl/rtu/rtl/pa_rtu_retire.v:759: Define or directive not defined: '`TDT_HINFO_ACTION'\n                                   && cbus_retire_ex2_halt_info[`TDT_HINFO_ACTION]\n                                                                ^~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/418753455/E906_RTL_FACTORY/gen_rtl/rtu/rtl/pa_rtu_retire.v:776: Define or directive not defined: '`TDT_HINFO_PENDING_HALT'\n                                    && !cbus_retire_ex2_halt_info[`TDT_HINFO_PENDING_HALT]\n                                                                  ^~~~~~~~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/418753455/E906_RTL_FACTORY/gen_rtl/rtu/rtl/pa_rtu_retire.v:776: syntax error, unexpected ']', expecting TYPE-IDENTIFIER\n                                    && !cbus_retire_ex2_halt_info[`TDT_HINFO_PENDING_HALT]\n                                                                                         ^\n%Error: data/full_repos/permissive/418753455/E906_RTL_FACTORY/gen_rtl/rtu/rtl/pa_rtu_retire.v:792: Define or directive not defined: '`TDT_HINFO_MATCH'\n                                    && cbus_retire_ex2_halt_info[`TDT_HINFO_MATCH]\n                                                                 ^~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/418753455/E906_RTL_FACTORY/gen_rtl/rtu/rtl/pa_rtu_retire.v:792: syntax error, unexpected ']', expecting TYPE-IDENTIFIER\n                                    && cbus_retire_ex2_halt_info[`TDT_HINFO_MATCH]\n                                                                                 ^\n%Error: data/full_repos/permissive/418753455/E906_RTL_FACTORY/gen_rtl/rtu/rtl/pa_rtu_retire.v:793: Define or directive not defined: '`TDT_HINFO_CHAIN'\n                                    && !cbus_retire_ex2_halt_info[`TDT_HINFO_CHAIN]\n                                                                  ^~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/418753455/E906_RTL_FACTORY/gen_rtl/rtu/rtl/pa_rtu_retire.v:794: Define or directive not defined: '`TDT_HINFO_TIMING'\n                                    && cbus_retire_ex2_halt_info[`TDT_HINFO_TIMING]\n                                                                 ^~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/418753455/E906_RTL_FACTORY/gen_rtl/rtu/rtl/pa_rtu_retire.v:795: Define or directive not defined: '`TDT_HINFO_ACTION'\n                                    && cbus_retire_ex2_halt_info[`TDT_HINFO_ACTION];\n                                                                 ^~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/418753455/E906_RTL_FACTORY/gen_rtl/rtu/rtl/pa_rtu_retire.v:828: Define or directive not defined: '`TDT_HINFO_PENDING_HALT'\n                                   && !cbus_retire_ex2_halt_info[`TDT_HINFO_PENDING_HALT];\n                                                                 ^~~~~~~~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/418753455/E906_RTL_FACTORY/gen_rtl/rtu/rtl/pa_rtu_retire.v:828: syntax error, unexpected ']', expecting TYPE-IDENTIFIER\n                                   && !cbus_retire_ex2_halt_info[`TDT_HINFO_PENDING_HALT];\n                                                                                        ^\n%Error: data/full_repos/permissive/418753455/E906_RTL_FACTORY/gen_rtl/rtu/rtl/pa_rtu_retire.v:830: Define or directive not defined: '`TDT_HINFO_PENDING_HALT'\n                                   && cbus_retire_ex2_halt_info[`TDT_HINFO_PENDING_HALT]\n                                                                ^~~~~~~~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/418753455/E906_RTL_FACTORY/gen_rtl/rtu/rtl/pa_rtu_retire.v:830: syntax error, unexpected ']', expecting TYPE-IDENTIFIER\n                                   && cbus_retire_ex2_halt_info[`TDT_HINFO_PENDING_HALT]\n                                                                                       ^\n%Error: data/full_repos/permissive/418753455/E906_RTL_FACTORY/gen_rtl/rtu/rtl/pa_rtu_retire.v:831: Define or directive not defined: '`TDT_HINFO_ACTION'\n                                   && !cbus_retire_ex2_halt_info[`TDT_HINFO_ACTION];\n                                                                 ^~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/418753455/E906_RTL_FACTORY/gen_rtl/rtu/rtl/pa_rtu_retire.v:834: Define or directive not defined: '`TDT_HINFO_PENDING_HALT'\n                                   && !cbus_retire_ex2_halt_info[`TDT_HINFO_PENDING_HALT]\n                                                                 ^~~~~~~~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/418753455/E906_RTL_FACTORY/gen_rtl/rtu/rtl/pa_rtu_retire.v:834: syntax error, unexpected ']', expecting TYPE-IDENTIFIER\n                                   && !cbus_retire_ex2_halt_info[`TDT_HINFO_PENDING_HALT]\n                                                                                        ^\n%Error: data/full_repos/permissive/418753455/E906_RTL_FACTORY/gen_rtl/rtu/rtl/pa_rtu_retire.v:835: Define or directive not defined: '`TDT_HINFO_MATCH'\n                                   && cbus_retire_ex2_halt_info[`TDT_HINFO_MATCH]\n                                                                ^~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/418753455/E906_RTL_FACTORY/gen_rtl/rtu/rtl/pa_rtu_retire.v:836: Define or directive not defined: '`TDT_HINFO_CHAIN'\n                                   && !cbus_retire_ex2_halt_info[`TDT_HINFO_CHAIN]\n                                                                 ^~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/418753455/E906_RTL_FACTORY/gen_rtl/rtu/rtl/pa_rtu_retire.v:837: Define or directive not defined: '`TDT_HINFO_TIMING'\n                                   && !cbus_retire_ex2_halt_info[`TDT_HINFO_TIMING]\n                                                                 ^~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/418753455/E906_RTL_FACTORY/gen_rtl/rtu/rtl/pa_rtu_retire.v:838: Define or directive not defined: '`TDT_HINFO_ACTION'\n                                   && !cbus_retire_ex2_halt_info[`TDT_HINFO_ACTION];\n                                                                 ^~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/418753455/E906_RTL_FACTORY/gen_rtl/rtu/rtl/pa_rtu_retire.v:851: Define or directive not defined: '`TDT_HINFO_PENDING_HALT'\n                                    && !cbus_retire_ex2_halt_info[`TDT_HINFO_PENDING_HALT];\n                                                                  ^~~~~~~~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/418753455/E906_RTL_FACTORY/gen_rtl/rtu/rtl/pa_rtu_retire.v:851: syntax error, unexpected ']', expecting TYPE-IDENTIFIER\n                                    && !cbus_retire_ex2_halt_info[`TDT_HINFO_PENDING_HALT];\n                                                                                         ^\n%Error: data/full_repos/permissive/418753455/E906_RTL_FACTORY/gen_rtl/rtu/rtl/pa_rtu_retire.v:857: Define or directive not defined: '`TDT_HINFO_MATCH'\n                                    && cbus_retire_ex2_halt_info[`TDT_HINFO_MATCH]\n                                                                 ^~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/418753455/E906_RTL_FACTORY/gen_rtl/rtu/rtl/pa_rtu_retire.v:857: syntax error, unexpected ']', expecting TYPE-IDENTIFIER\n                                    && cbus_retire_ex2_halt_info[`TDT_HINFO_MATCH]\n                                                                                 ^\n%Error: data/full_repos/permissive/418753455/E906_RTL_FACTORY/gen_rtl/rtu/rtl/pa_rtu_retire.v:858: Define or directive not defined: '`TDT_HINFO_CHAIN'\n                                    && !cbus_retire_ex2_halt_info[`TDT_HINFO_CHAIN]\n                                                                  ^~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/418753455/E906_RTL_FACTORY/gen_rtl/rtu/rtl/pa_rtu_retire.v:859: Define or directive not defined: '`TDT_HINFO_TIMING'\n                                    && cbus_retire_ex2_halt_info[`TDT_HINFO_TIMING]\n                                                                 ^~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/418753455/E906_RTL_FACTORY/gen_rtl/rtu/rtl/pa_rtu_retire.v:860: Define or directive not defined: '`TDT_HINFO_ACTION'\n                                    && !cbus_retire_ex2_halt_info[`TDT_HINFO_ACTION];\n                                                                  ^~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/418753455/E906_RTL_FACTORY/gen_rtl/rtu/rtl/pa_rtu_retire.v:879: Define or directive not defined: '`TDT_HINFO_LDST'\n                                               && cbus_retire_ex2_halt_info[`TDT_HINFO_LDST];\n                                                                            ^~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/418753455/E906_RTL_FACTORY/gen_rtl/rtu/rtl/pa_rtu_retire.v:879: syntax error, unexpected ']', expecting TYPE-IDENTIFIER\n                                               && cbus_retire_ex2_halt_info[`TDT_HINFO_LDST];\n                                                                                           ^\n%Error: data/full_repos/permissive/418753455/E906_RTL_FACTORY/gen_rtl/rtu/rtl/pa_rtu_retire.v:946: Define or directive not defined: '`TDT_HINFO_CAUSE'\n    halt_cause[3:0] = cbus_retire_ex2_halt_info[`TDT_HINFO_CAUSE:`TDT_HINFO_CAUSE-3];\n                                                ^~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/418753455/E906_RTL_FACTORY/gen_rtl/rtu/rtl/pa_rtu_retire.v:946: syntax error, unexpected ':', expecting TYPE-IDENTIFIER\n    halt_cause[3:0] = cbus_retire_ex2_halt_info[`TDT_HINFO_CAUSE:`TDT_HINFO_CAUSE-3];\n                                                                ^\n%Error: data/full_repos/permissive/418753455/E906_RTL_FACTORY/gen_rtl/rtu/rtl/pa_rtu_retire.v:946: Define or directive not defined: '`TDT_HINFO_CAUSE'\n    halt_cause[3:0] = cbus_retire_ex2_halt_info[`TDT_HINFO_CAUSE:`TDT_HINFO_CAUSE-3];\n                                                                 ^~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/418753455/E906_RTL_FACTORY/gen_rtl/rtu/rtl/pa_rtu_retire.v:1029: Define or directive not defined: '`TDT_HINFO_LDST'\n    bkpt_req_split_lsu_trigger_buf <= cbus_retire_ex2_halt_info[`TDT_HINFO_LDST];\n                                                                ^~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/418753455/E906_RTL_FACTORY/gen_rtl/rtu/rtl/pa_rtu_retire.v:1029: syntax error, unexpected ']', expecting TYPE-IDENTIFIER\n    bkpt_req_split_lsu_trigger_buf <= cbus_retire_ex2_halt_info[`TDT_HINFO_LDST];\n                                                                               ^\n%Error: data/full_repos/permissive/418753455/E906_RTL_FACTORY/gen_rtl/rtu/rtl/pa_rtu_retire.v:1036: Define or directive not defined: '`TDT_HINFO_WIDTH'\n    retire_buf_split_trigger_t1_halt_info[`TDT_HINFO_WIDTH-1:0] <= {`TDT_HINFO_WIDTH{1'b0}};\n                                          ^~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/418753455/E906_RTL_FACTORY/gen_rtl/rtu/rtl/pa_rtu_retire.v:1036: Define or directive not defined: '`TDT_HINFO_WIDTH'\n    retire_buf_split_trigger_t1_halt_info[`TDT_HINFO_WIDTH-1:0] <= {`TDT_HINFO_WIDTH{1'b0}};\n                                                                    ^~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/418753455/E906_RTL_FACTORY/gen_rtl/rtu/rtl/pa_rtu_retire.v:1038: Define or directive not defined: '`TDT_HINFO_WIDTH'\n    retire_buf_split_trigger_t1_halt_info[`TDT_HINFO_WIDTH-1:0] <= {`TDT_HINFO_WIDTH{1'b0}};\n                                          ^~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/418753455/E906_RTL_FACTORY/gen_rtl/rtu/rtl/pa_rtu_retire.v:1038: Define or directive not defined: '`TDT_HINFO_WIDTH'\n    retire_buf_split_trigger_t1_halt_info[`TDT_HINFO_WIDTH-1:0] <= {`TDT_HINFO_WIDTH{1'b0}};\n                                                                    ^~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/418753455/E906_RTL_FACTORY/gen_rtl/rtu/rtl/pa_rtu_retire.v:1040: Define or directive not defined: '`TDT_HINFO_WIDTH'\n    retire_buf_split_trigger_t1_halt_info[`TDT_HINFO_WIDTH-1:0] <=\n                                          ^~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/418753455/E906_RTL_FACTORY/gen_rtl/rtu/rtl/pa_rtu_retire.v:1041: Define or directive not defined: '`TDT_HINFO_WIDTH'\n    retire_buf_split_trigger_t1_halt_info[`TDT_HINFO_WIDTH-1:0]\n                                          ^~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/418753455/E906_RTL_FACTORY/gen_rtl/rtu/rtl/pa_rtu_retire.v:1042: Define or directive not defined: '`TDT_HINFO_WIDTH'\n                | cbus_retire_ex2_halt_info[`TDT_HINFO_WIDTH-1:0];\n                                            ^~~~~~~~~~~~~~~~\n%Error: Exiting due to too many errors encountered; --error-limit=50\n"
module pa_rtu_retire(
  cbus_retire_ex2_chgflw_vld,
  cbus_retire_ex2_cur_pc,
  cbus_retire_ex2_expt_inst,
  cbus_retire_ex2_flush,
  cbus_retire_ex2_halt_info,
  cbus_retire_ex2_inst_branch,
  cbus_retire_ex2_inst_dret,
  cbus_retire_ex2_inst_ebreak,
  cbus_retire_ex2_inst_int,
  cbus_retire_ex2_inst_mret,
  cbus_retire_ex2_inst_nmi,
  cbus_retire_ex2_inst_tail_int,
  cbus_retire_ex2_inst_vld,
  cbus_retire_ex2_int_hv,
  cbus_retire_ex2_int_lv,
  cbus_retire_ex2_ipop_int_mask,
  cbus_retire_ex2_may_debug,
  cbus_retire_ex2_next_pc,
  cbus_retire_ex2_split_inst,
  cbus_retire_ex2_tail_spec_inst,
  cbus_retire_ex2_trap_vec,
  cbus_retire_ex2_tval,
  cp0_rtu_ex1_mret,
  cp0_rtu_icg_en,
  cp0_rtu_in_nmi,
  cp0_xx_async_expt_en,
  cp0_yy_clk_en,
  cpurst_b,
  dtu_rtu_async_halt_req,
  dtu_rtu_dpc,
  dtu_rtu_ebreak_action,
  dtu_rtu_pending_tval,
  dtu_rtu_resume_req,
  dtu_rtu_step_en,
  dtu_rtu_sync_flush,
  dtu_rtu_sync_halt_req,
  forever_cpuclk,
  fpu_xx_no_op,
  ifu_rtu_reset_halt_req,
  int_retire_pending_int_hv,
  iu_xx_no_op,
  lockup_clk,
  lockup_clk_en,
  lockup_retire_dbg_vld,
  lockup_retire_nmi_vld,
  lsu_rtu_async_expt_vld,
  lsu_rtu_async_ld_inst,
  lsu_rtu_async_tval,
  lsu_rtu_ex2_bus_err,
  lsu_rtu_ex2_stall,
  lsu_rtu_ex2_tval,
  lsu_rtu_sync_ack,
  lsu_xx_no_op,
  pad_yy_icg_scan_en,
  retire_cbus_debug_may_spec_fail,
  retire_cbus_ex2_stall,
  retire_cbus_flush_stall,
  retire_int_nmi_ack,
  retire_lockup_dbg_req,
  retire_lockup_dbgon,
  retire_lockup_expt_vld,
  retire_lockup_nmi_exit,
  retire_lockup_retire_pc,
  retire_lockup_retire_vld,
  retire_top_dbg_mode_on,
  retire_top_dbg_stall,
  retire_top_flush_cur_state,
  retire_top_lsu_ex2_stall,
  retire_xx_ex2_expt_raw,
  rtu_cp0_bus_error,
  rtu_cp0_epc,
  rtu_cp0_exit_debug,
  rtu_cp0_int_level,
  rtu_cp0_nmi_vld,
  rtu_cp0_tval,
  rtu_dtu_dpc,
  rtu_dtu_halt_ack,
  rtu_dtu_pending_ack,
  rtu_dtu_retire_chgflw,
  rtu_dtu_retire_debug_expt_vld,
  rtu_dtu_retire_halt_info,
  rtu_dtu_retire_mret,
  rtu_dtu_retire_next_pc,
  rtu_dtu_retire_vld,
  rtu_dtu_tval,
  rtu_hpcp_retire_inst_vld,
  rtu_idu_flush_fe,
  rtu_idu_flush_stall,
  rtu_idu_inst_retire,
  rtu_idu_late_flush,
  rtu_ifu_chgflw_pc,
  rtu_ifu_chgflw_vld,
  rtu_ifu_dbg_mask,
  rtu_ifu_flush_fe,
  rtu_lsu_async_expt_ack,
  rtu_lsu_expt_ack,
  rtu_lsu_expt_exit,
  rtu_lsu_inst_retire,
  rtu_lsu_sync_req,
  rtu_pad_inst_retire,
  rtu_pad_inst_split,
  rtu_pad_retire_pc,
  rtu_sysio_halted,
  rtu_xx_no_op,
  rtu_yy_xx_async_flush,
  rtu_yy_xx_dbgon,
  rtu_yy_xx_expt_int,
  rtu_yy_xx_expt_vec,
  rtu_yy_xx_expt_vld,
  rtu_yy_xx_flush,
  rtu_yy_xx_int_hv,
  rtu_yy_xx_tail_int_vld
);


input           cbus_retire_ex2_chgflw_vld;           
input   [31:0]  cbus_retire_ex2_cur_pc;               
input           cbus_retire_ex2_expt_inst;            
input           cbus_retire_ex2_flush;                
input   [14:0]  cbus_retire_ex2_halt_info;            
input           cbus_retire_ex2_inst_branch;          
input           cbus_retire_ex2_inst_dret;            
input           cbus_retire_ex2_inst_ebreak;          
input           cbus_retire_ex2_inst_int;             
input           cbus_retire_ex2_inst_mret;            
input           cbus_retire_ex2_inst_nmi;             
input           cbus_retire_ex2_inst_tail_int;        
input           cbus_retire_ex2_inst_vld;             
input           cbus_retire_ex2_int_hv;               
input   [7 :0]  cbus_retire_ex2_int_lv;               
input           cbus_retire_ex2_ipop_int_mask;        
input           cbus_retire_ex2_may_debug;            
input   [31:0]  cbus_retire_ex2_next_pc;              
input           cbus_retire_ex2_split_inst;           
input           cbus_retire_ex2_tail_spec_inst;       
input   [11:0]  cbus_retire_ex2_trap_vec;             
input   [31:0]  cbus_retire_ex2_tval;                 
input           cp0_rtu_ex1_mret;                     
input           cp0_rtu_icg_en;                       
input           cp0_rtu_in_nmi;                       
input           cp0_xx_async_expt_en;                 
input           cp0_yy_clk_en;                        
input           cpurst_b;                             
input           dtu_rtu_async_halt_req;               
input   [31:0]  dtu_rtu_dpc;                          
input           dtu_rtu_ebreak_action;                
input   [31:0]  dtu_rtu_pending_tval;                 
input           dtu_rtu_resume_req;                   
input           dtu_rtu_step_en;                      
input           dtu_rtu_sync_flush;                   
input           dtu_rtu_sync_halt_req;                
input           forever_cpuclk;                       
input           fpu_xx_no_op;                         
input           ifu_rtu_reset_halt_req;               
input           int_retire_pending_int_hv;            
input           iu_xx_no_op;                          
input           lockup_clk_en;                        
input           lockup_retire_dbg_vld;                
input           lockup_retire_nmi_vld;                
input           lsu_rtu_async_expt_vld;               
input           lsu_rtu_async_ld_inst;                
input   [31:0]  lsu_rtu_async_tval;                   
input           lsu_rtu_ex2_bus_err;                  
input           lsu_rtu_ex2_stall;                    
input   [31:0]  lsu_rtu_ex2_tval;                     
input           lsu_rtu_sync_ack;                     
input           lsu_xx_no_op;                         
input           pad_yy_icg_scan_en;                   
output          lockup_clk;                           
output          retire_cbus_debug_may_spec_fail;      
output          retire_cbus_ex2_stall;                
output          retire_cbus_flush_stall;              
output          retire_int_nmi_ack;                   
output          retire_lockup_dbg_req;                
output          retire_lockup_dbgon;                  
output          retire_lockup_expt_vld;               
output          retire_lockup_nmi_exit;               
output  [31:0]  retire_lockup_retire_pc;              
output          retire_lockup_retire_vld;             
output          retire_top_dbg_mode_on;               
output          retire_top_dbg_stall;                 
output  [2 :0]  retire_top_flush_cur_state;           
output          retire_top_lsu_ex2_stall;             
output          retire_xx_ex2_expt_raw;               
output          rtu_cp0_bus_error;                    
output  [31:0]  rtu_cp0_epc;                          
output          rtu_cp0_exit_debug;                   
output  [7 :0]  rtu_cp0_int_level;                    
output          rtu_cp0_nmi_vld;                      
output  [31:0]  rtu_cp0_tval;                         
output  [31:0]  rtu_dtu_dpc;                          
output          rtu_dtu_halt_ack;                     
output          rtu_dtu_pending_ack;                  
output          rtu_dtu_retire_chgflw;                
output          rtu_dtu_retire_debug_expt_vld;        
output  [14:0]  rtu_dtu_retire_halt_info;             
output          rtu_dtu_retire_mret;                  
output  [31:0]  rtu_dtu_retire_next_pc;               
output          rtu_dtu_retire_vld;                   
output  [31:0]  rtu_dtu_tval;                         
output          rtu_hpcp_retire_inst_vld;             
output          rtu_idu_flush_fe;                     
output          rtu_idu_flush_stall;                  
output          rtu_idu_inst_retire;                  
output          rtu_idu_late_flush;                   
output  [31:0]  rtu_ifu_chgflw_pc;                    
output          rtu_ifu_chgflw_vld;                   
output          rtu_ifu_dbg_mask;                     
output          rtu_ifu_flush_fe;                     
output          rtu_lsu_async_expt_ack;               
output          rtu_lsu_expt_ack;                     
output          rtu_lsu_expt_exit;                    
output          rtu_lsu_inst_retire;                  
output          rtu_lsu_sync_req;                     
output          rtu_pad_inst_retire;                  
output          rtu_pad_inst_split;                   
output  [31:0]  rtu_pad_retire_pc;                    
output          rtu_sysio_halted;                     
output          rtu_xx_no_op;                         
output          rtu_yy_xx_async_flush;                
output          rtu_yy_xx_dbgon;                      
output          rtu_yy_xx_expt_int;                   
output  [11:0]  rtu_yy_xx_expt_vec;                   
output          rtu_yy_xx_expt_vld;                   
output          rtu_yy_xx_flush;                      
output          rtu_yy_xx_int_hv;                     
output          rtu_yy_xx_tail_int_vld;               


reg             bkpt_req_split_lsu_trigger_buf;       
reg             bkpt_req_split_trigger_t1_buf;        
reg             dbg_mode_on;                          
reg             dbg_mode_on_after_req;                
reg     [1 :0]  dbg_stall_cur_state;                  
reg     [1 :0]  dbg_stall_next_state;                 
reg     [2 :0]  flush_cur_state;                      
reg     [2 :0]  flush_next_state;                     
reg     [3 :0]  halt_cause;                           
reg             halt_req_split_trigger_t1_buf;        
reg             retire_async_flush;                   
reg             retire_buf_async_trap_vld;            
reg     [14:0]  retire_buf_split_trigger_t1_halt_info; 
reg             retire_buf_trap_vld;                  
reg             retire_buf_xret_vld;                  
reg             retire_int_flush;                     
reg             retire_trap_ack_async;                
reg             retire_trap_ack_int;                  
reg             retire_trap_ack_nmi;                  
reg     [31:0]  retire_trap_tval;                     
reg     [11:0]  retire_trap_vec;                      
reg     [14:0]  rtu_dtu_retire_halt_info;             
reg     [31:0]  rtu_dtu_tval;                         


wire            bkpt_req_buf_split_trigger_t1;        
wire            bkpt_req_ebreak;                      
wire            bkpt_req_pending;                     
wire            bkpt_req_split_trigger_t1;            
wire            bkpt_req_t1_retire_vld;               
wire            bkpt_req_t1_retire_vld_raw;           
wire            bkpt_req_trigger_t0;                  
wire            bkpt_req_trigger_t1;                  
wire            bkpt_req_trigger_t1_raw;              
wire            cbus_retire_ex2_chgflw_vld;           
wire    [31:0]  cbus_retire_ex2_cur_pc;               
wire            cbus_retire_ex2_expt_inst;            
wire            cbus_retire_ex2_flush;                
wire    [14:0]  cbus_retire_ex2_halt_info;            
wire            cbus_retire_ex2_inst_branch;          
wire            cbus_retire_ex2_inst_dret;            
wire            cbus_retire_ex2_inst_ebreak;          
wire            cbus_retire_ex2_inst_int;             
wire            cbus_retire_ex2_inst_mret;            
wire            cbus_retire_ex2_inst_nmi;             
wire            cbus_retire_ex2_inst_tail_int;        
wire            cbus_retire_ex2_inst_vld;             
wire            cbus_retire_ex2_int_hv;               
wire    [7 :0]  cbus_retire_ex2_int_lv;               
wire            cbus_retire_ex2_ipop_int_mask;        
wire            cbus_retire_ex2_may_debug;            
wire    [31:0]  cbus_retire_ex2_next_pc;              
wire            cbus_retire_ex2_split_inst;           
wire            cbus_retire_ex2_tail_spec_inst;       
wire    [11:0]  cbus_retire_ex2_trap_vec;             
wire    [31:0]  cbus_retire_ex2_tval;                 
wire            cp0_rtu_ex1_mret;                     
wire            cp0_rtu_icg_en;                       
wire            cp0_rtu_in_nmi;                       
wire            cp0_xx_async_expt_en;                 
wire            cp0_yy_clk_en;                        
wire            cpurst_b;                             
wire            dtu_rtu_async_halt_req;               
wire    [31:0]  dtu_rtu_dpc;                          
wire            dtu_rtu_ebreak_action;                
wire    [31:0]  dtu_rtu_pending_tval;                 
wire            dtu_rtu_resume_req;                   
wire            dtu_rtu_step_en;                      
wire            dtu_rtu_sync_flush;                   
wire            dtu_rtu_sync_halt_req;                
wire            forever_cpuclk;                       
wire            fpu_xx_no_op;                         
wire            halt_req;                             
wire            halt_req_buf_split_trigger_t1;        
wire            halt_req_dm_async;                    
wire            halt_req_dm_sync;                     
wire            halt_req_ebreak;                      
wire            halt_req_lockup_dm_sync;              
wire            halt_req_pending;                     
wire            halt_req_reset;                       
wire            halt_req_split_trigger_t1;            
wire            halt_req_step;                        
wire            halt_req_t1;                          
wire            halt_req_t1_raw;                      
wire            halt_req_t1_retire_vld;               
wire            halt_req_t1_retire_vld_raw;           
wire            halt_req_trigger_t0;                  
wire            halt_req_trigger_t1;                  
wire            halt_req_trigger_t1_raw;              
wire            ifu_rtu_reset_halt_req;               
wire            int_retire_pending_int_hv;            
wire            iu_xx_no_op;                          
wire            lockup_clk;                           
wire            lockup_clk_en;                        
wire            lockup_retire_dbg_vld;                
wire            lockup_retire_nmi_vld;                
wire            lsu_rtu_async_expt_vld;               
wire            lsu_rtu_async_ld_inst;                
wire    [31:0]  lsu_rtu_async_tval;                   
wire            lsu_rtu_ex2_bus_err;                  
wire            lsu_rtu_ex2_stall;                    
wire    [31:0]  lsu_rtu_ex2_tval;                     
wire            lsu_rtu_sync_ack;                     
wire            lsu_xx_no_op;                         
wire            pad_yy_icg_scan_en;                   
wire            retire_async_expt;                    
wire            retire_async_expt_en;                 
wire    [11:0]  retire_async_expt_vec;                
wire            retire_async_trap_vld;                
wire    [31:0]  retire_async_tval;                    
wire            retire_bkpt_expt;                     
wire            retire_bkpt_expt_lsu_trigger_t1;      
wire            retire_bkpt_expt_split_lsu_trigger_t1; 
wire            retire_bkpt_expt_t1;                  
wire            retire_cbus_debug_may_spec_fail;      
wire            retire_cbus_ex2_stall;                
wire            retire_cbus_flush_stall;              
wire    [31:0]  retire_chgflw_pc;                     
wire            retire_chgflw_vld;                    
wire            retire_clk;                           
wire            retire_clk_en;                        
wire            retire_cpu_no_op;                     
wire            retire_dbg_mode_async_trap_vld;       
wire            retire_dbg_stall;                     
wire            retire_dbg_stall_set;                 
wire            retire_debug_flush;                   
wire            retire_ex2_retire_normal;             
wire            retire_ex2_retire_vld;                
wire            retire_exit_debug;                    
wire            retire_expt_debug;                    
wire            retire_expt_inst;                     
wire            retire_flush_be;                      
wire            retire_flush_fe;                      
wire            retire_flush_fe_set;                  
wire            retire_flush_stall;                   
wire    [14:0]  retire_halt_info;                     
wire            retire_inst_expt;                     
wire    [11:0]  retire_inst_expt_vec;                 
wire            retire_int_inst;                      
wire            retire_int_nmi_ack;                   
wire            retire_int_vld;                       
wire            retire_lockup_dbg_req;                
wire            retire_lockup_dbgon;                  
wire            retire_lockup_expt_vld;               
wire            retire_lockup_nmi_exit;               
wire    [31:0]  retire_lockup_retire_pc;              
wire            retire_lockup_retire_vld;             
wire            retire_nmi_inst;                      
wire            retire_nmi_vld;                       
wire            retire_pending_bkpt_expt;             
wire            retire_sync_debug_may_spec_fail;      
wire            retire_sync_expt;                     
wire            retire_tail_int_vld;                  
wire            retire_top_dbg_mode_on;               
wire            retire_top_dbg_stall;                 
wire    [2 :0]  retire_top_flush_cur_state;           
wire            retire_top_lsu_ex2_stall;             
wire    [31:0]  retire_trap_epc;                      
wire            retire_trap_epc_sel_cur_pc;           
wire            retire_trap_tval_ex1;                 
wire            retire_trap_vld;                      
wire            retire_xx_ex2_expt_raw;               
wire            rtu_cp0_bus_error;                    
wire    [31:0]  rtu_cp0_epc;                          
wire            rtu_cp0_exit_debug;                   
wire    [7 :0]  rtu_cp0_int_level;                    
wire            rtu_cp0_nmi_vld;                      
wire    [31:0]  rtu_cp0_tval;                         
wire    [31:0]  rtu_dtu_dpc;                          
wire            rtu_dtu_halt_ack;                     
wire            rtu_dtu_pending_ack;                  
wire            rtu_dtu_retire_chgflw;                
wire            rtu_dtu_retire_debug_expt_vld;        
wire            rtu_dtu_retire_mret;                  
wire    [31:0]  rtu_dtu_retire_next_pc;               
wire            rtu_dtu_retire_vld;                   
wire            rtu_hpcp_retire_inst_vld;             
wire            rtu_idu_flush_fe;                     
wire            rtu_idu_flush_stall;                  
wire            rtu_idu_inst_retire;                  
wire            rtu_idu_late_flush;                   
wire    [31:0]  rtu_ifu_chgflw_pc;                    
wire            rtu_ifu_chgflw_vld;                   
wire            rtu_ifu_dbg_mask;                     
wire            rtu_ifu_flush_fe;                     
wire            rtu_lsu_async_expt_ack;               
wire            rtu_lsu_expt_ack;                     
wire            rtu_lsu_expt_exit;                    
wire            rtu_lsu_inst_retire;                  
wire            rtu_lsu_sync_req;                     
wire            rtu_pad_inst_retire;                  
wire            rtu_pad_inst_split;                   
wire    [31:0]  rtu_pad_retire_pc;                    
wire            rtu_sysio_halted;                     
wire            rtu_xx_no_op;                         
wire            rtu_yy_xx_async_flush;                
wire            rtu_yy_xx_dbgon;                      
wire            rtu_yy_xx_expt_int;                   
wire    [11:0]  rtu_yy_xx_expt_vec;                   
wire            rtu_yy_xx_expt_vld;                   
wire            rtu_yy_xx_flush;                      
wire            rtu_yy_xx_int_hv;                     
wire            rtu_yy_xx_tail_int_vld;               





assign retire_ex2_retire_vld    = cbus_retire_ex2_inst_vld
                                  && !cbus_retire_ex2_tail_spec_inst
                                  && !lsu_rtu_ex2_stall
                                  && !retire_dbg_stall;

assign retire_ex2_retire_normal = retire_ex2_retire_vld
                                  && !retire_sync_expt;











assign retire_inst_expt             = cbus_retire_ex2_expt_inst || retire_bkpt_expt;
assign retire_inst_expt_vec[11:0]   = cbus_retire_ex2_trap_vec[11:0];

assign retire_async_expt_en         = (cp0_xx_async_expt_en || !lsu_rtu_async_ld_inst)
                                      && !cbus_retire_ex2_split_inst;
assign retire_async_expt            = lsu_rtu_async_expt_vld;
assign retire_async_expt_vec[11:0]  = lsu_rtu_async_ld_inst ? 12'd5 : 12'd7;
assign retire_async_tval[31:0]      = lsu_rtu_async_tval[31:0];

assign retire_sync_expt             = retire_inst_expt
                                   || retire_pending_bkpt_expt;

assign retire_expt_inst             = retire_sync_expt
                                   || retire_async_expt;

assign retire_expt_debug            = retire_pending_bkpt_expt
                                   || retire_async_expt
                                   || cbus_retire_ex2_expt_inst
                                      && !retire_bkpt_expt;
assign retire_int_inst              = cbus_retire_ex2_inst_int;
assign retire_nmi_inst              = cbus_retire_ex2_inst_nmi;

assign retire_xx_ex2_expt_raw       = retire_expt_inst;











always @( retire_int_inst
       or retire_async_expt_vec[11:0]
       or retire_async_expt
       or retire_bkpt_expt
       or retire_inst_expt_vec[11:0]
       or retire_nmi_inst
       or lockup_retire_nmi_vld
       or retire_pending_bkpt_expt)
begin
  if (retire_pending_bkpt_expt) begin
    retire_trap_vec[11:0] = 12'd3;


    retire_trap_ack_async = 1'b0;
    retire_trap_ack_int   = 1'b0;
    retire_trap_ack_nmi   = 1'b0;
  end
  else if (retire_nmi_inst || lockup_retire_nmi_vld) begin
    retire_trap_vec[11:0] = 12'd24;


    retire_trap_ack_async = 1'b0;
    retire_trap_ack_int   = 1'b0;
    retire_trap_ack_nmi   = 1'b1;
  end
  else if (retire_int_inst) begin
    retire_trap_vec[11:0] = retire_inst_expt_vec[11:0];


    retire_trap_ack_async = 1'b0;
    retire_trap_ack_int   = 1'b1;
    retire_trap_ack_nmi   = 1'b0;
  end
  else if (retire_async_expt) begin
    retire_trap_vec[11:0] = retire_async_expt_vec[11:0];


    retire_trap_ack_async = 1'b1;
    retire_trap_ack_int   = 1'b0;
    retire_trap_ack_nmi   = 1'b0;
  end
  else if (retire_bkpt_expt) begin
    retire_trap_vec[11:0] = 12'd3;


    retire_trap_ack_async = 1'b0;
    retire_trap_ack_int   = 1'b0;
    retire_trap_ack_nmi   = 1'b0;
  end
  else begin
    retire_trap_vec[11:0] = retire_inst_expt_vec[11:0];


    retire_trap_ack_async = 1'b0;
    retire_trap_ack_int   = 1'b0;
    retire_trap_ack_nmi   = 1'b0;
  end

end







assign retire_trap_tval_ex1 = cbus_retire_ex2_expt_inst
                              && (cbus_retire_ex2_trap_vec[3:0] == 4'h1
                               || cbus_retire_ex2_trap_vec[3:0] == 4'h2
                               || cbus_retire_ex2_trap_vec[3:0] == 4'h4
                               || cbus_retire_ex2_trap_vec[3:0] == 4'h5
                               || cbus_retire_ex2_trap_vec[3:0] == 4'h6
                               || cbus_retire_ex2_trap_vec[3:0] == 4'h7
                               || cbus_retire_ex2_trap_vec[3:0] == 4'hc);








always @( dtu_rtu_pending_tval[31:0]
       or retire_int_inst
       or bkpt_req_trigger_t0
       or retire_async_expt
       or retire_async_tval[31:0]
       or retire_trap_tval_ex1
       or cbus_retire_ex2_tval[31:0]
       or retire_pending_bkpt_expt)
begin
  if (retire_pending_bkpt_expt)
    retire_trap_tval[31:0] = dtu_rtu_pending_tval[31:0];
  else if (retire_int_inst)
    retire_trap_tval[31:0] = 32'b0;
  else if (retire_async_expt)
    retire_trap_tval[31:0] = retire_async_tval[31:0];


  else if (retire_trap_tval_ex1 || bkpt_req_trigger_t0)
    retire_trap_tval[31:0] = cbus_retire_ex2_tval[31:0];
  else
    retire_trap_tval[31:0] = 32'b0;

end




assign retire_trap_epc_sel_cur_pc = retire_sync_expt
                                 || retire_async_expt
                                    && (!retire_async_expt_en
                                      || cbus_retire_ex2_inst_tail_int)
                                 || (retire_int_inst || retire_nmi_inst)
                                    && cbus_retire_ex2_ipop_int_mask;

assign retire_trap_epc[31:0]      = retire_trap_epc_sel_cur_pc
                                    ? cbus_retire_ex2_cur_pc[31:0]
                                    : cbus_retire_ex2_next_pc[31:0];




assign retire_trap_vld      = retire_ex2_retire_vld
                              && !halt_req && !dbg_mode_on
                              && (retire_expt_inst || retire_int_inst || retire_nmi_inst)
                           || lockup_retire_nmi_vld;





assign retire_nmi_vld       = retire_ex2_retire_vld
                              && !halt_req && !dbg_mode_on
                              && retire_trap_ack_nmi;

assign retire_int_vld       = retire_ex2_retire_vld
                              && !halt_req && !dbg_mode_on
                              && retire_trap_ack_int;

assign retire_tail_int_vld  = retire_ex2_retire_vld
                              && !halt_req && !dbg_mode_on
                              && !retire_expt_inst
                              && cbus_retire_ex2_inst_tail_int;

assign retire_int_nmi_ack   = retire_nmi_vld || lockup_retire_nmi_vld;





assign retire_async_trap_vld = retire_async_expt
                               && (retire_trap_vld
                                   && retire_trap_ack_async);


assign retire_dbg_mode_async_trap_vld = retire_async_expt
                                        && retire_ex2_retire_vld
                                        && !retire_pending_bkpt_expt;




assign retire_chgflw_vld      = retire_ex2_retire_vld && !retire_trap_vld
                                && (cbus_retire_ex2_chgflw_vld
                                 || cbus_retire_ex2_flush)
                                || retire_exit_debug;

assign retire_chgflw_pc[31:0] = retire_exit_debug
                                ? dtu_rtu_dpc[31:0]
                                : cbus_retire_ex2_next_pc[31:0];




parameter STALL_IDLE   = 2'b00;
parameter STALL_SET    = 2'b01;
parameter STALL_RETIRE = 2'b10;




assign retire_dbg_stall_set = cbus_retire_ex2_inst_vld
                              && !dbg_mode_on
                              && (cbus_retire_ex2_may_debug
                               || retire_sync_debug_may_spec_fail);
assign rtu_lsu_sync_req     = retire_dbg_stall_set;

always @ (posedge retire_clk or negedge cpurst_b)
begin
  if (!cpurst_b)
    dbg_stall_cur_state[1:0] <= 2'b0;
  else
    dbg_stall_cur_state[1:0] <= dbg_stall_next_state[1:0];
end


always @( retire_ex2_retire_vld
       or lsu_rtu_sync_ack
       or dbg_stall_cur_state[1:0]
       or retire_dbg_stall_set)
begin
  case(dbg_stall_cur_state[1:0])
  STALL_IDLE:
    if (retire_dbg_stall_set)
      dbg_stall_next_state[1:0] = STALL_SET;
    else
      dbg_stall_next_state[1:0] = STALL_IDLE;
  STALL_SET:
    if (lsu_rtu_sync_ack)
      dbg_stall_next_state[1:0] = STALL_RETIRE;
    else
      dbg_stall_next_state[1:0] = STALL_SET;
  STALL_RETIRE:
    if (retire_ex2_retire_vld)
      dbg_stall_next_state[1:0] = STALL_IDLE;
    else
      dbg_stall_next_state[1:0] = STALL_RETIRE;
  default:
      dbg_stall_next_state[1:0] = STALL_IDLE;
  endcase

end

assign retire_dbg_stall = (dbg_stall_cur_state[1:0] == STALL_IDLE)
                          && retire_dbg_stall_set
                       || (dbg_stall_cur_state[1:0] == STALL_SET);
assign retire_top_dbg_stall  = retire_dbg_stall;





assign halt_req_reset            = ifu_rtu_reset_halt_req;

assign halt_req_dm_async         = dtu_rtu_async_halt_req;

assign halt_req_lockup_dm_sync   = lockup_retire_dbg_vld;
assign halt_req_ebreak           = retire_ex2_retire_vld
                                   && dtu_rtu_ebreak_action
                                   && cbus_retire_ex2_inst_ebreak
                                   && !cbus_retire_ex2_halt_info[`TDT_HINFO_PENDING_HALT]
                                   && !dbg_mode_on_after_req;
assign halt_req_trigger_t0       = retire_ex2_retire_vld
                                   && cbus_retire_ex2_halt_info[`TDT_HINFO_MATCH]
                                   && !cbus_retire_ex2_halt_info[`TDT_HINFO_CHAIN]
                                   && !cbus_retire_ex2_halt_info[`TDT_HINFO_TIMING]
                                   && cbus_retire_ex2_halt_info[`TDT_HINFO_ACTION]
                                   && !cbus_retire_ex2_halt_info[`TDT_HINFO_PENDING_HALT]
                                   && !dbg_mode_on_after_req;
assign halt_req_pending          = retire_ex2_retire_vld
                                   && cbus_retire_ex2_halt_info[`TDT_HINFO_PENDING_HALT]
                                   && cbus_retire_ex2_halt_info[`TDT_HINFO_ACTION]
                                   && !dbg_mode_on_after_req;

assign halt_req                  = halt_req_reset
                                || halt_req_ebreak
                                || halt_req_trigger_t0
                                || halt_req_pending
                                || halt_req_dm_async
                                || halt_req_lockup_dm_sync;







assign halt_req_t1_retire_vld_raw = retire_ex2_retire_vld
                                    && !cbus_retire_ex2_halt_info[`TDT_HINFO_PENDING_HALT]
                                    && !dbg_mode_on_after_req;


assign halt_req_t1_retire_vld     = halt_req_t1_retire_vld_raw
                                    && !halt_req;

assign halt_req_dm_sync           = halt_req_t1_retire_vld
                                    && !cbus_retire_ex2_split_inst
                                    && !cbus_retire_ex2_inst_tail_int
                                    && dtu_rtu_sync_halt_req;
assign halt_req_step              = halt_req_t1_retire_vld
                                    && !cbus_retire_ex2_split_inst
                                    && !cbus_retire_ex2_inst_tail_int
                                    && dtu_rtu_step_en;
assign halt_req_trigger_t1_raw    = halt_req_t1_retire_vld
                                    && cbus_retire_ex2_halt_info[`TDT_HINFO_MATCH]
                                    && !cbus_retire_ex2_halt_info[`TDT_HINFO_CHAIN]
                                    && cbus_retire_ex2_halt_info[`TDT_HINFO_TIMING]
                                    && cbus_retire_ex2_halt_info[`TDT_HINFO_ACTION];



assign halt_req_trigger_t1        = halt_req_trigger_t1_raw
                                    && !cbus_retire_ex2_split_inst
                                    && !cbus_retire_ex2_inst_tail_int;
assign halt_req_split_trigger_t1  = halt_req_trigger_t1_raw
                                    && (cbus_retire_ex2_split_inst
                                     || cbus_retire_ex2_inst_tail_int);

assign halt_req_buf_split_trigger_t1 = halt_req_t1_retire_vld
                                       && !cbus_retire_ex2_split_inst
                                       && !cbus_retire_ex2_inst_tail_int
                                       && halt_req_split_trigger_t1_buf;


assign halt_req_t1_raw            = halt_req_dm_sync
                                 || halt_req_trigger_t1
                                 || halt_req_buf_split_trigger_t1
                                 || halt_req_step;



assign halt_req_t1                = halt_req_t1_raw
                                    && !retire_bkpt_expt_t1;




assign bkpt_req_ebreak           = retire_ex2_retire_vld
                                   && !dtu_rtu_ebreak_action
                                   && cbus_retire_ex2_inst_ebreak
                                   && !cbus_retire_ex2_halt_info[`TDT_HINFO_PENDING_HALT];
assign bkpt_req_pending          = retire_ex2_retire_vld
                                   && cbus_retire_ex2_halt_info[`TDT_HINFO_PENDING_HALT]
                                   && !cbus_retire_ex2_halt_info[`TDT_HINFO_ACTION];

assign bkpt_req_trigger_t0       = retire_ex2_retire_vld
                                   && !cbus_retire_ex2_halt_info[`TDT_HINFO_PENDING_HALT]
                                   && cbus_retire_ex2_halt_info[`TDT_HINFO_MATCH]
                                   && !cbus_retire_ex2_halt_info[`TDT_HINFO_CHAIN]
                                   && !cbus_retire_ex2_halt_info[`TDT_HINFO_TIMING]
                                   && !cbus_retire_ex2_halt_info[`TDT_HINFO_ACTION];

assign retire_bkpt_expt          = bkpt_req_ebreak
                                   || bkpt_req_trigger_t0;

assign retire_pending_bkpt_expt  = bkpt_req_pending;






assign bkpt_req_t1_retire_vld_raw = retire_ex2_retire_vld
                                    && !cbus_retire_ex2_halt_info[`TDT_HINFO_PENDING_HALT];

assign bkpt_req_t1_retire_vld     = bkpt_req_t1_retire_vld_raw
                                    && !halt_req;

assign bkpt_req_trigger_t1_raw    = bkpt_req_t1_retire_vld
                                    && cbus_retire_ex2_halt_info[`TDT_HINFO_MATCH]
                                    && !cbus_retire_ex2_halt_info[`TDT_HINFO_CHAIN]
                                    && cbus_retire_ex2_halt_info[`TDT_HINFO_TIMING]
                                    && !cbus_retire_ex2_halt_info[`TDT_HINFO_ACTION];


assign bkpt_req_trigger_t1        = bkpt_req_trigger_t1_raw
                                    && !cbus_retire_ex2_split_inst
                                    && !cbus_retire_ex2_inst_tail_int;
assign bkpt_req_split_trigger_t1  = bkpt_req_trigger_t1_raw
                                    && (cbus_retire_ex2_split_inst
                                     || cbus_retire_ex2_inst_tail_int);

assign bkpt_req_buf_split_trigger_t1 = bkpt_req_t1_retire_vld
                                       && bkpt_req_split_trigger_t1_buf
                                       && !cbus_retire_ex2_split_inst
                                       && !cbus_retire_ex2_inst_tail_int;

assign retire_bkpt_expt_t1        = bkpt_req_trigger_t1
                                 || bkpt_req_buf_split_trigger_t1;

assign retire_bkpt_expt_lsu_trigger_t1       = bkpt_req_trigger_t1
                                               && cbus_retire_ex2_halt_info[`TDT_HINFO_LDST];
assign retire_bkpt_expt_split_lsu_trigger_t1 = bkpt_req_buf_split_trigger_t1
                                               && bkpt_req_split_lsu_trigger_buf;





assign retire_cbus_debug_may_spec_fail = ifu_rtu_reset_halt_req
                                      || dtu_rtu_async_halt_req
                                      || lockup_retire_dbg_vld
                                      || dtu_rtu_resume_req
                                      || cbus_retire_ex2_inst_vld
                                         && (dtu_rtu_sync_halt_req
                                          || dtu_rtu_step_en
                                          || halt_req_split_trigger_t1_buf
                                          || bkpt_req_split_trigger_t1_buf
                                          || dtu_rtu_sync_flush);

assign retire_sync_debug_may_spec_fail = cbus_retire_ex2_inst_vld
                                         && (dtu_rtu_sync_halt_req
                                          || dtu_rtu_step_en
                                          || halt_req_split_trigger_t1_buf
                                          || bkpt_req_split_trigger_t1_buf
                                          || dtu_rtu_sync_flush);






assign retire_debug_flush  = retire_ex2_retire_vld
                             && dtu_rtu_sync_flush
                             && !cbus_retire_ex2_split_inst
                             && !cbus_retire_ex2_inst_tail_int
                             && !dbg_mode_on_after_req;






assign retire_exit_debug   = dbg_mode_on_after_req
                             && (dtu_rtu_resume_req
                              || retire_ex2_retire_vld
                                 && cbus_retire_ex2_inst_dret);







always @( halt_req_trigger_t0
       or halt_req_buf_split_trigger_t1
       or halt_req_pending
       or halt_req_dm_sync
       or lockup_retire_dbg_vld
       or cbus_retire_ex2_halt_info[11:8]
       or halt_req_reset
       or halt_req_ebreak
       or halt_req_trigger_t1
       or halt_req_dm_async)
begin
  if(halt_req_dm_async)
    halt_cause[3:0] = 4'd8;
  else if(halt_req_pending)
    halt_cause[3:0] = cbus_retire_ex2_halt_info[`TDT_HINFO_CAUSE:`TDT_HINFO_CAUSE-3];
  else if(halt_req_trigger_t0
       || halt_req_trigger_t1
       || halt_req_buf_split_trigger_t1)
    halt_cause[3:0] = 4'd2;
  else if(halt_req_ebreak)
    halt_cause[3:0] = 4'd1;
  else if(halt_req_reset)
    halt_cause[3:0] = 4'd5;
  else if(halt_req_dm_sync)
    halt_cause[3:0] = 4'd3;
  else if(lockup_retire_dbg_vld)
    halt_cause[3:0] = 4'd3;
  else
    halt_cause[3:0] = 4'd4;

end






always @ (posedge retire_clk or negedge cpurst_b)
begin
  if (!cpurst_b)
    dbg_mode_on_after_req <= 1'b0;
  else if (halt_req)
    dbg_mode_on_after_req <= 1'b1;
  else if (retire_exit_debug)
    dbg_mode_on_after_req <= 1'b0;
end



always @ (posedge retire_clk or negedge cpurst_b)
begin
  if (!cpurst_b)
    dbg_mode_on <= 1'b0;
  else if (retire_flush_be && dbg_mode_on_after_req)
    dbg_mode_on <= 1'b1;
  else if (retire_exit_debug)
    dbg_mode_on <= 1'b0;
end

always @ (posedge retire_clk or negedge cpurst_b)
begin
  if (!cpurst_b)
    retire_async_flush <= 1'b0;
  else
    retire_async_flush <= halt_req_dm_async;
end









always @ (posedge retire_clk or negedge cpurst_b)
begin
  if (!cpurst_b)
    halt_req_split_trigger_t1_buf <= 1'b0;
  else if (retire_flush_be || halt_req_trigger_t1)
    halt_req_split_trigger_t1_buf <= 1'b0;
  else if (halt_req_split_trigger_t1)
    halt_req_split_trigger_t1_buf <= 1'b1;
end

always @ (posedge retire_clk or negedge cpurst_b)
begin
  if (!cpurst_b) begin
    bkpt_req_split_trigger_t1_buf  <= 1'b0;
    bkpt_req_split_lsu_trigger_buf <= 1'b0;
  end
  else if (retire_flush_be || bkpt_req_trigger_t1) begin
    bkpt_req_split_trigger_t1_buf  <= 1'b0;
    bkpt_req_split_lsu_trigger_buf <= 1'b0;
  end
  else if (bkpt_req_split_trigger_t1) begin
    bkpt_req_split_trigger_t1_buf  <= 1'b1;
    bkpt_req_split_lsu_trigger_buf <= cbus_retire_ex2_halt_info[`TDT_HINFO_LDST];
  end
end

always @ (posedge retire_clk or negedge cpurst_b)
begin
  if (!cpurst_b)
    retire_buf_split_trigger_t1_halt_info[`TDT_HINFO_WIDTH-1:0] <= {`TDT_HINFO_WIDTH{1'b0}};
  else if (retire_flush_be || halt_req_trigger_t1 || bkpt_req_trigger_t1)
    retire_buf_split_trigger_t1_halt_info[`TDT_HINFO_WIDTH-1:0] <= {`TDT_HINFO_WIDTH{1'b0}};
  else if (halt_req_split_trigger_t1 || bkpt_req_split_trigger_t1)
    retire_buf_split_trigger_t1_halt_info[`TDT_HINFO_WIDTH-1:0] <=
    retire_buf_split_trigger_t1_halt_info[`TDT_HINFO_WIDTH-1:0]
                | cbus_retire_ex2_halt_info[`TDT_HINFO_WIDTH-1:0];
end






assign retire_halt_info[`TDT_HINFO_WIDTH-1:0] =
    cbus_retire_ex2_halt_info[`TDT_HINFO_WIDTH-1:0]
  | {`TDT_HINFO_WIDTH{(halt_req_buf_split_trigger_t1
                    || bkpt_req_buf_split_trigger_t1)}}
    & retire_buf_split_trigger_t1_halt_info[`TDT_HINFO_WIDTH-1:0];


























assign retire_flush_fe_set = retire_ex2_retire_vld
                             && (retire_expt_inst
                              || retire_nmi_inst
                              || lockup_retire_nmi_vld
                              || cbus_retire_ex2_flush
                                 && !retire_trap_ack_int
                              || retire_bkpt_expt_t1
                              || retire_debug_flush)
                             || halt_req
                             || halt_req_t1;

assign retire_cpu_no_op    = lsu_xx_no_op
                             && iu_xx_no_op
                             && fpu_xx_no_op
                             && rtu_xx_no_op;




parameter FLUSH_IDLE  = 3'b000;
parameter FLUSH_FE    = 3'b101;
parameter FLUSH_WAIT  = 3'b100;
parameter FLUSH_BE    = 3'b110;
parameter FLUSH_FE_BE = 3'b111;

always @ (posedge retire_clk or negedge cpurst_b)
begin
  if (!cpurst_b)
    flush_cur_state[2:0] <= 3'b0;
  else if (halt_req_dm_async)
    flush_cur_state[2:0] <= FLUSH_FE_BE;
  else
    flush_cur_state[2:0] <= flush_next_state[2:0];
end


always @( flush_cur_state[2:0]
       or retire_cpu_no_op
       or retire_flush_fe_set)
begin
  case(flush_cur_state[2:0])
  FLUSH_IDLE:
    if (retire_flush_fe_set)
      flush_next_state[2:0] = FLUSH_FE;
    else
      flush_next_state[2:0] = FLUSH_IDLE;
  FLUSH_FE:
    if (retire_cpu_no_op)
      flush_next_state[2:0] = FLUSH_BE;
    else
      flush_next_state[2:0] = FLUSH_WAIT;
  FLUSH_WAIT:
    if (retire_cpu_no_op)
      flush_next_state[2:0] = FLUSH_BE;
    else
      flush_next_state[2:0] = FLUSH_WAIT;
  FLUSH_BE:
    flush_next_state[2:0] = FLUSH_IDLE;
  FLUSH_FE_BE:
    flush_next_state[2:0] = FLUSH_IDLE;
  default:
    flush_next_state[2:0] = FLUSH_IDLE;
  endcase

end

assign retire_flush_stall = flush_cur_state[2];
assign retire_flush_fe    = flush_cur_state[0];
assign retire_flush_be    = flush_cur_state[1];

assign retire_top_flush_cur_state[2:0] = flush_cur_state[2:0];




always @ (posedge retire_clk or negedge cpurst_b)
begin
  if (!cpurst_b)
    retire_int_flush <= 1'b0;
  else if (retire_flush_be)
    retire_int_flush <= 1'b0;
  else if (retire_trap_vld && retire_expt_inst && retire_trap_ack_int)
    retire_int_flush <= 1'b1;
end




always @ (posedge retire_clk or negedge cpurst_b)
begin
  if (!cpurst_b) begin
    retire_buf_trap_vld       <= 1'b0;
    retire_buf_xret_vld       <= 1'b0;

    retire_buf_async_trap_vld <= 1'b0;
  end
  else if (retire_ex2_retire_vld) begin
    retire_buf_trap_vld       <= retire_trap_vld;
    retire_buf_xret_vld       <= retire_ex2_retire_normal
                                 && cbus_retire_ex2_inst_mret;

    retire_buf_async_trap_vld <= retire_async_trap_vld;
  end
  else if (retire_flush_be) begin
    retire_buf_trap_vld       <= 1'b0;
    retire_buf_xret_vld       <= 1'b0;

    retire_buf_async_trap_vld <= 1'b0;
  end
end







assign rtu_yy_xx_flush          = retire_flush_be;
assign rtu_yy_xx_async_flush    = retire_async_flush;
assign rtu_yy_xx_expt_vld       = retire_trap_vld;
assign rtu_yy_xx_tail_int_vld   = retire_tail_int_vld;
assign rtu_yy_xx_expt_int       = retire_int_vld;
assign rtu_yy_xx_expt_vec[11:0] = retire_trap_vec[11:0];
assign rtu_yy_xx_dbgon          = dbg_mode_on;

assign rtu_yy_xx_int_hv         = cbus_retire_ex2_inst_tail_int
                                  ? int_retire_pending_int_hv
                                  : cbus_retire_ex2_int_hv;


assign rtu_xx_no_op             = !cbus_retire_ex2_inst_vld;

assign retire_top_dbg_mode_on   = dbg_mode_on_after_req;




assign rtu_pad_inst_retire     = retire_ex2_retire_vld;
assign rtu_pad_inst_split      = cbus_retire_ex2_split_inst;
assign rtu_pad_retire_pc[31:0] = cbus_retire_ex2_cur_pc[31:0];
assign rtu_sysio_halted        = dbg_mode_on;






always @( halt_req_t1_raw
       or halt_req
       or retire_bkpt_expt_t1
       or halt_req_buf_split_trigger_t1
       or bkpt_req_buf_split_trigger_t1
       or halt_req_t1
       or retire_halt_info[14:0]
       or halt_cause[3:0])
begin
  rtu_dtu_retire_halt_info[`TDT_HINFO_WIDTH-1:0] = retire_halt_info[`TDT_HINFO_WIDTH-1:0];
  if(1'b1) begin
  rtu_dtu_retire_halt_info[`TDT_HINFO_ACTION]       = halt_req    || halt_req_t1;
  rtu_dtu_retire_halt_info[`TDT_HINFO_PENDING_HALT] = halt_req_t1 || retire_bkpt_expt_t1;
  rtu_dtu_retire_halt_info[`TDT_HINFO_ACTION01]     = retire_halt_info[`TDT_HINFO_ACTION01]
                                                      || halt_req_buf_split_trigger_t1
                                                      && bkpt_req_buf_split_trigger_t1
                                                      || retire_bkpt_expt_t1
                                                      && halt_req_t1_raw;
  rtu_dtu_retire_halt_info[`TDT_HINFO_CAUSE:`TDT_HINFO_CAUSE-3] = halt_cause[3:0];
  end

end


assign rtu_dtu_dpc[31:0]             = cbus_retire_ex2_cur_pc[31:0];


always @( retire_bkpt_expt_split_lsu_trigger_t1
       or cbus_retire_ex2_cur_pc[31:0]
       or lsu_rtu_ex2_tval[31:0]
       or retire_bkpt_expt_lsu_trigger_t1)
begin

  if(retire_bkpt_expt_lsu_trigger_t1)
    rtu_dtu_tval[31:0]               = lsu_rtu_ex2_tval[31:0];

  else if(retire_bkpt_expt_split_lsu_trigger_t1)
    rtu_dtu_tval[31:0]               = 32'b0;

  else
    rtu_dtu_tval[31:0]               = cbus_retire_ex2_cur_pc[31:0];

end

assign rtu_dtu_halt_ack              = halt_req;
assign rtu_dtu_pending_ack           = halt_req_pending || bkpt_req_pending;


assign rtu_dtu_retire_vld            = retire_ex2_retire_vld
                                       && (retire_flush_fe_set
                                           || !(cbus_retire_ex2_split_inst
                                             || cbus_retire_ex2_inst_tail_int));
assign rtu_dtu_retire_debug_expt_vld = retire_ex2_retire_vld
                                       && dbg_mode_on
                                       && retire_expt_debug;
assign rtu_dtu_retire_mret           = cbus_retire_ex2_inst_mret;
assign rtu_dtu_retire_chgflw         = cbus_retire_ex2_inst_branch;
assign rtu_dtu_retire_next_pc[31:0]  = cbus_retire_ex2_next_pc[31:0];




assign rtu_ifu_chgflw_vld       = retire_chgflw_vld;
assign rtu_ifu_flush_fe         = retire_flush_fe;
assign rtu_ifu_chgflw_pc[31:0]  = retire_chgflw_pc[31:0];

assign rtu_ifu_dbg_mask         = dbg_mode_on_after_req;




assign rtu_cp0_epc[31:0]        = retire_trap_epc[31:0];
assign rtu_cp0_tval[31:0]       = retire_trap_tval[31:0];
assign rtu_cp0_exit_debug       = retire_exit_debug;
assign rtu_cp0_nmi_vld          = retire_nmi_vld || lockup_retire_nmi_vld;
assign rtu_cp0_bus_error        = lsu_rtu_ex2_bus_err || lsu_rtu_async_expt_vld;
assign rtu_cp0_int_level[7:0]   = cbus_retire_ex2_int_lv[7:0];




assign rtu_idu_inst_retire      = retire_ex2_retire_vld;
assign rtu_idu_flush_stall      = retire_flush_stall;
assign rtu_idu_flush_fe         = retire_flush_fe;
assign rtu_idu_late_flush       = retire_int_flush;




assign rtu_lsu_expt_ack         = retire_flush_be && retire_buf_trap_vld;
assign rtu_lsu_expt_exit        = retire_flush_be && retire_buf_xret_vld;


assign rtu_lsu_async_expt_ack   = dbg_mode_on
                                  ? retire_dbg_mode_async_trap_vld
                                  : retire_flush_be && retire_buf_async_trap_vld;
assign rtu_lsu_inst_retire      = retire_ex2_retire_vld;




assign rtu_hpcp_retire_inst_vld = retire_ex2_retire_vld && !cbus_retire_ex2_split_inst;






assign retire_lockup_nmi_exit        = cp0_rtu_ex1_mret && cp0_rtu_in_nmi;

assign retire_lockup_dbg_req         = dtu_rtu_sync_halt_req;
assign retire_lockup_expt_vld        = retire_trap_vld
                                       && !retire_int_inst
                                       && !retire_nmi_inst
                                       && retire_trap_vec[11:0] != 12'd3
                                       && retire_trap_vec[11:0] != 12'd11;
assign retire_lockup_retire_vld      = retire_ex2_retire_vld;
assign retire_lockup_retire_pc[31:0] = cbus_retire_ex2_cur_pc[31:0];
assign retire_lockup_dbgon           = dbg_mode_on;





assign retire_cbus_flush_stall  = retire_flush_stall;
assign retire_cbus_ex2_stall    = retire_dbg_stall
                               || lsu_rtu_ex2_stall;
assign retire_top_lsu_ex2_stall = lsu_rtu_ex2_stall;




assign retire_clk_en = cbus_retire_ex2_inst_vld
                    || halt_req
                    || retire_exit_debug
                    || retire_flush_fe_set
                    || retire_buf_trap_vld
                    || retire_buf_xret_vld
                    || retire_buf_async_trap_vld
                    || flush_cur_state[2:0] != FLUSH_IDLE
                    || dbg_stall_cur_state[1:0] != STALL_IDLE
                    || retire_async_flush
                    || halt_req_trigger_t1
                    || halt_req_split_trigger_t1
                    || bkpt_req_trigger_t1
                    || bkpt_req_split_trigger_t1
                    || lockup_clk_en;


gated_clk_cell  x_retire_clk (
  .clk_in             (forever_cpuclk    ),
  .clk_out            (retire_clk        ),
  .external_en        (1'b0              ),
  .global_en          (cp0_yy_clk_en     ),
  .local_en           (retire_clk_en     ),
  .module_en          (cp0_rtu_icg_en    ),
  .pad_yy_icg_scan_en (pad_yy_icg_scan_en)
);








assign lockup_clk = retire_clk;


endmodule
module pa_rtu_retire(
  cbus_retire_ex2_chgflw_vld,
  cbus_retire_ex2_cur_pc,
  cbus_retire_ex2_expt_inst,
  cbus_retire_ex2_flush,
  cbus_retire_ex2_halt_info,
  cbus_retire_ex2_inst_branch,
  cbus_retire_ex2_inst_dret,
  cbus_retire_ex2_inst_ebreak,
  cbus_retire_ex2_inst_int,
  cbus_retire_ex2_inst_mret,
  cbus_retire_ex2_inst_nmi,
  cbus_retire_ex2_inst_tail_int,
  cbus_retire_ex2_inst_vld,
  cbus_retire_ex2_int_hv,
  cbus_retire_ex2_int_lv,
  cbus_retire_ex2_ipop_int_mask,
  cbus_retire_ex2_may_debug,
  cbus_retire_ex2_next_pc,
  cbus_retire_ex2_split_inst,
  cbus_retire_ex2_tail_spec_inst,
  cbus_retire_ex2_trap_vec,
  cbus_retire_ex2_tval,
  cp0_rtu_ex1_mret,
  cp0_rtu_icg_en,
  cp0_rtu_in_nmi,
  cp0_xx_async_expt_en,
  cp0_yy_clk_en,
  cpurst_b,
  dtu_rtu_async_halt_req,
  dtu_rtu_dpc,
  dtu_rtu_ebreak_action,
  dtu_rtu_pending_tval,
  dtu_rtu_resume_req,
  dtu_rtu_step_en,
  dtu_rtu_sync_flush,
  dtu_rtu_sync_halt_req,
  forever_cpuclk,
  fpu_xx_no_op,
  ifu_rtu_reset_halt_req,
  int_retire_pending_int_hv,
  iu_xx_no_op,
  lockup_clk,
  lockup_clk_en,
  lockup_retire_dbg_vld,
  lockup_retire_nmi_vld,
  lsu_rtu_async_expt_vld,
  lsu_rtu_async_ld_inst,
  lsu_rtu_async_tval,
  lsu_rtu_ex2_bus_err,
  lsu_rtu_ex2_stall,
  lsu_rtu_ex2_tval,
  lsu_rtu_sync_ack,
  lsu_xx_no_op,
  pad_yy_icg_scan_en,
  retire_cbus_debug_may_spec_fail,
  retire_cbus_ex2_stall,
  retire_cbus_flush_stall,
  retire_int_nmi_ack,
  retire_lockup_dbg_req,
  retire_lockup_dbgon,
  retire_lockup_expt_vld,
  retire_lockup_nmi_exit,
  retire_lockup_retire_pc,
  retire_lockup_retire_vld,
  retire_top_dbg_mode_on,
  retire_top_dbg_stall,
  retire_top_flush_cur_state,
  retire_top_lsu_ex2_stall,
  retire_xx_ex2_expt_raw,
  rtu_cp0_bus_error,
  rtu_cp0_epc,
  rtu_cp0_exit_debug,
  rtu_cp0_int_level,
  rtu_cp0_nmi_vld,
  rtu_cp0_tval,
  rtu_dtu_dpc,
  rtu_dtu_halt_ack,
  rtu_dtu_pending_ack,
  rtu_dtu_retire_chgflw,
  rtu_dtu_retire_debug_expt_vld,
  rtu_dtu_retire_halt_info,
  rtu_dtu_retire_mret,
  rtu_dtu_retire_next_pc,
  rtu_dtu_retire_vld,
  rtu_dtu_tval,
  rtu_hpcp_retire_inst_vld,
  rtu_idu_flush_fe,
  rtu_idu_flush_stall,
  rtu_idu_inst_retire,
  rtu_idu_late_flush,
  rtu_ifu_chgflw_pc,
  rtu_ifu_chgflw_vld,
  rtu_ifu_dbg_mask,
  rtu_ifu_flush_fe,
  rtu_lsu_async_expt_ack,
  rtu_lsu_expt_ack,
  rtu_lsu_expt_exit,
  rtu_lsu_inst_retire,
  rtu_lsu_sync_req,
  rtu_pad_inst_retire,
  rtu_pad_inst_split,
  rtu_pad_retire_pc,
  rtu_sysio_halted,
  rtu_xx_no_op,
  rtu_yy_xx_async_flush,
  rtu_yy_xx_dbgon,
  rtu_yy_xx_expt_int,
  rtu_yy_xx_expt_vec,
  rtu_yy_xx_expt_vld,
  rtu_yy_xx_flush,
  rtu_yy_xx_int_hv,
  rtu_yy_xx_tail_int_vld
);



input           cbus_retire_ex2_chgflw_vld;           
input   [31:0]  cbus_retire_ex2_cur_pc;               
input           cbus_retire_ex2_expt_inst;            
input           cbus_retire_ex2_flush;                
input   [14:0]  cbus_retire_ex2_halt_info;            
input           cbus_retire_ex2_inst_branch;          
input           cbus_retire_ex2_inst_dret;            
input           cbus_retire_ex2_inst_ebreak;          
input           cbus_retire_ex2_inst_int;             
input           cbus_retire_ex2_inst_mret;            
input           cbus_retire_ex2_inst_nmi;             
input           cbus_retire_ex2_inst_tail_int;        
input           cbus_retire_ex2_inst_vld;             
input           cbus_retire_ex2_int_hv;               
input   [7 :0]  cbus_retire_ex2_int_lv;               
input           cbus_retire_ex2_ipop_int_mask;        
input           cbus_retire_ex2_may_debug;            
input   [31:0]  cbus_retire_ex2_next_pc;              
input           cbus_retire_ex2_split_inst;           
input           cbus_retire_ex2_tail_spec_inst;       
input   [11:0]  cbus_retire_ex2_trap_vec;             
input   [31:0]  cbus_retire_ex2_tval;                 
input           cp0_rtu_ex1_mret;                     
input           cp0_rtu_icg_en;                       
input           cp0_rtu_in_nmi;                       
input           cp0_xx_async_expt_en;                 
input           cp0_yy_clk_en;                        
input           cpurst_b;                             
input           dtu_rtu_async_halt_req;               
input   [31:0]  dtu_rtu_dpc;                          
input           dtu_rtu_ebreak_action;                
input   [31:0]  dtu_rtu_pending_tval;                 
input           dtu_rtu_resume_req;                   
input           dtu_rtu_step_en;                      
input           dtu_rtu_sync_flush;                   
input           dtu_rtu_sync_halt_req;                
input           forever_cpuclk;                       
input           fpu_xx_no_op;                         
input           ifu_rtu_reset_halt_req;               
input           int_retire_pending_int_hv;            
input           iu_xx_no_op;                          
input           lockup_clk_en;                        
input           lockup_retire_dbg_vld;                
input           lockup_retire_nmi_vld;                
input           lsu_rtu_async_expt_vld;               
input           lsu_rtu_async_ld_inst;                
input   [31:0]  lsu_rtu_async_tval;                   
input           lsu_rtu_ex2_bus_err;                  
input           lsu_rtu_ex2_stall;                    
input   [31:0]  lsu_rtu_ex2_tval;                     
input           lsu_rtu_sync_ack;                     
input           lsu_xx_no_op;                         
input           pad_yy_icg_scan_en;                   
output          lockup_clk;                           
output          retire_cbus_debug_may_spec_fail;      
output          retire_cbus_ex2_stall;                
output          retire_cbus_flush_stall;              
output          retire_int_nmi_ack;                   
output          retire_lockup_dbg_req;                
output          retire_lockup_dbgon;                  
output          retire_lockup_expt_vld;               
output          retire_lockup_nmi_exit;               
output  [31:0]  retire_lockup_retire_pc;              
output          retire_lockup_retire_vld;             
output          retire_top_dbg_mode_on;               
output          retire_top_dbg_stall;                 
output  [2 :0]  retire_top_flush_cur_state;           
output          retire_top_lsu_ex2_stall;             
output          retire_xx_ex2_expt_raw;               
output          rtu_cp0_bus_error;                    
output  [31:0]  rtu_cp0_epc;                          
output          rtu_cp0_exit_debug;                   
output  [7 :0]  rtu_cp0_int_level;                    
output          rtu_cp0_nmi_vld;                      
output  [31:0]  rtu_cp0_tval;                         
output  [31:0]  rtu_dtu_dpc;                          
output          rtu_dtu_halt_ack;                     
output          rtu_dtu_pending_ack;                  
output          rtu_dtu_retire_chgflw;                
output          rtu_dtu_retire_debug_expt_vld;        
output  [14:0]  rtu_dtu_retire_halt_info;             
output          rtu_dtu_retire_mret;                  
output  [31:0]  rtu_dtu_retire_next_pc;               
output          rtu_dtu_retire_vld;                   
output  [31:0]  rtu_dtu_tval;                         
output          rtu_hpcp_retire_inst_vld;             
output          rtu_idu_flush_fe;                     
output          rtu_idu_flush_stall;                  
output          rtu_idu_inst_retire;                  
output          rtu_idu_late_flush;                   
output  [31:0]  rtu_ifu_chgflw_pc;                    
output          rtu_ifu_chgflw_vld;                   
output          rtu_ifu_dbg_mask;                     
output          rtu_ifu_flush_fe;                     
output          rtu_lsu_async_expt_ack;               
output          rtu_lsu_expt_ack;                     
output          rtu_lsu_expt_exit;                    
output          rtu_lsu_inst_retire;                  
output          rtu_lsu_sync_req;                     
output          rtu_pad_inst_retire;                  
output          rtu_pad_inst_split;                   
output  [31:0]  rtu_pad_retire_pc;                    
output          rtu_sysio_halted;                     
output          rtu_xx_no_op;                         
output          rtu_yy_xx_async_flush;                
output          rtu_yy_xx_dbgon;                      
output          rtu_yy_xx_expt_int;                   
output  [11:0]  rtu_yy_xx_expt_vec;                   
output          rtu_yy_xx_expt_vld;                   
output          rtu_yy_xx_flush;                      
output          rtu_yy_xx_int_hv;                     
output          rtu_yy_xx_tail_int_vld;               


reg             bkpt_req_split_lsu_trigger_buf;       
reg             bkpt_req_split_trigger_t1_buf;        
reg             dbg_mode_on;                          
reg             dbg_mode_on_after_req;                
reg     [1 :0]  dbg_stall_cur_state;                  
reg     [1 :0]  dbg_stall_next_state;                 
reg     [2 :0]  flush_cur_state;                      
reg     [2 :0]  flush_next_state;                     
reg     [3 :0]  halt_cause;                           
reg             halt_req_split_trigger_t1_buf;        
reg             retire_async_flush;                   
reg             retire_buf_async_trap_vld;            
reg     [14:0]  retire_buf_split_trigger_t1_halt_info; 
reg             retire_buf_trap_vld;                  
reg             retire_buf_xret_vld;                  
reg             retire_int_flush;                     
reg             retire_trap_ack_async;                
reg             retire_trap_ack_int;                  
reg             retire_trap_ack_nmi;                  
reg     [31:0]  retire_trap_tval;                     
reg     [11:0]  retire_trap_vec;                      
reg     [14:0]  rtu_dtu_retire_halt_info;             
reg     [31:0]  rtu_dtu_tval;                         


wire            bkpt_req_buf_split_trigger_t1;        
wire            bkpt_req_ebreak;                      
wire            bkpt_req_pending;                     
wire            bkpt_req_split_trigger_t1;            
wire            bkpt_req_t1_retire_vld;               
wire            bkpt_req_t1_retire_vld_raw;           
wire            bkpt_req_trigger_t0;                  
wire            bkpt_req_trigger_t1;                  
wire            bkpt_req_trigger_t1_raw;              
wire            cbus_retire_ex2_chgflw_vld;           
wire    [31:0]  cbus_retire_ex2_cur_pc;               
wire            cbus_retire_ex2_expt_inst;            
wire            cbus_retire_ex2_flush;                
wire    [14:0]  cbus_retire_ex2_halt_info;            
wire            cbus_retire_ex2_inst_branch;          
wire            cbus_retire_ex2_inst_dret;            
wire            cbus_retire_ex2_inst_ebreak;          
wire            cbus_retire_ex2_inst_int;             
wire            cbus_retire_ex2_inst_mret;            
wire            cbus_retire_ex2_inst_nmi;             
wire            cbus_retire_ex2_inst_tail_int;        
wire            cbus_retire_ex2_inst_vld;             
wire            cbus_retire_ex2_int_hv;               
wire    [7 :0]  cbus_retire_ex2_int_lv;               
wire            cbus_retire_ex2_ipop_int_mask;        
wire            cbus_retire_ex2_may_debug;            
wire    [31:0]  cbus_retire_ex2_next_pc;              
wire            cbus_retire_ex2_split_inst;           
wire            cbus_retire_ex2_tail_spec_inst;       
wire    [11:0]  cbus_retire_ex2_trap_vec;             
wire    [31:0]  cbus_retire_ex2_tval;                 
wire            cp0_rtu_ex1_mret;                     
wire            cp0_rtu_icg_en;                       
wire            cp0_rtu_in_nmi;                       
wire            cp0_xx_async_expt_en;                 
wire            cp0_yy_clk_en;                        
wire            cpurst_b;                             
wire            dtu_rtu_async_halt_req;               
wire    [31:0]  dtu_rtu_dpc;                          
wire            dtu_rtu_ebreak_action;                
wire    [31:0]  dtu_rtu_pending_tval;                 
wire            dtu_rtu_resume_req;                   
wire            dtu_rtu_step_en;                      
wire            dtu_rtu_sync_flush;                   
wire            dtu_rtu_sync_halt_req;                
wire            forever_cpuclk;                       
wire            fpu_xx_no_op;                         
wire            halt_req;                             
wire            halt_req_buf_split_trigger_t1;        
wire            halt_req_dm_async;                    
wire            halt_req_dm_sync;                     
wire            halt_req_ebreak;                      
wire            halt_req_lockup_dm_sync;              
wire            halt_req_pending;                     
wire            halt_req_reset;                       
wire            halt_req_split_trigger_t1;            
wire            halt_req_step;                        
wire            halt_req_t1;                          
wire            halt_req_t1_raw;                      
wire            halt_req_t1_retire_vld;               
wire            halt_req_t1_retire_vld_raw;           
wire            halt_req_trigger_t0;                  
wire            halt_req_trigger_t1;                  
wire            halt_req_trigger_t1_raw;              
wire            ifu_rtu_reset_halt_req;               
wire            int_retire_pending_int_hv;            
wire            iu_xx_no_op;                          
wire            lockup_clk;                           
wire            lockup_clk_en;                        
wire            lockup_retire_dbg_vld;                
wire            lockup_retire_nmi_vld;                
wire            lsu_rtu_async_expt_vld;               
wire            lsu_rtu_async_ld_inst;                
wire    [31:0]  lsu_rtu_async_tval;                   
wire            lsu_rtu_ex2_bus_err;                  
wire            lsu_rtu_ex2_stall;                    
wire    [31:0]  lsu_rtu_ex2_tval;                     
wire            lsu_rtu_sync_ack;                     
wire            lsu_xx_no_op;                         
wire            pad_yy_icg_scan_en;                   
wire            retire_async_expt;                    
wire            retire_async_expt_en;                 
wire    [11:0]  retire_async_expt_vec;                
wire            retire_async_trap_vld;                
wire    [31:0]  retire_async_tval;                    
wire            retire_bkpt_expt;                     
wire            retire_bkpt_expt_lsu_trigger_t1;      
wire            retire_bkpt_expt_split_lsu_trigger_t1; 
wire            retire_bkpt_expt_t1;                  
wire            retire_cbus_debug_may_spec_fail;      
wire            retire_cbus_ex2_stall;                
wire            retire_cbus_flush_stall;              
wire    [31:0]  retire_chgflw_pc;                     
wire            retire_chgflw_vld;                    
wire            retire_clk;                           
wire            retire_clk_en;                        
wire            retire_cpu_no_op;                     
wire            retire_dbg_mode_async_trap_vld;       
wire            retire_dbg_stall;                     
wire            retire_dbg_stall_set;                 
wire            retire_debug_flush;                   
wire            retire_ex2_retire_normal;             
wire            retire_ex2_retire_vld;                
wire            retire_exit_debug;                    
wire            retire_expt_debug;                    
wire            retire_expt_inst;                     
wire            retire_flush_be;                      
wire            retire_flush_fe;                      
wire            retire_flush_fe_set;                  
wire            retire_flush_stall;                   
wire    [14:0]  retire_halt_info;                     
wire            retire_inst_expt;                     
wire    [11:0]  retire_inst_expt_vec;                 
wire            retire_int_inst;                      
wire            retire_int_nmi_ack;                   
wire            retire_int_vld;                       
wire            retire_lockup_dbg_req;                
wire            retire_lockup_dbgon;                  
wire            retire_lockup_expt_vld;               
wire            retire_lockup_nmi_exit;               
wire    [31:0]  retire_lockup_retire_pc;              
wire            retire_lockup_retire_vld;             
wire            retire_nmi_inst;                      
wire            retire_nmi_vld;                       
wire            retire_pending_bkpt_expt;             
wire            retire_sync_debug_may_spec_fail;      
wire            retire_sync_expt;                     
wire            retire_tail_int_vld;                  
wire            retire_top_dbg_mode_on;               
wire            retire_top_dbg_stall;                 
wire    [2 :0]  retire_top_flush_cur_state;           
wire            retire_top_lsu_ex2_stall;             
wire    [31:0]  retire_trap_epc;                      
wire            retire_trap_epc_sel_cur_pc;           
wire            retire_trap_tval_ex1;                 
wire            retire_trap_vld;                      
wire            retire_xx_ex2_expt_raw;               
wire            rtu_cp0_bus_error;                    
wire    [31:0]  rtu_cp0_epc;                          
wire            rtu_cp0_exit_debug;                   
wire    [7 :0]  rtu_cp0_int_level;                    
wire            rtu_cp0_nmi_vld;                      
wire    [31:0]  rtu_cp0_tval;                         
wire    [31:0]  rtu_dtu_dpc;                          
wire            rtu_dtu_halt_ack;                     
wire            rtu_dtu_pending_ack;                  
wire            rtu_dtu_retire_chgflw;                
wire            rtu_dtu_retire_debug_expt_vld;        
wire            rtu_dtu_retire_mret;                  
wire    [31:0]  rtu_dtu_retire_next_pc;               
wire            rtu_dtu_retire_vld;                   
wire            rtu_hpcp_retire_inst_vld;             
wire            rtu_idu_flush_fe;                     
wire            rtu_idu_flush_stall;                  
wire            rtu_idu_inst_retire;                  
wire            rtu_idu_late_flush;                   
wire    [31:0]  rtu_ifu_chgflw_pc;                    
wire            rtu_ifu_chgflw_vld;                   
wire            rtu_ifu_dbg_mask;                     
wire            rtu_ifu_flush_fe;                     
wire            rtu_lsu_async_expt_ack;               
wire            rtu_lsu_expt_ack;                     
wire            rtu_lsu_expt_exit;                    
wire            rtu_lsu_inst_retire;                  
wire            rtu_lsu_sync_req;                     
wire            rtu_pad_inst_retire;                  
wire            rtu_pad_inst_split;                   
wire    [31:0]  rtu_pad_retire_pc;                    
wire            rtu_sysio_halted;                     
wire            rtu_xx_no_op;                         
wire            rtu_yy_xx_async_flush;                
wire            rtu_yy_xx_dbgon;                      
wire            rtu_yy_xx_expt_int;                   
wire    [11:0]  rtu_yy_xx_expt_vec;                   
wire            rtu_yy_xx_expt_vld;                   
wire            rtu_yy_xx_flush;                      
wire            rtu_yy_xx_int_hv;                     
wire            rtu_yy_xx_tail_int_vld;               





assign retire_ex2_retire_vld    = cbus_retire_ex2_inst_vld
                                  && !cbus_retire_ex2_tail_spec_inst
                                  && !lsu_rtu_ex2_stall
                                  && !retire_dbg_stall;

assign retire_ex2_retire_normal = retire_ex2_retire_vld
                                  && !retire_sync_expt;











assign retire_inst_expt             = cbus_retire_ex2_expt_inst || retire_bkpt_expt;
assign retire_inst_expt_vec[11:0]   = cbus_retire_ex2_trap_vec[11:0];

assign retire_async_expt_en         = (cp0_xx_async_expt_en || !lsu_rtu_async_ld_inst)
                                      && !cbus_retire_ex2_split_inst;
assign retire_async_expt            = lsu_rtu_async_expt_vld;
assign retire_async_expt_vec[11:0]  = lsu_rtu_async_ld_inst ? 12'd5 : 12'd7;
assign retire_async_tval[31:0]      = lsu_rtu_async_tval[31:0];

assign retire_sync_expt             = retire_inst_expt
                                   || retire_pending_bkpt_expt;

assign retire_expt_inst             = retire_sync_expt
                                   || retire_async_expt;

assign retire_expt_debug            = retire_pending_bkpt_expt
                                   || retire_async_expt
                                   || cbus_retire_ex2_expt_inst
                                      && !retire_bkpt_expt;
assign retire_int_inst              = cbus_retire_ex2_inst_int;
assign retire_nmi_inst              = cbus_retire_ex2_inst_nmi;

assign retire_xx_ex2_expt_raw       = retire_expt_inst;











always @( retire_int_inst
       or retire_async_expt_vec[11:0]
       or retire_async_expt
       or retire_bkpt_expt
       or retire_inst_expt_vec[11:0]
       or retire_nmi_inst
       or lockup_retire_nmi_vld
       or retire_pending_bkpt_expt)
begin
  if (retire_pending_bkpt_expt) begin
    retire_trap_vec[11:0] = 12'd3;


    retire_trap_ack_async = 1'b0;
    retire_trap_ack_int   = 1'b0;
    retire_trap_ack_nmi   = 1'b0;
  end
  else if (retire_nmi_inst || lockup_retire_nmi_vld) begin
    retire_trap_vec[11:0] = 12'd24;


    retire_trap_ack_async = 1'b0;
    retire_trap_ack_int   = 1'b0;
    retire_trap_ack_nmi   = 1'b1;
  end
  else if (retire_int_inst) begin
    retire_trap_vec[11:0] = retire_inst_expt_vec[11:0];


    retire_trap_ack_async = 1'b0;
    retire_trap_ack_int   = 1'b1;
    retire_trap_ack_nmi   = 1'b0;
  end
  else if (retire_async_expt) begin
    retire_trap_vec[11:0] = retire_async_expt_vec[11:0];


    retire_trap_ack_async = 1'b1;
    retire_trap_ack_int   = 1'b0;
    retire_trap_ack_nmi   = 1'b0;
  end
  else if (retire_bkpt_expt) begin
    retire_trap_vec[11:0] = 12'd3;


    retire_trap_ack_async = 1'b0;
    retire_trap_ack_int   = 1'b0;
    retire_trap_ack_nmi   = 1'b0;
  end
  else begin
    retire_trap_vec[11:0] = retire_inst_expt_vec[11:0];


    retire_trap_ack_async = 1'b0;
    retire_trap_ack_int   = 1'b0;
    retire_trap_ack_nmi   = 1'b0;
  end

end







assign retire_trap_tval_ex1 = cbus_retire_ex2_expt_inst
                              && (cbus_retire_ex2_trap_vec[3:0] == 4'h1
                               || cbus_retire_ex2_trap_vec[3:0] == 4'h2
                               || cbus_retire_ex2_trap_vec[3:0] == 4'h4
                               || cbus_retire_ex2_trap_vec[3:0] == 4'h5
                               || cbus_retire_ex2_trap_vec[3:0] == 4'h6
                               || cbus_retire_ex2_trap_vec[3:0] == 4'h7
                               || cbus_retire_ex2_trap_vec[3:0] == 4'hc);








always @( dtu_rtu_pending_tval[31:0]
       or retire_int_inst
       or bkpt_req_trigger_t0
       or retire_async_expt
       or retire_async_tval[31:0]
       or retire_trap_tval_ex1
       or cbus_retire_ex2_tval[31:0]
       or retire_pending_bkpt_expt)
begin
  if (retire_pending_bkpt_expt)
    retire_trap_tval[31:0] = dtu_rtu_pending_tval[31:0];
  else if (retire_int_inst)
    retire_trap_tval[31:0] = 32'b0;
  else if (retire_async_expt)
    retire_trap_tval[31:0] = retire_async_tval[31:0];


  else if (retire_trap_tval_ex1 || bkpt_req_trigger_t0)
    retire_trap_tval[31:0] = cbus_retire_ex2_tval[31:0];
  else
    retire_trap_tval[31:0] = 32'b0;

end




assign retire_trap_epc_sel_cur_pc = retire_sync_expt
                                 || retire_async_expt
                                    && (!retire_async_expt_en
                                      || cbus_retire_ex2_inst_tail_int)
                                 || (retire_int_inst || retire_nmi_inst)
                                    && cbus_retire_ex2_ipop_int_mask;

assign retire_trap_epc[31:0]      = retire_trap_epc_sel_cur_pc
                                    ? cbus_retire_ex2_cur_pc[31:0]
                                    : cbus_retire_ex2_next_pc[31:0];




assign retire_trap_vld      = retire_ex2_retire_vld
                              && !halt_req && !dbg_mode_on
                              && (retire_expt_inst || retire_int_inst || retire_nmi_inst)
                           || lockup_retire_nmi_vld;





assign retire_nmi_vld       = retire_ex2_retire_vld
                              && !halt_req && !dbg_mode_on
                              && retire_trap_ack_nmi;

assign retire_int_vld       = retire_ex2_retire_vld
                              && !halt_req && !dbg_mode_on
                              && retire_trap_ack_int;

assign retire_tail_int_vld  = retire_ex2_retire_vld
                              && !halt_req && !dbg_mode_on
                              && !retire_expt_inst
                              && cbus_retire_ex2_inst_tail_int;

assign retire_int_nmi_ack   = retire_nmi_vld || lockup_retire_nmi_vld;





assign retire_async_trap_vld = retire_async_expt
                               && (retire_trap_vld
                                   && retire_trap_ack_async);


assign retire_dbg_mode_async_trap_vld = retire_async_expt
                                        && retire_ex2_retire_vld
                                        && !retire_pending_bkpt_expt;




assign retire_chgflw_vld      = retire_ex2_retire_vld && !retire_trap_vld
                                && (cbus_retire_ex2_chgflw_vld
                                 || cbus_retire_ex2_flush)
                                || retire_exit_debug;

assign retire_chgflw_pc[31:0] = retire_exit_debug
                                ? dtu_rtu_dpc[31:0]
                                : cbus_retire_ex2_next_pc[31:0];




parameter STALL_IDLE   = 2'b00;
parameter STALL_SET    = 2'b01;
parameter STALL_RETIRE = 2'b10;




assign retire_dbg_stall_set = cbus_retire_ex2_inst_vld
                              && !dbg_mode_on
                              && (cbus_retire_ex2_may_debug
                               || retire_sync_debug_may_spec_fail);
assign rtu_lsu_sync_req     = retire_dbg_stall_set;

always @ (posedge retire_clk or negedge cpurst_b)
begin
  if (!cpurst_b)
    dbg_stall_cur_state[1:0] <= 2'b0;
  else
    dbg_stall_cur_state[1:0] <= dbg_stall_next_state[1:0];
end


always @( retire_ex2_retire_vld
       or lsu_rtu_sync_ack
       or dbg_stall_cur_state[1:0]
       or retire_dbg_stall_set)
begin
  case(dbg_stall_cur_state[1:0])
  STALL_IDLE:
    if (retire_dbg_stall_set)
      dbg_stall_next_state[1:0] = STALL_SET;
    else
      dbg_stall_next_state[1:0] = STALL_IDLE;
  STALL_SET:
    if (lsu_rtu_sync_ack)
      dbg_stall_next_state[1:0] = STALL_RETIRE;
    else
      dbg_stall_next_state[1:0] = STALL_SET;
  STALL_RETIRE:
    if (retire_ex2_retire_vld)
      dbg_stall_next_state[1:0] = STALL_IDLE;
    else
      dbg_stall_next_state[1:0] = STALL_RETIRE;
  default:
      dbg_stall_next_state[1:0] = STALL_IDLE;
  endcase

end

assign retire_dbg_stall = (dbg_stall_cur_state[1:0] == STALL_IDLE)
                          && retire_dbg_stall_set
                       || (dbg_stall_cur_state[1:0] == STALL_SET);
assign retire_top_dbg_stall  = retire_dbg_stall;





assign halt_req_reset            = ifu_rtu_reset_halt_req;

assign halt_req_dm_async         = dtu_rtu_async_halt_req;

assign halt_req_lockup_dm_sync   = lockup_retire_dbg_vld;
assign halt_req_ebreak           = retire_ex2_retire_vld
                                   && dtu_rtu_ebreak_action
                                   && cbus_retire_ex2_inst_ebreak
                                   && !cbus_retire_ex2_halt_info[`TDT_HINFO_PENDING_HALT]
                                   && !dbg_mode_on_after_req;
assign halt_req_trigger_t0       = retire_ex2_retire_vld
                                   && cbus_retire_ex2_halt_info[`TDT_HINFO_MATCH]
                                   && !cbus_retire_ex2_halt_info[`TDT_HINFO_CHAIN]
                                   && !cbus_retire_ex2_halt_info[`TDT_HINFO_TIMING]
                                   && cbus_retire_ex2_halt_info[`TDT_HINFO_ACTION]
                                   && !cbus_retire_ex2_halt_info[`TDT_HINFO_PENDING_HALT]
                                   && !dbg_mode_on_after_req;
assign halt_req_pending          = retire_ex2_retire_vld
                                   && cbus_retire_ex2_halt_info[`TDT_HINFO_PENDING_HALT]
                                   && cbus_retire_ex2_halt_info[`TDT_HINFO_ACTION]
                                   && !dbg_mode_on_after_req;

assign halt_req                  = halt_req_reset
                                || halt_req_ebreak
                                || halt_req_trigger_t0
                                || halt_req_pending
                                || halt_req_dm_async
                                || halt_req_lockup_dm_sync;







assign halt_req_t1_retire_vld_raw = retire_ex2_retire_vld
                                    && !cbus_retire_ex2_halt_info[`TDT_HINFO_PENDING_HALT]
                                    && !dbg_mode_on_after_req;


assign halt_req_t1_retire_vld     = halt_req_t1_retire_vld_raw
                                    && !halt_req;

assign halt_req_dm_sync           = halt_req_t1_retire_vld
                                    && !cbus_retire_ex2_split_inst
                                    && !cbus_retire_ex2_inst_tail_int
                                    && dtu_rtu_sync_halt_req;
assign halt_req_step              = halt_req_t1_retire_vld
                                    && !cbus_retire_ex2_split_inst
                                    && !cbus_retire_ex2_inst_tail_int
                                    && dtu_rtu_step_en;
assign halt_req_trigger_t1_raw    = halt_req_t1_retire_vld
                                    && cbus_retire_ex2_halt_info[`TDT_HINFO_MATCH]
                                    && !cbus_retire_ex2_halt_info[`TDT_HINFO_CHAIN]
                                    && cbus_retire_ex2_halt_info[`TDT_HINFO_TIMING]
                                    && cbus_retire_ex2_halt_info[`TDT_HINFO_ACTION];



assign halt_req_trigger_t1        = halt_req_trigger_t1_raw
                                    && !cbus_retire_ex2_split_inst
                                    && !cbus_retire_ex2_inst_tail_int;
assign halt_req_split_trigger_t1  = halt_req_trigger_t1_raw
                                    && (cbus_retire_ex2_split_inst
                                     || cbus_retire_ex2_inst_tail_int);

assign halt_req_buf_split_trigger_t1 = halt_req_t1_retire_vld
                                       && !cbus_retire_ex2_split_inst
                                       && !cbus_retire_ex2_inst_tail_int
                                       && halt_req_split_trigger_t1_buf;


assign halt_req_t1_raw            = halt_req_dm_sync
                                 || halt_req_trigger_t1
                                 || halt_req_buf_split_trigger_t1
                                 || halt_req_step;



assign halt_req_t1                = halt_req_t1_raw
                                    && !retire_bkpt_expt_t1;




assign bkpt_req_ebreak           = retire_ex2_retire_vld
                                   && !dtu_rtu_ebreak_action
                                   && cbus_retire_ex2_inst_ebreak
                                   && !cbus_retire_ex2_halt_info[`TDT_HINFO_PENDING_HALT];
assign bkpt_req_pending          = retire_ex2_retire_vld
                                   && cbus_retire_ex2_halt_info[`TDT_HINFO_PENDING_HALT]
                                   && !cbus_retire_ex2_halt_info[`TDT_HINFO_ACTION];

assign bkpt_req_trigger_t0       = retire_ex2_retire_vld
                                   && !cbus_retire_ex2_halt_info[`TDT_HINFO_PENDING_HALT]
                                   && cbus_retire_ex2_halt_info[`TDT_HINFO_MATCH]
                                   && !cbus_retire_ex2_halt_info[`TDT_HINFO_CHAIN]
                                   && !cbus_retire_ex2_halt_info[`TDT_HINFO_TIMING]
                                   && !cbus_retire_ex2_halt_info[`TDT_HINFO_ACTION];

assign retire_bkpt_expt          = bkpt_req_ebreak
                                   || bkpt_req_trigger_t0;

assign retire_pending_bkpt_expt  = bkpt_req_pending;






assign bkpt_req_t1_retire_vld_raw = retire_ex2_retire_vld
                                    && !cbus_retire_ex2_halt_info[`TDT_HINFO_PENDING_HALT];

assign bkpt_req_t1_retire_vld     = bkpt_req_t1_retire_vld_raw
                                    && !halt_req;

assign bkpt_req_trigger_t1_raw    = bkpt_req_t1_retire_vld
                                    && cbus_retire_ex2_halt_info[`TDT_HINFO_MATCH]
                                    && !cbus_retire_ex2_halt_info[`TDT_HINFO_CHAIN]
                                    && cbus_retire_ex2_halt_info[`TDT_HINFO_TIMING]
                                    && !cbus_retire_ex2_halt_info[`TDT_HINFO_ACTION];


assign bkpt_req_trigger_t1        = bkpt_req_trigger_t1_raw
                                    && !cbus_retire_ex2_split_inst
                                    && !cbus_retire_ex2_inst_tail_int;
assign bkpt_req_split_trigger_t1  = bkpt_req_trigger_t1_raw
                                    && (cbus_retire_ex2_split_inst
                                     || cbus_retire_ex2_inst_tail_int);

assign bkpt_req_buf_split_trigger_t1 = bkpt_req_t1_retire_vld
                                       && bkpt_req_split_trigger_t1_buf
                                       && !cbus_retire_ex2_split_inst
                                       && !cbus_retire_ex2_inst_tail_int;

assign retire_bkpt_expt_t1        = bkpt_req_trigger_t1
                                 || bkpt_req_buf_split_trigger_t1;

assign retire_bkpt_expt_lsu_trigger_t1       = bkpt_req_trigger_t1
                                               && cbus_retire_ex2_halt_info[`TDT_HINFO_LDST];
assign retire_bkpt_expt_split_lsu_trigger_t1 = bkpt_req_buf_split_trigger_t1
                                               && bkpt_req_split_lsu_trigger_buf;





assign retire_cbus_debug_may_spec_fail = ifu_rtu_reset_halt_req
                                      || dtu_rtu_async_halt_req
                                      || lockup_retire_dbg_vld
                                      || dtu_rtu_resume_req
                                      || cbus_retire_ex2_inst_vld
                                         && (dtu_rtu_sync_halt_req
                                          || dtu_rtu_step_en
                                          || halt_req_split_trigger_t1_buf
                                          || bkpt_req_split_trigger_t1_buf
                                          || dtu_rtu_sync_flush);

assign retire_sync_debug_may_spec_fail = cbus_retire_ex2_inst_vld
                                         && (dtu_rtu_sync_halt_req
                                          || dtu_rtu_step_en
                                          || halt_req_split_trigger_t1_buf
                                          || bkpt_req_split_trigger_t1_buf
                                          || dtu_rtu_sync_flush);






assign retire_debug_flush  = retire_ex2_retire_vld
                             && dtu_rtu_sync_flush
                             && !cbus_retire_ex2_split_inst
                             && !cbus_retire_ex2_inst_tail_int
                             && !dbg_mode_on_after_req;






assign retire_exit_debug   = dbg_mode_on_after_req
                             && (dtu_rtu_resume_req
                              || retire_ex2_retire_vld
                                 && cbus_retire_ex2_inst_dret);







always @( halt_req_trigger_t0
       or halt_req_buf_split_trigger_t1
       or halt_req_pending
       or halt_req_dm_sync
       or lockup_retire_dbg_vld
       or cbus_retire_ex2_halt_info[11:8]
       or halt_req_reset
       or halt_req_ebreak
       or halt_req_trigger_t1
       or halt_req_dm_async)
begin
  if(halt_req_dm_async)
    halt_cause[3:0] = 4'd8;
  else if(halt_req_pending)
    halt_cause[3:0] = cbus_retire_ex2_halt_info[`TDT_HINFO_CAUSE:`TDT_HINFO_CAUSE-3];
  else if(halt_req_trigger_t0
       || halt_req_trigger_t1
       || halt_req_buf_split_trigger_t1)
    halt_cause[3:0] = 4'd2;
  else if(halt_req_ebreak)
    halt_cause[3:0] = 4'd1;
  else if(halt_req_reset)
    halt_cause[3:0] = 4'd5;
  else if(halt_req_dm_sync)
    halt_cause[3:0] = 4'd3;
  else if(lockup_retire_dbg_vld)
    halt_cause[3:0] = 4'd3;
  else
    halt_cause[3:0] = 4'd4;

end






always @ (posedge retire_clk or negedge cpurst_b)
begin
  if (!cpurst_b)
    dbg_mode_on_after_req <= 1'b0;
  else if (halt_req)
    dbg_mode_on_after_req <= 1'b1;
  else if (retire_exit_debug)
    dbg_mode_on_after_req <= 1'b0;
end



always @ (posedge retire_clk or negedge cpurst_b)
begin
  if (!cpurst_b)
    dbg_mode_on <= 1'b0;
  else if (retire_flush_be && dbg_mode_on_after_req)
    dbg_mode_on <= 1'b1;
  else if (retire_exit_debug)
    dbg_mode_on <= 1'b0;
end

always @ (posedge retire_clk or negedge cpurst_b)
begin
  if (!cpurst_b)
    retire_async_flush <= 1'b0;
  else
    retire_async_flush <= halt_req_dm_async;
end









always @ (posedge retire_clk or negedge cpurst_b)
begin
  if (!cpurst_b)
    halt_req_split_trigger_t1_buf <= 1'b0;
  else if (retire_flush_be || halt_req_trigger_t1)
    halt_req_split_trigger_t1_buf <= 1'b0;
  else if (halt_req_split_trigger_t1)
    halt_req_split_trigger_t1_buf <= 1'b1;
end

always @ (posedge retire_clk or negedge cpurst_b)
begin
  if (!cpurst_b) begin
    bkpt_req_split_trigger_t1_buf  <= 1'b0;
    bkpt_req_split_lsu_trigger_buf <= 1'b0;
  end
  else if (retire_flush_be || bkpt_req_trigger_t1) begin
    bkpt_req_split_trigger_t1_buf  <= 1'b0;
    bkpt_req_split_lsu_trigger_buf <= 1'b0;
  end
  else if (bkpt_req_split_trigger_t1) begin
    bkpt_req_split_trigger_t1_buf  <= 1'b1;
    bkpt_req_split_lsu_trigger_buf <= cbus_retire_ex2_halt_info[`TDT_HINFO_LDST];
  end
end

always @ (posedge retire_clk or negedge cpurst_b)
begin
  if (!cpurst_b)
    retire_buf_split_trigger_t1_halt_info[`TDT_HINFO_WIDTH-1:0] <= {`TDT_HINFO_WIDTH{1'b0}};
  else if (retire_flush_be || halt_req_trigger_t1 || bkpt_req_trigger_t1)
    retire_buf_split_trigger_t1_halt_info[`TDT_HINFO_WIDTH-1:0] <= {`TDT_HINFO_WIDTH{1'b0}};
  else if (halt_req_split_trigger_t1 || bkpt_req_split_trigger_t1)
    retire_buf_split_trigger_t1_halt_info[`TDT_HINFO_WIDTH-1:0] <=
    retire_buf_split_trigger_t1_halt_info[`TDT_HINFO_WIDTH-1:0]
                | cbus_retire_ex2_halt_info[`TDT_HINFO_WIDTH-1:0];
end






assign retire_halt_info[`TDT_HINFO_WIDTH-1:0] =
    cbus_retire_ex2_halt_info[`TDT_HINFO_WIDTH-1:0]
  | {`TDT_HINFO_WIDTH{(halt_req_buf_split_trigger_t1
                    || bkpt_req_buf_split_trigger_t1)}}
    & retire_buf_split_trigger_t1_halt_info[`TDT_HINFO_WIDTH-1:0];


























assign retire_flush_fe_set = retire_ex2_retire_vld
                             && (retire_expt_inst
                              || retire_nmi_inst
                              || lockup_retire_nmi_vld
                              || cbus_retire_ex2_flush
                                 && !retire_trap_ack_int
                              || retire_bkpt_expt_t1
                              || retire_debug_flush)
                             || halt_req
                             || halt_req_t1;

assign retire_cpu_no_op    = lsu_xx_no_op
                             && iu_xx_no_op
                             && fpu_xx_no_op
                             && rtu_xx_no_op;




parameter FLUSH_IDLE  = 3'b000;
parameter FLUSH_FE    = 3'b101;
parameter FLUSH_WAIT  = 3'b100;
parameter FLUSH_BE    = 3'b110;
parameter FLUSH_FE_BE = 3'b111;

always @ (posedge retire_clk or negedge cpurst_b)
begin
  if (!cpurst_b)
    flush_cur_state[2:0] <= 3'b0;
  else if (halt_req_dm_async)
    flush_cur_state[2:0] <= FLUSH_FE_BE;
  else
    flush_cur_state[2:0] <= flush_next_state[2:0];
end


always @( flush_cur_state[2:0]
       or retire_cpu_no_op
       or retire_flush_fe_set)
begin
  case(flush_cur_state[2:0])
  FLUSH_IDLE:
    if (retire_flush_fe_set)
      flush_next_state[2:0] = FLUSH_FE;
    else
      flush_next_state[2:0] = FLUSH_IDLE;
  FLUSH_FE:
    if (retire_cpu_no_op)
      flush_next_state[2:0] = FLUSH_BE;
    else
      flush_next_state[2:0] = FLUSH_WAIT;
  FLUSH_WAIT:
    if (retire_cpu_no_op)
      flush_next_state[2:0] = FLUSH_BE;
    else
      flush_next_state[2:0] = FLUSH_WAIT;
  FLUSH_BE:
    flush_next_state[2:0] = FLUSH_IDLE;
  FLUSH_FE_BE:
    flush_next_state[2:0] = FLUSH_IDLE;
  default:
    flush_next_state[2:0] = FLUSH_IDLE;
  endcase

end

assign retire_flush_stall = flush_cur_state[2];
assign retire_flush_fe    = flush_cur_state[0];
assign retire_flush_be    = flush_cur_state[1];

assign retire_top_flush_cur_state[2:0] = flush_cur_state[2:0];




always @ (posedge retire_clk or negedge cpurst_b)
begin
  if (!cpurst_b)
    retire_int_flush <= 1'b0;
  else if (retire_flush_be)
    retire_int_flush <= 1'b0;
  else if (retire_trap_vld && retire_expt_inst && retire_trap_ack_int)
    retire_int_flush <= 1'b1;
end




always @ (posedge retire_clk or negedge cpurst_b)
begin
  if (!cpurst_b) begin
    retire_buf_trap_vld       <= 1'b0;
    retire_buf_xret_vld       <= 1'b0;

    retire_buf_async_trap_vld <= 1'b0;
  end
  else if (retire_ex2_retire_vld) begin
    retire_buf_trap_vld       <= retire_trap_vld;
    retire_buf_xret_vld       <= retire_ex2_retire_normal
                                 && cbus_retire_ex2_inst_mret;

    retire_buf_async_trap_vld <= retire_async_trap_vld;
  end
  else if (retire_flush_be) begin
    retire_buf_trap_vld       <= 1'b0;
    retire_buf_xret_vld       <= 1'b0;

    retire_buf_async_trap_vld <= 1'b0;
  end
end







assign rtu_yy_xx_flush          = retire_flush_be;
assign rtu_yy_xx_async_flush    = retire_async_flush;
assign rtu_yy_xx_expt_vld       = retire_trap_vld;
assign rtu_yy_xx_tail_int_vld   = retire_tail_int_vld;
assign rtu_yy_xx_expt_int       = retire_int_vld;
assign rtu_yy_xx_expt_vec[11:0] = retire_trap_vec[11:0];
assign rtu_yy_xx_dbgon          = dbg_mode_on;

assign rtu_yy_xx_int_hv         = cbus_retire_ex2_inst_tail_int
                                  ? int_retire_pending_int_hv
                                  : cbus_retire_ex2_int_hv;


assign rtu_xx_no_op             = !cbus_retire_ex2_inst_vld;

assign retire_top_dbg_mode_on   = dbg_mode_on_after_req;




assign rtu_pad_inst_retire     = retire_ex2_retire_vld;
assign rtu_pad_inst_split      = cbus_retire_ex2_split_inst;
assign rtu_pad_retire_pc[31:0] = cbus_retire_ex2_cur_pc[31:0];
assign rtu_sysio_halted        = dbg_mode_on;






always @( halt_req_t1_raw
       or halt_req
       or retire_bkpt_expt_t1
       or halt_req_buf_split_trigger_t1
       or bkpt_req_buf_split_trigger_t1
       or halt_req_t1
       or retire_halt_info[14:0]
       or halt_cause[3:0])
begin
  rtu_dtu_retire_halt_info[`TDT_HINFO_WIDTH-1:0] = retire_halt_info[`TDT_HINFO_WIDTH-1:0];
  if(1'b1) begin
  rtu_dtu_retire_halt_info[`TDT_HINFO_ACTION]       = halt_req    || halt_req_t1;
  rtu_dtu_retire_halt_info[`TDT_HINFO_PENDING_HALT] = halt_req_t1 || retire_bkpt_expt_t1;
  rtu_dtu_retire_halt_info[`TDT_HINFO_ACTION01]     = retire_halt_info[`TDT_HINFO_ACTION01]
                                                      || halt_req_buf_split_trigger_t1
                                                      && bkpt_req_buf_split_trigger_t1
                                                      || retire_bkpt_expt_t1
                                                      && halt_req_t1_raw;
  rtu_dtu_retire_halt_info[`TDT_HINFO_CAUSE:`TDT_HINFO_CAUSE-3] = halt_cause[3:0];
  end

end


assign rtu_dtu_dpc[31:0]             = cbus_retire_ex2_cur_pc[31:0];


always @( retire_bkpt_expt_split_lsu_trigger_t1
       or cbus_retire_ex2_cur_pc[31:0]
       or lsu_rtu_ex2_tval[31:0]
       or retire_bkpt_expt_lsu_trigger_t1)
begin

  if(retire_bkpt_expt_lsu_trigger_t1)
    rtu_dtu_tval[31:0]               = lsu_rtu_ex2_tval[31:0];

  else if(retire_bkpt_expt_split_lsu_trigger_t1)
    rtu_dtu_tval[31:0]               = 32'b0;

  else
    rtu_dtu_tval[31:0]               = cbus_retire_ex2_cur_pc[31:0];

end

assign rtu_dtu_halt_ack              = halt_req;
assign rtu_dtu_pending_ack           = halt_req_pending || bkpt_req_pending;


assign rtu_dtu_retire_vld            = retire_ex2_retire_vld
                                       && (retire_flush_fe_set
                                           || !(cbus_retire_ex2_split_inst
                                             || cbus_retire_ex2_inst_tail_int));
assign rtu_dtu_retire_debug_expt_vld = retire_ex2_retire_vld
                                       && dbg_mode_on
                                       && retire_expt_debug;
assign rtu_dtu_retire_mret           = cbus_retire_ex2_inst_mret;
assign rtu_dtu_retire_chgflw         = cbus_retire_ex2_inst_branch;
assign rtu_dtu_retire_next_pc[31:0]  = cbus_retire_ex2_next_pc[31:0];




assign rtu_ifu_chgflw_vld       = retire_chgflw_vld;
assign rtu_ifu_flush_fe         = retire_flush_fe;
assign rtu_ifu_chgflw_pc[31:0]  = retire_chgflw_pc[31:0];

assign rtu_ifu_dbg_mask         = dbg_mode_on_after_req;




assign rtu_cp0_epc[31:0]        = retire_trap_epc[31:0];
assign rtu_cp0_tval[31:0]       = retire_trap_tval[31:0];
assign rtu_cp0_exit_debug       = retire_exit_debug;
assign rtu_cp0_nmi_vld          = retire_nmi_vld || lockup_retire_nmi_vld;
assign rtu_cp0_bus_error        = lsu_rtu_ex2_bus_err || lsu_rtu_async_expt_vld;
assign rtu_cp0_int_level[7:0]   = cbus_retire_ex2_int_lv[7:0];




assign rtu_idu_inst_retire      = retire_ex2_retire_vld;
assign rtu_idu_flush_stall      = retire_flush_stall;
assign rtu_idu_flush_fe         = retire_flush_fe;
assign rtu_idu_late_flush       = retire_int_flush;




assign rtu_lsu_expt_ack         = retire_flush_be && retire_buf_trap_vld;
assign rtu_lsu_expt_exit        = retire_flush_be && retire_buf_xret_vld;


assign rtu_lsu_async_expt_ack   = dbg_mode_on
                                  ? retire_dbg_mode_async_trap_vld
                                  : retire_flush_be && retire_buf_async_trap_vld;
assign rtu_lsu_inst_retire      = retire_ex2_retire_vld;




assign rtu_hpcp_retire_inst_vld = retire_ex2_retire_vld && !cbus_retire_ex2_split_inst;






assign retire_lockup_nmi_exit        = cp0_rtu_ex1_mret && cp0_rtu_in_nmi;

assign retire_lockup_dbg_req         = dtu_rtu_sync_halt_req;
assign retire_lockup_expt_vld        = retire_trap_vld
                                       && !retire_int_inst
                                       && !retire_nmi_inst
                                       && retire_trap_vec[11:0] != 12'd3
                                       && retire_trap_vec[11:0] != 12'd11;
assign retire_lockup_retire_vld      = retire_ex2_retire_vld;
assign retire_lockup_retire_pc[31:0] = cbus_retire_ex2_cur_pc[31:0];
assign retire_lockup_dbgon           = dbg_mode_on;





assign retire_cbus_flush_stall  = retire_flush_stall;
assign retire_cbus_ex2_stall    = retire_dbg_stall
                               || lsu_rtu_ex2_stall;
assign retire_top_lsu_ex2_stall = lsu_rtu_ex2_stall;




assign retire_clk_en = cbus_retire_ex2_inst_vld
                    || halt_req
                    || retire_exit_debug
                    || retire_flush_fe_set
                    || retire_buf_trap_vld
                    || retire_buf_xret_vld
                    || retire_buf_async_trap_vld
                    || flush_cur_state[2:0] != FLUSH_IDLE
                    || dbg_stall_cur_state[1:0] != STALL_IDLE
                    || retire_async_flush
                    || halt_req_trigger_t1
                    || halt_req_split_trigger_t1
                    || bkpt_req_trigger_t1
                    || bkpt_req_split_trigger_t1
                    || lockup_clk_en;


gated_clk_cell  x_retire_clk (
  .clk_in             (forever_cpuclk    ),
  .clk_out            (retire_clk        ),
  .external_en        (1'b0              ),
  .global_en          (cp0_yy_clk_en     ),
  .local_en           (retire_clk_en     ),
  .module_en          (cp0_rtu_icg_en    ),
  .pad_yy_icg_scan_en (pad_yy_icg_scan_en)
);








assign lockup_clk = retire_clk;


endmodule