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

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 550523f5 was feeac0d, checked in by Jiri Svoboda <jiri@…>, 12 years ago

Simplify use of list_foreach.

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