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 *.log
.idea/ .idea/
.vscode/ .vscode/
build

View File

@ -14,7 +14,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED True)
set(CMAKE_C_STANDARD 17) set(CMAKE_C_STANDARD 17)
set(CMAKE_CXX_EXTENSIONS OFF) 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_definitions(-DCMAKE_EXPORT_COMPILE_COMMANDS=ON)
add_compile_options(-O3 -g -Wall -Wextra -Wunused-function -Wpedantic) 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 * [ ] Add [Trace v2.0](https://github.com/riscv-non-isa/riscv-trace-spec) support
## Compile ## 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: It is possible to use cmake:
``` ```
@ -138,11 +119,17 @@ make
note that SystemC must be compiled with cmake: note that SystemC must be compiled with cmake:
``` ```
sudo apt-get install build-essential
cd <systemc directory> cd <systemc directory>
mkdir build mkdir build
cd build cd build
cmake ../ -DCMAKE_CXX_STANDARD=17 cmake ../ -DCMAKE_CXX_STANDARD=17
make make -j
```
install spdlog
```
apt install libspdlog-dev
``` ```
### Arguments ### Arguments

View File

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