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