xref: /haiku/src/system/kernel/arch/riscv64/arch_user_debugger.cpp (revision 4c8e85b316c35a9161f5a1c50ad70bc91c83a76f)
1 /*
2  * Copyright 2019, Adrien Destugues, pulkomandy@pulkomandy.tk.
3  * Distributed under the terms of the MIT License.
4  */
5 
6 
7 #include <debugger.h>
8 #include <int.h>
9 #include <thread.h>
10 #include <arch/user_debugger.h>
11 
12 
13 void
14 arch_clear_team_debug_info(struct arch_team_debug_info *info)
15 {
16 }
17 
18 
19 void
20 arch_destroy_team_debug_info(struct arch_team_debug_info *info)
21 {
22 	arch_clear_team_debug_info(info);
23 }
24 
25 
26 void
27 arch_clear_thread_debug_info(struct arch_thread_debug_info *info)
28 {
29 }
30 
31 
32 void
33 arch_destroy_thread_debug_info(struct arch_thread_debug_info *info)
34 {
35 	arch_clear_thread_debug_info(info);
36 }
37 
38 
39 void
40 arch_update_thread_single_step()
41 {
42 }
43 
44 
45 void
46 arch_set_debug_cpu_state(const debug_cpu_state *cpuState)
47 {
48 	iframe* frame = thread_get_current_thread()->arch_info.userFrame;
49 
50 	frame->ra  = cpuState->x[ 0];
51 	frame->sp  = cpuState->x[ 1];
52 	frame->gp  = cpuState->x[ 2];
53 	frame->tp  = cpuState->x[ 3];
54 	frame->t0  = cpuState->x[ 4];
55 	frame->t1  = cpuState->x[ 5];
56 	frame->t2  = cpuState->x[ 6];
57 	frame->fp  = cpuState->x[ 7];
58 	frame->s1  = cpuState->x[ 8];
59 	frame->a0  = cpuState->x[ 9];
60 	frame->a1  = cpuState->x[10];
61 	frame->a2  = cpuState->x[11];
62 	frame->a3  = cpuState->x[12];
63 	frame->a4  = cpuState->x[13];
64 	frame->a5  = cpuState->x[14];
65 	frame->a6  = cpuState->x[15];
66 	frame->a7  = cpuState->x[16];
67 	frame->s2  = cpuState->x[17];
68 	frame->s3  = cpuState->x[18];
69 	frame->s4  = cpuState->x[19];
70 	frame->s5  = cpuState->x[20];
71 	frame->s6  = cpuState->x[21];
72 	frame->s7  = cpuState->x[22];
73 	frame->s8  = cpuState->x[23];
74 	frame->s9  = cpuState->x[24];
75 	frame->s10 = cpuState->x[25];
76 	frame->s11 = cpuState->x[26];
77 	frame->t3  = cpuState->x[27];
78 	frame->t4  = cpuState->x[28];
79 	frame->t5  = cpuState->x[29];
80 	frame->t6  = cpuState->x[30];
81 	frame->epc = cpuState->pc;
82 	restore_fpu((fpu_context*)&cpuState->f[0]);
83 }
84 
85 
86 void
87 arch_get_debug_cpu_state(debug_cpu_state *cpuState)
88 {
89 	arch_get_thread_debug_cpu_state(thread_get_current_thread(), cpuState);
90 }
91 
92 
93 status_t
94 arch_get_thread_debug_cpu_state(Thread* thread, debug_cpu_state* cpuState)
95 {
96 	iframe* frame = thread->arch_info.userFrame;
97 	if (frame == NULL)
98 		return B_BAD_DATA;
99 
100 	cpuState->x[ 0] = frame->ra;
101 	cpuState->x[ 1] = frame->sp;
102 	cpuState->x[ 2] = frame->gp;
103 	cpuState->x[ 3] = frame->tp;
104 	cpuState->x[ 4] = frame->t0;
105 	cpuState->x[ 5] = frame->t1;
106 	cpuState->x[ 6] = frame->t2;
107 	cpuState->x[ 7] = frame->fp;
108 	cpuState->x[ 8] = frame->s1;
109 	cpuState->x[ 9] = frame->a0;
110 	cpuState->x[10] = frame->a1;
111 	cpuState->x[11] = frame->a2;
112 	cpuState->x[12] = frame->a3;
113 	cpuState->x[13] = frame->a4;
114 	cpuState->x[14] = frame->a5;
115 	cpuState->x[15] = frame->a6;
116 	cpuState->x[16] = frame->a7;
117 	cpuState->x[17] = frame->s2;
118 	cpuState->x[18] = frame->s3;
119 	cpuState->x[19] = frame->s4;
120 	cpuState->x[20] = frame->s5;
121 	cpuState->x[21] = frame->s6;
122 	cpuState->x[22] = frame->s7;
123 	cpuState->x[23] = frame->s8;
124 	cpuState->x[24] = frame->s9;
125 	cpuState->x[25] = frame->s10;
126 	cpuState->x[26] = frame->s11;
127 	cpuState->x[27] = frame->t3;
128 	cpuState->x[28] = frame->t4;
129 	cpuState->x[29] = frame->t5;
130 	cpuState->x[30] = frame->t6;
131 	cpuState->pc = frame->epc;
132 	// TODO: don't assume that kernel code don't use FPU
133 	if (thread == thread_get_current_thread())
134 		save_fpu((fpu_context*)&cpuState->f[0]);
135 	else
136 		memcpy(&cpuState->f[0], &thread->arch_info.fpuContext,
137 			sizeof(thread->arch_info.fpuContext));
138 
139 	return B_OK;
140 }
141 
142 
143 status_t
144 arch_set_breakpoint(void *address)
145 {
146 	return B_ERROR;
147 }
148 
149 
150 status_t
151 arch_clear_breakpoint(void *address)
152 {
153 	return B_ERROR;
154 }
155 
156 
157 status_t
158 arch_set_watchpoint(void *address, uint32 type, int32 length)
159 {
160 	return B_ERROR;
161 }
162 
163 
164 status_t
165 arch_clear_watchpoint(void *address)
166 {
167 	return B_ERROR;
168 }
169 
170 bool
171 arch_has_breakpoints(struct arch_team_debug_info *info)
172 {
173 	return false;
174 }
175