1 | /*
|
---|
2 | * Copyright (c) 2005 Jakub Jermar
|
---|
3 | * All rights reserved.
|
---|
4 | *
|
---|
5 | * Redistribution and use in source and binary forms, with or without
|
---|
6 | * modification, are permitted provided that the following conditions
|
---|
7 | * are met:
|
---|
8 | *
|
---|
9 | * - Redistributions of source code must retain the above copyright
|
---|
10 | * notice, this list of conditions and the following disclaimer.
|
---|
11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
12 | * notice, this list of conditions and the following disclaimer in the
|
---|
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
|
---|
15 | * derived from this software without specific prior written permission.
|
---|
16 | *
|
---|
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
|
---|
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
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
|
---|
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
|
---|
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
27 | */
|
---|
28 |
|
---|
29 | /** @addtogroup genericconsole
|
---|
30 | * @{
|
---|
31 | */
|
---|
32 |
|
---|
33 | /**
|
---|
34 | * @file cmd.c
|
---|
35 | * @brief Kernel console command wrappers.
|
---|
36 | *
|
---|
37 | * This file is meant to contain all wrapper functions for
|
---|
38 | * all kconsole commands. The point is in separating
|
---|
39 | * kconsole specific wrappers from kconsole-unaware functions
|
---|
40 | * from other subsystems.
|
---|
41 | */
|
---|
42 |
|
---|
43 | #include <console/cmd.h>
|
---|
44 | #include <console/console.h>
|
---|
45 | #include <console/kconsole.h>
|
---|
46 | #include <print.h>
|
---|
47 | #include <panic.h>
|
---|
48 | #include <typedefs.h>
|
---|
49 | #include <adt/list.h>
|
---|
50 | #include <arch.h>
|
---|
51 | #include <config.h>
|
---|
52 | #include <func.h>
|
---|
53 | #include <str.h>
|
---|
54 | #include <macros.h>
|
---|
55 | #include <debug.h>
|
---|
56 | #include <cpu.h>
|
---|
57 | #include <mm/tlb.h>
|
---|
58 | #include <arch/mm/tlb.h>
|
---|
59 | #include <mm/frame.h>
|
---|
60 | #include <main/version.h>
|
---|
61 | #include <mm/slab.h>
|
---|
62 | #include <proc/scheduler.h>
|
---|
63 | #include <proc/thread.h>
|
---|
64 | #include <proc/task.h>
|
---|
65 | #include <ipc/ipc.h>
|
---|
66 | #include <ipc/irq.h>
|
---|
67 | #include <ipc/event.h>
|
---|
68 | #include <sysinfo/sysinfo.h>
|
---|
69 | #include <symtab.h>
|
---|
70 | #include <errno.h>
|
---|
71 |
|
---|
72 | #ifdef CONFIG_TEST
|
---|
73 | #include <test.h>
|
---|
74 | #endif
|
---|
75 |
|
---|
76 | /* Data and methods for 'help' command. */
|
---|
77 | static int cmd_help(cmd_arg_t *argv);
|
---|
78 | static cmd_info_t help_info = {
|
---|
79 | .name = "help",
|
---|
80 | .description = "List supported commands.",
|
---|
81 | .func = cmd_help,
|
---|
82 | .argc = 0
|
---|
83 | };
|
---|
84 |
|
---|
85 | /* Data and methods for 'reboot' command. */
|
---|
86 | static int cmd_reboot(cmd_arg_t *argv);
|
---|
87 | static cmd_info_t reboot_info = {
|
---|
88 | .name = "reboot",
|
---|
89 | .description = "Reboot system.",
|
---|
90 | .func = cmd_reboot,
|
---|
91 | .argc = 0
|
---|
92 | };
|
---|
93 |
|
---|
94 | /* Data and methods for 'uptime' command. */
|
---|
95 | static int cmd_uptime(cmd_arg_t *argv);
|
---|
96 | static cmd_info_t uptime_info = {
|
---|
97 | .name = "uptime",
|
---|
98 | .description = "Show system uptime.",
|
---|
99 | .func = cmd_uptime,
|
---|
100 | .argc = 0
|
---|
101 | };
|
---|
102 |
|
---|
103 | /* Data and methods for 'continue' command. */
|
---|
104 | static int cmd_continue(cmd_arg_t *argv);
|
---|
105 | static cmd_info_t continue_info = {
|
---|
106 | .name = "continue",
|
---|
107 | .description = "Return console back to userspace.",
|
---|
108 | .func = cmd_continue,
|
---|
109 | .argc = 0
|
---|
110 | };
|
---|
111 |
|
---|
112 | #ifdef CONFIG_TEST
|
---|
113 |
|
---|
114 | /* Data and methods for 'test' command. */
|
---|
115 | static char test_buf[MAX_CMDLINE + 1];
|
---|
116 | static int cmd_test(cmd_arg_t *argv);
|
---|
117 | static cmd_arg_t test_argv[] = {
|
---|
118 | {
|
---|
119 | .type = ARG_TYPE_STRING_OPTIONAL,
|
---|
120 | .buffer = test_buf,
|
---|
121 | .len = sizeof(test_buf)
|
---|
122 | }
|
---|
123 | };
|
---|
124 | static cmd_info_t test_info = {
|
---|
125 | .name = "test",
|
---|
126 | .description = "<test> List kernel tests or run a test.",
|
---|
127 | .func = cmd_test,
|
---|
128 | .argc = 1,
|
---|
129 | .argv = test_argv
|
---|
130 | };
|
---|
131 |
|
---|
132 | /* Data and methods for 'bench' command. */
|
---|
133 | static int cmd_bench(cmd_arg_t *argv);
|
---|
134 | static cmd_arg_t bench_argv[] = {
|
---|
135 | {
|
---|
136 | .type = ARG_TYPE_STRING,
|
---|
137 | .buffer = test_buf,
|
---|
138 | .len = sizeof(test_buf)
|
---|
139 | },
|
---|
140 | {
|
---|
141 | .type = ARG_TYPE_INT,
|
---|
142 | }
|
---|
143 | };
|
---|
144 | static cmd_info_t bench_info = {
|
---|
145 | .name = "bench",
|
---|
146 | .description = "<test> <count> Run kernel test as benchmark.",
|
---|
147 | .func = cmd_bench,
|
---|
148 | .argc = 2,
|
---|
149 | .argv = bench_argv
|
---|
150 | };
|
---|
151 |
|
---|
152 | #endif /* CONFIG_TEST */
|
---|
153 |
|
---|
154 | /* Data and methods for 'description' command. */
|
---|
155 | static int cmd_desc(cmd_arg_t *argv);
|
---|
156 | static void desc_help(void);
|
---|
157 | static char desc_buf[MAX_CMDLINE + 1];
|
---|
158 | static cmd_arg_t desc_argv = {
|
---|
159 | .type = ARG_TYPE_STRING,
|
---|
160 | .buffer = desc_buf,
|
---|
161 | .len = sizeof(desc_buf)
|
---|
162 | };
|
---|
163 | static cmd_info_t desc_info = {
|
---|
164 | .name = "describe",
|
---|
165 | .description = "<command> Describe specified command.",
|
---|
166 | .help = desc_help,
|
---|
167 | .func = cmd_desc,
|
---|
168 | .argc = 1,
|
---|
169 | .argv = &desc_argv
|
---|
170 | };
|
---|
171 |
|
---|
172 | /* Data and methods for 'symaddr' command. */
|
---|
173 | static int cmd_symaddr(cmd_arg_t *argv);
|
---|
174 | static char symaddr_buf[MAX_CMDLINE + 1];
|
---|
175 | static cmd_arg_t symaddr_argv = {
|
---|
176 | .type = ARG_TYPE_STRING,
|
---|
177 | .buffer = symaddr_buf,
|
---|
178 | .len = sizeof(symaddr_buf)
|
---|
179 | };
|
---|
180 | static cmd_info_t symaddr_info = {
|
---|
181 | .name = "symaddr",
|
---|
182 | .description = "<symbol> Return symbol address.",
|
---|
183 | .func = cmd_symaddr,
|
---|
184 | .argc = 1,
|
---|
185 | .argv = &symaddr_argv
|
---|
186 | };
|
---|
187 |
|
---|
188 | /* Data and methods for 'set4' command. */
|
---|
189 | static char set_buf[MAX_CMDLINE + 1];
|
---|
190 | static int cmd_set4(cmd_arg_t *argv);
|
---|
191 | static cmd_arg_t set4_argv[] = {
|
---|
192 | {
|
---|
193 | .type = ARG_TYPE_STRING,
|
---|
194 | .buffer = set_buf,
|
---|
195 | .len = sizeof(set_buf)
|
---|
196 | },
|
---|
197 | {
|
---|
198 | .type = ARG_TYPE_INT
|
---|
199 | }
|
---|
200 | };
|
---|
201 | static cmd_info_t set4_info = {
|
---|
202 | .name = "set4",
|
---|
203 | .description = "<addr> <value> Set 4B memory location to a value.",
|
---|
204 | .func = cmd_set4,
|
---|
205 | .argc = 2,
|
---|
206 | .argv = set4_argv
|
---|
207 | };
|
---|
208 |
|
---|
209 | /* Data and methods for 'call0' and 'mcall0' command. */
|
---|
210 | static char call0_buf[MAX_CMDLINE + 1];
|
---|
211 | static char carg1_buf[MAX_CMDLINE + 1];
|
---|
212 | static char carg2_buf[MAX_CMDLINE + 1];
|
---|
213 | static char carg3_buf[MAX_CMDLINE + 1];
|
---|
214 |
|
---|
215 | static int cmd_call0(cmd_arg_t *argv);
|
---|
216 | static cmd_arg_t call0_argv = {
|
---|
217 | .type = ARG_TYPE_STRING,
|
---|
218 | .buffer = call0_buf,
|
---|
219 | .len = sizeof(call0_buf)
|
---|
220 | };
|
---|
221 | static cmd_info_t call0_info = {
|
---|
222 | .name = "call0",
|
---|
223 | .description = "<function> Call function().",
|
---|
224 | .func = cmd_call0,
|
---|
225 | .argc = 1,
|
---|
226 | .argv = &call0_argv
|
---|
227 | };
|
---|
228 |
|
---|
229 | /* Data and methods for 'mcall0' command. */
|
---|
230 | static int cmd_mcall0(cmd_arg_t *argv);
|
---|
231 | static cmd_arg_t mcall0_argv = {
|
---|
232 | .type = ARG_TYPE_STRING,
|
---|
233 | .buffer = call0_buf,
|
---|
234 | .len = sizeof(call0_buf)
|
---|
235 | };
|
---|
236 | static cmd_info_t mcall0_info = {
|
---|
237 | .name = "mcall0",
|
---|
238 | .description = "<function> Call function() on each CPU.",
|
---|
239 | .func = cmd_mcall0,
|
---|
240 | .argc = 1,
|
---|
241 | .argv = &mcall0_argv
|
---|
242 | };
|
---|
243 |
|
---|
244 | /* Data and methods for 'call1' command. */
|
---|
245 | static int cmd_call1(cmd_arg_t *argv);
|
---|
246 | static cmd_arg_t call1_argv[] = {
|
---|
247 | {
|
---|
248 | .type = ARG_TYPE_STRING,
|
---|
249 | .buffer = call0_buf,
|
---|
250 | .len = sizeof(call0_buf)
|
---|
251 | },
|
---|
252 | {
|
---|
253 | .type = ARG_TYPE_VAR,
|
---|
254 | .buffer = carg1_buf,
|
---|
255 | .len = sizeof(carg1_buf)
|
---|
256 | }
|
---|
257 | };
|
---|
258 | static cmd_info_t call1_info = {
|
---|
259 | .name = "call1",
|
---|
260 | .description = "<function> <arg1> Call function(arg1).",
|
---|
261 | .func = cmd_call1,
|
---|
262 | .argc = 2,
|
---|
263 | .argv = call1_argv
|
---|
264 | };
|
---|
265 |
|
---|
266 | /* Data and methods for 'call2' command. */
|
---|
267 | static int cmd_call2(cmd_arg_t *argv);
|
---|
268 | static cmd_arg_t call2_argv[] = {
|
---|
269 | {
|
---|
270 | .type = ARG_TYPE_STRING,
|
---|
271 | .buffer = call0_buf,
|
---|
272 | .len = sizeof(call0_buf)
|
---|
273 | },
|
---|
274 | {
|
---|
275 | .type = ARG_TYPE_VAR,
|
---|
276 | .buffer = carg1_buf,
|
---|
277 | .len = sizeof(carg1_buf)
|
---|
278 | },
|
---|
279 | {
|
---|
280 | .type = ARG_TYPE_VAR,
|
---|
281 | .buffer = carg2_buf,
|
---|
282 | .len = sizeof(carg2_buf)
|
---|
283 | }
|
---|
284 | };
|
---|
285 | static cmd_info_t call2_info = {
|
---|
286 | .name = "call2",
|
---|
287 | .description = "<function> <arg1> <arg2> Call function(arg1, arg2).",
|
---|
288 | .func = cmd_call2,
|
---|
289 | .argc = 3,
|
---|
290 | .argv = call2_argv
|
---|
291 | };
|
---|
292 |
|
---|
293 | /* Data and methods for 'call3' command. */
|
---|
294 | static int cmd_call3(cmd_arg_t *argv);
|
---|
295 | static cmd_arg_t call3_argv[] = {
|
---|
296 | {
|
---|
297 | .type = ARG_TYPE_STRING,
|
---|
298 | .buffer = call0_buf,
|
---|
299 | .len = sizeof(call0_buf)
|
---|
300 | },
|
---|
301 | {
|
---|
302 | .type = ARG_TYPE_VAR,
|
---|
303 | .buffer = carg1_buf,
|
---|
304 | .len = sizeof(carg1_buf)
|
---|
305 | },
|
---|
306 | {
|
---|
307 | .type = ARG_TYPE_VAR,
|
---|
308 | .buffer = carg2_buf,
|
---|
309 | .len = sizeof(carg2_buf)
|
---|
310 | },
|
---|
311 | {
|
---|
312 | .type = ARG_TYPE_VAR,
|
---|
313 | .buffer = carg3_buf,
|
---|
314 | .len = sizeof(carg3_buf)
|
---|
315 | }
|
---|
316 |
|
---|
317 | };
|
---|
318 | static cmd_info_t call3_info = {
|
---|
319 | .name = "call3",
|
---|
320 | .description = "<function> <arg1> <arg2> <arg3> Call function(arg1, arg2, arg3).",
|
---|
321 | .func = cmd_call3,
|
---|
322 | .argc = 4,
|
---|
323 | .argv = call3_argv
|
---|
324 | };
|
---|
325 |
|
---|
326 | /* Data and methods for 'halt' command. */
|
---|
327 | static int cmd_halt(cmd_arg_t *argv);
|
---|
328 | static cmd_info_t halt_info = {
|
---|
329 | .name = "halt",
|
---|
330 | .description = "Halt the kernel.",
|
---|
331 | .func = cmd_halt,
|
---|
332 | .argc = 0
|
---|
333 | };
|
---|
334 |
|
---|
335 | /* Data and methods for 'physmem' command. */
|
---|
336 | static int cmd_physmem(cmd_arg_t *argv);
|
---|
337 | cmd_info_t physmem_info = {
|
---|
338 | .name = "physmem",
|
---|
339 | .description = "Print physical memory configuration.",
|
---|
340 | .help = NULL,
|
---|
341 | .func = cmd_physmem,
|
---|
342 | .argc = 0,
|
---|
343 | .argv = NULL
|
---|
344 | };
|
---|
345 |
|
---|
346 | /* Data and methods for 'tlb' command. */
|
---|
347 | static int cmd_tlb(cmd_arg_t *argv);
|
---|
348 | cmd_info_t tlb_info = {
|
---|
349 | .name = "tlb",
|
---|
350 | .description = "Print TLB of the current CPU.",
|
---|
351 | .help = NULL,
|
---|
352 | .func = cmd_tlb,
|
---|
353 | .argc = 0,
|
---|
354 | .argv = NULL
|
---|
355 | };
|
---|
356 |
|
---|
357 | static char flag_buf[MAX_CMDLINE + 1];
|
---|
358 |
|
---|
359 | static int cmd_threads(cmd_arg_t *argv);
|
---|
360 | static cmd_arg_t threads_argv = {
|
---|
361 | .type = ARG_TYPE_STRING_OPTIONAL,
|
---|
362 | .buffer = flag_buf,
|
---|
363 | .len = sizeof(flag_buf)
|
---|
364 | };
|
---|
365 | static cmd_info_t threads_info = {
|
---|
366 | .name = "threads",
|
---|
367 | .description = "List all threads (use -a for additional information).",
|
---|
368 | .func = cmd_threads,
|
---|
369 | .argc = 1,
|
---|
370 | .argv = &threads_argv
|
---|
371 | };
|
---|
372 |
|
---|
373 | static int cmd_tasks(cmd_arg_t *argv);
|
---|
374 | static cmd_arg_t tasks_argv = {
|
---|
375 | .type = ARG_TYPE_STRING_OPTIONAL,
|
---|
376 | .buffer = flag_buf,
|
---|
377 | .len = sizeof(flag_buf)
|
---|
378 | };
|
---|
379 | static cmd_info_t tasks_info = {
|
---|
380 | .name = "tasks",
|
---|
381 | .description = "List all tasks (use -a for additional information).",
|
---|
382 | .func = cmd_tasks,
|
---|
383 | .argc = 1,
|
---|
384 | .argv = &tasks_argv
|
---|
385 | };
|
---|
386 |
|
---|
387 | #ifdef CONFIG_UDEBUG
|
---|
388 |
|
---|
389 | /* Data and methods for 'btrace' command */
|
---|
390 | static int cmd_btrace(cmd_arg_t *argv);
|
---|
391 | static cmd_arg_t btrace_argv = {
|
---|
392 | .type = ARG_TYPE_INT,
|
---|
393 | };
|
---|
394 | static cmd_info_t btrace_info = {
|
---|
395 | .name = "btrace",
|
---|
396 | .description = "<threadid> Show thread stack trace.",
|
---|
397 | .func = cmd_btrace,
|
---|
398 | .argc = 1,
|
---|
399 | .argv = &btrace_argv
|
---|
400 | };
|
---|
401 |
|
---|
402 | #endif /* CONFIG_UDEBUG */
|
---|
403 |
|
---|
404 | static int cmd_sched(cmd_arg_t *argv);
|
---|
405 | static cmd_info_t sched_info = {
|
---|
406 | .name = "scheduler",
|
---|
407 | .description = "Show scheduler information.",
|
---|
408 | .func = cmd_sched,
|
---|
409 | .argc = 0
|
---|
410 | };
|
---|
411 |
|
---|
412 | static int cmd_slabs(cmd_arg_t *argv);
|
---|
413 | static cmd_info_t slabs_info = {
|
---|
414 | .name = "slabs",
|
---|
415 | .description = "List slab caches.",
|
---|
416 | .func = cmd_slabs,
|
---|
417 | .argc = 0
|
---|
418 | };
|
---|
419 |
|
---|
420 | static int cmd_sysinfo(cmd_arg_t *argv);
|
---|
421 | static cmd_info_t sysinfo_info = {
|
---|
422 | .name = "sysinfo",
|
---|
423 | .description = "Dump sysinfo.",
|
---|
424 | .func = cmd_sysinfo,
|
---|
425 | .argc = 0
|
---|
426 | };
|
---|
427 |
|
---|
428 | /* Data and methods for 'zones' command */
|
---|
429 | static int cmd_zones(cmd_arg_t *argv);
|
---|
430 | static cmd_info_t zones_info = {
|
---|
431 | .name = "zones",
|
---|
432 | .description = "List memory zones.",
|
---|
433 | .func = cmd_zones,
|
---|
434 | .argc = 0
|
---|
435 | };
|
---|
436 |
|
---|
437 | /* Data and methods for 'zone' command */
|
---|
438 | static int cmd_zone(cmd_arg_t *argv);
|
---|
439 | static cmd_arg_t zone_argv = {
|
---|
440 | .type = ARG_TYPE_INT,
|
---|
441 | };
|
---|
442 |
|
---|
443 | static cmd_info_t zone_info = {
|
---|
444 | .name = "zone",
|
---|
445 | .description = "<zone> Show memory zone structure.",
|
---|
446 | .func = cmd_zone,
|
---|
447 | .argc = 1,
|
---|
448 | .argv = &zone_argv
|
---|
449 | };
|
---|
450 |
|
---|
451 | /* Data and methods for 'ipc' command */
|
---|
452 | static int cmd_ipc(cmd_arg_t *argv);
|
---|
453 | static cmd_arg_t ipc_argv = {
|
---|
454 | .type = ARG_TYPE_INT,
|
---|
455 | };
|
---|
456 | static cmd_info_t ipc_info = {
|
---|
457 | .name = "ipc",
|
---|
458 | .description = "<taskid> Show IPC information of a task.",
|
---|
459 | .func = cmd_ipc,
|
---|
460 | .argc = 1,
|
---|
461 | .argv = &ipc_argv
|
---|
462 | };
|
---|
463 |
|
---|
464 | /* Data and methods for 'kill' command */
|
---|
465 | static int cmd_kill(cmd_arg_t *argv);
|
---|
466 | static cmd_arg_t kill_argv = {
|
---|
467 | .type = ARG_TYPE_INT,
|
---|
468 | };
|
---|
469 | static cmd_info_t kill_info = {
|
---|
470 | .name = "kill",
|
---|
471 | .description = "<taskid> Kill a task.",
|
---|
472 | .func = cmd_kill,
|
---|
473 | .argc = 1,
|
---|
474 | .argv = &kill_argv
|
---|
475 | };
|
---|
476 |
|
---|
477 | /* Data and methods for 'cpus' command. */
|
---|
478 | static int cmd_cpus(cmd_arg_t *argv);
|
---|
479 | cmd_info_t cpus_info = {
|
---|
480 | .name = "cpus",
|
---|
481 | .description = "List all processors.",
|
---|
482 | .help = NULL,
|
---|
483 | .func = cmd_cpus,
|
---|
484 | .argc = 0,
|
---|
485 | .argv = NULL
|
---|
486 | };
|
---|
487 |
|
---|
488 | /* Data and methods for 'version' command. */
|
---|
489 | static int cmd_version(cmd_arg_t *argv);
|
---|
490 | cmd_info_t version_info = {
|
---|
491 | .name = "version",
|
---|
492 | .description = "Print version information.",
|
---|
493 | .help = NULL,
|
---|
494 | .func = cmd_version,
|
---|
495 | .argc = 0,
|
---|
496 | .argv = NULL
|
---|
497 | };
|
---|
498 |
|
---|
499 | static cmd_info_t *basic_commands[] = {
|
---|
500 | &call0_info,
|
---|
501 | &mcall0_info,
|
---|
502 | &call1_info,
|
---|
503 | &call2_info,
|
---|
504 | &call3_info,
|
---|
505 | &continue_info,
|
---|
506 | &cpus_info,
|
---|
507 | &desc_info,
|
---|
508 | &halt_info,
|
---|
509 | &help_info,
|
---|
510 | &ipc_info,
|
---|
511 | &kill_info,
|
---|
512 | &physmem_info,
|
---|
513 | &reboot_info,
|
---|
514 | &sched_info,
|
---|
515 | &set4_info,
|
---|
516 | &slabs_info,
|
---|
517 | &symaddr_info,
|
---|
518 | &sysinfo_info,
|
---|
519 | &tasks_info,
|
---|
520 | &threads_info,
|
---|
521 | &tlb_info,
|
---|
522 | &uptime_info,
|
---|
523 | &version_info,
|
---|
524 | &zones_info,
|
---|
525 | &zone_info,
|
---|
526 | #ifdef CONFIG_TEST
|
---|
527 | &test_info,
|
---|
528 | &bench_info,
|
---|
529 | #endif
|
---|
530 | #ifdef CONFIG_UDEBUG
|
---|
531 | &btrace_info,
|
---|
532 | #endif
|
---|
533 | NULL
|
---|
534 | };
|
---|
535 |
|
---|
536 |
|
---|
537 | /** Initialize command info structure.
|
---|
538 | *
|
---|
539 | * @param cmd Command info structure.
|
---|
540 | *
|
---|
541 | */
|
---|
542 | void cmd_initialize(cmd_info_t *cmd)
|
---|
543 | {
|
---|
544 | spinlock_initialize(&cmd->lock, "cmd.lock");
|
---|
545 | link_initialize(&cmd->link);
|
---|
546 | }
|
---|
547 |
|
---|
548 | /** Initialize and register commands. */
|
---|
549 | void cmd_init(void)
|
---|
550 | {
|
---|
551 | unsigned int i;
|
---|
552 |
|
---|
553 | for (i = 0; basic_commands[i]; i++) {
|
---|
554 | cmd_initialize(basic_commands[i]);
|
---|
555 | }
|
---|
556 |
|
---|
557 | for (i = 0; basic_commands[i]; i++) {
|
---|
558 | if (!cmd_register(basic_commands[i])) {
|
---|
559 | printf("Cannot register command %s\n",
|
---|
560 | basic_commands[i]->name);
|
---|
561 | }
|
---|
562 | }
|
---|
563 | }
|
---|
564 |
|
---|
565 | /** List supported commands.
|
---|
566 | *
|
---|
567 | * @param argv Argument vector.
|
---|
568 | *
|
---|
569 | * @return 0 on failure, 1 on success.
|
---|
570 | */
|
---|
571 | int cmd_help(cmd_arg_t *argv)
|
---|
572 | {
|
---|
573 | spinlock_lock(&cmd_lock);
|
---|
574 |
|
---|
575 | size_t len = 0;
|
---|
576 | list_foreach(cmd_list, cur) {
|
---|
577 | cmd_info_t *hlp;
|
---|
578 | hlp = list_get_instance(cur, cmd_info_t, link);
|
---|
579 |
|
---|
580 | spinlock_lock(&hlp->lock);
|
---|
581 | if (str_length(hlp->name) > len)
|
---|
582 | len = str_length(hlp->name);
|
---|
583 | spinlock_unlock(&hlp->lock);
|
---|
584 | }
|
---|
585 |
|
---|
586 | unsigned int _len = (unsigned int) len;
|
---|
587 | if ((_len != len) || (((int) _len) < 0)) {
|
---|
588 | printf("Command length overflow\n");
|
---|
589 | return 1;
|
---|
590 | }
|
---|
591 |
|
---|
592 | list_foreach(cmd_list, cur) {
|
---|
593 | cmd_info_t *hlp;
|
---|
594 | hlp = list_get_instance(cur, cmd_info_t, link);
|
---|
595 |
|
---|
596 | spinlock_lock(&hlp->lock);
|
---|
597 | printf("%-*s %s\n", _len, hlp->name, hlp->description);
|
---|
598 | spinlock_unlock(&hlp->lock);
|
---|
599 | }
|
---|
600 |
|
---|
601 | spinlock_unlock(&cmd_lock);
|
---|
602 |
|
---|
603 | return 1;
|
---|
604 | }
|
---|
605 |
|
---|
606 | /** Reboot the system.
|
---|
607 | *
|
---|
608 | * @param argv Argument vector.
|
---|
609 | *
|
---|
610 | * @return 0 on failure, 1 on success.
|
---|
611 | */
|
---|
612 | int cmd_reboot(cmd_arg_t *argv)
|
---|
613 | {
|
---|
614 | reboot();
|
---|
615 |
|
---|
616 | /* Not reached */
|
---|
617 | return 1;
|
---|
618 | }
|
---|
619 |
|
---|
620 | /** Print system uptime information.
|
---|
621 | *
|
---|
622 | * @param argv Argument vector.
|
---|
623 | *
|
---|
624 | * @return 0 on failure, 1 on success.
|
---|
625 | */
|
---|
626 | int cmd_uptime(cmd_arg_t *argv)
|
---|
627 | {
|
---|
628 | ASSERT(uptime);
|
---|
629 |
|
---|
630 | /* This doesn't have to be very accurate */
|
---|
631 | sysarg_t sec = uptime->seconds1;
|
---|
632 |
|
---|
633 | printf("Up %" PRIun " days, %" PRIun " hours, %" PRIun " minutes, %" PRIun " seconds\n",
|
---|
634 | sec / 86400, (sec % 86400) / 3600, (sec % 3600) / 60, sec % 60);
|
---|
635 |
|
---|
636 | return 1;
|
---|
637 | }
|
---|
638 |
|
---|
639 | /** Describe specified command.
|
---|
640 | *
|
---|
641 | * @param argv Argument vector.
|
---|
642 | *
|
---|
643 | * @return 0 on failure, 1 on success.
|
---|
644 | */
|
---|
645 | int cmd_desc(cmd_arg_t *argv)
|
---|
646 | {
|
---|
647 | spinlock_lock(&cmd_lock);
|
---|
648 |
|
---|
649 | list_foreach(cmd_list, cur) {
|
---|
650 | cmd_info_t *hlp;
|
---|
651 |
|
---|
652 | hlp = list_get_instance(cur, cmd_info_t, link);
|
---|
653 | spinlock_lock(&hlp->lock);
|
---|
654 |
|
---|
655 | if (str_lcmp(hlp->name, (const char *) argv->buffer, str_length(hlp->name)) == 0) {
|
---|
656 | printf("%s - %s\n", hlp->name, hlp->description);
|
---|
657 | if (hlp->help)
|
---|
658 | hlp->help();
|
---|
659 | spinlock_unlock(&hlp->lock);
|
---|
660 | break;
|
---|
661 | }
|
---|
662 |
|
---|
663 | spinlock_unlock(&hlp->lock);
|
---|
664 | }
|
---|
665 |
|
---|
666 | spinlock_unlock(&cmd_lock);
|
---|
667 |
|
---|
668 | return 1;
|
---|
669 | }
|
---|
670 |
|
---|
671 | /** Search symbol table */
|
---|
672 | int cmd_symaddr(cmd_arg_t *argv)
|
---|
673 | {
|
---|
674 | symtab_print_search((char *) argv->buffer);
|
---|
675 |
|
---|
676 | return 1;
|
---|
677 | }
|
---|
678 |
|
---|
679 | /** Call function with zero parameters */
|
---|
680 | int cmd_call0(cmd_arg_t *argv)
|
---|
681 | {
|
---|
682 | uintptr_t symaddr;
|
---|
683 | char *symbol;
|
---|
684 | sysarg_t (*fnc)(void);
|
---|
685 | fncptr_t fptr;
|
---|
686 | int rc;
|
---|
687 |
|
---|
688 | symbol = (char *) argv->buffer;
|
---|
689 | rc = symtab_addr_lookup(symbol, &symaddr);
|
---|
690 |
|
---|
691 | if (rc == ENOENT)
|
---|
692 | printf("Symbol %s not found.\n", symbol);
|
---|
693 | else if (rc == EOVERFLOW) {
|
---|
694 | symtab_print_search(symbol);
|
---|
695 | printf("Duplicate symbol, be more specific.\n");
|
---|
696 | } else if (rc == EOK) {
|
---|
697 | ipl_t ipl;
|
---|
698 |
|
---|
699 | ipl = interrupts_disable();
|
---|
700 | fnc = (sysarg_t (*)(void)) arch_construct_function(&fptr,
|
---|
701 | (void *) symaddr, (void *) cmd_call0);
|
---|
702 | printf("Calling %s() (%p)\n", symbol, (void *) symaddr);
|
---|
703 | printf("Result: %#" PRIxn "\n", fnc());
|
---|
704 | interrupts_restore(ipl);
|
---|
705 | } else {
|
---|
706 | printf("No symbol information available.\n");
|
---|
707 | }
|
---|
708 | return 1;
|
---|
709 | }
|
---|
710 |
|
---|
711 | /** Call function with zero parameters on each CPU */
|
---|
712 | int cmd_mcall0(cmd_arg_t *argv)
|
---|
713 | {
|
---|
714 | /*
|
---|
715 | * For each CPU, create a thread which will
|
---|
716 | * call the function.
|
---|
717 | */
|
---|
718 |
|
---|
719 | unsigned int i;
|
---|
720 | for (i = 0; i < config.cpu_count; i++) {
|
---|
721 | if (!cpus[i].active)
|
---|
722 | continue;
|
---|
723 |
|
---|
724 | thread_t *thread;
|
---|
725 | if ((thread = thread_create((void (*)(void *)) cmd_call0,
|
---|
726 | (void *) argv, TASK, THREAD_FLAG_NONE, "call0"))) {
|
---|
727 | printf("cpu%u: ", i);
|
---|
728 | thread_wire(thread, &cpus[i]);
|
---|
729 | thread_ready(thread);
|
---|
730 | thread_join(thread);
|
---|
731 | thread_detach(thread);
|
---|
732 | } else
|
---|
733 | printf("Unable to create thread for cpu%u\n", i);
|
---|
734 | }
|
---|
735 |
|
---|
736 | return 1;
|
---|
737 | }
|
---|
738 |
|
---|
739 | /** Call function with one parameter */
|
---|
740 | int cmd_call1(cmd_arg_t *argv)
|
---|
741 | {
|
---|
742 | uintptr_t symaddr;
|
---|
743 | char *symbol;
|
---|
744 | sysarg_t (*fnc)(sysarg_t, ...);
|
---|
745 | sysarg_t arg1 = argv[1].intval;
|
---|
746 | fncptr_t fptr;
|
---|
747 | int rc;
|
---|
748 |
|
---|
749 | symbol = (char *) argv->buffer;
|
---|
750 | rc = symtab_addr_lookup(symbol, &symaddr);
|
---|
751 |
|
---|
752 | if (rc == ENOENT) {
|
---|
753 | printf("Symbol %s not found.\n", symbol);
|
---|
754 | } else if (rc == EOVERFLOW) {
|
---|
755 | symtab_print_search(symbol);
|
---|
756 | printf("Duplicate symbol, be more specific.\n");
|
---|
757 | } else if (rc == EOK) {
|
---|
758 | ipl_t ipl;
|
---|
759 |
|
---|
760 | ipl = interrupts_disable();
|
---|
761 | fnc = (sysarg_t (*)(sysarg_t, ...))
|
---|
762 | arch_construct_function(&fptr, (void *) symaddr,
|
---|
763 | (void *) cmd_call1);
|
---|
764 | printf("Calling f(%#" PRIxn "): %p: %s\n", arg1,
|
---|
765 | (void *) symaddr, symbol);
|
---|
766 | printf("Result: %#" PRIxn "\n", fnc(arg1));
|
---|
767 | interrupts_restore(ipl);
|
---|
768 | } else {
|
---|
769 | printf("No symbol information available.\n");
|
---|
770 | }
|
---|
771 |
|
---|
772 | return 1;
|
---|
773 | }
|
---|
774 |
|
---|
775 | /** Call function with two parameters */
|
---|
776 | int cmd_call2(cmd_arg_t *argv)
|
---|
777 | {
|
---|
778 | uintptr_t symaddr;
|
---|
779 | char *symbol;
|
---|
780 | sysarg_t (*fnc)(sysarg_t, sysarg_t, ...);
|
---|
781 | sysarg_t arg1 = argv[1].intval;
|
---|
782 | sysarg_t arg2 = argv[2].intval;
|
---|
783 | fncptr_t fptr;
|
---|
784 | int rc;
|
---|
785 |
|
---|
786 | symbol = (char *) argv->buffer;
|
---|
787 | rc = symtab_addr_lookup(symbol, &symaddr);
|
---|
788 |
|
---|
789 | if (rc == ENOENT) {
|
---|
790 | printf("Symbol %s not found.\n", symbol);
|
---|
791 | } else if (rc == EOVERFLOW) {
|
---|
792 | symtab_print_search(symbol);
|
---|
793 | printf("Duplicate symbol, be more specific.\n");
|
---|
794 | } else if (rc == EOK) {
|
---|
795 | ipl_t ipl;
|
---|
796 |
|
---|
797 | ipl = interrupts_disable();
|
---|
798 | fnc = (sysarg_t (*)(sysarg_t, sysarg_t, ...))
|
---|
799 | arch_construct_function(&fptr, (void *) symaddr,
|
---|
800 | (void *) cmd_call2);
|
---|
801 | printf("Calling f(%#" PRIxn ", %#" PRIxn "): %p: %s\n",
|
---|
802 | arg1, arg2, (void *) symaddr, symbol);
|
---|
803 | printf("Result: %#" PRIxn "\n", fnc(arg1, arg2));
|
---|
804 | interrupts_restore(ipl);
|
---|
805 | } else {
|
---|
806 | printf("No symbol information available.\n");
|
---|
807 | }
|
---|
808 | return 1;
|
---|
809 | }
|
---|
810 |
|
---|
811 | /** Call function with three parameters */
|
---|
812 | int cmd_call3(cmd_arg_t *argv)
|
---|
813 | {
|
---|
814 | uintptr_t symaddr;
|
---|
815 | char *symbol;
|
---|
816 | sysarg_t (*fnc)(sysarg_t, sysarg_t, sysarg_t, ...);
|
---|
817 | sysarg_t arg1 = argv[1].intval;
|
---|
818 | sysarg_t arg2 = argv[2].intval;
|
---|
819 | sysarg_t arg3 = argv[3].intval;
|
---|
820 | fncptr_t fptr;
|
---|
821 | int rc;
|
---|
822 |
|
---|
823 | symbol = (char *) argv->buffer;
|
---|
824 | rc = symtab_addr_lookup(symbol, &symaddr);
|
---|
825 |
|
---|
826 | if (rc == ENOENT) {
|
---|
827 | printf("Symbol %s not found.\n", symbol);
|
---|
828 | } else if (rc == EOVERFLOW) {
|
---|
829 | symtab_print_search(symbol);
|
---|
830 | printf("Duplicate symbol, be more specific.\n");
|
---|
831 | } else if (rc == EOK) {
|
---|
832 | ipl_t ipl;
|
---|
833 |
|
---|
834 | ipl = interrupts_disable();
|
---|
835 | fnc = (sysarg_t (*)(sysarg_t, sysarg_t, sysarg_t, ...))
|
---|
836 | arch_construct_function(&fptr, (void *) symaddr,
|
---|
837 | (void *) cmd_call3);
|
---|
838 | printf("Calling f(%#" PRIxn ",%#" PRIxn ", %#" PRIxn "): %p: %s\n",
|
---|
839 | arg1, arg2, arg3, (void *) symaddr, symbol);
|
---|
840 | printf("Result: %#" PRIxn "\n", fnc(arg1, arg2, arg3));
|
---|
841 | interrupts_restore(ipl);
|
---|
842 | } else {
|
---|
843 | printf("No symbol information available.\n");
|
---|
844 | }
|
---|
845 | return 1;
|
---|
846 | }
|
---|
847 |
|
---|
848 | /** Print detailed description of 'describe' command. */
|
---|
849 | void desc_help(void)
|
---|
850 | {
|
---|
851 | printf("Syntax: describe command_name\n");
|
---|
852 | }
|
---|
853 |
|
---|
854 | /** Halt the kernel.
|
---|
855 | *
|
---|
856 | * @param argv Argument vector (ignored).
|
---|
857 | *
|
---|
858 | * @return 0 on failure, 1 on success (never returns).
|
---|
859 | */
|
---|
860 | int cmd_halt(cmd_arg_t *argv)
|
---|
861 | {
|
---|
862 | halt();
|
---|
863 | return 1;
|
---|
864 | }
|
---|
865 |
|
---|
866 | /** Command for printing TLB contents.
|
---|
867 | *
|
---|
868 | * @param argv Not used.
|
---|
869 | *
|
---|
870 | * @return Always returns 1.
|
---|
871 | */
|
---|
872 | int cmd_tlb(cmd_arg_t *argv)
|
---|
873 | {
|
---|
874 | tlb_print();
|
---|
875 | return 1;
|
---|
876 | }
|
---|
877 |
|
---|
878 | /** Command for printing physical memory configuration.
|
---|
879 | *
|
---|
880 | * @param argv Not used.
|
---|
881 | *
|
---|
882 | * @return Always returns 1.
|
---|
883 | */
|
---|
884 | int cmd_physmem(cmd_arg_t *argv)
|
---|
885 | {
|
---|
886 | physmem_print();
|
---|
887 | return 1;
|
---|
888 | }
|
---|
889 |
|
---|
890 | /** Write 4 byte value to address */
|
---|
891 | int cmd_set4(cmd_arg_t *argv)
|
---|
892 | {
|
---|
893 | uintptr_t addr;
|
---|
894 | uint32_t arg1 = argv[1].intval;
|
---|
895 | bool pointer = false;
|
---|
896 | int rc;
|
---|
897 |
|
---|
898 | if (((char *) argv->buffer)[0] == '*') {
|
---|
899 | rc = symtab_addr_lookup((char *) argv->buffer + 1, &addr);
|
---|
900 | pointer = true;
|
---|
901 | } else if (((char *) argv->buffer)[0] >= '0' &&
|
---|
902 | ((char *) argv->buffer)[0] <= '9') {
|
---|
903 | uint64_t value;
|
---|
904 | rc = str_uint64_t((char *) argv->buffer, NULL, 0, true, &value);
|
---|
905 | if (rc == EOK)
|
---|
906 | addr = (uintptr_t) value;
|
---|
907 | } else
|
---|
908 | rc = symtab_addr_lookup((char *) argv->buffer, &addr);
|
---|
909 |
|
---|
910 | if (rc == ENOENT)
|
---|
911 | printf("Symbol %s not found.\n", (char *) argv->buffer);
|
---|
912 | else if (rc == EINVAL)
|
---|
913 | printf("Invalid address.\n");
|
---|
914 | else if (rc == EOVERFLOW) {
|
---|
915 | symtab_print_search((char *) argv->buffer);
|
---|
916 | printf("Duplicate symbol (be more specific) or address overflow.\n");
|
---|
917 | } else if (rc == EOK) {
|
---|
918 | if (pointer)
|
---|
919 | addr = *(uintptr_t *) addr;
|
---|
920 | printf("Writing %#" PRIx32" -> %p\n", arg1, (void *) addr);
|
---|
921 | *(uint32_t *) addr = arg1;
|
---|
922 | } else
|
---|
923 | printf("No symbol information available.\n");
|
---|
924 |
|
---|
925 | return 1;
|
---|
926 | }
|
---|
927 |
|
---|
928 | /** Command for listings SLAB caches
|
---|
929 | *
|
---|
930 | * @param argv Ignores
|
---|
931 | *
|
---|
932 | * @return Always 1
|
---|
933 | */
|
---|
934 | int cmd_slabs(cmd_arg_t *argv)
|
---|
935 | {
|
---|
936 | slab_print_list();
|
---|
937 | return 1;
|
---|
938 | }
|
---|
939 |
|
---|
940 | /** Command for dumping sysinfo
|
---|
941 | *
|
---|
942 | * @param argv Ignores
|
---|
943 | *
|
---|
944 | * @return Always 1
|
---|
945 | */
|
---|
946 | int cmd_sysinfo(cmd_arg_t *argv)
|
---|
947 | {
|
---|
948 | sysinfo_dump(NULL);
|
---|
949 | return 1;
|
---|
950 | }
|
---|
951 |
|
---|
952 | /** Command for listing thread information
|
---|
953 | *
|
---|
954 | * @param argv Ignored
|
---|
955 | *
|
---|
956 | * @return Always 1
|
---|
957 | */
|
---|
958 | int cmd_threads(cmd_arg_t *argv)
|
---|
959 | {
|
---|
960 | if (str_cmp(flag_buf, "-a") == 0)
|
---|
961 | thread_print_list(true);
|
---|
962 | else if (str_cmp(flag_buf, "") == 0)
|
---|
963 | thread_print_list(false);
|
---|
964 | else
|
---|
965 | printf("Unknown argument \"%s\".\n", flag_buf);
|
---|
966 |
|
---|
967 | return 1;
|
---|
968 | }
|
---|
969 |
|
---|
970 | /** Command for listing task information
|
---|
971 | *
|
---|
972 | * @param argv Ignored
|
---|
973 | *
|
---|
974 | * @return Always 1
|
---|
975 | */
|
---|
976 | int cmd_tasks(cmd_arg_t *argv)
|
---|
977 | {
|
---|
978 | if (str_cmp(flag_buf, "-a") == 0)
|
---|
979 | task_print_list(true);
|
---|
980 | else if (str_cmp(flag_buf, "") == 0)
|
---|
981 | task_print_list(false);
|
---|
982 | else
|
---|
983 | printf("Unknown argument \"%s\".\n", flag_buf);
|
---|
984 |
|
---|
985 | return 1;
|
---|
986 | }
|
---|
987 |
|
---|
988 | #ifdef CONFIG_UDEBUG
|
---|
989 |
|
---|
990 | /** Command for printing thread stack trace
|
---|
991 | *
|
---|
992 | * @param argv Integer argument from cmdline expected
|
---|
993 | *
|
---|
994 | * return Always 1
|
---|
995 | *
|
---|
996 | */
|
---|
997 | int cmd_btrace(cmd_arg_t *argv)
|
---|
998 | {
|
---|
999 | thread_stack_trace(argv[0].intval);
|
---|
1000 | return 1;
|
---|
1001 | }
|
---|
1002 |
|
---|
1003 | #endif /* CONFIG_UDEBUG */
|
---|
1004 |
|
---|
1005 | /** Command for printing scheduler information
|
---|
1006 | *
|
---|
1007 | * @param argv Ignores
|
---|
1008 | *
|
---|
1009 | * @return Always 1
|
---|
1010 | */
|
---|
1011 | int cmd_sched(cmd_arg_t *argv)
|
---|
1012 | {
|
---|
1013 | sched_print_list();
|
---|
1014 | return 1;
|
---|
1015 | }
|
---|
1016 |
|
---|
1017 | /** Command for listing memory zones
|
---|
1018 | *
|
---|
1019 | * @param argv Ignored
|
---|
1020 | *
|
---|
1021 | * return Always 1
|
---|
1022 | */
|
---|
1023 | int cmd_zones(cmd_arg_t *argv)
|
---|
1024 | {
|
---|
1025 | zones_print_list();
|
---|
1026 | return 1;
|
---|
1027 | }
|
---|
1028 |
|
---|
1029 | /** Command for memory zone details
|
---|
1030 | *
|
---|
1031 | * @param argv Integer argument from cmdline expected
|
---|
1032 | *
|
---|
1033 | * return Always 1
|
---|
1034 | */
|
---|
1035 | int cmd_zone(cmd_arg_t *argv)
|
---|
1036 | {
|
---|
1037 | zone_print_one(argv[0].intval);
|
---|
1038 | return 1;
|
---|
1039 | }
|
---|
1040 |
|
---|
1041 | /** Command for printing task IPC details
|
---|
1042 | *
|
---|
1043 | * @param argv Integer argument from cmdline expected
|
---|
1044 | *
|
---|
1045 | * return Always 1
|
---|
1046 | */
|
---|
1047 | int cmd_ipc(cmd_arg_t *argv)
|
---|
1048 | {
|
---|
1049 | ipc_print_task(argv[0].intval);
|
---|
1050 | return 1;
|
---|
1051 | }
|
---|
1052 |
|
---|
1053 | /** Command for killing a task
|
---|
1054 | *
|
---|
1055 | * @param argv Integer argument from cmdline expected
|
---|
1056 | *
|
---|
1057 | * return 0 on failure, 1 on success.
|
---|
1058 | */
|
---|
1059 | int cmd_kill(cmd_arg_t *argv)
|
---|
1060 | {
|
---|
1061 | if (task_kill(argv[0].intval) != EOK)
|
---|
1062 | return 0;
|
---|
1063 |
|
---|
1064 | return 1;
|
---|
1065 | }
|
---|
1066 |
|
---|
1067 | /** Command for listing processors.
|
---|
1068 | *
|
---|
1069 | * @param argv Ignored.
|
---|
1070 | *
|
---|
1071 | * return Always 1.
|
---|
1072 | */
|
---|
1073 | int cmd_cpus(cmd_arg_t *argv)
|
---|
1074 | {
|
---|
1075 | cpu_list();
|
---|
1076 | return 1;
|
---|
1077 | }
|
---|
1078 |
|
---|
1079 | /** Command for printing kernel version.
|
---|
1080 | *
|
---|
1081 | * @param argv Ignored.
|
---|
1082 | *
|
---|
1083 | * return Always 1.
|
---|
1084 | */
|
---|
1085 | int cmd_version(cmd_arg_t *argv)
|
---|
1086 | {
|
---|
1087 | version_print();
|
---|
1088 | return 1;
|
---|
1089 | }
|
---|
1090 |
|
---|
1091 | /** Command for returning console back to userspace.
|
---|
1092 | *
|
---|
1093 | * @param argv Ignored.
|
---|
1094 | *
|
---|
1095 | * return Always 1.
|
---|
1096 | */
|
---|
1097 | int cmd_continue(cmd_arg_t *argv)
|
---|
1098 | {
|
---|
1099 | printf("The kernel will now relinquish the console.\n");
|
---|
1100 | release_console();
|
---|
1101 |
|
---|
1102 | event_notify_0(EVENT_KCONSOLE, false);
|
---|
1103 | indev_pop_character(stdin);
|
---|
1104 |
|
---|
1105 | return 1;
|
---|
1106 | }
|
---|
1107 |
|
---|
1108 | #ifdef CONFIG_TEST
|
---|
1109 | static bool run_test(const test_t *test)
|
---|
1110 | {
|
---|
1111 | printf("%s (%s)\n", test->name, test->desc);
|
---|
1112 |
|
---|
1113 | /* Update and read thread accounting
|
---|
1114 | for benchmarking */
|
---|
1115 | irq_spinlock_lock(&TASK->lock, true);
|
---|
1116 | uint64_t ucycles0, kcycles0;
|
---|
1117 | task_get_accounting(TASK, &ucycles0, &kcycles0);
|
---|
1118 | irq_spinlock_unlock(&TASK->lock, true);
|
---|
1119 |
|
---|
1120 | /* Execute the test */
|
---|
1121 | test_quiet = false;
|
---|
1122 | const char *ret = test->entry();
|
---|
1123 |
|
---|
1124 | /* Update and read thread accounting */
|
---|
1125 | uint64_t ucycles1, kcycles1;
|
---|
1126 | irq_spinlock_lock(&TASK->lock, true);
|
---|
1127 | task_get_accounting(TASK, &ucycles1, &kcycles1);
|
---|
1128 | irq_spinlock_unlock(&TASK->lock, true);
|
---|
1129 |
|
---|
1130 | uint64_t ucycles, kcycles;
|
---|
1131 | char usuffix, ksuffix;
|
---|
1132 | order_suffix(ucycles1 - ucycles0, &ucycles, &usuffix);
|
---|
1133 | order_suffix(kcycles1 - kcycles0, &kcycles, &ksuffix);
|
---|
1134 |
|
---|
1135 | printf("Time: %" PRIu64 "%c user cycles, %" PRIu64 "%c kernel cycles\n",
|
---|
1136 | ucycles, usuffix, kcycles, ksuffix);
|
---|
1137 |
|
---|
1138 | if (ret == NULL) {
|
---|
1139 | printf("Test passed\n");
|
---|
1140 | return true;
|
---|
1141 | }
|
---|
1142 |
|
---|
1143 | printf("%s\n", ret);
|
---|
1144 | return false;
|
---|
1145 | }
|
---|
1146 |
|
---|
1147 | static bool run_bench(const test_t *test, const uint32_t cnt)
|
---|
1148 | {
|
---|
1149 | uint32_t i;
|
---|
1150 | bool ret = true;
|
---|
1151 | uint64_t ucycles, kcycles;
|
---|
1152 | char usuffix, ksuffix;
|
---|
1153 |
|
---|
1154 | if (cnt < 1)
|
---|
1155 | return true;
|
---|
1156 |
|
---|
1157 | uint64_t *data = (uint64_t *) malloc(sizeof(uint64_t) * cnt, 0);
|
---|
1158 | if (data == NULL) {
|
---|
1159 | printf("Error allocating memory for statistics\n");
|
---|
1160 | return false;
|
---|
1161 | }
|
---|
1162 |
|
---|
1163 | for (i = 0; i < cnt; i++) {
|
---|
1164 | printf("%s (%u/%u) ... ", test->name, i + 1, cnt);
|
---|
1165 |
|
---|
1166 | /* Update and read thread accounting
|
---|
1167 | for benchmarking */
|
---|
1168 | irq_spinlock_lock(&TASK->lock, true);
|
---|
1169 | uint64_t ucycles0, kcycles0;
|
---|
1170 | task_get_accounting(TASK, &ucycles0, &kcycles0);
|
---|
1171 | irq_spinlock_unlock(&TASK->lock, true);
|
---|
1172 |
|
---|
1173 | /* Execute the test */
|
---|
1174 | test_quiet = true;
|
---|
1175 | const char *test_ret = test->entry();
|
---|
1176 |
|
---|
1177 | /* Update and read thread accounting */
|
---|
1178 | irq_spinlock_lock(&TASK->lock, true);
|
---|
1179 | uint64_t ucycles1, kcycles1;
|
---|
1180 | task_get_accounting(TASK, &ucycles1, &kcycles1);
|
---|
1181 | irq_spinlock_unlock(&TASK->lock, true);
|
---|
1182 |
|
---|
1183 | if (test_ret != NULL) {
|
---|
1184 | printf("%s\n", test_ret);
|
---|
1185 | ret = false;
|
---|
1186 | break;
|
---|
1187 | }
|
---|
1188 |
|
---|
1189 | data[i] = ucycles1 - ucycles0 + kcycles1 - kcycles0;
|
---|
1190 | order_suffix(ucycles1 - ucycles0, &ucycles, &usuffix);
|
---|
1191 | order_suffix(kcycles1 - kcycles0, &kcycles, &ksuffix);
|
---|
1192 | printf("OK (%" PRIu64 "%c user cycles, %" PRIu64 "%c kernel cycles)\n",
|
---|
1193 | ucycles, usuffix, kcycles, ksuffix);
|
---|
1194 | }
|
---|
1195 |
|
---|
1196 | if (ret) {
|
---|
1197 | printf("\n");
|
---|
1198 |
|
---|
1199 | uint64_t sum = 0;
|
---|
1200 |
|
---|
1201 | for (i = 0; i < cnt; i++) {
|
---|
1202 | sum += data[i];
|
---|
1203 | }
|
---|
1204 |
|
---|
1205 | order_suffix(sum / (uint64_t) cnt, &ucycles, &usuffix);
|
---|
1206 | printf("Average\t\t%" PRIu64 "%c\n", ucycles, usuffix);
|
---|
1207 | }
|
---|
1208 |
|
---|
1209 | free(data);
|
---|
1210 |
|
---|
1211 | return ret;
|
---|
1212 | }
|
---|
1213 |
|
---|
1214 | static void list_tests(void)
|
---|
1215 | {
|
---|
1216 | size_t len = 0;
|
---|
1217 | test_t *test;
|
---|
1218 |
|
---|
1219 | for (test = tests; test->name != NULL; test++) {
|
---|
1220 | if (str_length(test->name) > len)
|
---|
1221 | len = str_length(test->name);
|
---|
1222 | }
|
---|
1223 |
|
---|
1224 | unsigned int _len = (unsigned int) len;
|
---|
1225 | if ((_len != len) || (((int) _len) < 0)) {
|
---|
1226 | printf("Command length overflow\n");
|
---|
1227 | return;
|
---|
1228 | }
|
---|
1229 |
|
---|
1230 | for (test = tests; test->name != NULL; test++)
|
---|
1231 | printf("%-*s %s%s\n", _len, test->name, test->desc,
|
---|
1232 | (test->safe ? "" : " (unsafe)"));
|
---|
1233 |
|
---|
1234 | printf("%-*s Run all safe tests\n", _len, "*");
|
---|
1235 | }
|
---|
1236 |
|
---|
1237 | /** Command for listing and running kernel tests
|
---|
1238 | *
|
---|
1239 | * @param argv Argument vector.
|
---|
1240 | *
|
---|
1241 | * return Always 1.
|
---|
1242 | *
|
---|
1243 | */
|
---|
1244 | int cmd_test(cmd_arg_t *argv)
|
---|
1245 | {
|
---|
1246 | test_t *test;
|
---|
1247 |
|
---|
1248 | if (str_cmp((char *) argv->buffer, "*") == 0) {
|
---|
1249 | for (test = tests; test->name != NULL; test++) {
|
---|
1250 | if (test->safe) {
|
---|
1251 | printf("\n");
|
---|
1252 | if (!run_test(test))
|
---|
1253 | break;
|
---|
1254 | }
|
---|
1255 | }
|
---|
1256 | } else if (str_cmp((char *) argv->buffer, "") != 0) {
|
---|
1257 | bool fnd = false;
|
---|
1258 |
|
---|
1259 | for (test = tests; test->name != NULL; test++) {
|
---|
1260 | if (str_cmp(test->name, (char *) argv->buffer) == 0) {
|
---|
1261 | fnd = true;
|
---|
1262 | run_test(test);
|
---|
1263 | break;
|
---|
1264 | }
|
---|
1265 | }
|
---|
1266 |
|
---|
1267 | if (!fnd)
|
---|
1268 | printf("Unknown test\n");
|
---|
1269 | } else
|
---|
1270 | list_tests();
|
---|
1271 |
|
---|
1272 | return 1;
|
---|
1273 | }
|
---|
1274 |
|
---|
1275 | /** Command for returning kernel tests as benchmarks
|
---|
1276 | *
|
---|
1277 | * @param argv Argument vector.
|
---|
1278 | *
|
---|
1279 | * return Always 1.
|
---|
1280 | */
|
---|
1281 | int cmd_bench(cmd_arg_t *argv)
|
---|
1282 | {
|
---|
1283 | test_t *test;
|
---|
1284 | uint32_t cnt = argv[1].intval;
|
---|
1285 |
|
---|
1286 | if (str_cmp((char *) argv->buffer, "*") == 0) {
|
---|
1287 | for (test = tests; test->name != NULL; test++) {
|
---|
1288 | if (test->safe) {
|
---|
1289 | if (!run_bench(test, cnt))
|
---|
1290 | break;
|
---|
1291 | }
|
---|
1292 | }
|
---|
1293 | } else {
|
---|
1294 | bool fnd = false;
|
---|
1295 |
|
---|
1296 | for (test = tests; test->name != NULL; test++) {
|
---|
1297 | if (str_cmp(test->name, (char *) argv->buffer) == 0) {
|
---|
1298 | fnd = true;
|
---|
1299 |
|
---|
1300 | if (test->safe)
|
---|
1301 | run_bench(test, cnt);
|
---|
1302 | else
|
---|
1303 | printf("Unsafe test\n");
|
---|
1304 |
|
---|
1305 | break;
|
---|
1306 | }
|
---|
1307 | }
|
---|
1308 |
|
---|
1309 | if (!fnd)
|
---|
1310 | printf("Unknown test\n");
|
---|
1311 | }
|
---|
1312 |
|
---|
1313 | return 1;
|
---|
1314 | }
|
---|
1315 |
|
---|
1316 | #endif
|
---|
1317 |
|
---|
1318 | /** @}
|
---|
1319 | */
|
---|