Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame^] | 1 | From f26a978c638bcbc621669dce0ab89e43af42af98 Mon Sep 17 00:00:00 2001 |
| 2 | From: Khem Raj <raj.khem@gmail.com> |
| 3 | Date: Mon, 26 Oct 2020 21:32:22 -0700 |
| 4 | Subject: [PATCH] Define correct gregs for RISCV32 |
| 5 | |
| 6 | Upstream-Status: Pending |
| 7 | Signed-off-by: Khem Raj <raj.khem@gmail.com> |
| 8 | |
| 9 | Updated patch for 6.2.1 |
| 10 | Signed-off-by: Yi Fan Yu <yifan.yu@windriver.com> |
| 11 | |
| 12 | --- |
| 13 | src/debug.c | 26 ++++++++++++++++++++++++-- |
| 14 | 1 file changed, 24 insertions(+), 2 deletions(-) |
| 15 | |
| 16 | diff --git a/src/debug.c b/src/debug.c |
| 17 | index 2da2c5d..1d778fa 100644 |
| 18 | --- a/src/debug.c |
| 19 | +++ b/src/debug.c |
| 20 | @@ -1116,7 +1116,9 @@ static void *getMcontextEip(ucontext_t *uc) { |
| 21 | #endif |
| 22 | #elif defined(__linux__) |
| 23 | /* Linux */ |
| 24 | - #if defined(__i386__) || ((defined(__X86_64__) || defined(__x86_64__)) && defined(__ILP32__)) |
| 25 | + #if defined(__riscv) && __riscv_xlen == 32 |
| 26 | + return (void*) uc->uc_mcontext.__gregs[REG_PC]; |
| 27 | + #elif defined(__i386__) || ((defined(__X86_64__) || defined(__x86_64__)) && defined(__ILP32__)) |
| 28 | return (void*) uc->uc_mcontext.gregs[14]; /* Linux 32 */ |
| 29 | #elif defined(__X86_64__) || defined(__x86_64__) |
| 30 | return (void*) uc->uc_mcontext.gregs[16]; /* Linux 64 */ |
| 31 | @@ -1298,8 +1300,28 @@ void logRegisters(ucontext_t *uc) { |
| 32 | #endif |
| 33 | /* Linux */ |
| 34 | #elif defined(__linux__) |
| 35 | + /* Linux RISCV32 */ |
| 36 | + #if defined(__riscv) && __riscv_xlen == 32 |
| 37 | + serverLog(LL_WARNING, |
| 38 | + "\n" |
| 39 | + "RA:%08lx S0:%08lx S1:%08lx S2:%08lx\n" |
| 40 | + "SP:%08lx PC:%08lx A0:%08lx A1:%08lx\n" |
| 41 | + "A2 :%08lx A3:%08lx A4:%08lx", |
| 42 | + (unsigned long) uc->uc_mcontext.__gregs[REG_RA], |
| 43 | + (unsigned long) uc->uc_mcontext.__gregs[REG_S0], |
| 44 | + (unsigned long) uc->uc_mcontext.__gregs[REG_S1], |
| 45 | + (unsigned long) uc->uc_mcontext.__gregs[REG_S2], |
| 46 | + (unsigned long) uc->uc_mcontext.__gregs[REG_SP], |
| 47 | + (unsigned long) uc->uc_mcontext.__gregs[REG_PC], |
| 48 | + (unsigned long) uc->uc_mcontext.__gregs[REG_A0 + 0], |
| 49 | + (unsigned long) uc->uc_mcontext.__gregs[REG_A0 + 1], |
| 50 | + (unsigned long) uc->uc_mcontext.__gregs[REG_A0 + 2], |
| 51 | + (unsigned long) uc->uc_mcontext.__gregs[REG_A0 + 3], |
| 52 | + (unsigned long) uc->uc_mcontext.__gregs[REG_A0 + 4] |
| 53 | + ); |
| 54 | + logStackContent((void**)uc->uc_mcontext.__gregs[REG_SP]); |
| 55 | /* Linux x86 */ |
| 56 | - #if defined(__i386__) || ((defined(__X86_64__) || defined(__x86_64__)) && defined(__ILP32__)) |
| 57 | + #elif defined(__i386__) || ((defined(__X86_64__) || defined(__x86_64__)) && defined(__ILP32__)) |
| 58 | serverLog(LL_WARNING, |
| 59 | "\n" |
| 60 | "EAX:%08lx EBX:%08lx ECX:%08lx EDX:%08lx\n" |