Enable build.

This commit is contained in:
colin.liang 2022-10-13 19:23:28 +08:00
parent 91756df67e
commit 8f3d66097c
4 changed files with 158 additions and 168 deletions

3
.gitignore vendored
View File

@ -49,3 +49,6 @@ gh-md-toc
*.log
.idea/
.vscode/
build

View File

@ -14,7 +14,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED True)
set(CMAKE_C_STANDARD 17)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_PREFIX_PATH ../systemc-2.3.3/build/ ../spdlog/install/)
set(CMAKE_PREFIX_PATH ../systemc-2.3.3/build/)
add_definitions(-DCMAKE_EXPORT_COMPILE_COMMANDS=ON)
add_compile_options(-O3 -g -Wall -Wextra -Wunused-function -Wpedantic)

View File

@ -108,25 +108,6 @@ Task to do:
* [ ] Add [Trace v2.0](https://github.com/riscv-non-isa/riscv-trace-spec) support
## Compile
In order to compile the project you need SystemC-2.3.2 installed in your system.
Just change SYSTEMC path in Makefile.
```
$ make
```
Then, you need to modifiy your LD_LIBRARY_PATH environtment variable to add
path systemc library. In my case:
```
$ export LD_LIBRARY_PATH=/home/marius/Work/RiscV/code/systemc-2.3.2/lib-linux64
```
And then you can execute the simulator:
```
$ ./RISCV_TLM asm/BasicLoop.hex
```
### Using cmake
It is possible to use cmake:
```
@ -138,11 +119,17 @@ make
note that SystemC must be compiled with cmake:
```
sudo apt-get install build-essential
cd <systemc directory>
mkdir build
cd build
cmake ../ -DCMAKE_CXX_STANDARD=17
make
make -j
```
install spdlog
```
apt install libspdlog-dev
```
### Arguments

View File

@ -14,7 +14,7 @@
#include <iomanip>
#include <sys/socket.h>
#include <netinet/in.h>
#include <boost/algorithm/string.hpp>
// #include <boost/algorithm/string.hpp>
#include "Debug.h"
@ -75,166 +75,166 @@ namespace riscv_tlm {
}
void Debug::handle_gdb_loop() {
std::cout << "Handle_GDB_Loop\n";
// std::cout << "Handle_GDB_Loop\n";
Registers<std::uint32_t> *register_bank = dbg_cpu->getRegisterBank();
// Registers<std::uint32_t> *register_bank = dbg_cpu->getRegisterBank();
while (true) {
std::string msg = receive_packet();
// while (true) {
// std::string msg = receive_packet();
if (msg.empty() ) {
std::cout << "remote connection seems to be closed, terminating ..."
<< std::endl;
break;
} else if (msg == "+") {
// NOTE: just ignore this message, nothing to do in this case
} else if (boost::starts_with(msg, "qSupported")) {
send_packet(conn, "PacketSize=256;swbreak+;hwbreak+;vContSupported+;multiprocess-");
} else if (msg == "vMustReplyEmpty") {
send_packet(conn, "");
} else if (msg == "Hg0") {
send_packet(conn, "OK");
} else if (msg == "Hc0") {
send_packet(conn, "");
} else if (msg == "qTStatus") {
send_packet(conn, "");
} else if (msg == "?") {
send_packet(conn, "S05");
} else if (msg == "qfThreadInfo") {
send_packet(conn, "");
} else if (boost::starts_with(msg, "qL")) {
send_packet(conn, "");
} else if (msg == "Hc-1") {
send_packet(conn, "OK");
} else if (msg == "qC") {
send_packet(conn, "-1");
} else if (msg == "qAttached") {
send_packet(conn, "0"); // 0 process started, 1 attached to process
} else if (msg == "g") {
// if (msg.empty() ) {
// std::cout << "remote connection seems to be closed, terminating ..."
// << std::endl;
// break;
// } else if (msg == "+") {
// // NOTE: just ignore this message, nothing to do in this case
// } else if (boost::starts_with(msg, "qSupported")) {
// send_packet(conn, "PacketSize=256;swbreak+;hwbreak+;vContSupported+;multiprocess-");
// } else if (msg == "vMustReplyEmpty") {
// send_packet(conn, "");
// } else if (msg == "Hg0") {
// send_packet(conn, "OK");
// } else if (msg == "Hc0") {
// send_packet(conn, "");
// } else if (msg == "qTStatus") {
// send_packet(conn, "");
// } else if (msg == "?") {
// send_packet(conn, "S05");
// } else if (msg == "qfThreadInfo") {
// send_packet(conn, "");
// } else if (boost::starts_with(msg, "qL")) {
// send_packet(conn, "");
// } else if (msg == "Hc-1") {
// send_packet(conn, "OK");
// } else if (msg == "qC") {
// send_packet(conn, "-1");
// } else if (msg == "qAttached") {
// send_packet(conn, "0"); // 0 process started, 1 attached to process
// } else if (msg == "g") {
std::stringstream stream;
stream << std::setfill('0') << std::hex;
for (int i = 1; i < 32; i++) {
stream << std::setw(8) << register_bank->getValue(i);
}
send_packet(conn, stream.str());
} else if (boost::starts_with(msg, "p")) {
long n = strtol(msg.c_str() + 1, 0, 16);
std::uint64_t reg_value;
if (n < 32) {
reg_value = register_bank->getValue(n);
} else if (n == 32) {
reg_value = register_bank->getPC();
} else {
// see: https://github.com/riscv/riscv-gnu-toolchain/issues/217
// risc-v register 834
reg_value = register_bank->getCSR(n - 65);
}
std::stringstream stream;
stream << std::setfill('0') << std::hex;
stream << std::setw(8) << htonl(reg_value);
send_packet(conn, stream.str());
} else if (boost::starts_with(msg, "P")) {
char *pEnd;
long reg = strtol(msg.c_str() + 1, &pEnd, 16);
int val = strtol(pEnd + 1, 0, 16);
register_bank->setValue(reg + 1, val);
send_packet(conn, "OK");
} else if (boost::starts_with(msg, "m")) {
char *pEnd;
long addr = strtol(msg.c_str() + 1, &pEnd, 16);;
int len = strtol(pEnd + 1, &pEnd, 16);
// std::stringstream stream;
// stream << std::setfill('0') << std::hex;
// for (int i = 1; i < 32; i++) {
// stream << std::setw(8) << register_bank->getValue(i);
// }
// send_packet(conn, stream.str());
// } else if (boost::starts_with(msg, "p")) {
// long n = strtol(msg.c_str() + 1, 0, 16);
// std::uint64_t reg_value;
// if (n < 32) {
// reg_value = register_bank->getValue(n);
// } else if (n == 32) {
// reg_value = register_bank->getPC();
// } else {
// // see: https://github.com/riscv/riscv-gnu-toolchain/issues/217
// // risc-v register 834
// reg_value = register_bank->getCSR(n - 65);
// }
// std::stringstream stream;
// stream << std::setfill('0') << std::hex;
// stream << std::setw(8) << htonl(reg_value);
// send_packet(conn, stream.str());
// } else if (boost::starts_with(msg, "P")) {
// char *pEnd;
// long reg = strtol(msg.c_str() + 1, &pEnd, 16);
// int val = strtol(pEnd + 1, 0, 16);
// register_bank->setValue(reg + 1, val);
// send_packet(conn, "OK");
// } else if (boost::starts_with(msg, "m")) {
// char *pEnd;
// long addr = strtol(msg.c_str() + 1, &pEnd, 16);;
// int len = strtol(pEnd + 1, &pEnd, 16);
dbg_trans.set_data_ptr(pyld_array);
dbg_trans.set_command(tlm::TLM_READ_COMMAND);
dbg_trans.set_address(addr);
dbg_trans.set_data_length(len);
dbg_mem->transport_dbg(dbg_trans);
// dbg_trans.set_data_ptr(pyld_array);
// dbg_trans.set_command(tlm::TLM_READ_COMMAND);
// dbg_trans.set_address(addr);
// dbg_trans.set_data_length(len);
// dbg_mem->transport_dbg(dbg_trans);
std::stringstream stream;
stream << std::setfill('0') << std::hex;
for (auto &c: pyld_array) {
stream << std::setw(2) << (0xFF & c);
}
// std::stringstream stream;
// stream << std::setfill('0') << std::hex;
// for (auto &c: pyld_array) {
// stream << std::setw(2) << (0xFF & c);
// }
send_packet(conn, stream.str());
// send_packet(conn, stream.str());
} else if (boost::starts_with(msg, "M")) {
printf("M TBD\n");
send_packet(conn, "OK");
} else if (boost::starts_with(msg, "X")) {
send_packet(conn, ""); // binary data unsupported
} else if (msg == "qOffsets") {
send_packet(conn, "Text=0;Data=0;Bss=0");
} else if (msg == "qSymbol::") {
send_packet(conn, "OK");
} else if (msg == "vCont?") {
send_packet(conn, "vCont;cs");
} else if (msg == "c") {
bool breakpoint_hit = false;
bool bkpt = false;
do {
bkpt = dbg_cpu->CPU_step();
uint32_t currentPC = register_bank->getPC();
// } else if (boost::starts_with(msg, "M")) {
// printf("M TBD\n");
// send_packet(conn, "OK");
// } else if (boost::starts_with(msg, "X")) {
// send_packet(conn, ""); // binary data unsupported
// } else if (msg == "qOffsets") {
// send_packet(conn, "Text=0;Data=0;Bss=0");
// } else if (msg == "qSymbol::") {
// send_packet(conn, "OK");
// } else if (msg == "vCont?") {
// send_packet(conn, "vCont;cs");
// } else if (msg == "c") {
// bool breakpoint_hit = false;
// bool bkpt = false;
// do {
// bkpt = dbg_cpu->CPU_step();
// uint32_t currentPC = register_bank->getPC();
auto search = breakpoints.find(currentPC);
if (search != breakpoints.end()) {
breakpoint_hit = true;
}
} while ((breakpoint_hit == false) && (bkpt == false));
// auto search = breakpoints.find(currentPC);
// if (search != breakpoints.end()) {
// breakpoint_hit = true;
// }
// } while ((breakpoint_hit == false) && (bkpt == false));
std::cout << "Breakpoint hit at 0x" << std::hex << register_bank->getPC() << std::endl;
send_packet(conn, "S05");
} else if (msg == "s") {
// std::cout << "Breakpoint hit at 0x" << std::hex << register_bank->getPC() << std::endl;
// send_packet(conn, "S05");
// } else if (msg == "s") {
bool breakpoint;
dbg_cpu->CPU_step();
// bool breakpoint;
// dbg_cpu->CPU_step();
uint32_t currentPC = register_bank->getPC();
auto search = breakpoints.find(currentPC);
if (search != breakpoints.end()) {
breakpoint = true;
} else {
breakpoint = false;
}
// uint32_t currentPC = register_bank->getPC();
// auto search = breakpoints.find(currentPC);
// if (search != breakpoints.end()) {
// breakpoint = true;
// } else {
// breakpoint = false;
// }
if (breakpoint) {
send_packet(conn, "S03");
} else {
send_packet(conn, "S05");
}
// if (breakpoint) {
// send_packet(conn, "S03");
// } else {
// send_packet(conn, "S05");
// }
} else if (boost::starts_with(msg, "vKill")) {
send_packet(conn, "OK");
break;
} else if (boost::starts_with(msg, "Z1")) {
char *pEnd;
long addr = strtol(msg.c_str() + 3, &pEnd, 16);;
breakpoints.insert(addr);
std::cout << "Breakpoint set to address 0x" << std::hex << addr << std::endl;
send_packet(conn, "OK");
} else if (boost::starts_with(msg, "z1")) {
char *pEnd;
long addr = strtol(msg.c_str() + 3, &pEnd, 16);;
breakpoints.erase(addr);
send_packet(conn, "OK");
} else if (boost::starts_with(msg, "z0")) {
char *pEnd;
long addr = strtol(msg.c_str() + 3, &pEnd, 16);;
breakpoints.erase(addr);
send_packet(conn, "");
} else if (boost::starts_with(msg, "Z0")) {
char *pEnd;
long addr = strtol(msg.c_str() + 3, &pEnd, 16);;
breakpoints.insert(addr);
std::cout << "Breakpoint set to address 0x" << std::hex << addr << std::endl;
send_packet(conn, "OK");
} else {
std::cout << "unsupported message '" << msg
<< "' detected, terminating ..." << std::endl;
break;
}
}
// } else if (boost::starts_with(msg, "vKill")) {
// send_packet(conn, "OK");
// break;
// } else if (boost::starts_with(msg, "Z1")) {
// char *pEnd;
// long addr = strtol(msg.c_str() + 3, &pEnd, 16);;
// breakpoints.insert(addr);
// std::cout << "Breakpoint set to address 0x" << std::hex << addr << std::endl;
// send_packet(conn, "OK");
// } else if (boost::starts_with(msg, "z1")) {
// char *pEnd;
// long addr = strtol(msg.c_str() + 3, &pEnd, 16);;
// breakpoints.erase(addr);
// send_packet(conn, "OK");
// } else if (boost::starts_with(msg, "z0")) {
// char *pEnd;
// long addr = strtol(msg.c_str() + 3, &pEnd, 16);;
// breakpoints.erase(addr);
// send_packet(conn, "");
// } else if (boost::starts_with(msg, "Z0")) {
// char *pEnd;
// long addr = strtol(msg.c_str() + 3, &pEnd, 16);;
// breakpoints.insert(addr);
// std::cout << "Breakpoint set to address 0x" << std::hex << addr << std::endl;
// send_packet(conn, "OK");
// } else {
// std::cout << "unsupported message '" << msg
// << "' detected, terminating ..." << std::endl;
// break;
// }
// }
}
std::string Debug::compute_checksum_string(const std::string &msg) {