kernel/arch/user_debugger: implement for risv64

Change-Id: I9cdf7a6a5b66cdd83133485f98067ce9a5fb819d
Reviewed-on: https://review.haiku-os.org/c/haiku/+/4058
Reviewed-by: Alex von Gluck IV <kallisti5@unixzen.com>
This commit is contained in:
X512 2021-06-06 22:55:15 +09:00 committed by Alex von Gluck IV
parent d031c09ceb
commit de8c1bcc32
2 changed files with 84 additions and 3 deletions

View File

@ -6,9 +6,11 @@
#define _ARCH_RISCV64_DEBUGGER_H
//#warning RISCV64: fixme
struct riscv64_debug_cpu_state {
uint32 dummy;
uint64 x[31];
uint64 pc;
double f[32];
uint64 fcsr;
} __attribute__((aligned(8)));

View File

@ -45,19 +45,98 @@ arch_update_thread_single_step()
void
arch_set_debug_cpu_state(const debug_cpu_state *cpuState)
{
iframe* frame = thread_get_current_thread()->arch_info.userFrame;
frame->ra = cpuState->x[ 0];
frame->sp = cpuState->x[ 1];
frame->gp = cpuState->x[ 2];
frame->tp = cpuState->x[ 3];
frame->t0 = cpuState->x[ 4];
frame->t1 = cpuState->x[ 5];
frame->t2 = cpuState->x[ 6];
frame->fp = cpuState->x[ 7];
frame->s1 = cpuState->x[ 8];
frame->a0 = cpuState->x[ 9];
frame->a1 = cpuState->x[10];
frame->a2 = cpuState->x[11];
frame->a3 = cpuState->x[12];
frame->a4 = cpuState->x[13];
frame->a5 = cpuState->x[14];
frame->a6 = cpuState->x[15];
frame->a7 = cpuState->x[16];
frame->s2 = cpuState->x[17];
frame->s3 = cpuState->x[18];
frame->s4 = cpuState->x[19];
frame->s5 = cpuState->x[20];
frame->s6 = cpuState->x[21];
frame->s7 = cpuState->x[22];
frame->s8 = cpuState->x[23];
frame->s9 = cpuState->x[24];
frame->s10 = cpuState->x[25];
frame->s11 = cpuState->x[26];
frame->t3 = cpuState->x[27];
frame->t4 = cpuState->x[28];
frame->t5 = cpuState->x[29];
frame->t6 = cpuState->x[30];
frame->epc = cpuState->pc;
restore_fpu((fpu_context*)&cpuState->f[0]);
}
void
arch_get_debug_cpu_state(debug_cpu_state *cpuState)
{
arch_get_thread_debug_cpu_state(thread_get_current_thread(), cpuState);
}
status_t
arch_get_thread_debug_cpu_state(Thread* thread, debug_cpu_state* cpuState)
{
return B_UNSUPPORTED;
iframe* frame = thread->arch_info.userFrame;
if (frame == NULL)
return B_BAD_DATA;
cpuState->x[ 0] = frame->ra;
cpuState->x[ 1] = frame->sp;
cpuState->x[ 2] = frame->gp;
cpuState->x[ 3] = frame->tp;
cpuState->x[ 4] = frame->t0;
cpuState->x[ 5] = frame->t1;
cpuState->x[ 6] = frame->t2;
cpuState->x[ 7] = frame->fp;
cpuState->x[ 8] = frame->s1;
cpuState->x[ 9] = frame->a0;
cpuState->x[10] = frame->a1;
cpuState->x[11] = frame->a2;
cpuState->x[12] = frame->a3;
cpuState->x[13] = frame->a4;
cpuState->x[14] = frame->a5;
cpuState->x[15] = frame->a6;
cpuState->x[16] = frame->a7;
cpuState->x[17] = frame->s2;
cpuState->x[18] = frame->s3;
cpuState->x[19] = frame->s4;
cpuState->x[20] = frame->s5;
cpuState->x[21] = frame->s6;
cpuState->x[22] = frame->s7;
cpuState->x[23] = frame->s8;
cpuState->x[24] = frame->s9;
cpuState->x[25] = frame->s10;
cpuState->x[26] = frame->s11;
cpuState->x[27] = frame->t3;
cpuState->x[28] = frame->t4;
cpuState->x[29] = frame->t5;
cpuState->x[30] = frame->t6;
cpuState->pc = frame->epc;
// TODO: don't assume that kernel code don't use FPU
if (thread == thread_get_current_thread())
save_fpu((fpu_context*)&cpuState->f[0]);
else
memcpy(&cpuState->f[0], &thread->arch_info.fpuContext,
sizeof(thread->arch_info.fpuContext));
return B_OK;
}