Skip to content

Commit

Permalink
snRuntime: Update dump.h routines
Browse files Browse the repository at this point in the history
  • Loading branch information
colluca committed Dec 8, 2023
1 parent 3410421 commit 35fbc72
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions sw/snRuntime/src/dump.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,23 @@
//
// Authors: Samuel Riedel, ETH Zurich <[email protected]>
// Viviane Potocnik, ETH Zurich <[email protected]>
// Luca Colagrande, ETH Zurich <[email protected]>

// Dump a value via CSR
// !!! Careful: This is only supported in simulation and an experimental
// feature. All writes to unimplemented CSR registers will be dumped by Snitch.
// This can be exploited to quickly print measurement values from all cores
// simultaneously without the hassle of printf. To specify multiple metrics,
// different CSRs can be used. The macro will define a function that will then
// always print via the same CSR. E.g., `dump(errors, 8)` will define a function
// with the following signature: `dump_errors(uint32_t val)`, which will print
// the given value via the 8th register. Alternatively, the `write_csr(reg,
// val)` macro can be used directly.
// always print via the same CSR. E.g., `dump(uint32_t, errors, 8)` will define
// a function with the following signature: `dump_errors(uint32_t val)`, which
// will print the given value via the 8th register. Alternatively, the
// `write_csr(reg, val)` macro can be used directly.

#define dump_float(name, reg) \
static __attribute__((always_inline)) inline void dump_##name(float val) { \
asm volatile("csrw " #reg ", %0" ::"rK"(val)); \
#define NAMED_DUMP(type, name, reg) \
static __attribute__((always_inline)) inline void dump_##name(type val) { \
asm volatile("csrw " #reg ", %0" ::"rK"(val)); \
}

#define dump_uint(name, reg) \
static \
__attribute__((always_inline)) inline void dump_##name(uint32_t val) { \
asm volatile("csrw " #reg ", %0" ::"rK"(val)); \
}
// TODO(colluca): do not hardcode the CSR address
#define DUMP(val) ({ asm volatile("csrw 0x7C3, %0" ::"rK"(val)); })

0 comments on commit 35fbc72

Please sign in to comment.