From fa90f0dbb1cb706e90cf4e3edaf0bb678a8a6a0e Mon Sep 17 00:00:00 2001 From: Joel Stanley Date: Mon, 11 May 2020 13:22:00 +0930 Subject: [PATCH 1/3] mw_debug: Add CFLAGS and fix warnings CFLAGS was defined but not used anywhere. This adds them to the compile line, and fixes the warnings (and errors!) that result. Signed-off-by: Joel Stanley --- scripts/mw_debug/Makefile | 2 +- scripts/mw_debug/mw_debug.c | 18 ++++++++++++------ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/scripts/mw_debug/Makefile b/scripts/mw_debug/Makefile index 9920e71..dd1611f 100644 --- a/scripts/mw_debug/Makefile +++ b/scripts/mw_debug/Makefile @@ -3,7 +3,7 @@ CFLAGS = -O2 -g -Wall -std=c99 all: mw_debug mw_debug: mw_debug.c - $(CC) -o $@ $^ -lurjtag + $(CC) -o $@ $^ $(CFLAGS) -lurjtag clean: rm -f mw_debug diff --git a/scripts/mw_debug/mw_debug.c b/scripts/mw_debug/mw_debug.c index 8359242..08083b3 100644 --- a/scripts/mw_debug/mw_debug.c +++ b/scripts/mw_debug/mw_debug.c @@ -1,3 +1,6 @@ +#define _POSIX_C_SOURCE 200809L +#define _GNU_SOURCE + #include #include #include @@ -15,6 +18,7 @@ #include #include #include +#include #define DBG_WB_ADDR 0x00 #define DBG_WB_DATA 0x01 @@ -104,6 +108,7 @@ static int sim_init(const char *target) static int sim_reset(void) { + return 0; } static void add_bits(uint8_t **p, int *b, uint64_t d, int c) @@ -152,7 +157,7 @@ static int sim_command(uint8_t op, uint8_t addr, uint64_t *data) { uint8_t buf[16], *p; uint64_t d = data ? *data : 0; - int r, s, b = 0; + int r, b = 0; memset(buf, 0, 16); p = buf+1; @@ -280,6 +285,7 @@ static int jtag_init(const char *target) static int jtag_reset(void) { + return 0; } static int jtag_command(uint8_t op, uint8_t addr, uint64_t *data) @@ -382,8 +388,8 @@ static void core_status(void) else if (stat & DBG_CORE_STAT_TERM) statstr = "odd state (TERM but no STOP)"; printf("Core: %s%s\n", statstr, statstr2); - printf(" NIA: %016llx\n", (unsigned long long)nia); - printf(" MSR: %016llx\n", msr); + printf(" NIA: %016" PRIx64 "\n", nia); + printf(" MSR: %016" PRIx64 "\n", msr); } static void core_stop(void) @@ -438,12 +444,12 @@ static void gpr_read(uint64_t reg, uint64_t count) data = 0xdeadbeef; check(dmi_read(DBG_CORE_GSPR_DATA, &data), "reading GPR data"); if (reg <= 31) - printf("r%d", reg); + printf("r%"PRId64, reg); else if ((reg - 32) < sizeof(fast_spr_names) / sizeof(fast_spr_names[0])) printf("%s", fast_spr_names[reg - 32]); else - printf("gspr%d", reg); - printf(":\t%016llx\n", data); + printf("gspr%"PRId64, reg); + printf(":\t%016"PRIx64"\n", data); } } From 2bf5bf4bac5625cef6e2fe21c829d36dd6c3e5e3 Mon Sep 17 00:00:00 2001 From: Joel Stanley Date: Sun, 10 May 2020 13:30:26 +0930 Subject: [PATCH 2/3] mw_debug: Add usage text Signed-off-by: Joel Stanley --- scripts/mw_debug/mw_debug.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/scripts/mw_debug/mw_debug.c b/scripts/mw_debug/mw_debug.c index 08083b3..fec9722 100644 --- a/scripts/mw_debug/mw_debug.c +++ b/scripts/mw_debug/mw_debug.c @@ -511,7 +511,33 @@ static void load(const char *filename, uint64_t addr) static void usage(const char *cmd) { - fprintf(stderr, "Usage: %s \n", cmd); + fprintf(stderr, "Usage: %s -b \n", cmd); + + fprintf(stderr, "\n"); + fprintf(stderr, " CPU core:\n"); + fprintf(stderr, " start\n"); + fprintf(stderr, " stop\n"); + fprintf(stderr, " step\n"); + fprintf(stderr, " creset core reset\n"); + fprintf(stderr, " icreset icache reset\n"); + + fprintf(stderr, "\n"); + fprintf(stderr, " Memory:\n"); + fprintf(stderr, " mr \n"); + fprintf(stderr, " mw \n"); + fprintf(stderr, " load [addr] If omitted address is 0\n"); + + fprintf(stderr, "\n"); + fprintf(stderr, " Registers:\n"); + fprintf(stderr, " gpr [count]\n"); + fprintf(stderr, " status\n"); + + fprintf(stderr, "\n"); + fprintf(stderr, " JTAG:\n"); + fprintf(stderr, " dmiread \n"); + fprintf(stderr, " dmiwrite \n"); + fprintf(stderr, " quit\n"); + exit(1); } From 5860c2d1b6ed52a5d5c85586c591475513c9528a Mon Sep 17 00:00:00 2001 From: Joel Stanley Date: Mon, 11 May 2020 13:52:41 +0930 Subject: [PATCH 3/3] mw_debug: Add README This describes how to build the tool on Fedora, and on Debian which lacks a packaged liburjtag as of mid 2020. Signed-off-by: Joel Stanley --- scripts/mw_debug/Makefile | 1 + scripts/mw_debug/README | 63 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 scripts/mw_debug/README diff --git a/scripts/mw_debug/Makefile b/scripts/mw_debug/Makefile index dd1611f..a669e74 100644 --- a/scripts/mw_debug/Makefile +++ b/scripts/mw_debug/Makefile @@ -1,4 +1,5 @@ CFLAGS = -O2 -g -Wall -std=c99 +# CFLAGS += -I urjtag/urjtag/include/ -L urjtag/urjtag/src/.libs/ all: mw_debug diff --git a/scripts/mw_debug/README b/scripts/mw_debug/README new file mode 100644 index 0000000..aa26f8e --- /dev/null +++ b/scripts/mw_debug/README @@ -0,0 +1,63 @@ +mw_debug is the microwatt debugger. + +It can talk to the simulator using a socket. + +On an Arty board it uses the FTDI device via liburjtag. + +## Building on Fedora + +``` +dnf install urjtag-devel +make +``` + +If you commonly use it against one target, create an alias as follows: +``` +alias mw="$HOME/microwatt/scripts/mw_debug/mw_debug -b jtag" +$ mw gpr 0 10 +Connected to libftdi driver. +Found device ID: 0x0362d093 +r0: 0000000000001094 +r1: 0000000000001ed0 +r2: 000000000000a000 +r3: 0000000000000003 +r4: 000000000000000d +r5: 00000000ffff2ca5 +r6: 00000000ffff3eb8 +r7: 0000000000000000 +r8: 00000000ffff3c33 +r9: 0000000000000003 +Core: running + NIA: 00000000000011d4 + MSR: 8000000000000001 +``` + +## Building on Debian + +Debian disables the library in the urjtag package. Instead, build against +local urjtag: + +``` +sudo apt install libftdi-dev +git clone https://git.code.sf.net/p/urjtag/git urjtag +cd urjtag/urjtag +./autogen.sh +make +``` + +And then uncomment the following line in Makefile to build against that copy + +``` +CFLAGS += -I urjtag/urjtag/include/ -L urjtag/urjtag/src/.libs/ +``` + +To run: +``` +alias mw="LD_LIBRARY_PATH=$HOME/microwatt/scripts/mw_debug/urjtag/urjtag/src/.libs/ $HOME/microwatt/scripts/mw_debug/mw_debug -b jtag" +$ mw +Connected to libftdi driver. +Found device ID: 0x0362d093 +Core: running + NIA: 00000000000011b8 + MSR: 8000000000000001 +```