Rev 2020 | Rev 2030 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2020 | Rev 2027 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | * Copyright (C) 2005 Jakub Jermar |
2 | * Copyright (C) 2005 Jakub Jermar |
3 | * All rights reserved. |
3 | * All rights reserved. |
4 | * |
4 | * |
5 | * Redistribution and use in source and binary forms, with or without |
5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions |
6 | * modification, are permitted provided that the following conditions |
7 | * are met: |
7 | * are met: |
8 | * |
8 | * |
9 | * - Redistributions of source code must retain the above copyright |
9 | * - Redistributions of source code must retain the above copyright |
10 | * notice, this list of conditions and the following disclaimer. |
10 | * notice, this list of conditions and the following disclaimer. |
11 | * - Redistributions in binary form must reproduce the above copyright |
11 | * - Redistributions in binary form must reproduce the above copyright |
12 | * notice, this list of conditions and the following disclaimer in the |
12 | * notice, this list of conditions and the following disclaimer in the |
13 | * documentation and/or other materials provided with the distribution. |
13 | * documentation and/or other materials provided with the distribution. |
14 | * - The name of the author may not be used to endorse or promote products |
14 | * - The name of the author may not be used to endorse or promote products |
15 | * derived from this software without specific prior written permission. |
15 | * derived from this software without specific prior written permission. |
16 | * |
16 | * |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | */ |
27 | */ |
28 | 28 | ||
29 | /** @addtogroup genericconsole |
29 | /** @addtogroup genericconsole |
30 | * @{ |
30 | * @{ |
31 | */ |
31 | */ |
32 | 32 | ||
33 | /** |
33 | /** |
34 | * @file cmd.c |
34 | * @file cmd.c |
35 | * @brief Kernel console command wrappers. |
35 | * @brief Kernel console command wrappers. |
36 | * |
36 | * |
37 | * This file is meant to contain all wrapper functions for |
37 | * This file is meant to contain all wrapper functions for |
38 | * all kconsole commands. The point is in separating |
38 | * all kconsole commands. The point is in separating |
39 | * kconsole specific wrappers from kconsole-unaware functions |
39 | * kconsole specific wrappers from kconsole-unaware functions |
40 | * from other subsystems. |
40 | * from other subsystems. |
41 | */ |
41 | */ |
42 | 42 | ||
43 | #include <console/cmd.h> |
43 | #include <console/cmd.h> |
44 | #include <console/console.h> |
44 | #include <console/console.h> |
45 | #include <console/kconsole.h> |
45 | #include <console/kconsole.h> |
46 | #include <print.h> |
46 | #include <print.h> |
47 | #include <panic.h> |
47 | #include <panic.h> |
48 | #include <typedefs.h> |
48 | #include <typedefs.h> |
49 | #include <arch/types.h> |
49 | #include <arch/types.h> |
50 | #include <adt/list.h> |
50 | #include <adt/list.h> |
51 | #include <arch.h> |
51 | #include <arch.h> |
52 | #include <func.h> |
52 | #include <func.h> |
53 | #include <macros.h> |
53 | #include <macros.h> |
54 | #include <debug.h> |
54 | #include <debug.h> |
55 | #include <symtab.h> |
55 | #include <symtab.h> |
56 | #include <cpu.h> |
56 | #include <cpu.h> |
57 | #include <mm/tlb.h> |
57 | #include <mm/tlb.h> |
58 | #include <arch/mm/tlb.h> |
58 | #include <arch/mm/tlb.h> |
59 | #include <mm/frame.h> |
59 | #include <mm/frame.h> |
60 | #include <main/version.h> |
60 | #include <main/version.h> |
61 | #include <mm/slab.h> |
61 | #include <mm/slab.h> |
62 | #include <proc/scheduler.h> |
62 | #include <proc/scheduler.h> |
63 | #include <proc/thread.h> |
63 | #include <proc/thread.h> |
64 | #include <proc/task.h> |
64 | #include <proc/task.h> |
65 | #include <ipc/ipc.h> |
65 | #include <ipc/ipc.h> |
66 | #include <ipc/irq.h> |
66 | #include <ipc/irq.h> |
67 | 67 | ||
68 | #ifdef CONFIG_TEST |
68 | #ifdef CONFIG_TEST |
69 | #include <test.h> |
69 | #include <test.h> |
70 | #endif |
70 | #endif |
71 | 71 | ||
- | 72 | #ifdef CONFIG_BENCH |
|
- | 73 | #include <arch/cycle.h> |
|
- | 74 | #endif |
|
- | 75 | ||
72 | /* Data and methods for 'help' command. */ |
76 | /* Data and methods for 'help' command. */ |
73 | static int cmd_help(cmd_arg_t *argv); |
77 | static int cmd_help(cmd_arg_t *argv); |
74 | static cmd_info_t help_info = { |
78 | static cmd_info_t help_info = { |
75 | .name = "help", |
79 | .name = "help", |
76 | .description = "List of supported commands.", |
80 | .description = "List of supported commands.", |
77 | .func = cmd_help, |
81 | .func = cmd_help, |
78 | .argc = 0 |
82 | .argc = 0 |
79 | }; |
83 | }; |
80 | 84 | ||
81 | static cmd_info_t exit_info = { |
85 | static cmd_info_t exit_info = { |
82 | .name = "exit", |
86 | .name = "exit", |
83 | .description = "Exit kconsole", |
87 | .description = "Exit kconsole", |
84 | .argc = 0 |
88 | .argc = 0 |
85 | }; |
89 | }; |
86 | 90 | ||
87 | static int cmd_continue(cmd_arg_t *argv); |
91 | static int cmd_continue(cmd_arg_t *argv); |
88 | static cmd_info_t continue_info = { |
92 | static cmd_info_t continue_info = { |
89 | .name = "continue", |
93 | .name = "continue", |
90 | .description = "Return console back to userspace.", |
94 | .description = "Return console back to userspace.", |
91 | .func = cmd_continue, |
95 | .func = cmd_continue, |
92 | .argc = 0 |
96 | .argc = 0 |
93 | }; |
97 | }; |
94 | 98 | ||
95 | #ifdef CONFIG_TEST |
99 | #ifdef CONFIG_TEST |
96 | static int cmd_tests(cmd_arg_t *argv); |
100 | static int cmd_tests(cmd_arg_t *argv); |
97 | static cmd_info_t tests_info = { |
101 | static cmd_info_t tests_info = { |
98 | .name = "tests", |
102 | .name = "tests", |
99 | .description = "Print available kernel tests.", |
103 | .description = "Print available kernel tests.", |
100 | .func = cmd_tests, |
104 | .func = cmd_tests, |
101 | .argc = 0 |
105 | .argc = 0 |
102 | }; |
106 | }; |
103 | 107 | ||
104 | static char test_buf[MAX_CMDLINE + 1]; |
108 | static char test_buf[MAX_CMDLINE + 1]; |
105 | static int cmd_test(cmd_arg_t *argv); |
109 | static int cmd_test(cmd_arg_t *argv); |
106 | static cmd_arg_t test_argv[] = { |
110 | static cmd_arg_t test_argv[] = { |
107 | { |
111 | { |
108 | .type = ARG_TYPE_STRING, |
112 | .type = ARG_TYPE_STRING, |
109 | .buffer = test_buf, |
113 | .buffer = test_buf, |
110 | .len = sizeof(test_buf) |
114 | .len = sizeof(test_buf) |
111 | } |
115 | } |
112 | }; |
116 | }; |
113 | static cmd_info_t test_info = { |
117 | static cmd_info_t test_info = { |
114 | .name = "test", |
118 | .name = "test", |
115 | .description = "Run kernel test.", |
119 | .description = "Run kernel test.", |
116 | .func = cmd_test, |
120 | .func = cmd_test, |
117 | .argc = 1, |
121 | .argc = 1, |
118 | .argv = test_argv |
122 | .argv = test_argv |
119 | }; |
123 | }; |
120 | #endif |
124 | #endif |
121 | 125 | ||
122 | /* Data and methods for 'description' command. */ |
126 | /* Data and methods for 'description' command. */ |
123 | static int cmd_desc(cmd_arg_t *argv); |
127 | static int cmd_desc(cmd_arg_t *argv); |
124 | static void desc_help(void); |
128 | static void desc_help(void); |
125 | static char desc_buf[MAX_CMDLINE+1]; |
129 | static char desc_buf[MAX_CMDLINE+1]; |
126 | static cmd_arg_t desc_argv = { |
130 | static cmd_arg_t desc_argv = { |
127 | .type = ARG_TYPE_STRING, |
131 | .type = ARG_TYPE_STRING, |
128 | .buffer = desc_buf, |
132 | .buffer = desc_buf, |
129 | .len = sizeof(desc_buf) |
133 | .len = sizeof(desc_buf) |
130 | }; |
134 | }; |
131 | static cmd_info_t desc_info = { |
135 | static cmd_info_t desc_info = { |
132 | .name = "describe", |
136 | .name = "describe", |
133 | .description = "Describe specified command.", |
137 | .description = "Describe specified command.", |
134 | .help = desc_help, |
138 | .help = desc_help, |
135 | .func = cmd_desc, |
139 | .func = cmd_desc, |
136 | .argc = 1, |
140 | .argc = 1, |
137 | .argv = &desc_argv |
141 | .argv = &desc_argv |
138 | }; |
142 | }; |
139 | 143 | ||
140 | /* Data and methods for 'symaddr' command. */ |
144 | /* Data and methods for 'symaddr' command. */ |
141 | static int cmd_symaddr(cmd_arg_t *argv); |
145 | static int cmd_symaddr(cmd_arg_t *argv); |
142 | static char symaddr_buf[MAX_CMDLINE+1]; |
146 | static char symaddr_buf[MAX_CMDLINE+1]; |
143 | static cmd_arg_t symaddr_argv = { |
147 | static cmd_arg_t symaddr_argv = { |
144 | .type = ARG_TYPE_STRING, |
148 | .type = ARG_TYPE_STRING, |
145 | .buffer = symaddr_buf, |
149 | .buffer = symaddr_buf, |
146 | .len = sizeof(symaddr_buf) |
150 | .len = sizeof(symaddr_buf) |
147 | }; |
151 | }; |
148 | static cmd_info_t symaddr_info = { |
152 | static cmd_info_t symaddr_info = { |
149 | .name = "symaddr", |
153 | .name = "symaddr", |
150 | .description = "Return symbol address.", |
154 | .description = "Return symbol address.", |
151 | .func = cmd_symaddr, |
155 | .func = cmd_symaddr, |
152 | .argc = 1, |
156 | .argc = 1, |
153 | .argv = &symaddr_argv |
157 | .argv = &symaddr_argv |
154 | }; |
158 | }; |
155 | 159 | ||
156 | static char set_buf[MAX_CMDLINE+1]; |
160 | static char set_buf[MAX_CMDLINE+1]; |
157 | static int cmd_set4(cmd_arg_t *argv); |
161 | static int cmd_set4(cmd_arg_t *argv); |
158 | static cmd_arg_t set4_argv[] = { |
162 | static cmd_arg_t set4_argv[] = { |
159 | { |
163 | { |
160 | .type = ARG_TYPE_STRING, |
164 | .type = ARG_TYPE_STRING, |
161 | .buffer = set_buf, |
165 | .buffer = set_buf, |
162 | .len = sizeof(set_buf) |
166 | .len = sizeof(set_buf) |
163 | }, |
167 | }, |
164 | { |
168 | { |
165 | .type = ARG_TYPE_INT |
169 | .type = ARG_TYPE_INT |
166 | } |
170 | } |
167 | }; |
171 | }; |
168 | static cmd_info_t set4_info = { |
172 | static cmd_info_t set4_info = { |
169 | .name = "set4", |
173 | .name = "set4", |
170 | .description = "set <dest_addr> <value> - 4byte version", |
174 | .description = "set <dest_addr> <value> - 4byte version", |
171 | .func = cmd_set4, |
175 | .func = cmd_set4, |
172 | .argc = 2, |
176 | .argc = 2, |
173 | .argv = set4_argv |
177 | .argv = set4_argv |
174 | }; |
178 | }; |
175 | 179 | ||
176 | /* Data and methods for 'call0' command. */ |
180 | /* Data and methods for 'call0' command. */ |
177 | static char call0_buf[MAX_CMDLINE+1]; |
181 | static char call0_buf[MAX_CMDLINE+1]; |
178 | static char carg1_buf[MAX_CMDLINE+1]; |
182 | static char carg1_buf[MAX_CMDLINE+1]; |
179 | static char carg2_buf[MAX_CMDLINE+1]; |
183 | static char carg2_buf[MAX_CMDLINE+1]; |
180 | static char carg3_buf[MAX_CMDLINE+1]; |
184 | static char carg3_buf[MAX_CMDLINE+1]; |
181 | 185 | ||
182 | static int cmd_call0(cmd_arg_t *argv); |
186 | static int cmd_call0(cmd_arg_t *argv); |
183 | static cmd_arg_t call0_argv = { |
187 | static cmd_arg_t call0_argv = { |
184 | .type = ARG_TYPE_STRING, |
188 | .type = ARG_TYPE_STRING, |
185 | .buffer = call0_buf, |
189 | .buffer = call0_buf, |
186 | .len = sizeof(call0_buf) |
190 | .len = sizeof(call0_buf) |
187 | }; |
191 | }; |
188 | static cmd_info_t call0_info = { |
192 | static cmd_info_t call0_info = { |
189 | .name = "call0", |
193 | .name = "call0", |
190 | .description = "call0 <function> -> call function().", |
194 | .description = "call0 <function> -> call function().", |
191 | .func = cmd_call0, |
195 | .func = cmd_call0, |
192 | .argc = 1, |
196 | .argc = 1, |
193 | .argv = &call0_argv |
197 | .argv = &call0_argv |
194 | }; |
198 | }; |
195 | 199 | ||
196 | /* Data and methods for 'call1' command. */ |
200 | /* Data and methods for 'call1' command. */ |
197 | static int cmd_call1(cmd_arg_t *argv); |
201 | static int cmd_call1(cmd_arg_t *argv); |
198 | static cmd_arg_t call1_argv[] = { |
202 | static cmd_arg_t call1_argv[] = { |
199 | { |
203 | { |
200 | .type = ARG_TYPE_STRING, |
204 | .type = ARG_TYPE_STRING, |
201 | .buffer = call0_buf, |
205 | .buffer = call0_buf, |
202 | .len = sizeof(call0_buf) |
206 | .len = sizeof(call0_buf) |
203 | }, |
207 | }, |
204 | { |
208 | { |
205 | .type = ARG_TYPE_VAR, |
209 | .type = ARG_TYPE_VAR, |
206 | .buffer = carg1_buf, |
210 | .buffer = carg1_buf, |
207 | .len = sizeof(carg1_buf) |
211 | .len = sizeof(carg1_buf) |
208 | } |
212 | } |
209 | }; |
213 | }; |
210 | static cmd_info_t call1_info = { |
214 | static cmd_info_t call1_info = { |
211 | .name = "call1", |
215 | .name = "call1", |
212 | .description = "call1 <function> <arg1> -> call function(arg1).", |
216 | .description = "call1 <function> <arg1> -> call function(arg1).", |
213 | .func = cmd_call1, |
217 | .func = cmd_call1, |
214 | .argc = 2, |
218 | .argc = 2, |
215 | .argv = call1_argv |
219 | .argv = call1_argv |
216 | }; |
220 | }; |
217 | 221 | ||
218 | /* Data and methods for 'call2' command. */ |
222 | /* Data and methods for 'call2' command. */ |
219 | static int cmd_call2(cmd_arg_t *argv); |
223 | static int cmd_call2(cmd_arg_t *argv); |
220 | static cmd_arg_t call2_argv[] = { |
224 | static cmd_arg_t call2_argv[] = { |
221 | { |
225 | { |
222 | .type = ARG_TYPE_STRING, |
226 | .type = ARG_TYPE_STRING, |
223 | .buffer = call0_buf, |
227 | .buffer = call0_buf, |
224 | .len = sizeof(call0_buf) |
228 | .len = sizeof(call0_buf) |
225 | }, |
229 | }, |
226 | { |
230 | { |
227 | .type = ARG_TYPE_VAR, |
231 | .type = ARG_TYPE_VAR, |
228 | .buffer = carg1_buf, |
232 | .buffer = carg1_buf, |
229 | .len = sizeof(carg1_buf) |
233 | .len = sizeof(carg1_buf) |
230 | }, |
234 | }, |
231 | { |
235 | { |
232 | .type = ARG_TYPE_VAR, |
236 | .type = ARG_TYPE_VAR, |
233 | .buffer = carg2_buf, |
237 | .buffer = carg2_buf, |
234 | .len = sizeof(carg2_buf) |
238 | .len = sizeof(carg2_buf) |
235 | } |
239 | } |
236 | }; |
240 | }; |
237 | static cmd_info_t call2_info = { |
241 | static cmd_info_t call2_info = { |
238 | .name = "call2", |
242 | .name = "call2", |
239 | .description = "call2 <function> <arg1> <arg2> -> call function(arg1,arg2).", |
243 | .description = "call2 <function> <arg1> <arg2> -> call function(arg1,arg2).", |
240 | .func = cmd_call2, |
244 | .func = cmd_call2, |
241 | .argc = 3, |
245 | .argc = 3, |
242 | .argv = call2_argv |
246 | .argv = call2_argv |
243 | }; |
247 | }; |
244 | 248 | ||
245 | /* Data and methods for 'call3' command. */ |
249 | /* Data and methods for 'call3' command. */ |
246 | static int cmd_call3(cmd_arg_t *argv); |
250 | static int cmd_call3(cmd_arg_t *argv); |
247 | static cmd_arg_t call3_argv[] = { |
251 | static cmd_arg_t call3_argv[] = { |
248 | { |
252 | { |
249 | .type = ARG_TYPE_STRING, |
253 | .type = ARG_TYPE_STRING, |
250 | .buffer = call0_buf, |
254 | .buffer = call0_buf, |
251 | .len = sizeof(call0_buf) |
255 | .len = sizeof(call0_buf) |
252 | }, |
256 | }, |
253 | { |
257 | { |
254 | .type = ARG_TYPE_VAR, |
258 | .type = ARG_TYPE_VAR, |
255 | .buffer = carg1_buf, |
259 | .buffer = carg1_buf, |
256 | .len = sizeof(carg1_buf) |
260 | .len = sizeof(carg1_buf) |
257 | }, |
261 | }, |
258 | { |
262 | { |
259 | .type = ARG_TYPE_VAR, |
263 | .type = ARG_TYPE_VAR, |
260 | .buffer = carg2_buf, |
264 | .buffer = carg2_buf, |
261 | .len = sizeof(carg2_buf) |
265 | .len = sizeof(carg2_buf) |
262 | }, |
266 | }, |
263 | { |
267 | { |
264 | .type = ARG_TYPE_VAR, |
268 | .type = ARG_TYPE_VAR, |
265 | .buffer = carg3_buf, |
269 | .buffer = carg3_buf, |
266 | .len = sizeof(carg3_buf) |
270 | .len = sizeof(carg3_buf) |
267 | } |
271 | } |
268 | 272 | ||
269 | }; |
273 | }; |
270 | static cmd_info_t call3_info = { |
274 | static cmd_info_t call3_info = { |
271 | .name = "call3", |
275 | .name = "call3", |
272 | .description = "call3 <function> <arg1> <arg2> <arg3> -> call function(arg1,arg2,arg3).", |
276 | .description = "call3 <function> <arg1> <arg2> <arg3> -> call function(arg1,arg2,arg3).", |
273 | .func = cmd_call3, |
277 | .func = cmd_call3, |
274 | .argc = 4, |
278 | .argc = 4, |
275 | .argv = call3_argv |
279 | .argv = call3_argv |
276 | }; |
280 | }; |
277 | 281 | ||
278 | /* Data and methods for 'halt' command. */ |
282 | /* Data and methods for 'halt' command. */ |
279 | static int cmd_halt(cmd_arg_t *argv); |
283 | static int cmd_halt(cmd_arg_t *argv); |
280 | static cmd_info_t halt_info = { |
284 | static cmd_info_t halt_info = { |
281 | .name = "halt", |
285 | .name = "halt", |
282 | .description = "Halt the kernel.", |
286 | .description = "Halt the kernel.", |
283 | .func = cmd_halt, |
287 | .func = cmd_halt, |
284 | .argc = 0 |
288 | .argc = 0 |
285 | }; |
289 | }; |
286 | 290 | ||
287 | /* Data and methods for 'tlb' command. */ |
291 | /* Data and methods for 'tlb' command. */ |
288 | static int cmd_tlb(cmd_arg_t *argv); |
292 | static int cmd_tlb(cmd_arg_t *argv); |
289 | cmd_info_t tlb_info = { |
293 | cmd_info_t tlb_info = { |
290 | .name = "tlb", |
294 | .name = "tlb", |
291 | .description = "Print TLB of current processor.", |
295 | .description = "Print TLB of current processor.", |
292 | .help = NULL, |
296 | .help = NULL, |
293 | .func = cmd_tlb, |
297 | .func = cmd_tlb, |
294 | .argc = 0, |
298 | .argc = 0, |
295 | .argv = NULL |
299 | .argv = NULL |
296 | }; |
300 | }; |
297 | 301 | ||
298 | static int cmd_threads(cmd_arg_t *argv); |
302 | static int cmd_threads(cmd_arg_t *argv); |
299 | static cmd_info_t threads_info = { |
303 | static cmd_info_t threads_info = { |
300 | .name = "threads", |
304 | .name = "threads", |
301 | .description = "List all threads.", |
305 | .description = "List all threads.", |
302 | .func = cmd_threads, |
306 | .func = cmd_threads, |
303 | .argc = 0 |
307 | .argc = 0 |
304 | }; |
308 | }; |
305 | 309 | ||
306 | static int cmd_tasks(cmd_arg_t *argv); |
310 | static int cmd_tasks(cmd_arg_t *argv); |
307 | static cmd_info_t tasks_info = { |
311 | static cmd_info_t tasks_info = { |
308 | .name = "tasks", |
312 | .name = "tasks", |
309 | .description = "List all tasks.", |
313 | .description = "List all tasks.", |
310 | .func = cmd_tasks, |
314 | .func = cmd_tasks, |
311 | .argc = 0 |
315 | .argc = 0 |
312 | }; |
316 | }; |
313 | 317 | ||
314 | 318 | ||
315 | static int cmd_sched(cmd_arg_t *argv); |
319 | static int cmd_sched(cmd_arg_t *argv); |
316 | static cmd_info_t sched_info = { |
320 | static cmd_info_t sched_info = { |
317 | .name = "scheduler", |
321 | .name = "scheduler", |
318 | .description = "List all scheduler information.", |
322 | .description = "List all scheduler information.", |
319 | .func = cmd_sched, |
323 | .func = cmd_sched, |
320 | .argc = 0 |
324 | .argc = 0 |
321 | }; |
325 | }; |
322 | 326 | ||
323 | static int cmd_slabs(cmd_arg_t *argv); |
327 | static int cmd_slabs(cmd_arg_t *argv); |
324 | static cmd_info_t slabs_info = { |
328 | static cmd_info_t slabs_info = { |
325 | .name = "slabs", |
329 | .name = "slabs", |
326 | .description = "List slab caches.", |
330 | .description = "List slab caches.", |
327 | .func = cmd_slabs, |
331 | .func = cmd_slabs, |
328 | .argc = 0 |
332 | .argc = 0 |
329 | }; |
333 | }; |
330 | 334 | ||
331 | /* Data and methods for 'zones' command */ |
335 | /* Data and methods for 'zones' command */ |
332 | static int cmd_zones(cmd_arg_t *argv); |
336 | static int cmd_zones(cmd_arg_t *argv); |
333 | static cmd_info_t zones_info = { |
337 | static cmd_info_t zones_info = { |
334 | .name = "zones", |
338 | .name = "zones", |
335 | .description = "List of memory zones.", |
339 | .description = "List of memory zones.", |
336 | .func = cmd_zones, |
340 | .func = cmd_zones, |
337 | .argc = 0 |
341 | .argc = 0 |
338 | }; |
342 | }; |
339 | 343 | ||
340 | /* Data and methods for 'ipc_task' command */ |
344 | /* Data and methods for 'ipc_task' command */ |
341 | static int cmd_ipc_task(cmd_arg_t *argv); |
345 | static int cmd_ipc_task(cmd_arg_t *argv); |
342 | static cmd_arg_t ipc_task_argv = { |
346 | static cmd_arg_t ipc_task_argv = { |
343 | .type = ARG_TYPE_INT, |
347 | .type = ARG_TYPE_INT, |
344 | }; |
348 | }; |
345 | static cmd_info_t ipc_task_info = { |
349 | static cmd_info_t ipc_task_info = { |
346 | .name = "ipc_task", |
350 | .name = "ipc_task", |
347 | .description = "ipc_task <taskid> Show IPC information of given task.", |
351 | .description = "ipc_task <taskid> Show IPC information of given task.", |
348 | .func = cmd_ipc_task, |
352 | .func = cmd_ipc_task, |
349 | .argc = 1, |
353 | .argc = 1, |
350 | .argv = &ipc_task_argv |
354 | .argv = &ipc_task_argv |
351 | }; |
355 | }; |
352 | 356 | ||
353 | /* Data and methods for 'zone' command */ |
357 | /* Data and methods for 'zone' command */ |
354 | static int cmd_zone(cmd_arg_t *argv); |
358 | static int cmd_zone(cmd_arg_t *argv); |
355 | static cmd_arg_t zone_argv = { |
359 | static cmd_arg_t zone_argv = { |
356 | .type = ARG_TYPE_INT, |
360 | .type = ARG_TYPE_INT, |
357 | }; |
361 | }; |
358 | 362 | ||
359 | static cmd_info_t zone_info = { |
363 | static cmd_info_t zone_info = { |
360 | .name = "zone", |
364 | .name = "zone", |
361 | .description = "Show memory zone structure.", |
365 | .description = "Show memory zone structure.", |
362 | .func = cmd_zone, |
366 | .func = cmd_zone, |
363 | .argc = 1, |
367 | .argc = 1, |
364 | .argv = &zone_argv |
368 | .argv = &zone_argv |
365 | }; |
369 | }; |
366 | 370 | ||
367 | /* Data and methods for 'cpus' command. */ |
371 | /* Data and methods for 'cpus' command. */ |
368 | static int cmd_cpus(cmd_arg_t *argv); |
372 | static int cmd_cpus(cmd_arg_t *argv); |
369 | cmd_info_t cpus_info = { |
373 | cmd_info_t cpus_info = { |
370 | .name = "cpus", |
374 | .name = "cpus", |
371 | .description = "List all processors.", |
375 | .description = "List all processors.", |
372 | .help = NULL, |
376 | .help = NULL, |
373 | .func = cmd_cpus, |
377 | .func = cmd_cpus, |
374 | .argc = 0, |
378 | .argc = 0, |
375 | .argv = NULL |
379 | .argv = NULL |
376 | }; |
380 | }; |
377 | 381 | ||
378 | /* Data and methods for 'version' command. */ |
382 | /* Data and methods for 'version' command. */ |
379 | static int cmd_version(cmd_arg_t *argv); |
383 | static int cmd_version(cmd_arg_t *argv); |
380 | cmd_info_t version_info = { |
384 | cmd_info_t version_info = { |
381 | .name = "version", |
385 | .name = "version", |
382 | .description = "Print version information.", |
386 | .description = "Print version information.", |
383 | .help = NULL, |
387 | .help = NULL, |
384 | .func = cmd_version, |
388 | .func = cmd_version, |
385 | .argc = 0, |
389 | .argc = 0, |
386 | .argv = NULL |
390 | .argv = NULL |
387 | }; |
391 | }; |
388 | 392 | ||
389 | static cmd_info_t *basic_commands[] = { |
393 | static cmd_info_t *basic_commands[] = { |
390 | &call0_info, |
394 | &call0_info, |
391 | &call1_info, |
395 | &call1_info, |
392 | &call2_info, |
396 | &call2_info, |
393 | &call3_info, |
397 | &call3_info, |
394 | &continue_info, |
398 | &continue_info, |
395 | &cpus_info, |
399 | &cpus_info, |
396 | &desc_info, |
400 | &desc_info, |
397 | &exit_info, |
401 | &exit_info, |
398 | &halt_info, |
402 | &halt_info, |
399 | &help_info, |
403 | &help_info, |
400 | &ipc_task_info, |
404 | &ipc_task_info, |
401 | &set4_info, |
405 | &set4_info, |
402 | &slabs_info, |
406 | &slabs_info, |
403 | &symaddr_info, |
407 | &symaddr_info, |
404 | &sched_info, |
408 | &sched_info, |
405 | &threads_info, |
409 | &threads_info, |
406 | &tasks_info, |
410 | &tasks_info, |
407 | &tlb_info, |
411 | &tlb_info, |
408 | &version_info, |
412 | &version_info, |
409 | &zones_info, |
413 | &zones_info, |
410 | &zone_info, |
414 | &zone_info, |
411 | #ifdef CONFIG_TEST |
415 | #ifdef CONFIG_TEST |
412 | &tests_info, |
416 | &tests_info, |
413 | &test_info, |
417 | &test_info, |
414 | #endif |
418 | #endif |
415 | NULL |
419 | NULL |
416 | }; |
420 | }; |
417 | 421 | ||
418 | 422 | ||
419 | /** Initialize command info structure. |
423 | /** Initialize command info structure. |
420 | * |
424 | * |
421 | * @param cmd Command info structure. |
425 | * @param cmd Command info structure. |
422 | * |
426 | * |
423 | */ |
427 | */ |
424 | void cmd_initialize(cmd_info_t *cmd) |
428 | void cmd_initialize(cmd_info_t *cmd) |
425 | { |
429 | { |
426 | spinlock_initialize(&cmd->lock, "cmd"); |
430 | spinlock_initialize(&cmd->lock, "cmd"); |
427 | link_initialize(&cmd->link); |
431 | link_initialize(&cmd->link); |
428 | } |
432 | } |
429 | 433 | ||
430 | /** Initialize and register commands. */ |
434 | /** Initialize and register commands. */ |
431 | void cmd_init(void) |
435 | void cmd_init(void) |
432 | { |
436 | { |
433 | int i; |
437 | int i; |
434 | 438 | ||
435 | for (i=0;basic_commands[i]; i++) { |
439 | for (i=0;basic_commands[i]; i++) { |
436 | cmd_initialize(basic_commands[i]); |
440 | cmd_initialize(basic_commands[i]); |
437 | if (!cmd_register(basic_commands[i])) |
441 | if (!cmd_register(basic_commands[i])) |
438 | panic("could not register command %s\n", |
442 | panic("could not register command %s\n", |
439 | basic_commands[i]->name); |
443 | basic_commands[i]->name); |
440 | } |
444 | } |
441 | } |
445 | } |
442 | 446 | ||
443 | 447 | ||
444 | /** List supported commands. |
448 | /** List supported commands. |
445 | * |
449 | * |
446 | * @param argv Argument vector. |
450 | * @param argv Argument vector. |
447 | * |
451 | * |
448 | * @return 0 on failure, 1 on success. |
452 | * @return 0 on failure, 1 on success. |
449 | */ |
453 | */ |
450 | int cmd_help(cmd_arg_t *argv) |
454 | int cmd_help(cmd_arg_t *argv) |
451 | { |
455 | { |
452 | link_t *cur; |
456 | link_t *cur; |
453 | 457 | ||
454 | spinlock_lock(&cmd_lock); |
458 | spinlock_lock(&cmd_lock); |
455 | 459 | ||
456 | for (cur = cmd_head.next; cur != &cmd_head; cur = cur->next) { |
460 | for (cur = cmd_head.next; cur != &cmd_head; cur = cur->next) { |
457 | cmd_info_t *hlp; |
461 | cmd_info_t *hlp; |
458 | 462 | ||
459 | hlp = list_get_instance(cur, cmd_info_t, link); |
463 | hlp = list_get_instance(cur, cmd_info_t, link); |
460 | spinlock_lock(&hlp->lock); |
464 | spinlock_lock(&hlp->lock); |
461 | 465 | ||
462 | printf("%s - %s\n", hlp->name, hlp->description); |
466 | printf("%s - %s\n", hlp->name, hlp->description); |
463 | 467 | ||
464 | spinlock_unlock(&hlp->lock); |
468 | spinlock_unlock(&hlp->lock); |
465 | } |
469 | } |
466 | 470 | ||
467 | spinlock_unlock(&cmd_lock); |
471 | spinlock_unlock(&cmd_lock); |
468 | 472 | ||
469 | return 1; |
473 | return 1; |
470 | } |
474 | } |
471 | 475 | ||
472 | /** Describe specified command. |
476 | /** Describe specified command. |
473 | * |
477 | * |
474 | * @param argv Argument vector. |
478 | * @param argv Argument vector. |
475 | * |
479 | * |
476 | * @return 0 on failure, 1 on success. |
480 | * @return 0 on failure, 1 on success. |
477 | */ |
481 | */ |
478 | int cmd_desc(cmd_arg_t *argv) |
482 | int cmd_desc(cmd_arg_t *argv) |
479 | { |
483 | { |
480 | link_t *cur; |
484 | link_t *cur; |
481 | 485 | ||
482 | spinlock_lock(&cmd_lock); |
486 | spinlock_lock(&cmd_lock); |
483 | 487 | ||
484 | for (cur = cmd_head.next; cur != &cmd_head; cur = cur->next) { |
488 | for (cur = cmd_head.next; cur != &cmd_head; cur = cur->next) { |
485 | cmd_info_t *hlp; |
489 | cmd_info_t *hlp; |
486 | 490 | ||
487 | hlp = list_get_instance(cur, cmd_info_t, link); |
491 | hlp = list_get_instance(cur, cmd_info_t, link); |
488 | spinlock_lock(&hlp->lock); |
492 | spinlock_lock(&hlp->lock); |
489 | 493 | ||
490 | if (strncmp(hlp->name, (const char *) argv->buffer, strlen(hlp->name)) == 0) { |
494 | if (strncmp(hlp->name, (const char *) argv->buffer, strlen(hlp->name)) == 0) { |
491 | printf("%s - %s\n", hlp->name, hlp->description); |
495 | printf("%s - %s\n", hlp->name, hlp->description); |
492 | if (hlp->help) |
496 | if (hlp->help) |
493 | hlp->help(); |
497 | hlp->help(); |
494 | spinlock_unlock(&hlp->lock); |
498 | spinlock_unlock(&hlp->lock); |
495 | break; |
499 | break; |
496 | } |
500 | } |
497 | 501 | ||
498 | spinlock_unlock(&hlp->lock); |
502 | spinlock_unlock(&hlp->lock); |
499 | } |
503 | } |
500 | 504 | ||
501 | spinlock_unlock(&cmd_lock); |
505 | spinlock_unlock(&cmd_lock); |
502 | 506 | ||
503 | return 1; |
507 | return 1; |
504 | } |
508 | } |
505 | 509 | ||
506 | /** Search symbol table */ |
510 | /** Search symbol table */ |
507 | int cmd_symaddr(cmd_arg_t *argv) |
511 | int cmd_symaddr(cmd_arg_t *argv) |
508 | { |
512 | { |
509 | symtab_print_search(argv->buffer); |
513 | symtab_print_search(argv->buffer); |
510 | 514 | ||
511 | return 1; |
515 | return 1; |
512 | } |
516 | } |
513 | 517 | ||
514 | /** Call function with zero parameters */ |
518 | /** Call function with zero parameters */ |
515 | int cmd_call0(cmd_arg_t *argv) |
519 | int cmd_call0(cmd_arg_t *argv) |
516 | { |
520 | { |
517 | uintptr_t symaddr; |
521 | uintptr_t symaddr; |
518 | char *symbol; |
522 | char *symbol; |
519 | unative_t (*f)(void); |
523 | unative_t (*f)(void); |
520 | #ifdef ia64 |
524 | #ifdef ia64 |
521 | struct { |
525 | struct { |
522 | unative_t f; |
526 | unative_t f; |
523 | unative_t gp; |
527 | unative_t gp; |
524 | }fptr; |
528 | }fptr; |
525 | #endif |
529 | #endif |
526 | 530 | ||
527 | symaddr = get_symbol_addr(argv->buffer); |
531 | symaddr = get_symbol_addr(argv->buffer); |
528 | if (!symaddr) |
532 | if (!symaddr) |
529 | printf("Symbol %s not found.\n", argv->buffer); |
533 | printf("Symbol %s not found.\n", argv->buffer); |
530 | else if (symaddr == (uintptr_t) -1) { |
534 | else if (symaddr == (uintptr_t) -1) { |
531 | symtab_print_search(argv->buffer); |
535 | symtab_print_search(argv->buffer); |
532 | printf("Duplicate symbol, be more specific.\n"); |
536 | printf("Duplicate symbol, be more specific.\n"); |
533 | } else { |
537 | } else { |
534 | symbol = get_symtab_entry(symaddr); |
538 | symbol = get_symtab_entry(symaddr); |
535 | printf("Calling f(): %.*p: %s\n", sizeof(uintptr_t) * 2, symaddr, symbol); |
539 | printf("Calling f(): %.*p: %s\n", sizeof(uintptr_t) * 2, symaddr, symbol); |
536 | #ifdef ia64 |
540 | #ifdef ia64 |
537 | fptr.f = symaddr; |
541 | fptr.f = symaddr; |
538 | fptr.gp = ((unative_t *)cmd_call2)[1]; |
542 | fptr.gp = ((unative_t *)cmd_call2)[1]; |
539 | f = (unative_t (*)(void)) &fptr; |
543 | f = (unative_t (*)(void)) &fptr; |
540 | #else |
544 | #else |
541 | f = (unative_t (*)(void)) symaddr; |
545 | f = (unative_t (*)(void)) symaddr; |
542 | #endif |
546 | #endif |
543 | printf("Result: %#zx\n", f()); |
547 | printf("Result: %#zx\n", f()); |
544 | } |
548 | } |
545 | 549 | ||
546 | return 1; |
550 | return 1; |
547 | } |
551 | } |
548 | 552 | ||
549 | /** Call function with one parameter */ |
553 | /** Call function with one parameter */ |
550 | int cmd_call1(cmd_arg_t *argv) |
554 | int cmd_call1(cmd_arg_t *argv) |
551 | { |
555 | { |
552 | uintptr_t symaddr; |
556 | uintptr_t symaddr; |
553 | char *symbol; |
557 | char *symbol; |
554 | unative_t (*f)(unative_t,...); |
558 | unative_t (*f)(unative_t,...); |
555 | unative_t arg1 = argv[1].intval; |
559 | unative_t arg1 = argv[1].intval; |
556 | #ifdef ia64 |
560 | #ifdef ia64 |
557 | struct { |
561 | struct { |
558 | unative_t f; |
562 | unative_t f; |
559 | unative_t gp; |
563 | unative_t gp; |
560 | }fptr; |
564 | }fptr; |
561 | #endif |
565 | #endif |
562 | 566 | ||
563 | symaddr = get_symbol_addr(argv->buffer); |
567 | symaddr = get_symbol_addr(argv->buffer); |
564 | if (!symaddr) |
568 | if (!symaddr) |
565 | printf("Symbol %s not found.\n", argv->buffer); |
569 | printf("Symbol %s not found.\n", argv->buffer); |
566 | else if (symaddr == (uintptr_t) -1) { |
570 | else if (symaddr == (uintptr_t) -1) { |
567 | symtab_print_search(argv->buffer); |
571 | symtab_print_search(argv->buffer); |
568 | printf("Duplicate symbol, be more specific.\n"); |
572 | printf("Duplicate symbol, be more specific.\n"); |
569 | } else { |
573 | } else { |
570 | symbol = get_symtab_entry(symaddr); |
574 | symbol = get_symtab_entry(symaddr); |
571 | 575 | ||
572 | printf("Calling f(%#zx): %.*p: %s\n", arg1, sizeof(uintptr_t) * 2, symaddr, symbol); |
576 | printf("Calling f(%#zx): %.*p: %s\n", arg1, sizeof(uintptr_t) * 2, symaddr, symbol); |
573 | #ifdef ia64 |
577 | #ifdef ia64 |
574 | fptr.f = symaddr; |
578 | fptr.f = symaddr; |
575 | fptr.gp = ((unative_t *)cmd_call2)[1]; |
579 | fptr.gp = ((unative_t *)cmd_call2)[1]; |
576 | f = (unative_t (*)(unative_t,...)) &fptr; |
580 | f = (unative_t (*)(unative_t,...)) &fptr; |
577 | #else |
581 | #else |
578 | f = (unative_t (*)(unative_t,...)) symaddr; |
582 | f = (unative_t (*)(unative_t,...)) symaddr; |
579 | #endif |
583 | #endif |
580 | printf("Result: %#zx\n", f(arg1)); |
584 | printf("Result: %#zx\n", f(arg1)); |
581 | } |
585 | } |
582 | 586 | ||
583 | return 1; |
587 | return 1; |
584 | } |
588 | } |
585 | 589 | ||
586 | /** Call function with two parameters */ |
590 | /** Call function with two parameters */ |
587 | int cmd_call2(cmd_arg_t *argv) |
591 | int cmd_call2(cmd_arg_t *argv) |
588 | { |
592 | { |
589 | uintptr_t symaddr; |
593 | uintptr_t symaddr; |
590 | char *symbol; |
594 | char *symbol; |
591 | unative_t (*f)(unative_t,unative_t,...); |
595 | unative_t (*f)(unative_t,unative_t,...); |
592 | unative_t arg1 = argv[1].intval; |
596 | unative_t arg1 = argv[1].intval; |
593 | unative_t arg2 = argv[2].intval; |
597 | unative_t arg2 = argv[2].intval; |
594 | #ifdef ia64 |
598 | #ifdef ia64 |
595 | struct { |
599 | struct { |
596 | unative_t f; |
600 | unative_t f; |
597 | unative_t gp; |
601 | unative_t gp; |
598 | }fptr; |
602 | }fptr; |
599 | #endif |
603 | #endif |
600 | 604 | ||
601 | symaddr = get_symbol_addr(argv->buffer); |
605 | symaddr = get_symbol_addr(argv->buffer); |
602 | if (!symaddr) |
606 | if (!symaddr) |
603 | printf("Symbol %s not found.\n", argv->buffer); |
607 | printf("Symbol %s not found.\n", argv->buffer); |
604 | else if (symaddr == (uintptr_t) -1) { |
608 | else if (symaddr == (uintptr_t) -1) { |
605 | symtab_print_search(argv->buffer); |
609 | symtab_print_search(argv->buffer); |
606 | printf("Duplicate symbol, be more specific.\n"); |
610 | printf("Duplicate symbol, be more specific.\n"); |
607 | } else { |
611 | } else { |
608 | symbol = get_symtab_entry(symaddr); |
612 | symbol = get_symtab_entry(symaddr); |
609 | printf("Calling f(0x%zx,0x%zx): %.*p: %s\n", |
613 | printf("Calling f(0x%zx,0x%zx): %.*p: %s\n", |
610 | arg1, arg2, sizeof(uintptr_t) * 2, symaddr, symbol); |
614 | arg1, arg2, sizeof(uintptr_t) * 2, symaddr, symbol); |
611 | #ifdef ia64 |
615 | #ifdef ia64 |
612 | fptr.f = symaddr; |
616 | fptr.f = symaddr; |
613 | fptr.gp = ((unative_t *)cmd_call2)[1]; |
617 | fptr.gp = ((unative_t *)cmd_call2)[1]; |
614 | f = (unative_t (*)(unative_t,unative_t,...)) &fptr; |
618 | f = (unative_t (*)(unative_t,unative_t,...)) &fptr; |
615 | #else |
619 | #else |
616 | f = (unative_t (*)(unative_t,unative_t,...)) symaddr; |
620 | f = (unative_t (*)(unative_t,unative_t,...)) symaddr; |
617 | #endif |
621 | #endif |
618 | printf("Result: %#zx\n", f(arg1, arg2)); |
622 | printf("Result: %#zx\n", f(arg1, arg2)); |
619 | } |
623 | } |
620 | 624 | ||
621 | return 1; |
625 | return 1; |
622 | } |
626 | } |
623 | 627 | ||
624 | /** Call function with three parameters */ |
628 | /** Call function with three parameters */ |
625 | int cmd_call3(cmd_arg_t *argv) |
629 | int cmd_call3(cmd_arg_t *argv) |
626 | { |
630 | { |
627 | uintptr_t symaddr; |
631 | uintptr_t symaddr; |
628 | char *symbol; |
632 | char *symbol; |
629 | unative_t (*f)(unative_t,unative_t,unative_t,...); |
633 | unative_t (*f)(unative_t,unative_t,unative_t,...); |
630 | unative_t arg1 = argv[1].intval; |
634 | unative_t arg1 = argv[1].intval; |
631 | unative_t arg2 = argv[2].intval; |
635 | unative_t arg2 = argv[2].intval; |
632 | unative_t arg3 = argv[3].intval; |
636 | unative_t arg3 = argv[3].intval; |
633 | #ifdef ia64 |
637 | #ifdef ia64 |
634 | struct { |
638 | struct { |
635 | unative_t f; |
639 | unative_t f; |
636 | unative_t gp; |
640 | unative_t gp; |
637 | }fptr; |
641 | }fptr; |
638 | #endif |
642 | #endif |
639 | 643 | ||
640 | symaddr = get_symbol_addr(argv->buffer); |
644 | symaddr = get_symbol_addr(argv->buffer); |
641 | if (!symaddr) |
645 | if (!symaddr) |
642 | printf("Symbol %s not found.\n", argv->buffer); |
646 | printf("Symbol %s not found.\n", argv->buffer); |
643 | else if (symaddr == (uintptr_t) -1) { |
647 | else if (symaddr == (uintptr_t) -1) { |
644 | symtab_print_search(argv->buffer); |
648 | symtab_print_search(argv->buffer); |
645 | printf("Duplicate symbol, be more specific.\n"); |
649 | printf("Duplicate symbol, be more specific.\n"); |
646 | } else { |
650 | } else { |
647 | symbol = get_symtab_entry(symaddr); |
651 | symbol = get_symtab_entry(symaddr); |
648 | printf("Calling f(0x%zx,0x%zx, 0x%zx): %.*p: %s\n", |
652 | printf("Calling f(0x%zx,0x%zx, 0x%zx): %.*p: %s\n", |
649 | arg1, arg2, arg3, sizeof(uintptr_t) * 2, symaddr, symbol); |
653 | arg1, arg2, arg3, sizeof(uintptr_t) * 2, symaddr, symbol); |
650 | #ifdef ia64 |
654 | #ifdef ia64 |
651 | fptr.f = symaddr; |
655 | fptr.f = symaddr; |
652 | fptr.gp = ((unative_t *)cmd_call2)[1]; |
656 | fptr.gp = ((unative_t *)cmd_call2)[1]; |
653 | f = (unative_t (*)(unative_t,unative_t,unative_t,...)) &fptr; |
657 | f = (unative_t (*)(unative_t,unative_t,unative_t,...)) &fptr; |
654 | #else |
658 | #else |
655 | f = (unative_t (*)(unative_t,unative_t,unative_t,...)) symaddr; |
659 | f = (unative_t (*)(unative_t,unative_t,unative_t,...)) symaddr; |
656 | #endif |
660 | #endif |
657 | printf("Result: %#zx\n", f(arg1, arg2, arg3)); |
661 | printf("Result: %#zx\n", f(arg1, arg2, arg3)); |
658 | } |
662 | } |
659 | 663 | ||
660 | return 1; |
664 | return 1; |
661 | } |
665 | } |
662 | 666 | ||
663 | 667 | ||
664 | /** Print detailed description of 'describe' command. */ |
668 | /** Print detailed description of 'describe' command. */ |
665 | void desc_help(void) |
669 | void desc_help(void) |
666 | { |
670 | { |
667 | printf("Syntax: describe command_name\n"); |
671 | printf("Syntax: describe command_name\n"); |
668 | } |
672 | } |
669 | 673 | ||
670 | /** Halt the kernel. |
674 | /** Halt the kernel. |
671 | * |
675 | * |
672 | * @param argv Argument vector (ignored). |
676 | * @param argv Argument vector (ignored). |
673 | * |
677 | * |
674 | * @return 0 on failure, 1 on success (never returns). |
678 | * @return 0 on failure, 1 on success (never returns). |
675 | */ |
679 | */ |
676 | int cmd_halt(cmd_arg_t *argv) |
680 | int cmd_halt(cmd_arg_t *argv) |
677 | { |
681 | { |
678 | halt(); |
682 | halt(); |
679 | return 1; |
683 | return 1; |
680 | } |
684 | } |
681 | 685 | ||
682 | /** Command for printing TLB contents. |
686 | /** Command for printing TLB contents. |
683 | * |
687 | * |
684 | * @param argv Not used. |
688 | * @param argv Not used. |
685 | * |
689 | * |
686 | * @return Always returns 1. |
690 | * @return Always returns 1. |
687 | */ |
691 | */ |
688 | int cmd_tlb(cmd_arg_t *argv) |
692 | int cmd_tlb(cmd_arg_t *argv) |
689 | { |
693 | { |
690 | tlb_print(); |
694 | tlb_print(); |
691 | return 1; |
695 | return 1; |
692 | } |
696 | } |
693 | 697 | ||
694 | /** Write 4 byte value to address */ |
698 | /** Write 4 byte value to address */ |
695 | int cmd_set4(cmd_arg_t *argv) |
699 | int cmd_set4(cmd_arg_t *argv) |
696 | { |
700 | { |
697 | uint32_t *addr ; |
701 | uint32_t *addr ; |
698 | uint32_t arg1 = argv[1].intval; |
702 | uint32_t arg1 = argv[1].intval; |
699 | bool pointer = false; |
703 | bool pointer = false; |
700 | 704 | ||
701 | if (((char *)argv->buffer)[0] == '*') { |
705 | if (((char *)argv->buffer)[0] == '*') { |
702 | addr = (uint32_t *) get_symbol_addr(argv->buffer+1); |
706 | addr = (uint32_t *) get_symbol_addr(argv->buffer+1); |
703 | pointer = true; |
707 | pointer = true; |
704 | } else if (((char *)argv->buffer)[0] >= '0' && |
708 | } else if (((char *)argv->buffer)[0] >= '0' && |
705 | ((char *)argv->buffer)[0] <= '9') |
709 | ((char *)argv->buffer)[0] <= '9') |
706 | addr = (uint32_t *)atoi((char *)argv->buffer); |
710 | addr = (uint32_t *)atoi((char *)argv->buffer); |
707 | else |
711 | else |
708 | addr = (uint32_t *)get_symbol_addr(argv->buffer); |
712 | addr = (uint32_t *)get_symbol_addr(argv->buffer); |
709 | 713 | ||
710 | if (!addr) |
714 | if (!addr) |
711 | printf("Symbol %s not found.\n", argv->buffer); |
715 | printf("Symbol %s not found.\n", argv->buffer); |
712 | else if (addr == (uint32_t *) -1) { |
716 | else if (addr == (uint32_t *) -1) { |
713 | symtab_print_search(argv->buffer); |
717 | symtab_print_search(argv->buffer); |
714 | printf("Duplicate symbol, be more specific.\n"); |
718 | printf("Duplicate symbol, be more specific.\n"); |
715 | } else { |
719 | } else { |
716 | if (pointer) |
720 | if (pointer) |
717 | addr = (uint32_t *)(*(unative_t *)addr); |
721 | addr = (uint32_t *)(*(unative_t *)addr); |
718 | printf("Writing 0x%x -> %.*p\n", arg1, sizeof(uintptr_t) * 2, addr); |
722 | printf("Writing 0x%x -> %.*p\n", arg1, sizeof(uintptr_t) * 2, addr); |
719 | *addr = arg1; |
723 | *addr = arg1; |
720 | 724 | ||
721 | } |
725 | } |
722 | 726 | ||
723 | return 1; |
727 | return 1; |
724 | } |
728 | } |
725 | 729 | ||
726 | /** Command for listings SLAB caches |
730 | /** Command for listings SLAB caches |
727 | * |
731 | * |
728 | * @param argv Ignores |
732 | * @param argv Ignores |
729 | * |
733 | * |
730 | * @return Always 1 |
734 | * @return Always 1 |
731 | */ |
735 | */ |
732 | int cmd_slabs(cmd_arg_t * argv) { |
736 | int cmd_slabs(cmd_arg_t * argv) { |
733 | slab_print_list(); |
737 | slab_print_list(); |
734 | return 1; |
738 | return 1; |
735 | } |
739 | } |
736 | 740 | ||
737 | 741 | ||
738 | /** Command for listings Thread information |
742 | /** Command for listings Thread information |
739 | * |
743 | * |
740 | * @param argv Ignores |
744 | * @param argv Ignores |
741 | * |
745 | * |
742 | * @return Always 1 |
746 | * @return Always 1 |
743 | */ |
747 | */ |
744 | int cmd_threads(cmd_arg_t * argv) { |
748 | int cmd_threads(cmd_arg_t * argv) { |
745 | thread_print_list(); |
749 | thread_print_list(); |
746 | return 1; |
750 | return 1; |
747 | } |
751 | } |
748 | 752 | ||
749 | /** Command for listings Task information |
753 | /** Command for listings Task information |
750 | * |
754 | * |
751 | * @param argv Ignores |
755 | * @param argv Ignores |
752 | * |
756 | * |
753 | * @return Always 1 |
757 | * @return Always 1 |
754 | */ |
758 | */ |
755 | int cmd_tasks(cmd_arg_t * argv) { |
759 | int cmd_tasks(cmd_arg_t * argv) { |
756 | task_print_list(); |
760 | task_print_list(); |
757 | return 1; |
761 | return 1; |
758 | } |
762 | } |
759 | 763 | ||
760 | /** Command for listings Thread information |
764 | /** Command for listings Thread information |
761 | * |
765 | * |
762 | * @param argv Ignores |
766 | * @param argv Ignores |
763 | * |
767 | * |
764 | * @return Always 1 |
768 | * @return Always 1 |
765 | */ |
769 | */ |
766 | int cmd_sched(cmd_arg_t * argv) { |
770 | int cmd_sched(cmd_arg_t * argv) { |
767 | sched_print_list(); |
771 | sched_print_list(); |
768 | return 1; |
772 | return 1; |
769 | } |
773 | } |
770 | 774 | ||
771 | /** Command for listing memory zones |
775 | /** Command for listing memory zones |
772 | * |
776 | * |
773 | * @param argv Ignored |
777 | * @param argv Ignored |
774 | * |
778 | * |
775 | * return Always 1 |
779 | * return Always 1 |
776 | */ |
780 | */ |
777 | int cmd_zones(cmd_arg_t * argv) { |
781 | int cmd_zones(cmd_arg_t * argv) { |
778 | zone_print_list(); |
782 | zone_print_list(); |
779 | return 1; |
783 | return 1; |
780 | } |
784 | } |
781 | 785 | ||
782 | /** Command for memory zone details |
786 | /** Command for memory zone details |
783 | * |
787 | * |
784 | * @param argv Integer argument from cmdline expected |
788 | * @param argv Integer argument from cmdline expected |
785 | * |
789 | * |
786 | * return Always 1 |
790 | * return Always 1 |
787 | */ |
791 | */ |
788 | int cmd_zone(cmd_arg_t * argv) { |
792 | int cmd_zone(cmd_arg_t * argv) { |
789 | zone_print_one(argv[0].intval); |
793 | zone_print_one(argv[0].intval); |
790 | return 1; |
794 | return 1; |
791 | } |
795 | } |
792 | 796 | ||
793 | /** Command for printing task ipc details |
797 | /** Command for printing task ipc details |
794 | * |
798 | * |
795 | * @param argv Integer argument from cmdline expected |
799 | * @param argv Integer argument from cmdline expected |
796 | * |
800 | * |
797 | * return Always 1 |
801 | * return Always 1 |
798 | */ |
802 | */ |
799 | int cmd_ipc_task(cmd_arg_t * argv) { |
803 | int cmd_ipc_task(cmd_arg_t * argv) { |
800 | ipc_print_task(argv[0].intval); |
804 | ipc_print_task(argv[0].intval); |
801 | return 1; |
805 | return 1; |
802 | } |
806 | } |
803 | 807 | ||
804 | 808 | ||
805 | /** Command for listing processors. |
809 | /** Command for listing processors. |
806 | * |
810 | * |
807 | * @param argv Ignored. |
811 | * @param argv Ignored. |
808 | * |
812 | * |
809 | * return Always 1. |
813 | * return Always 1. |
810 | */ |
814 | */ |
811 | int cmd_cpus(cmd_arg_t *argv) |
815 | int cmd_cpus(cmd_arg_t *argv) |
812 | { |
816 | { |
813 | cpu_list(); |
817 | cpu_list(); |
814 | return 1; |
818 | return 1; |
815 | } |
819 | } |
816 | 820 | ||
817 | /** Command for printing kernel version. |
821 | /** Command for printing kernel version. |
818 | * |
822 | * |
819 | * @param argv Ignored. |
823 | * @param argv Ignored. |
820 | * |
824 | * |
821 | * return Always 1. |
825 | * return Always 1. |
822 | */ |
826 | */ |
823 | int cmd_version(cmd_arg_t *argv) |
827 | int cmd_version(cmd_arg_t *argv) |
824 | { |
828 | { |
825 | version_print(); |
829 | version_print(); |
826 | return 1; |
830 | return 1; |
827 | } |
831 | } |
828 | 832 | ||
829 | /** Command for returning console back to userspace. |
833 | /** Command for returning console back to userspace. |
830 | * |
834 | * |
831 | * @param argv Ignored. |
835 | * @param argv Ignored. |
832 | * |
836 | * |
833 | * return Always 1. |
837 | * return Always 1. |
834 | */ |
838 | */ |
835 | int cmd_continue(cmd_arg_t *argv) |
839 | int cmd_continue(cmd_arg_t *argv) |
836 | { |
840 | { |
837 | printf("The kernel will now relinquish the console.\n"); |
841 | printf("The kernel will now relinquish the console.\n"); |
838 | printf("Use userspace controls to redraw the screen.\n"); |
842 | printf("Use userspace controls to redraw the screen.\n"); |
839 | arch_release_console(); |
843 | arch_release_console(); |
840 | return 1; |
844 | return 1; |
841 | } |
845 | } |
842 | 846 | ||
843 | #ifdef CONFIG_TEST |
847 | #ifdef CONFIG_TEST |
844 | /** Command for printing kernel tests list. |
848 | /** Command for printing kernel tests list. |
845 | * |
849 | * |
846 | * @param argv Ignored. |
850 | * @param argv Ignored. |
847 | * |
851 | * |
848 | * return Always 1. |
852 | * return Always 1. |
849 | */ |
853 | */ |
850 | int cmd_tests(cmd_arg_t *argv) |
854 | int cmd_tests(cmd_arg_t *argv) |
851 | { |
855 | { |
852 | test_t *test; |
856 | test_t *test; |
853 | 857 | ||
854 | for (test = tests; test->name != NULL; test++) |
858 | for (test = tests; test->name != NULL; test++) |
855 | printf("%s\t\t%s%s\n", test->name, test->desc, (test->safe ? "" : " (unsafe)")); |
859 | printf("%s\t\t%s%s\n", test->name, test->desc, (test->safe ? "" : " (unsafe)")); |
856 | 860 | ||
857 | printf("*\t\tRun all safe tests\n"); |
861 | printf("*\t\tRun all safe tests\n"); |
858 | return 1; |
862 | return 1; |
859 | } |
863 | } |
860 | 864 | ||
- | 865 | static bool run_test(const test_t * test) |
|
- | 866 | { |
|
- | 867 | printf("%s\t\t%s\n", test->name, test->desc); |
|
- | 868 | #ifdef CONFIG_BENCH |
|
- | 869 | uint64_t t0 = get_cycle(); |
|
- | 870 | #endif |
|
- | 871 | char * ret = test->entry(); |
|
- | 872 | #ifdef CONFIG_BENCH |
|
- | 873 | uint64_t dt = get_cycle() - t0; |
|
- | 874 | printf("Time: %llu cycles\n", dt); |
|
- | 875 | #endif |
|
- | 876 | ||
- | 877 | if (ret == NULL) { |
|
- | 878 | printf("Test passed\n"); |
|
- | 879 | return true; |
|
- | 880 | } |
|
- | 881 | ||
- | 882 | printf("%s\n", ret); |
|
- | 883 | return false; |
|
- | 884 | } |
|
- | 885 | ||
861 | /** Command for returning kernel tests |
886 | /** Command for returning kernel tests |
862 | * |
887 | * |
863 | * @param argv Argument vector. |
888 | * @param argv Argument vector. |
864 | * |
889 | * |
865 | * return Always 1. |
890 | * return Always 1. |
866 | */ |
891 | */ |
867 | int cmd_test(cmd_arg_t *argv) |
892 | int cmd_test(cmd_arg_t *argv) |
868 | { |
893 | { |
869 | test_t *test; |
894 | test_t *test; |
870 | 895 | ||
871 | if (strcmp(argv->buffer, "*") == 0) { |
896 | if (strcmp(argv->buffer, "*") == 0) { |
872 | for (test = tests; test->name != NULL; test++) { |
897 | for (test = tests; test->name != NULL; test++) { |
873 | if (test->safe) { |
898 | if (test->safe) { |
- | 899 | printf("\n"); |
|
874 | printf("\n%s\t\t%s\n\n", test->name, test->desc); |
900 | if (!run_test(test)) |
875 | test->entry(); |
901 | break; |
876 | } |
902 | } |
877 | } |
903 | } |
878 | } else { |
904 | } else { |
879 | bool fnd = false; |
905 | bool fnd = false; |
880 | 906 | ||
881 | for (test = tests; test->name != NULL; test++) { |
907 | for (test = tests; test->name != NULL; test++) { |
882 | if (strcmp(test->name, argv->buffer) == 0) { |
908 | if (strcmp(test->name, argv->buffer) == 0) { |
883 | fnd = true; |
909 | fnd = true; |
884 | test->entry(); |
910 | run_test(test); |
885 | break; |
911 | break; |
886 | } |
912 | } |
887 | } |
913 | } |
888 | 914 | ||
889 | if (!fnd) |
915 | if (!fnd) |
890 | printf("Unknown test.\n"); |
916 | printf("Unknown test\n"); |
891 | } |
917 | } |
892 | 918 | ||
893 | return 1; |
919 | return 1; |
894 | } |
920 | } |
895 | #endif |
921 | #endif |
896 | 922 | ||
897 | /** @} |
923 | /** @} |
898 | */ |
924 | */ |
899 | 925 |