source: mainline/kernel/generic/src/console/cmd.c@ e367939c

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since e367939c was b1c57a8, checked in by Jakub Jermar <jakub@…>, 11 years ago

Merge from lp:~adam-hraska+lp/helenos/rcu/.

Only merge from the feature branch and resolve all conflicts.

  • Property mode set to 100644
File size: 34.8 KB
Line 
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 <log.h>
48#include <panic.h>
49#include <typedefs.h>
50#include <adt/list.h>
51#include <arch.h>
52#include <config.h>
53#include <func.h>
54#include <str.h>
55#include <macros.h>
56#include <debug.h>
57#include <cpu.h>
58#include <mm/tlb.h>
59#include <mm/km.h>
60#include <arch/mm/tlb.h>
61#include <mm/frame.h>
62#include <main/version.h>
63#include <mm/slab.h>
64#include <proc/scheduler.h>
65#include <proc/thread.h>
66#include <proc/task.h>
67#include <ipc/ipc.h>
68#include <ipc/irq.h>
69#include <ipc/event.h>
70#include <sysinfo/sysinfo.h>
71#include <symtab.h>
72#include <synch/workqueue.h>
73#include <synch/rcu.h>
74#include <errno.h>
75
76#ifdef CONFIG_TEST
77#include <test.h>
78#endif
79
80/* Data and methods for 'help' command. */
81static int cmd_help(cmd_arg_t *argv);
82static cmd_info_t help_info = {
83 .name = "help",
84 .description = "List supported commands.",
85 .func = cmd_help,
86 .argc = 0
87};
88
89/* Data and methods for pio_read_8 command */
90static int cmd_pio_read_8(cmd_arg_t *argv);
91static cmd_arg_t pio_read_8_argv[] = { { .type = ARG_TYPE_INT } };
92static cmd_info_t pio_read_8_info = {
93 .name = "pio_read_8",
94 .description = "pio_read_8 <address> Read 1 byte from memory (or port).",
95 .func = cmd_pio_read_8,
96 .argc = 1,
97 .argv = pio_read_8_argv
98};
99
100/* Data and methods for pio_read_16 command */
101static int cmd_pio_read_16(cmd_arg_t *argv);
102static cmd_arg_t pio_read_16_argv[] = { { .type = ARG_TYPE_INT } };
103static cmd_info_t pio_read_16_info = {
104 .name = "pio_read_16",
105 .description = "pio_read_16 <address> Read 2 bytes from memory (or port).",
106 .func = cmd_pio_read_16,
107 .argc = 1,
108 .argv = pio_read_16_argv
109};
110
111/* Data and methods for pio_read_32 command */
112static int cmd_pio_read_32(cmd_arg_t *argv);
113static cmd_arg_t pio_read_32_argv[] = { { .type = ARG_TYPE_INT } };
114static cmd_info_t pio_read_32_info = {
115 .name = "pio_read_32",
116 .description = "pio_read_32 <address> Read 4 bytes from memory (or port).",
117 .func = cmd_pio_read_32,
118 .argc = 1,
119 .argv = pio_read_32_argv
120};
121
122/* Data and methods for pio_write_8 command */
123static int cmd_pio_write_8(cmd_arg_t *argv);
124static cmd_arg_t pio_write_8_argv[] = {
125 { .type = ARG_TYPE_INT },
126 { .type = ARG_TYPE_INT }
127};
128static cmd_info_t pio_write_8_info = {
129 .name = "pio_write_8",
130 .description = "pio_write_8 <address> <value> Write 1 byte to memory (or port).",
131 .func = cmd_pio_write_8,
132 .argc = 2,
133 .argv = pio_write_8_argv
134};
135
136/* Data and methods for pio_write_16 command */
137static int cmd_pio_write_16(cmd_arg_t *argv);
138static cmd_arg_t pio_write_16_argv[] = {
139 { .type = ARG_TYPE_INT },
140 { .type = ARG_TYPE_INT }
141};
142static cmd_info_t pio_write_16_info = {
143 .name = "pio_write_16",
144 .description = "pio_write_16 <address> <value> Write 2 bytes to memory (or port).",
145 .func = cmd_pio_write_16,
146 .argc = 2,
147 .argv = pio_write_16_argv
148};
149
150/* Data and methods for pio_write_32 command */
151static int cmd_pio_write_32(cmd_arg_t *argv);
152static cmd_arg_t pio_write_32_argv[] = {
153 { .type = ARG_TYPE_INT },
154 { .type = ARG_TYPE_INT }
155};
156static cmd_info_t pio_write_32_info = {
157 .name = "pio_write_32",
158 .description = "pio_write_32 <address> <value> Write 4 bytes to memory (or port).",
159 .func = cmd_pio_write_32,
160 .argc = 2,
161 .argv = pio_write_32_argv
162};
163
164/* Data and methods for 'reboot' command. */
165static int cmd_reboot(cmd_arg_t *argv);
166static cmd_info_t reboot_info = {
167 .name = "reboot",
168 .description = "Reboot system.",
169 .func = cmd_reboot,
170 .argc = 0
171};
172
173/* Data and methods for 'uptime' command. */
174static int cmd_uptime(cmd_arg_t *argv);
175static cmd_info_t uptime_info = {
176 .name = "uptime",
177 .description = "Show system uptime.",
178 .func = cmd_uptime,
179 .argc = 0
180};
181
182/* Data and methods for 'continue' command. */
183static int cmd_continue(cmd_arg_t *argv);
184static cmd_info_t continue_info = {
185 .name = "continue",
186 .description = "Return console back to userspace.",
187 .func = cmd_continue,
188 .argc = 0
189};
190
191#ifdef CONFIG_TEST
192
193/* Data and methods for 'test' command. */
194static char test_buf[MAX_CMDLINE + 1];
195static int cmd_test(cmd_arg_t *argv);
196static cmd_arg_t test_argv[] = {
197 {
198 .type = ARG_TYPE_STRING_OPTIONAL,
199 .buffer = test_buf,
200 .len = sizeof(test_buf)
201 }
202};
203static cmd_info_t test_info = {
204 .name = "test",
205 .description = "<test> List kernel tests or run a test.",
206 .func = cmd_test,
207 .argc = 1,
208 .argv = test_argv
209};
210
211/* Data and methods for 'bench' command. */
212static int cmd_bench(cmd_arg_t *argv);
213static cmd_arg_t bench_argv[] = {
214 {
215 .type = ARG_TYPE_STRING,
216 .buffer = test_buf,
217 .len = sizeof(test_buf)
218 },
219 {
220 .type = ARG_TYPE_INT,
221 }
222};
223static cmd_info_t bench_info = {
224 .name = "bench",
225 .description = "<test> <count> Run kernel test as benchmark.",
226 .func = cmd_bench,
227 .argc = 2,
228 .argv = bench_argv
229};
230
231#endif /* CONFIG_TEST */
232
233/* Data and methods for 'description' command. */
234static int cmd_desc(cmd_arg_t *argv);
235static void desc_help(void);
236static char desc_buf[MAX_CMDLINE + 1];
237static cmd_arg_t desc_argv = {
238 .type = ARG_TYPE_STRING,
239 .buffer = desc_buf,
240 .len = sizeof(desc_buf)
241};
242static cmd_info_t desc_info = {
243 .name = "describe",
244 .description = "<command> Describe specified command.",
245 .help = desc_help,
246 .func = cmd_desc,
247 .argc = 1,
248 .argv = &desc_argv
249};
250
251/* Data and methods for 'symaddr' command. */
252static int cmd_symaddr(cmd_arg_t *argv);
253static char symaddr_buf[MAX_CMDLINE + 1];
254static cmd_arg_t symaddr_argv = {
255 .type = ARG_TYPE_STRING,
256 .buffer = symaddr_buf,
257 .len = sizeof(symaddr_buf)
258};
259static cmd_info_t symaddr_info = {
260 .name = "symaddr",
261 .description = "<symbol> Return symbol address.",
262 .func = cmd_symaddr,
263 .argc = 1,
264 .argv = &symaddr_argv
265};
266
267/* Data and methods for 'set4' command. */
268static char set_buf[MAX_CMDLINE + 1];
269static int cmd_set4(cmd_arg_t *argv);
270static cmd_arg_t set4_argv[] = {
271 {
272 .type = ARG_TYPE_STRING,
273 .buffer = set_buf,
274 .len = sizeof(set_buf)
275 },
276 {
277 .type = ARG_TYPE_INT
278 }
279};
280static cmd_info_t set4_info = {
281 .name = "set4",
282 .description = "<addr> <value> Set 4B memory location to a value.",
283 .func = cmd_set4,
284 .argc = 2,
285 .argv = set4_argv
286};
287
288/* Data and methods for 'call0' and 'mcall0' command. */
289static char call0_buf[MAX_CMDLINE + 1];
290static char carg1_buf[MAX_CMDLINE + 1];
291static char carg2_buf[MAX_CMDLINE + 1];
292static char carg3_buf[MAX_CMDLINE + 1];
293
294static int cmd_call0(cmd_arg_t *argv);
295static cmd_arg_t call0_argv = {
296 .type = ARG_TYPE_STRING,
297 .buffer = call0_buf,
298 .len = sizeof(call0_buf)
299};
300static cmd_info_t call0_info = {
301 .name = "call0",
302 .description = "<function> Call function().",
303 .func = cmd_call0,
304 .argc = 1,
305 .argv = &call0_argv
306};
307
308/* Data and methods for 'mcall0' command. */
309static int cmd_mcall0(cmd_arg_t *argv);
310static cmd_arg_t mcall0_argv = {
311 .type = ARG_TYPE_STRING,
312 .buffer = call0_buf,
313 .len = sizeof(call0_buf)
314};
315static cmd_info_t mcall0_info = {
316 .name = "mcall0",
317 .description = "<function> Call function() on each CPU.",
318 .func = cmd_mcall0,
319 .argc = 1,
320 .argv = &mcall0_argv
321};
322
323/* Data and methods for 'call1' command. */
324static int cmd_call1(cmd_arg_t *argv);
325static cmd_arg_t call1_argv[] = {
326 {
327 .type = ARG_TYPE_STRING,
328 .buffer = call0_buf,
329 .len = sizeof(call0_buf)
330 },
331 {
332 .type = ARG_TYPE_VAR,
333 .buffer = carg1_buf,
334 .len = sizeof(carg1_buf)
335 }
336};
337static cmd_info_t call1_info = {
338 .name = "call1",
339 .description = "<function> <arg1> Call function(arg1).",
340 .func = cmd_call1,
341 .argc = 2,
342 .argv = call1_argv
343};
344
345/* Data and methods for 'call2' command. */
346static int cmd_call2(cmd_arg_t *argv);
347static cmd_arg_t call2_argv[] = {
348 {
349 .type = ARG_TYPE_STRING,
350 .buffer = call0_buf,
351 .len = sizeof(call0_buf)
352 },
353 {
354 .type = ARG_TYPE_VAR,
355 .buffer = carg1_buf,
356 .len = sizeof(carg1_buf)
357 },
358 {
359 .type = ARG_TYPE_VAR,
360 .buffer = carg2_buf,
361 .len = sizeof(carg2_buf)
362 }
363};
364static cmd_info_t call2_info = {
365 .name = "call2",
366 .description = "<function> <arg1> <arg2> Call function(arg1, arg2).",
367 .func = cmd_call2,
368 .argc = 3,
369 .argv = call2_argv
370};
371
372/* Data and methods for 'call3' command. */
373static int cmd_call3(cmd_arg_t *argv);
374static cmd_arg_t call3_argv[] = {
375 {
376 .type = ARG_TYPE_STRING,
377 .buffer = call0_buf,
378 .len = sizeof(call0_buf)
379 },
380 {
381 .type = ARG_TYPE_VAR,
382 .buffer = carg1_buf,
383 .len = sizeof(carg1_buf)
384 },
385 {
386 .type = ARG_TYPE_VAR,
387 .buffer = carg2_buf,
388 .len = sizeof(carg2_buf)
389 },
390 {
391 .type = ARG_TYPE_VAR,
392 .buffer = carg3_buf,
393 .len = sizeof(carg3_buf)
394 }
395
396};
397static cmd_info_t call3_info = {
398 .name = "call3",
399 .description = "<function> <arg1> <arg2> <arg3> Call function(arg1, arg2, arg3).",
400 .func = cmd_call3,
401 .argc = 4,
402 .argv = call3_argv
403};
404
405/* Data and methods for 'halt' command. */
406static int cmd_halt(cmd_arg_t *argv);
407static cmd_info_t halt_info = {
408 .name = "halt",
409 .description = "Halt the kernel.",
410 .func = cmd_halt,
411 .argc = 0
412};
413
414/* Data and methods for 'physmem' command. */
415static int cmd_physmem(cmd_arg_t *argv);
416cmd_info_t physmem_info = {
417 .name = "physmem",
418 .description = "Print physical memory configuration.",
419 .help = NULL,
420 .func = cmd_physmem,
421 .argc = 0,
422 .argv = NULL
423};
424
425/* Data and methods for 'tlb' command. */
426static int cmd_tlb(cmd_arg_t *argv);
427cmd_info_t tlb_info = {
428 .name = "tlb",
429 .description = "Print TLB of the current CPU.",
430 .help = NULL,
431 .func = cmd_tlb,
432 .argc = 0,
433 .argv = NULL
434};
435
436static char flag_buf[MAX_CMDLINE + 1];
437
438static int cmd_threads(cmd_arg_t *argv);
439static cmd_arg_t threads_argv = {
440 .type = ARG_TYPE_STRING_OPTIONAL,
441 .buffer = flag_buf,
442 .len = sizeof(flag_buf)
443};
444static cmd_info_t threads_info = {
445 .name = "threads",
446 .description = "List all threads (use -a for additional information).",
447 .func = cmd_threads,
448 .argc = 1,
449 .argv = &threads_argv
450};
451
452static int cmd_tasks(cmd_arg_t *argv);
453static cmd_arg_t tasks_argv = {
454 .type = ARG_TYPE_STRING_OPTIONAL,
455 .buffer = flag_buf,
456 .len = sizeof(flag_buf)
457};
458static cmd_info_t tasks_info = {
459 .name = "tasks",
460 .description = "List all tasks (use -a for additional information).",
461 .func = cmd_tasks,
462 .argc = 1,
463 .argv = &tasks_argv
464};
465
466#ifdef CONFIG_UDEBUG
467
468/* Data and methods for 'btrace' command */
469static int cmd_btrace(cmd_arg_t *argv);
470static cmd_arg_t btrace_argv = {
471 .type = ARG_TYPE_INT,
472};
473static cmd_info_t btrace_info = {
474 .name = "btrace",
475 .description = "<threadid> Show thread stack trace.",
476 .func = cmd_btrace,
477 .argc = 1,
478 .argv = &btrace_argv
479};
480
481#endif /* CONFIG_UDEBUG */
482
483static int cmd_sched(cmd_arg_t *argv);
484static cmd_info_t sched_info = {
485 .name = "scheduler",
486 .description = "Show scheduler information.",
487 .func = cmd_sched,
488 .argc = 0
489};
490
491static int cmd_slabs(cmd_arg_t *argv);
492static cmd_info_t slabs_info = {
493 .name = "slabs",
494 .description = "List slab caches.",
495 .func = cmd_slabs,
496 .argc = 0
497};
498
499static int cmd_sysinfo(cmd_arg_t *argv);
500static cmd_info_t sysinfo_info = {
501 .name = "sysinfo",
502 .description = "Dump sysinfo.",
503 .func = cmd_sysinfo,
504 .argc = 0
505};
506
507/* Data and methods for 'zones' command */
508static int cmd_zones(cmd_arg_t *argv);
509static cmd_info_t zones_info = {
510 .name = "zones",
511 .description = "List memory zones.",
512 .func = cmd_zones,
513 .argc = 0
514};
515
516/* Data and methods for 'zone' command */
517static int cmd_zone(cmd_arg_t *argv);
518static cmd_arg_t zone_argv = {
519 .type = ARG_TYPE_INT,
520};
521
522static cmd_info_t zone_info = {
523 .name = "zone",
524 .description = "<zone> Show memory zone structure.",
525 .func = cmd_zone,
526 .argc = 1,
527 .argv = &zone_argv
528};
529
530/* Data and methods for the 'workq' command */
531static int cmd_workq(cmd_arg_t *argv);
532static cmd_info_t workq_info = {
533 .name = "workq",
534 .description = "Show global workq information.",
535 .func = cmd_workq,
536 .argc = 0
537};
538
539/* Data and methods for the 'workq' command */
540static int cmd_rcu(cmd_arg_t *argv);
541static cmd_info_t rcu_info = {
542 .name = "rcu",
543 .description = "Show RCU run-time statistics.",
544 .func = cmd_rcu,
545 .argc = 0
546};
547
548/* Data and methods for 'ipc' command */
549static int cmd_ipc(cmd_arg_t *argv);
550static cmd_arg_t ipc_argv = {
551 .type = ARG_TYPE_INT,
552};
553static cmd_info_t ipc_info = {
554 .name = "ipc",
555 .description = "<taskid> Show IPC information of a task.",
556 .func = cmd_ipc,
557 .argc = 1,
558 .argv = &ipc_argv
559};
560
561/* Data and methods for 'kill' command */
562static int cmd_kill(cmd_arg_t *argv);
563static cmd_arg_t kill_argv = {
564 .type = ARG_TYPE_INT,
565};
566static cmd_info_t kill_info = {
567 .name = "kill",
568 .description = "<taskid> Kill a task.",
569 .func = cmd_kill,
570 .argc = 1,
571 .argv = &kill_argv
572};
573
574/* Data and methods for 'cpus' command. */
575static int cmd_cpus(cmd_arg_t *argv);
576cmd_info_t cpus_info = {
577 .name = "cpus",
578 .description = "List all processors.",
579 .help = NULL,
580 .func = cmd_cpus,
581 .argc = 0,
582 .argv = NULL
583};
584
585/* Data and methods for 'version' command. */
586static int cmd_version(cmd_arg_t *argv);
587cmd_info_t version_info = {
588 .name = "version",
589 .description = "Print version information.",
590 .help = NULL,
591 .func = cmd_version,
592 .argc = 0,
593 .argv = NULL
594};
595
596static cmd_info_t *basic_commands[] = {
597 &call0_info,
598 &mcall0_info,
599 &call1_info,
600 &call2_info,
601 &call3_info,
602 &continue_info,
603 &cpus_info,
604 &desc_info,
605 &halt_info,
606 &help_info,
607 &ipc_info,
608 &kill_info,
609 &physmem_info,
610 &reboot_info,
611 &rcu_info,
612 &sched_info,
613 &set4_info,
614 &slabs_info,
615 &symaddr_info,
616 &sysinfo_info,
617 &tasks_info,
618 &threads_info,
619 &tlb_info,
620 &uptime_info,
621 &version_info,
622 &workq_info,
623 &zones_info,
624 &zone_info,
625#ifdef CONFIG_TEST
626 &test_info,
627 &bench_info,
628#endif
629#ifdef CONFIG_UDEBUG
630 &btrace_info,
631#endif
632 &pio_read_8_info,
633 &pio_read_16_info,
634 &pio_read_32_info,
635 &pio_write_8_info,
636 &pio_write_16_info,
637 &pio_write_32_info,
638 NULL
639};
640
641
642/** Initialize command info structure.
643 *
644 * @param cmd Command info structure.
645 *
646 */
647void cmd_initialize(cmd_info_t *cmd)
648{
649 spinlock_initialize(&cmd->lock, "cmd.lock");
650 link_initialize(&cmd->link);
651}
652
653/** Initialize and register commands. */
654void cmd_init(void)
655{
656 unsigned int i;
657
658 for (i = 0; basic_commands[i]; i++) {
659 cmd_initialize(basic_commands[i]);
660 }
661
662 for (i = 0; basic_commands[i]; i++) {
663 if (!cmd_register(basic_commands[i])) {
664 log(LF_OTHER, LVL_ERROR,
665 "Cannot register command %s",
666 basic_commands[i]->name);
667 }
668 }
669}
670
671/** List supported commands.
672 *
673 * @param argv Argument vector.
674 *
675 * @return 0 on failure, 1 on success.
676 */
677int cmd_help(cmd_arg_t *argv)
678{
679 spinlock_lock(&cmd_lock);
680
681 size_t len = 0;
682 list_foreach(cmd_list, link, cmd_info_t, hlp) {
683 spinlock_lock(&hlp->lock);
684 if (str_length(hlp->name) > len)
685 len = str_length(hlp->name);
686 spinlock_unlock(&hlp->lock);
687 }
688
689 unsigned int _len = (unsigned int) len;
690 if ((_len != len) || (((int) _len) < 0)) {
691 log(LF_OTHER, LVL_ERROR, "Command length overflow");
692 return 1;
693 }
694
695 list_foreach(cmd_list, link, cmd_info_t, hlp) {
696 spinlock_lock(&hlp->lock);
697 printf("%-*s %s\n", _len, hlp->name, hlp->description);
698 spinlock_unlock(&hlp->lock);
699 }
700
701 spinlock_unlock(&cmd_lock);
702
703 return 1;
704}
705
706/** Read 1 byte from phys memory or io port.
707 *
708 * @param argv Argument vector.
709 *
710 * @return 0 on failure, 1 on success.
711 */
712static int cmd_pio_read_8(cmd_arg_t *argv)
713{
714 uint8_t *ptr = NULL;
715
716#ifdef IO_SPACE_BOUNDARY
717 if ((void *) argv->intval < IO_SPACE_BOUNDARY)
718 ptr = (void *) argv[0].intval;
719 else
720#endif
721 ptr = (uint8_t *) km_map(argv[0].intval, sizeof(uint8_t),
722 PAGE_NOT_CACHEABLE);
723
724 const uint8_t val = pio_read_8(ptr);
725 printf("read %" PRIxn ": %" PRIx8 "\n", argv[0].intval, val);
726
727#ifdef IO_SPACE_BOUNDARY
728 if ((void *) argv->intval < IO_SPACE_BOUNDARY)
729 return 1;
730#endif
731
732 km_unmap((uintptr_t) ptr, sizeof(uint8_t));
733 return 1;
734}
735
736/** Read 2 bytes from phys memory or io port.
737 *
738 * @param argv Argument vector.
739 *
740 * @return 0 on failure, 1 on success.
741 */
742static int cmd_pio_read_16(cmd_arg_t *argv)
743{
744 uint16_t *ptr = NULL;
745
746#ifdef IO_SPACE_BOUNDARY
747 if ((void *) argv->intval < IO_SPACE_BOUNDARY)
748 ptr = (void *) argv[0].intval;
749 else
750#endif
751 ptr = (uint16_t *) km_map(argv[0].intval, sizeof(uint16_t),
752 PAGE_NOT_CACHEABLE);
753
754 const uint16_t val = pio_read_16(ptr);
755 printf("read %" PRIxn ": %" PRIx16 "\n", argv[0].intval, val);
756
757#ifdef IO_SPACE_BOUNDARY
758 if ((void *) argv->intval < IO_SPACE_BOUNDARY)
759 return 1;
760#endif
761
762 km_unmap((uintptr_t) ptr, sizeof(uint16_t));
763 return 1;
764}
765
766/** Read 4 bytes from phys memory or io port.
767 *
768 * @param argv Argument vector.
769 *
770 * @return 0 on failure, 1 on success.
771 */
772static int cmd_pio_read_32(cmd_arg_t *argv)
773{
774 uint32_t *ptr = NULL;
775
776#ifdef IO_SPACE_BOUNDARY
777 if ((void *) argv->intval < IO_SPACE_BOUNDARY)
778 ptr = (void *) argv[0].intval;
779 else
780#endif
781 ptr = (uint32_t *) km_map(argv[0].intval, sizeof(uint32_t),
782 PAGE_NOT_CACHEABLE);
783
784 const uint32_t val = pio_read_32(ptr);
785 printf("read %" PRIxn ": %" PRIx32 "\n", argv[0].intval, val);
786
787#ifdef IO_SPACE_BOUNDARY
788 if ((void *) argv->intval < IO_SPACE_BOUNDARY)
789 return 1;
790#endif
791
792 km_unmap((uintptr_t) ptr, sizeof(uint32_t));
793 return 1;
794}
795
796/** Write 1 byte to phys memory or io port.
797 *
798 * @param argv Argument vector.
799 *
800 * @return 0 on failure, 1 on success.
801 */
802static int cmd_pio_write_8(cmd_arg_t *argv)
803{
804 uint8_t *ptr = NULL;
805
806#ifdef IO_SPACE_BOUNDARY
807 if ((void *) argv->intval < IO_SPACE_BOUNDARY)
808 ptr = (void *) argv[0].intval;
809 else
810#endif
811 ptr = (uint8_t *) km_map(argv[0].intval, sizeof(uint8_t),
812 PAGE_NOT_CACHEABLE);
813
814 printf("write %" PRIxn ": %" PRIx8 "\n", argv[0].intval,
815 (uint8_t) argv[1].intval);
816 pio_write_8(ptr, (uint8_t) argv[1].intval);
817
818#ifdef IO_SPACE_BOUNDARY
819 if ((void *) argv->intval < IO_SPACE_BOUNDARY)
820 return 1;
821#endif
822
823 km_unmap((uintptr_t) ptr, sizeof(uint8_t));
824 return 1;
825}
826
827/** Write 2 bytes to phys memory or io port.
828 *
829 * @param argv Argument vector.
830 *
831 * @return 0 on failure, 1 on success.
832 */
833static int cmd_pio_write_16(cmd_arg_t *argv)
834{
835 uint16_t *ptr = NULL;
836
837#ifdef IO_SPACE_BOUNDARY
838 if ((void *) argv->intval < IO_SPACE_BOUNDARY)
839 ptr = (void *) argv[0].intval;
840 else
841#endif
842 ptr = (uint16_t *) km_map(argv[0].intval, sizeof(uint16_t),
843 PAGE_NOT_CACHEABLE);
844
845 printf("write %" PRIxn ": %" PRIx16 "\n", argv[0].intval,
846 (uint16_t) argv[1].intval);
847 pio_write_16(ptr, (uint16_t) argv[1].intval);
848
849#ifdef IO_SPACE_BOUNDARY
850 if ((void *) argv->intval < IO_SPACE_BOUNDARY)
851 return 1;
852#endif
853
854 km_unmap((uintptr_t) ptr, sizeof(uint16_t));
855 return 1;
856}
857
858/** Write 4 bytes to phys memory or io port.
859 *
860 * @param argv Argument vector.
861 *
862 * @return 0 on failure, 1 on success.
863 */
864static int cmd_pio_write_32(cmd_arg_t *argv)
865{
866 uint32_t *ptr = NULL;
867
868#ifdef IO_SPACE_BOUNDARY
869 if ((void *) argv->intval < IO_SPACE_BOUNDARY)
870 ptr = (void *) argv[0].intval;
871 else
872#endif
873 ptr = (uint32_t *) km_map(argv[0].intval, sizeof(uint32_t),
874 PAGE_NOT_CACHEABLE);
875
876 printf("write %" PRIxn ": %" PRIx32 "\n", argv[0].intval,
877 (uint32_t) argv[1].intval);
878 pio_write_32(ptr, (uint32_t) argv[1].intval);
879
880#ifdef IO_SPACE_BOUNDARY
881 if ((void *) argv->intval < IO_SPACE_BOUNDARY)
882 return 1;
883#endif
884
885 km_unmap((uintptr_t) ptr, sizeof(uint32_t));
886 return 1;
887}
888
889/** Reboot the system.
890 *
891 * @param argv Argument vector.
892 *
893 * @return 0 on failure, 1 on success.
894 */
895int cmd_reboot(cmd_arg_t *argv)
896{
897 reboot();
898
899 /* Not reached */
900 return 1;
901}
902
903/** Print system uptime information.
904 *
905 * @param argv Argument vector.
906 *
907 * @return 0 on failure, 1 on success.
908 */
909int cmd_uptime(cmd_arg_t *argv)
910{
911 ASSERT(uptime);
912
913 /* This doesn't have to be very accurate */
914 sysarg_t sec = uptime->seconds1;
915
916 printf("Up %" PRIun " days, %" PRIun " hours, %" PRIun " minutes, %" PRIun " seconds\n",
917 sec / 86400, (sec % 86400) / 3600, (sec % 3600) / 60, sec % 60);
918
919 return 1;
920}
921
922/** Describe specified command.
923 *
924 * @param argv Argument vector.
925 *
926 * @return 0 on failure, 1 on success.
927 */
928int cmd_desc(cmd_arg_t *argv)
929{
930 spinlock_lock(&cmd_lock);
931
932 list_foreach(cmd_list, link, cmd_info_t, hlp) {
933 spinlock_lock(&hlp->lock);
934
935 if (str_lcmp(hlp->name, (const char *) argv->buffer, str_length(hlp->name)) == 0) {
936 printf("%s - %s\n", hlp->name, hlp->description);
937 if (hlp->help)
938 hlp->help();
939 spinlock_unlock(&hlp->lock);
940 break;
941 }
942
943 spinlock_unlock(&hlp->lock);
944 }
945
946 spinlock_unlock(&cmd_lock);
947
948 return 1;
949}
950
951/** Search symbol table */
952int cmd_symaddr(cmd_arg_t *argv)
953{
954 symtab_print_search((char *) argv->buffer);
955
956 return 1;
957}
958
959/** Call function with zero parameters */
960int cmd_call0(cmd_arg_t *argv)
961{
962 uintptr_t symaddr;
963 char *symbol;
964 sysarg_t (*fnc)(void);
965 fncptr_t fptr;
966 int rc;
967
968 symbol = (char *) argv->buffer;
969 rc = symtab_addr_lookup(symbol, &symaddr);
970
971 if (rc == ENOENT)
972 printf("Symbol %s not found.\n", symbol);
973 else if (rc == EOVERFLOW) {
974 symtab_print_search(symbol);
975 printf("Duplicate symbol, be more specific.\n");
976 } else if (rc == EOK) {
977 ipl_t ipl;
978
979 ipl = interrupts_disable();
980 fnc = (sysarg_t (*)(void)) arch_construct_function(&fptr,
981 (void *) symaddr, (void *) cmd_call0);
982 printf("Calling %s() (%p)\n", symbol, (void *) symaddr);
983 printf("Result: %#" PRIxn "\n", fnc());
984 interrupts_restore(ipl);
985 } else {
986 printf("No symbol information available.\n");
987 }
988 return 1;
989}
990
991/** Call function with zero parameters on each CPU */
992int cmd_mcall0(cmd_arg_t *argv)
993{
994 /*
995 * For each CPU, create a thread which will
996 * call the function.
997 */
998
999 unsigned int i;
1000 for (i = 0; i < config.cpu_count; i++) {
1001 if (!cpus[i].active)
1002 continue;
1003
1004 thread_t *thread;
1005 if ((thread = thread_create((void (*)(void *)) cmd_call0,
1006 (void *) argv, TASK, THREAD_FLAG_NONE, "call0"))) {
1007 printf("cpu%u: ", i);
1008 thread_wire(thread, &cpus[i]);
1009 thread_ready(thread);
1010 thread_join(thread);
1011 thread_detach(thread);
1012 } else
1013 printf("Unable to create thread for cpu%u\n", i);
1014 }
1015
1016 return 1;
1017}
1018
1019/** Call function with one parameter */
1020int cmd_call1(cmd_arg_t *argv)
1021{
1022 uintptr_t symaddr;
1023 char *symbol;
1024 sysarg_t (*fnc)(sysarg_t, ...);
1025 sysarg_t arg1 = argv[1].intval;
1026 fncptr_t fptr;
1027 int rc;
1028
1029 symbol = (char *) argv->buffer;
1030 rc = symtab_addr_lookup(symbol, &symaddr);
1031
1032 if (rc == ENOENT) {
1033 printf("Symbol %s not found.\n", symbol);
1034 } else if (rc == EOVERFLOW) {
1035 symtab_print_search(symbol);
1036 printf("Duplicate symbol, be more specific.\n");
1037 } else if (rc == EOK) {
1038 ipl_t ipl;
1039
1040 ipl = interrupts_disable();
1041 fnc = (sysarg_t (*)(sysarg_t, ...))
1042 arch_construct_function(&fptr, (void *) symaddr,
1043 (void *) cmd_call1);
1044 printf("Calling f(%#" PRIxn "): %p: %s\n", arg1,
1045 (void *) symaddr, symbol);
1046 printf("Result: %#" PRIxn "\n", fnc(arg1));
1047 interrupts_restore(ipl);
1048 } else {
1049 printf("No symbol information available.\n");
1050 }
1051
1052 return 1;
1053}
1054
1055/** Call function with two parameters */
1056int cmd_call2(cmd_arg_t *argv)
1057{
1058 uintptr_t symaddr;
1059 char *symbol;
1060 sysarg_t (*fnc)(sysarg_t, sysarg_t, ...);
1061 sysarg_t arg1 = argv[1].intval;
1062 sysarg_t arg2 = argv[2].intval;
1063 fncptr_t fptr;
1064 int rc;
1065
1066 symbol = (char *) argv->buffer;
1067 rc = symtab_addr_lookup(symbol, &symaddr);
1068
1069 if (rc == ENOENT) {
1070 printf("Symbol %s not found.\n", symbol);
1071 } else if (rc == EOVERFLOW) {
1072 symtab_print_search(symbol);
1073 printf("Duplicate symbol, be more specific.\n");
1074 } else if (rc == EOK) {
1075 ipl_t ipl;
1076
1077 ipl = interrupts_disable();
1078 fnc = (sysarg_t (*)(sysarg_t, sysarg_t, ...))
1079 arch_construct_function(&fptr, (void *) symaddr,
1080 (void *) cmd_call2);
1081 printf("Calling f(%#" PRIxn ", %#" PRIxn "): %p: %s\n",
1082 arg1, arg2, (void *) symaddr, symbol);
1083 printf("Result: %#" PRIxn "\n", fnc(arg1, arg2));
1084 interrupts_restore(ipl);
1085 } else {
1086 printf("No symbol information available.\n");
1087 }
1088 return 1;
1089}
1090
1091/** Call function with three parameters */
1092int cmd_call3(cmd_arg_t *argv)
1093{
1094 uintptr_t symaddr;
1095 char *symbol;
1096 sysarg_t (*fnc)(sysarg_t, sysarg_t, sysarg_t, ...);
1097 sysarg_t arg1 = argv[1].intval;
1098 sysarg_t arg2 = argv[2].intval;
1099 sysarg_t arg3 = argv[3].intval;
1100 fncptr_t fptr;
1101 int rc;
1102
1103 symbol = (char *) argv->buffer;
1104 rc = symtab_addr_lookup(symbol, &symaddr);
1105
1106 if (rc == ENOENT) {
1107 printf("Symbol %s not found.\n", symbol);
1108 } else if (rc == EOVERFLOW) {
1109 symtab_print_search(symbol);
1110 printf("Duplicate symbol, be more specific.\n");
1111 } else if (rc == EOK) {
1112 ipl_t ipl;
1113
1114 ipl = interrupts_disable();
1115 fnc = (sysarg_t (*)(sysarg_t, sysarg_t, sysarg_t, ...))
1116 arch_construct_function(&fptr, (void *) symaddr,
1117 (void *) cmd_call3);
1118 printf("Calling f(%#" PRIxn ",%#" PRIxn ", %#" PRIxn "): %p: %s\n",
1119 arg1, arg2, arg3, (void *) symaddr, symbol);
1120 printf("Result: %#" PRIxn "\n", fnc(arg1, arg2, arg3));
1121 interrupts_restore(ipl);
1122 } else {
1123 printf("No symbol information available.\n");
1124 }
1125 return 1;
1126}
1127
1128/** Print detailed description of 'describe' command. */
1129void desc_help(void)
1130{
1131 printf("Syntax: describe command_name\n");
1132}
1133
1134/** Halt the kernel.
1135 *
1136 * @param argv Argument vector (ignored).
1137 *
1138 * @return 0 on failure, 1 on success (never returns).
1139 */
1140int cmd_halt(cmd_arg_t *argv)
1141{
1142 halt();
1143 return 1;
1144}
1145
1146/** Command for printing TLB contents.
1147 *
1148 * @param argv Not used.
1149 *
1150 * @return Always returns 1.
1151 */
1152int cmd_tlb(cmd_arg_t *argv)
1153{
1154 tlb_print();
1155 return 1;
1156}
1157
1158/** Command for printing physical memory configuration.
1159 *
1160 * @param argv Not used.
1161 *
1162 * @return Always returns 1.
1163 */
1164int cmd_physmem(cmd_arg_t *argv)
1165{
1166 physmem_print();
1167 return 1;
1168}
1169
1170/** Write 4 byte value to address */
1171int cmd_set4(cmd_arg_t *argv)
1172{
1173 uintptr_t addr = 0; // Prevent -Werror=maybe-uninitialized
1174 uint32_t arg1 = argv[1].intval;
1175 bool pointer = false;
1176 int rc;
1177
1178 if (((char *) argv->buffer)[0] == '*') {
1179 rc = symtab_addr_lookup((char *) argv->buffer + 1, &addr);
1180 pointer = true;
1181 } else if (((char *) argv->buffer)[0] >= '0' &&
1182 ((char *) argv->buffer)[0] <= '9') {
1183 uint64_t value;
1184 rc = str_uint64_t((char *) argv->buffer, NULL, 0, true, &value);
1185 if (rc == EOK)
1186 addr = (uintptr_t) value;
1187 } else
1188 rc = symtab_addr_lookup((char *) argv->buffer, &addr);
1189
1190 if (rc == ENOENT)
1191 printf("Symbol %s not found.\n", (char *) argv->buffer);
1192 else if (rc == EINVAL)
1193 printf("Invalid address.\n");
1194 else if (rc == EOVERFLOW) {
1195 symtab_print_search((char *) argv->buffer);
1196 printf("Duplicate symbol (be more specific) or address overflow.\n");
1197 } else if (rc == EOK) {
1198 if (pointer)
1199 addr = *(uintptr_t *) addr;
1200 printf("Writing %#" PRIx32" -> %p\n", arg1, (void *) addr);
1201 *(uint32_t *) addr = arg1;
1202 } else
1203 printf("No symbol information available.\n");
1204
1205 return 1;
1206}
1207
1208/** Command for listings SLAB caches
1209 *
1210 * @param argv Ignores
1211 *
1212 * @return Always 1
1213 */
1214int cmd_slabs(cmd_arg_t *argv)
1215{
1216 slab_print_list();
1217 return 1;
1218}
1219
1220/** Command for dumping sysinfo
1221 *
1222 * @param argv Ignores
1223 *
1224 * @return Always 1
1225 */
1226int cmd_sysinfo(cmd_arg_t *argv)
1227{
1228 sysinfo_dump(NULL);
1229 return 1;
1230}
1231
1232/** Command for listing thread information
1233 *
1234 * @param argv Ignored
1235 *
1236 * @return Always 1
1237 */
1238int cmd_threads(cmd_arg_t *argv)
1239{
1240 if (str_cmp(flag_buf, "-a") == 0)
1241 thread_print_list(true);
1242 else if (str_cmp(flag_buf, "") == 0)
1243 thread_print_list(false);
1244 else
1245 printf("Unknown argument \"%s\".\n", flag_buf);
1246
1247 return 1;
1248}
1249
1250/** Command for listing task information
1251 *
1252 * @param argv Ignored
1253 *
1254 * @return Always 1
1255 */
1256int cmd_tasks(cmd_arg_t *argv)
1257{
1258 if (str_cmp(flag_buf, "-a") == 0)
1259 task_print_list(true);
1260 else if (str_cmp(flag_buf, "") == 0)
1261 task_print_list(false);
1262 else
1263 printf("Unknown argument \"%s\".\n", flag_buf);
1264
1265 return 1;
1266}
1267
1268#ifdef CONFIG_UDEBUG
1269
1270/** Command for printing thread stack trace
1271 *
1272 * @param argv Integer argument from cmdline expected
1273 *
1274 * return Always 1
1275 *
1276 */
1277int cmd_btrace(cmd_arg_t *argv)
1278{
1279 thread_stack_trace(argv[0].intval);
1280 return 1;
1281}
1282
1283#endif /* CONFIG_UDEBUG */
1284
1285/** Command for printing scheduler information
1286 *
1287 * @param argv Ignores
1288 *
1289 * @return Always 1
1290 */
1291int cmd_sched(cmd_arg_t *argv)
1292{
1293 sched_print_list();
1294 return 1;
1295}
1296
1297/** Prints information about the global work queue.
1298 *
1299 * @param argv Ignores
1300 *
1301 * @return Always 1
1302 */
1303int cmd_workq(cmd_arg_t *argv)
1304{
1305 workq_global_print_info();
1306 return 1;
1307}
1308
1309/** Prints RCU statistics.
1310 *
1311 * @param argv Ignores
1312 *
1313 * @return Always 1
1314 */
1315int cmd_rcu(cmd_arg_t *argv)
1316{
1317 rcu_print_stat();
1318 return 1;
1319}
1320
1321/** Command for listing memory zones
1322 *
1323 * @param argv Ignored
1324 *
1325 * return Always 1
1326 */
1327int cmd_zones(cmd_arg_t *argv)
1328{
1329 zones_print_list();
1330 return 1;
1331}
1332
1333/** Command for memory zone details
1334 *
1335 * @param argv Integer argument from cmdline expected
1336 *
1337 * return Always 1
1338 */
1339int cmd_zone(cmd_arg_t *argv)
1340{
1341 zone_print_one(argv[0].intval);
1342 return 1;
1343}
1344
1345/** Command for printing task IPC details
1346 *
1347 * @param argv Integer argument from cmdline expected
1348 *
1349 * return Always 1
1350 */
1351int cmd_ipc(cmd_arg_t *argv)
1352{
1353 ipc_print_task(argv[0].intval);
1354 return 1;
1355}
1356
1357/** Command for killing a task
1358 *
1359 * @param argv Integer argument from cmdline expected
1360 *
1361 * return 0 on failure, 1 on success.
1362 */
1363int cmd_kill(cmd_arg_t *argv)
1364{
1365 if (task_kill(argv[0].intval) != EOK)
1366 return 0;
1367
1368 return 1;
1369}
1370
1371/** Command for listing processors.
1372 *
1373 * @param argv Ignored.
1374 *
1375 * return Always 1.
1376 */
1377int cmd_cpus(cmd_arg_t *argv)
1378{
1379 cpu_list();
1380 return 1;
1381}
1382
1383/** Command for printing kernel version.
1384 *
1385 * @param argv Ignored.
1386 *
1387 * return Always 1.
1388 */
1389int cmd_version(cmd_arg_t *argv)
1390{
1391 version_print();
1392 return 1;
1393}
1394
1395/** Command for returning console back to userspace.
1396 *
1397 * @param argv Ignored.
1398 *
1399 * return Always 1.
1400 */
1401int cmd_continue(cmd_arg_t *argv)
1402{
1403 printf("The kernel will now relinquish the console.\n");
1404 release_console();
1405 indev_pop_character(stdin);
1406
1407 return 1;
1408}
1409
1410#ifdef CONFIG_TEST
1411static bool run_test(const test_t *test)
1412{
1413 printf("%s (%s)\n", test->name, test->desc);
1414
1415 /* Update and read thread accounting
1416 for benchmarking */
1417 irq_spinlock_lock(&TASK->lock, true);
1418 uint64_t ucycles0, kcycles0;
1419 task_get_accounting(TASK, &ucycles0, &kcycles0);
1420 irq_spinlock_unlock(&TASK->lock, true);
1421
1422 /* Execute the test */
1423 test_quiet = false;
1424 const char *ret = test->entry();
1425
1426 /* Update and read thread accounting */
1427 uint64_t ucycles1, kcycles1;
1428 irq_spinlock_lock(&TASK->lock, true);
1429 task_get_accounting(TASK, &ucycles1, &kcycles1);
1430 irq_spinlock_unlock(&TASK->lock, true);
1431
1432 uint64_t ucycles, kcycles;
1433 char usuffix, ksuffix;
1434 order_suffix(ucycles1 - ucycles0, &ucycles, &usuffix);
1435 order_suffix(kcycles1 - kcycles0, &kcycles, &ksuffix);
1436
1437 printf("Time: %" PRIu64 "%c user cycles, %" PRIu64 "%c kernel cycles\n",
1438 ucycles, usuffix, kcycles, ksuffix);
1439
1440 if (ret == NULL) {
1441 printf("Test passed\n");
1442 return true;
1443 }
1444
1445 printf("%s\n", ret);
1446 return false;
1447}
1448
1449static bool run_bench(const test_t *test, const uint32_t cnt)
1450{
1451 uint32_t i;
1452 bool ret = true;
1453 uint64_t ucycles, kcycles;
1454 char usuffix, ksuffix;
1455
1456 if (cnt < 1)
1457 return true;
1458
1459 uint64_t *data = (uint64_t *) malloc(sizeof(uint64_t) * cnt, 0);
1460 if (data == NULL) {
1461 printf("Error allocating memory for statistics\n");
1462 return false;
1463 }
1464
1465 for (i = 0; i < cnt; i++) {
1466 printf("%s (%u/%u) ... ", test->name, i + 1, cnt);
1467
1468 /* Update and read thread accounting
1469 for benchmarking */
1470 irq_spinlock_lock(&TASK->lock, true);
1471 uint64_t ucycles0, kcycles0;
1472 task_get_accounting(TASK, &ucycles0, &kcycles0);
1473 irq_spinlock_unlock(&TASK->lock, true);
1474
1475 /* Execute the test */
1476 test_quiet = true;
1477 const char *test_ret = test->entry();
1478
1479 /* Update and read thread accounting */
1480 irq_spinlock_lock(&TASK->lock, true);
1481 uint64_t ucycles1, kcycles1;
1482 task_get_accounting(TASK, &ucycles1, &kcycles1);
1483 irq_spinlock_unlock(&TASK->lock, true);
1484
1485 if (test_ret != NULL) {
1486 printf("%s\n", test_ret);
1487 ret = false;
1488 break;
1489 }
1490
1491 data[i] = ucycles1 - ucycles0 + kcycles1 - kcycles0;
1492 order_suffix(ucycles1 - ucycles0, &ucycles, &usuffix);
1493 order_suffix(kcycles1 - kcycles0, &kcycles, &ksuffix);
1494 printf("OK (%" PRIu64 "%c user cycles, %" PRIu64 "%c kernel cycles)\n",
1495 ucycles, usuffix, kcycles, ksuffix);
1496 }
1497
1498 if (ret) {
1499 printf("\n");
1500
1501 uint64_t sum = 0;
1502
1503 for (i = 0; i < cnt; i++) {
1504 sum += data[i];
1505 }
1506
1507 order_suffix(sum / (uint64_t) cnt, &ucycles, &usuffix);
1508 printf("Average\t\t%" PRIu64 "%c\n", ucycles, usuffix);
1509 }
1510
1511 free(data);
1512
1513 return ret;
1514}
1515
1516static void list_tests(void)
1517{
1518 size_t len = 0;
1519 test_t *test;
1520
1521 for (test = tests; test->name != NULL; test++) {
1522 if (str_length(test->name) > len)
1523 len = str_length(test->name);
1524 }
1525
1526 unsigned int _len = (unsigned int) len;
1527 if ((_len != len) || (((int) _len) < 0)) {
1528 printf("Command length overflow\n");
1529 return;
1530 }
1531
1532 for (test = tests; test->name != NULL; test++)
1533 printf("%-*s %s%s\n", _len, test->name, test->desc,
1534 (test->safe ? "" : " (unsafe)"));
1535
1536 printf("%-*s Run all safe tests\n", _len, "*");
1537}
1538
1539/** Command for listing and running kernel tests
1540 *
1541 * @param argv Argument vector.
1542 *
1543 * return Always 1.
1544 *
1545 */
1546int cmd_test(cmd_arg_t *argv)
1547{
1548 test_t *test;
1549
1550 if (str_cmp((char *) argv->buffer, "*") == 0) {
1551 for (test = tests; test->name != NULL; test++) {
1552 if (test->safe) {
1553 printf("\n");
1554 if (!run_test(test))
1555 break;
1556 }
1557 }
1558 } else if (str_cmp((char *) argv->buffer, "") != 0) {
1559 bool fnd = false;
1560
1561 for (test = tests; test->name != NULL; test++) {
1562 if (str_cmp(test->name, (char *) argv->buffer) == 0) {
1563 fnd = true;
1564 run_test(test);
1565 break;
1566 }
1567 }
1568
1569 if (!fnd)
1570 printf("Unknown test\n");
1571 } else
1572 list_tests();
1573
1574 return 1;
1575}
1576
1577/** Command for returning kernel tests as benchmarks
1578 *
1579 * @param argv Argument vector.
1580 *
1581 * return Always 1.
1582 */
1583int cmd_bench(cmd_arg_t *argv)
1584{
1585 test_t *test;
1586 uint32_t cnt = argv[1].intval;
1587
1588 if (str_cmp((char *) argv->buffer, "*") == 0) {
1589 for (test = tests; test->name != NULL; test++) {
1590 if (test->safe) {
1591 if (!run_bench(test, cnt))
1592 break;
1593 }
1594 }
1595 } else {
1596 bool fnd = false;
1597
1598 for (test = tests; test->name != NULL; test++) {
1599 if (str_cmp(test->name, (char *) argv->buffer) == 0) {
1600 fnd = true;
1601
1602 if (test->safe)
1603 run_bench(test, cnt);
1604 else
1605 printf("Unsafe test\n");
1606
1607 break;
1608 }
1609 }
1610
1611 if (!fnd)
1612 printf("Unknown test\n");
1613 }
1614
1615 return 1;
1616}
1617
1618#endif
1619
1620/** @}
1621 */
Note: See TracBrowser for help on using the repository browser.