Skip to content

Commit

Permalink
[emulator] write MMIO store to file
Browse files Browse the repository at this point in the history
Signed-off-by: Avimitin <[email protected]>
  • Loading branch information
Avimitin committed Jun 11, 2024
1 parent f119fb2 commit 8cf3e7d
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ __pycache__
.envrc
test-results
target
.ccls-cache
3 changes: 3 additions & 0 deletions ipemu/csrc/dpi.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
static bool terminated = false;

void sigint_handler(int s) {
ProgramOutputStoreFile.close();
terminated = true;
dpi_finish();
}
Expand All @@ -29,12 +30,14 @@ void sigint_handler(int s) {
Log("SimulationExit") \
.info("detect returning instruction, gracefully quit simulation"); \
vbridge_impl_instance.on_exit(); \
ProgramOutputStoreFile.close(); \
dpi_finish(); \
} catch (std::runtime_error & e) { \
terminated = true; \
svSetScope( \
svGetScopeFromName("TOP.TestBench.dpiError")); \
dpi_error(fmt::format("runtime_error occurs: {}", e.what()).c_str()); \
ProgramOutputStoreFile.close(); \
}

#if VM_TRACE
Expand Down
11 changes: 9 additions & 2 deletions ipemu/csrc/simple_sim.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
#pragma once

#include <fstream>
#include <iostream>

#include <fmt/core.h>

#include "simif.h"
#include "spdlog_ext.h"
#include "uartlite.h"

// File that contains program stdout/stderr from MMIO
// Initialize in vbridge_impl.cc, closed in dpi.cc
//
// Require C++ 17 here to have inline keyword feature, so that the compiler can collapse all symbol into one declaration and bypass mold error.
inline std::ofstream ProgramOutputStoreFile;

class simple_sim : public simif_t {
private:
char *mem;
Expand Down Expand Up @@ -56,8 +63,8 @@ class simple_sim : public simif_t {
if (uart_addr <= addr && addr < uart_addr + sizeof(uartlite_regs)) {
bool res = uart.do_write(addr - uart_addr, len, bytes);
while (uart.exist_tx()) {
std::cerr << uart.getc();
std::cerr.flush();
ProgramOutputStoreFile << uart.getc();
ProgramOutputStoreFile.flush();
}
return res;
}
Expand Down
4 changes: 4 additions & 0 deletions ipemu/csrc/vbridge_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,8 @@ static VBridgeImpl vbridgeImplFromArgs() {
args::Flag no_console_logging(parser, "no_console_logging", "Disable console logging utilities.", { "no-console-logging" });
args::ValueFlag<std::string> log_path(parser, "log path", "Path to store logging file", {"log-path"});

args::ValueFlag<std::string> program_output_path(parser, "program output path", "Path to store stdout/stderr produce by program", {"program-output-path"});

args::ValueFlag<size_t> vlen(parser, "vlen", "match from RTL config, tobe removed", {"vlen"}, args::Options::Required);
args::ValueFlag<size_t> dlen(parser, "dlen", "match from RTL config, tobe removed", {"dlen"}, args::Options::Required);
args::ValueFlag<size_t> tl_bank_number(parser, "tl_bank_number", "match from RTL config, tobe removed", {"tl_bank_number"}, args::Options::Required);
Expand Down Expand Up @@ -247,6 +249,8 @@ static VBridgeImpl vbridgeImplFromArgs() {

Log = JsonLogger(no_logging.Get(), no_file_logging.Get(), no_console_logging.Get(), log_path.Get());

ProgramOutputStoreFile.open(program_output_path.Get());

Config cosim_config {
.bin_path = bin_path.Get(),
.wave_path = wave_path.Get(),
Expand Down

0 comments on commit 8cf3e7d

Please sign in to comment.