@@ -12,8 +12,6 @@ Machine::Machine(MachineConfig config, bool load_symtab, bool load_executable)
1212    : machine_config(std::move(config))
1313    , stat(ST_READY) {
1414    regs = new  Registers ();
15-     controlst
16-         = new  CSR::ControlState (machine_config.get_simulated_xlen (), machine_config.get_isa_word ());
1715    if  (load_executable) {
1816        ProgramLoader program (machine_config.elf ());
1917        this ->machine_config .set_simulated_endian (program.get_endian ());
@@ -79,19 +77,16 @@ Machine::Machine(MachineConfig config, bool load_symtab, bool load_executable)
7977        access_time_burst,
8078        access_enable_burst);
8179
82-     controlst = new  CSR::ControlState (machine_config.get_simulated_xlen (), machine_config.get_isa_word ());
83-     if  (machine_config.get_vm_enabled ()) {
84-         tlb_program.emplace (cch_program, PROGRAM, machine_config.access_tlb_program ());
85-         tlb_data.emplace (cch_data, DATA, machine_config.access_tlb_data ());
86-         controlst->write_internal (CSR::Id::SATP, 0 );
87-         tlb_program->on_csr_write (CSR::Id::SATP, 0 );
88-         tlb_data->on_csr_write (CSR::Id::SATP, 0 );
89-     }
80+     controlst
81+         = new  CSR::ControlState (machine_config.get_simulated_xlen (), machine_config.get_isa_word ());
9082
91-     instr_if_ = tlb_program ? static_cast <FrontendMemory *>(&*tlb_program)
92-                             : static_cast <FrontendMemory *>(cch_program);
93-     data_if_ = tlb_data ? static_cast <FrontendMemory *>(&*tlb_data)
94-                         : static_cast <FrontendMemory *>(cch_data);
83+     tlb_program = new  TLB (
84+         cch_program, PROGRAM, machine_config.access_tlb_program (), machine_config.get_vm_enabled ());
85+     tlb_data = new  TLB (
86+         cch_data, DATA, machine_config.access_tlb_data (), machine_config.get_vm_enabled ());
87+     controlst->write_internal (CSR::Id::SATP, 0 );
88+     tlb_program->on_csr_write (CSR::Id::SATP, 0 );
89+     tlb_data->on_csr_write (CSR::Id::SATP, 0 );
9590
9691    predictor = new  BranchPredictor (
9792        machine_config.get_bp_enabled (), machine_config.get_bp_type (),
@@ -100,11 +95,12 @@ Machine::Machine(MachineConfig config, bool load_symtab, bool load_executable)
10095
10196    if  (machine_config.pipelined ()) {
10297        cr = new  CorePipelined (
103-                      regs, predictor, instr_if_, data_if_ , controlst,
104-                     machine_config. get_simulated_xlen (),  machine_config.get_isa_word (), machine_config.hazard_unit ());
98+             regs, predictor, tlb_program, tlb_data , controlst, machine_config. get_simulated_xlen () ,
99+             machine_config.get_isa_word (), machine_config.hazard_unit ());
105100    } else  {
106-         cr = new  CoreSingle (regs, predictor, instr_if_, data_if_, controlst,
107-                             machine_config.get_simulated_xlen (), machine_config.get_isa_word ());
101+         cr = new  CoreSingle (
102+             regs, predictor, tlb_program, tlb_data, controlst, machine_config.get_simulated_xlen (),
103+             machine_config.get_isa_word ());
108104    }
109105    connect (
110106        this , &Machine::set_interrupt_signal, controlst, &CSR::ControlState::set_interrupt_signal);
@@ -211,14 +207,16 @@ Machine::~Machine() {
211207    regs = nullptr ;
212208    delete  mem;
213209    mem = nullptr ;
210+     delete  tlb_program;
211+     tlb_program = nullptr ;
212+     delete  tlb_data;
213+     tlb_data = nullptr ;
214214    delete  cch_program;
215215    cch_program = nullptr ;
216216    delete  cch_data;
217217    cch_data = nullptr ;
218218    delete  cch_level2;
219219    cch_level2 = nullptr ;
220-     tlb_program.reset ();
221-     tlb_data.reset ();
222220    delete  data_bus;
223221    data_bus = nullptr ;
224222    delete  mem_program_only;
0 commit comments