Skip to content

Commit

Permalink
Use dedicated methods for default memory ctors (#1089)
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelkryukov authored Sep 6, 2019
1 parent 047bdc8 commit 0f293f1
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 50 deletions.
2 changes: 1 addition & 1 deletion simulator/export/gdb/gdb_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ GDBSim::GDBSim( const std::string& isa)
{
cpu = Simulator::create_configured_isa_simulator( isa);
cpu->enable_driver_hooks();
memory = FuncMemory::create_hierarchied_memory();
memory = FuncMemory::create_default_hierarchied_memory();
kernel = Kernel::create_configured_kernel();
cpu->set_memory( memory);
cpu->set_kernel( kernel);
Expand Down
2 changes: 1 addition & 1 deletion simulator/export/standalone/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace config {

int main( int argc, const char* argv[]) try {
config::handleArgs( argc, argv, 1);
auto memory = FuncMemory::create_hierarchied_memory();
auto memory = FuncMemory::create_default_hierarchied_memory();

auto sim = Simulator::create_configured_simulator();
sim->set_memory( memory);
Expand Down
16 changes: 8 additions & 8 deletions simulator/func_sim/t/unit_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ static auto run_over_empty_memory( const std::string& isa)
{
auto sim = Simulator::create_functional_simulator( isa);
sim->enable_driver_hooks();
auto m = FuncMemory::create_hierarchied_memory();
auto m = FuncMemory::create_default_hierarchied_memory();
sim->set_memory( m);
auto kernel = Kernel::create_dummy_kernel();
kernel->set_simulator( sim);
Expand All @@ -44,7 +44,7 @@ TEST_CASE( "FuncSim: create empty memory and get lost")

TEST_CASE( "FuncSim: get lost without pc")
{
auto m = FuncMemory::create_hierarchied_memory();
auto m = FuncMemory::create_default_hierarchied_memory();
auto sim = Simulator::create_functional_simulator("mips32");
sim->set_memory( m);
auto kernel = Kernel::create_dummy_kernel();
Expand All @@ -60,7 +60,7 @@ TEST_CASE( "Process_Wrong_Args_Of_Constr: Func_Sim_init_and_load")
{
// Call constructor and init
auto sim = Simulator::create_functional_simulator("mips32");
auto mem = FuncMemory::create_hierarchied_memory();
auto mem = FuncMemory::create_default_hierarchied_memory();
sim->set_memory( mem);
auto kernel = Kernel::create_dummy_kernel();
kernel->set_simulator( sim);
Expand All @@ -74,7 +74,7 @@ TEST_CASE( "Process_Wrong_Args_Of_Constr: Func_Sim_init_and_load")
TEST_CASE( "Make_A_Step: Func_Sim")
{
auto sim = Simulator::create_functional_simulator("mips32");
auto mem = FuncMemory::create_hierarchied_memory();
auto mem = FuncMemory::create_default_hierarchied_memory();
sim->set_memory( mem);
auto kernel = Kernel::create_dummy_kernel();
kernel->set_simulator( sim);
Expand All @@ -94,7 +94,7 @@ TEST_CASE( "Make_A_Step: Func_Sim")
TEST_CASE( "Run one instruction: Func_Sim")
{
auto sim = Simulator::create_functional_simulator("mips32");
auto mem = FuncMemory::create_hierarchied_memory();
auto mem = FuncMemory::create_default_hierarchied_memory();
sim->set_memory( mem);

auto kernel = Kernel::create_dummy_kernel();
Expand Down Expand Up @@ -143,7 +143,7 @@ TEST_CASE( "FuncSim: Register size")
TEST_CASE( "Run_SMC_trace: Func_Sim")
{
auto sim = Simulator::create_functional_simulator("mips32");
auto mem = FuncMemory::create_hierarchied_memory();
auto mem = FuncMemory::create_default_hierarchied_memory();
sim->set_memory( mem);

auto kernel = Kernel::create_mars_kernel();
Expand All @@ -162,7 +162,7 @@ TEST_CASE( "Torture_Test: MIPS32 calls without kernel")
{
bool log = false;
auto sim = Simulator::create_functional_simulator("mips32", log);
auto mem = FuncMemory::create_hierarchied_memory( 36);
auto mem = FuncMemory::create_hierarchied_memory( 36, 10, 12);
sim->set_memory( mem);

auto kernel = Kernel::create_dummy_kernel();
Expand All @@ -186,7 +186,7 @@ static auto get_simulator_with_test( const std::string& isa, const std::string&
{
bool log = false;
auto sim = Simulator::create_functional_simulator(isa, log);
auto mem = FuncMemory::create_hierarchied_memory();
auto mem = FuncMemory::create_default_hierarchied_memory();
sim->set_memory( mem);
if ( enable_hooks)
sim->enable_driver_hooks();
Expand Down
2 changes: 1 addition & 1 deletion simulator/kernel/mars/t/unit_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ struct System
explicit System( KernelArgs&&... args)
: sim( Simulator::create_simulator( "mips64", true, false))
, mars_kernel( create_mars_kernel(std::forward<KernelArgs>(args)...))
, mem( FuncMemory::create_hierarchied_memory())
, mem( FuncMemory::create_default_hierarchied_memory())
{
mars_kernel->set_simulator( sim);
sim->set_memory( mem);
Expand Down
6 changes: 3 additions & 3 deletions simulator/memory/cen64/t/unit_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// Mock CEN64 with our casual FuncMemory implementation
struct bus_controller
{
bus_controller() : memory( FuncMemory::create_hierarchied_memory()) {}
bus_controller() : memory( FuncMemory::create_default_hierarchied_memory()) {}
const std::shared_ptr<FuncMemory> memory;
};

Expand Down Expand Up @@ -53,7 +53,7 @@ TEST_CASE( "CEN64Memory: unsupported" )
bus_controller bus;
auto cen64_memory = create_cen64_memory(&bus);
CHECK_THROWS_AS( cen64_memory->dump(), CEN64MemoryUnsupportedInterface);
CHECK_THROWS_AS( cen64_memory->duplicate_to( FuncMemory::create_plain_memory()), CEN64MemoryUnsupportedInterface);
CHECK_THROWS_AS( cen64_memory->duplicate_to( FuncMemory::create_4M_plain_memory()), CEN64MemoryUnsupportedInterface);
CHECK_THROWS_AS( cen64_memory->strlen( 0x0), CEN64MemoryUnsupportedInterface);
}

Expand All @@ -78,7 +78,7 @@ TEST_CASE( "CEN64Memory" )
static const std::string valid_elf_file = TEST_PATH "/mips_bin_exmpl.out";
static const uint64 dataSectAddr = 0x4100c0;

auto golden_memory = FuncMemory::create_hierarchied_memory();
auto golden_memory = FuncMemory::create_default_hierarchied_memory();
bus_controller bus;
auto cen64_memory = create_cen64_memory(&bus);

Expand Down
16 changes: 10 additions & 6 deletions simulator/memory/memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,17 @@ class ReadableAndWritableMemory : public ReadableMemory, public WriteableMemory
class FuncMemory : public ReadableAndWritableMemory
{
public:
static std::shared_ptr<FuncMemory>
create_hierarchied_memory( uint32 addr_bits = 36,
uint32 page_bits = 10,
uint32 offset_bits = 12);
static std::shared_ptr<FuncMemory> create_hierarchied_memory( uint32 addr_bits, uint32 page_bits, uint32 offset_bits);
static std::shared_ptr<FuncMemory> create_default_hierarchied_memory()
{
return create_hierarchied_memory( 36, 10, 12);
}

static std::shared_ptr<FuncMemory>
create_plain_memory( uint32 addr_bits = 20);
static std::shared_ptr<FuncMemory> create_plain_memory( uint32 addr_bits);
static std::shared_ptr<FuncMemory> create_4M_plain_memory()
{
return create_plain_memory( 22);
}

template<typename T, Endian endian> void masked_write( T value, Addr addr, T mask)
{
Expand Down
44 changes: 22 additions & 22 deletions simulator/memory/t/unit_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ static const uint64 dataSectAddrShifted = 0x100c0;
//
TEST_CASE( "Func_memory_init: Process_Wrong_Args_Of_Constr")
{
CHECK_NOTHROW( FuncMemory::create_hierarchied_memory( )); // check memory initialization with default parameters
CHECK_NOTHROW( FuncMemory::create_default_hierarchied_memory( )); // check memory initialization with default parameters
CHECK_NOTHROW( FuncMemory::create_hierarchied_memory( 48, 15, 10)); // check memory initialization with custom parameters
CHECK_THROWS_AS( FuncMemory::create_hierarchied_memory( 64, 15, 32), FuncMemoryBadMapping); // check memory initialization with 4GB bytes page
CHECK_THROWS_AS( FuncMemory::create_hierarchied_memory( 48, 32, 10), FuncMemoryBadMapping); // check memory initialization with 4GB pages set
Expand All @@ -32,7 +32,7 @@ TEST_CASE( "Func_memory_init: Process_Wrong_Args_Of_Constr")

TEST_CASE( "Func_memory_init: Process_Correct_ElfInit")
{
auto ptr = FuncMemory::create_hierarchied_memory();
auto ptr = FuncMemory::create_default_hierarchied_memory();
CHECK_NOTHROW( ElfLoader( valid_elf_file).load_to( ptr.get()));
}

Expand Down Expand Up @@ -60,7 +60,7 @@ TEST_CASE( "Func_memory: StartPC Invalid")

TEST_CASE( "Func_memory: Bad section")
{
auto ptr = FuncMemory::create_hierarchied_memory();
auto ptr = FuncMemory::create_default_hierarchied_memory();
CHECK_THROWS_AS( ElfLoader( TEST_PATH "/empty.bin").load_to( ptr.get()), InvalidElfSection);
CHECK_THROWS_AS( ElfLoader( TEST_PATH "/empty.bin").get_startPC(), InvalidEntryPoint);
}
Expand All @@ -87,7 +87,7 @@ TEST_CASE( "Hierarchied memory: out of range")

TEST_CASE( "Func_memory: Read_Method_Test")
{
auto func_mem = FuncMemory::create_hierarchied_memory();
auto func_mem = FuncMemory::create_default_hierarchied_memory();
ElfLoader( valid_elf_file).load_to( func_mem.get());

// read 4 bytes from the func_mem start addr
Expand All @@ -113,7 +113,7 @@ TEST_CASE( "Func_memory: Read_Method_Test")

TEST_CASE( "Func_memory: Write_Read_Initialized_Mem_Test")
{
auto func_mem = FuncMemory::create_hierarchied_memory();
auto func_mem = FuncMemory::create_default_hierarchied_memory();
ElfLoader( valid_elf_file).load_to( func_mem.get());

// write 1 into the byte pointed by dataSectAddr
Expand All @@ -134,7 +134,7 @@ TEST_CASE( "Func_memory: Write_Read_Initialized_Mem_Test")

TEST_CASE( "Func_memory: Write_Read_Not_Initialized_Mem_Test")
{
auto func_mem = FuncMemory::create_hierarchied_memory();
auto func_mem = FuncMemory::create_default_hierarchied_memory();
ElfLoader( valid_elf_file).load_to( func_mem.get());

uint64 write_addr = 0x3FFFFE;
Expand All @@ -153,7 +153,7 @@ TEST_CASE( "Func_memory: Write_Read_Not_Initialized_Mem_Test")

TEST_CASE( "Func_memory: Host_Guest_Memcpy_1b")
{
auto func_mem = FuncMemory::create_hierarchied_memory();
auto func_mem = FuncMemory::create_default_hierarchied_memory();

// Single byte
const Byte write_data_1{ 0xA5};
Expand All @@ -170,7 +170,7 @@ TEST_CASE( "Func_memory: Host_Guest_Memcpy_1b")

TEST_CASE( "Func_memory: Host_Guest_Memcpy_8b")
{
auto func_mem = FuncMemory::create_hierarchied_memory();
auto func_mem = FuncMemory::create_default_hierarchied_memory();

// 8 bytes
const constexpr size_t size = 8;
Expand All @@ -192,7 +192,7 @@ TEST_CASE( "Func_memory: Host_Guest_Memcpy_8b")

TEST_CASE( "Func_memory: Host_Guest_Memcpy_1024b")
{
auto func_mem = FuncMemory::create_hierarchied_memory();
auto func_mem = FuncMemory::create_default_hierarchied_memory();

// 1 KByte
const constexpr size_t size = 1024;
Expand All @@ -214,7 +214,7 @@ TEST_CASE( "Func_memory: Host_Guest_Memcpy_1024b")

TEST_CASE( "Func_memory: Dump")
{
auto func_mem = FuncMemory::create_hierarchied_memory();
auto func_mem = FuncMemory::create_default_hierarchied_memory();
ElfLoader( valid_elf_file).load_to( func_mem.get());

CHECK( func_mem->dump() ==
Expand Down Expand Up @@ -248,7 +248,7 @@ TEST_CASE( "Func_memory: Dump")

TEST_CASE( "Func_memory: Duplicate")
{
auto mem1 = FuncMemory::create_hierarchied_memory();
auto mem1 = FuncMemory::create_default_hierarchied_memory();
auto mem2 = FuncMemory::create_hierarchied_memory( 48, 15, 10);

ElfLoader( valid_elf_file).load_to( mem1.get(), -0x400000);
Expand All @@ -260,7 +260,7 @@ TEST_CASE( "Func_memory: Duplicate")

TEST_CASE( "Func_memory: Plain Memory")
{
auto mem1 = FuncMemory::create_hierarchied_memory();
auto mem1 = FuncMemory::create_default_hierarchied_memory();
auto mem2 = FuncMemory::create_plain_memory( 24);

ElfLoader( valid_elf_file).load_to( mem1.get(), -0x400000);
Expand All @@ -273,7 +273,7 @@ TEST_CASE( "Func_memory: Plain Memory")
TEST_CASE( "Func_memory: Duplicate Plain Memory")
{
auto mem1 = FuncMemory::create_plain_memory( 24);
auto mem2 = FuncMemory::create_hierarchied_memory();
auto mem2 = FuncMemory::create_default_hierarchied_memory();

ElfLoader( valid_elf_file).load_to( mem1.get(), -0x400000);
mem1->duplicate_to( mem2);
Expand Down Expand Up @@ -303,7 +303,7 @@ TEST_CASE( "Func_memory: String length, no zero bytes")
TEST_CASE( "Func_memory: String length")
{
const std::string hw("Hello World!");
auto mem = FuncMemory::create_hierarchied_memory( 24);
auto mem = FuncMemory::create_default_hierarchied_memory();
mem->memcpy_host_to_guest( 0x10, byte_cast( hw.c_str()), hw.size());
CHECK( mem->strlen( 0x10) == 12);
CHECK( mem->strlen( 0x12) == 10);
Expand All @@ -315,28 +315,28 @@ TEST_CASE( "Func_memory: String length")

TEST_CASE( "Func_memory: String length, empty memory")
{
auto mem = FuncMemory::create_hierarchied_memory( 24);
auto mem = FuncMemory::create_default_hierarchied_memory();
CHECK( mem->strlen( 0x10) == 0);
}

TEST_CASE( "Func_memory: String length, plain memory")
{
const std::string hw("Hello World!");
auto mem = FuncMemory::create_plain_memory();
auto mem = FuncMemory::create_4M_plain_memory();
mem->memcpy_host_to_guest( 0x10, byte_cast( hw.c_str()), hw.size());
CHECK( mem->strlen( 0x10) == 12);
}

TEST_CASE( "Func_memory: Write string")
{
auto mem = FuncMemory::create_plain_memory();
auto mem = FuncMemory::create_4M_plain_memory();
mem->write_string( "MIPT-MIPS is cool", 0x20);
CHECK( mem->read_string( 0x20) == "MIPT-MIPS is cool");
}

TEST_CASE( "Func_memory: Write string limited")
{
auto mem = FuncMemory::create_plain_memory();
auto mem = FuncMemory::create_4M_plain_memory();
mem->write_string_limited( "MIPT-MIPS is cool", 0x20, 9);
CHECK( mem->read_string( 0x20) == "MIPT-MIPS");
}
Expand All @@ -355,15 +355,15 @@ TEST_CASE( "Func_memory: Write to 0")
uint64 get_v_dst() const { return 0; }
void load(uint64 /* unused */) { }
} store;
auto mem = FuncMemory::create_plain_memory();
auto mem = FuncMemory::create_4M_plain_memory();
CHECK_THROWS_AS( mem->load_store( &store), Exception);
}

TEST_CASE( "Func_memory Replicant: read and write")
{
auto mem1 = FuncMemory::create_plain_memory();
auto mem2 = FuncMemory::create_plain_memory();
auto mem3 = FuncMemory::create_plain_memory();
auto mem1 = FuncMemory::create_4M_plain_memory();
auto mem2 = FuncMemory::create_4M_plain_memory();
auto mem3 = FuncMemory::create_4M_plain_memory();
FuncMemoryReplicant mem12( mem1);
mem12.add_replica( mem2);

Expand Down
12 changes: 6 additions & 6 deletions simulator/modules/core/t/unit_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ TEST_CASE( "Perf_Sim_init: Process_Correct_Args_Of_Constr")
{
// Just call a constructor
auto sim = Simulator::create_simulator( "mips32", false, false);
auto mem = FuncMemory::create_hierarchied_memory();
auto mem = FuncMemory::create_default_hierarchied_memory();
CHECK_NOTHROW( sim->set_memory( mem));
CHECK( sim->get_exit_code() == 0);
}

TEST_CASE( "Perf_Sim_init: push a nop")
{
auto sim = CycleAccurateSimulator::create_simulator( "mips32", false);
auto mem = FuncMemory::create_hierarchied_memory();
auto mem = FuncMemory::create_default_hierarchied_memory();
sim->set_memory( mem);

auto kernel = Kernel::create_dummy_kernel();
Expand All @@ -41,7 +41,7 @@ TEST_CASE( "Perf_Sim_init: push a nop")

TEST_CASE( "PerfSim: create empty memory and get lost")
{
auto m = FuncMemory::create_hierarchied_memory();
auto m = FuncMemory::create_default_hierarchied_memory();
auto sim = CycleAccurateSimulator::create_simulator( "mips32", false);
sim->set_memory( m);
CHECK_THROWS_AS( sim->run_no_limit(), Deadlock);
Expand Down Expand Up @@ -93,7 +93,7 @@ TEST_CASE( "Perf_Sim: Register size")
static auto get_mars32_tt_simulator( bool has_hooks)
{
auto sim = CycleAccurateSimulator::create_simulator( "mars", false);
auto mem = FuncMemory::create_hierarchied_memory();
auto mem = FuncMemory::create_default_hierarchied_memory();
sim->set_memory( mem);

auto kernel = Kernel::create_mars_kernel();
Expand Down Expand Up @@ -128,7 +128,7 @@ TEST_CASE( "Torture_Test: Perf_Sim, MARS 32, Core Universal hooked")
static auto get_smc_loaded_simulator( bool init_checker)
{
auto sim = CycleAccurateSimulator::create_simulator( "mars", false);
auto mem = FuncMemory::create_hierarchied_memory();
auto mem = FuncMemory::create_default_hierarchied_memory();
sim->set_memory( mem);

auto kernel = Kernel::create_mars_kernel();
Expand Down Expand Up @@ -156,7 +156,7 @@ TEST_CASE( "Perf_Sim: Run_SMC_Trace_WithChecker")
TEST_CASE( "Torture_Test: Perf_Sim, RISC-V 32 simple trace")
{
auto sim = CycleAccurateSimulator::create_simulator( "riscv32", false);
auto mem = FuncMemory::create_hierarchied_memory();
auto mem = FuncMemory::create_default_hierarchied_memory();
sim->set_memory( mem);
auto kernel = Kernel::create_dummy_kernel();
kernel->connect_memory( mem);
Expand Down
2 changes: 1 addition & 1 deletion simulator/modules/writeback/checker/checker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
template <typename ISA>
void Checker<ISA>::init( Endian endian, const FuncMemory& outer_mem, Kernel* kernel)
{
auto memory = FuncMemory::create_hierarchied_memory();
auto memory = FuncMemory::create_default_hierarchied_memory();
sim = std::make_shared<FuncSim<ISA>>( endian);
outer_mem.duplicate_to( memory);
sim->set_memory( std::move( memory));
Expand Down
Loading

0 comments on commit 0f293f1

Please sign in to comment.