Changed memory to be addressable to byte instead to word (32bits)

This commit is contained in:
mariusmonton 2018-09-20 12:22:13 +02:00
parent 8e8418e3e2
commit 11fae01cba
2 changed files with 11 additions and 43 deletions

View File

@ -30,7 +30,7 @@ public:
// TLM-2 socket, defaults to 32-bits wide, base protocol // TLM-2 socket, defaults to 32-bits wide, base protocol
tlm_utils::simple_target_socket<Memory> socket; tlm_utils::simple_target_socket<Memory> socket;
enum { SIZE = 1024 * 1024 }; enum { SIZE = 1024 * 1024 * 16 };
const sc_time LATENCY; const sc_time LATENCY;
Memory(sc_module_name name, string filename); Memory(sc_module_name name, string filename);
@ -57,15 +57,9 @@ public:
virtual unsigned int transport_dbg(tlm::tlm_generic_payload& trans); virtual unsigned int transport_dbg(tlm::tlm_generic_payload& trans);
private: private:
int mem[SIZE]; uint8_t mem[SIZE];
uint32_t program_counter; uint32_t program_counter;
/**
* Reads file and stores in Code Memory. Uses propietary file format
* @brief Reads file and stores in Code Memory
* @param filename File name
*/
virtual void readCustomHexFile(string filename);
/** /**
* @brief Read Intel hex file * @brief Read Intel hex file

View File

@ -9,7 +9,7 @@ Memory::Memory(sc_module_name name, string filename): sc_module(name)
socket.register_get_direct_mem_ptr(this, &Memory::get_direct_mem_ptr); socket.register_get_direct_mem_ptr(this, &Memory::get_direct_mem_ptr);
socket.register_transport_dbg( this, &Memory::transport_dbg); socket.register_transport_dbg( this, &Memory::transport_dbg);
memset(mem, 0, SIZE*sizeof(int)); memset(mem, 0, SIZE*sizeof(uint8_t));
// readCustomHexFile("memory.hex"); // readCustomHexFile("memory.hex");
readHexFile(filename); readHexFile(filename);
@ -36,7 +36,7 @@ uint32_t Memory::getPCfromHEX() {
void Memory::b_transport( tlm::tlm_generic_payload& trans, sc_time& delay ) void Memory::b_transport( tlm::tlm_generic_payload& trans, sc_time& delay )
{ {
tlm::tlm_command cmd = trans.get_command(); tlm::tlm_command cmd = trans.get_command();
sc_dt::uint64 adr = trans.get_address() / 4; sc_dt::uint64 adr = trans.get_address();
unsigned char* ptr = trans.get_data_ptr(); unsigned char* ptr = trans.get_data_ptr();
unsigned int len = trans.get_data_length(); unsigned int len = trans.get_data_length();
unsigned char* byt = trans.get_byte_enable_ptr(); unsigned char* byt = trans.get_byte_enable_ptr();
@ -64,7 +64,7 @@ void Memory::b_transport( tlm::tlm_generic_payload& trans, sc_time& delay )
} }
//cout << "MEM: addr=" << hex << adr << endl << endl; //cout << "MEM: addr=" << hex << adr << endl << endl;
//cout << "MEM: data=" << mem[adr] << endl; //cout << "MEM: data=" << hex << mem[adr] << endl;
// Obliged to implement read and write commands // Obliged to implement read and write commands
if ( cmd == tlm::TLM_READ_COMMAND ) if ( cmd == tlm::TLM_READ_COMMAND )
@ -119,7 +119,7 @@ void Memory::invalidation_process()
unsigned int Memory::transport_dbg(tlm::tlm_generic_payload& trans) unsigned int Memory::transport_dbg(tlm::tlm_generic_payload& trans)
{ {
tlm::tlm_command cmd = trans.get_command(); tlm::tlm_command cmd = trans.get_command();
sc_dt::uint64 adr = trans.get_address() / 4; sc_dt::uint64 adr = trans.get_address();
unsigned char* ptr = trans.get_data_ptr(); unsigned char* ptr = trans.get_data_ptr();
unsigned int len = trans.get_data_length(); unsigned int len = trans.get_data_length();
@ -134,29 +134,6 @@ unsigned int Memory::transport_dbg(tlm::tlm_generic_payload& trans)
return num_bytes; return num_bytes;
} }
void Memory::readCustomHexFile(string filename) {
ifstream hexfile;
string line;
int i = 0;
hexfile.open(filename);
if (hexfile.is_open()) {
while(getline(hexfile, line) ) {
/* # is a comentary in the file */
if (line[0] != '#') {
cout << "i: " << i << endl;
mem[i] = stol(line.substr(0,8), nullptr, 16);
i++;
}
}
hexfile.close();
} else {
SC_REPORT_ERROR("Memory", "Open file error");
}
}
void Memory::readHexFile(string filename) { void Memory::readHexFile(string filename) {
ifstream hexfile; ifstream hexfile;
string line; string line;
@ -175,18 +152,15 @@ void Memory::readHexFile(string filename) {
{ {
/* Data */ /* Data */
byte_count = stol(line.substr(1,2), nullptr, 16); byte_count = stol(line.substr(1,2), nullptr, 16);
address = stol(line.substr(3,4), nullptr, 16) / 4; address = stol(line.substr(3,4), nullptr, 16);
address = address + extended_address; address = address + extended_address;
for (i=0; i < byte_count/4; i++) { for (i=0; i < byte_count; i++) {
mem[address+i] = stol(line.substr(9+(i*8), 2), nullptr, 16); mem[address+i] = stol(line.substr(9+(i*2), 2), nullptr, 16);
mem[address+i] |= stol(line.substr(11+(i*8),2), nullptr, 16) << 8;
mem[address+i] |= stol(line.substr(13+(i*8),2), nullptr, 16) << 16;
mem[address+i] |= stol(line.substr(15+(i*8),2), nullptr, 16) << 24;
} }
} else if (line.substr(7,2) == "02") { } else if (line.substr(7,2) == "02") {
/* Extended segment address */ /* Extended segment address */
extended_address = stol(line.substr(9,4), nullptr, 16 ) * 4; extended_address = stol(line.substr(9,4), nullptr, 16) * 16;
} else if (line.substr(7,2) == "03") { } else if (line.substr(7,2) == "03") {
/* Start segment address */ /* Start segment address */
uint32_t code_segment; uint32_t code_segment;