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

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since e2b762ec was e2b762ec, checked in by Jiri Svoboda <jirik.svoboda@…>, 16 years ago

Make kernel symbol information optional.

  • Property mode set to 100644
File size: 24.1 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 <arch/types.h>
49#include <adt/list.h>
50#include <arch.h>
51#include <config.h>
52#include <func.h>
53#include <string.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
68#ifdef CONFIG_SYMTAB
69#include <symtab.h>
70#endif
71
72#ifdef CONFIG_TEST
73#include <test.h>
74#endif
75
76/* Data and methods for 'help' command. */
77static int cmd_help(cmd_arg_t *argv);
78static cmd_info_t help_info = {
79 .name = "help",
80 .description = "List of supported commands.",
81 .func = cmd_help,
82 .argc = 0
83};
84
85static int cmd_reboot(cmd_arg_t *argv);
86static cmd_info_t reboot_info = {
87 .name = "reboot",
88 .description = "Reboot.",
89 .func = cmd_reboot,
90 .argc = 0
91};
92
93static int cmd_uptime(cmd_arg_t *argv);
94static cmd_info_t uptime_info = {
95 .name = "uptime",
96 .description = "Print uptime information.",
97 .func = cmd_uptime,
98 .argc = 0
99};
100
101static int cmd_continue(cmd_arg_t *argv);
102static cmd_info_t continue_info = {
103 .name = "continue",
104 .description = "Return console back to userspace.",
105 .func = cmd_continue,
106 .argc = 0
107};
108
109#ifdef CONFIG_TEST
110static int cmd_tests(cmd_arg_t *argv);
111static cmd_info_t tests_info = {
112 .name = "tests",
113 .description = "Print available kernel tests.",
114 .func = cmd_tests,
115 .argc = 0
116};
117
118static char test_buf[MAX_CMDLINE + 1];
119static int cmd_test(cmd_arg_t *argv);
120static cmd_arg_t test_argv[] = {
121 {
122 .type = ARG_TYPE_STRING,
123 .buffer = test_buf,
124 .len = sizeof(test_buf)
125 }
126};
127static cmd_info_t test_info = {
128 .name = "test",
129 .description = "Run kernel test.",
130 .func = cmd_test,
131 .argc = 1,
132 .argv = test_argv
133};
134
135static int cmd_bench(cmd_arg_t *argv);
136static cmd_arg_t bench_argv[] = {
137 {
138 .type = ARG_TYPE_STRING,
139 .buffer = test_buf,
140 .len = sizeof(test_buf)
141 },
142 {
143 .type = ARG_TYPE_INT,
144 }
145};
146static cmd_info_t bench_info = {
147 .name = "bench",
148 .description = "Run kernel test as benchmark.",
149 .func = cmd_bench,
150 .argc = 2,
151 .argv = bench_argv
152};
153#endif
154
155/* Data and methods for 'description' command. */
156static int cmd_desc(cmd_arg_t *argv);
157static void desc_help(void);
158static char desc_buf[MAX_CMDLINE+1];
159static cmd_arg_t desc_argv = {
160 .type = ARG_TYPE_STRING,
161 .buffer = desc_buf,
162 .len = sizeof(desc_buf)
163};
164static cmd_info_t desc_info = {
165 .name = "describe",
166 .description = "Describe specified command.",
167 .help = desc_help,
168 .func = cmd_desc,
169 .argc = 1,
170 .argv = &desc_argv
171};
172
173#ifdef CONFIG_SYMTAB
174/* Data and methods for 'symaddr' command. */
175static int cmd_symaddr(cmd_arg_t *argv);
176static char symaddr_buf[MAX_CMDLINE+1];
177static cmd_arg_t symaddr_argv = {
178 .type = ARG_TYPE_STRING,
179 .buffer = symaddr_buf,
180 .len = sizeof(symaddr_buf)
181};
182static cmd_info_t symaddr_info = {
183 .name = "symaddr",
184 .description = "Return symbol address.",
185 .func = cmd_symaddr,
186 .argc = 1,
187 .argv = &symaddr_argv
188};
189#endif
190
191static char set_buf[MAX_CMDLINE+1];
192static int cmd_set4(cmd_arg_t *argv);
193static cmd_arg_t set4_argv[] = {
194 {
195 .type = ARG_TYPE_STRING,
196 .buffer = set_buf,
197 .len = sizeof(set_buf)
198 },
199 {
200 .type = ARG_TYPE_INT
201 }
202};
203static cmd_info_t set4_info = {
204 .name = "set4",
205 .description = "set <dest_addr> <value> - 4byte version",
206 .func = cmd_set4,
207 .argc = 2,
208 .argv = set4_argv
209};
210
211/* Data and methods for 'call0' command. */
212static char call0_buf[MAX_CMDLINE + 1];
213static char carg1_buf[MAX_CMDLINE + 1];
214static char carg2_buf[MAX_CMDLINE + 1];
215static char carg3_buf[MAX_CMDLINE + 1];
216
217static int cmd_call0(cmd_arg_t *argv);
218static cmd_arg_t call0_argv = {
219 .type = ARG_TYPE_STRING,
220 .buffer = call0_buf,
221 .len = sizeof(call0_buf)
222};
223static cmd_info_t call0_info = {
224 .name = "call0",
225 .description = "call0 <function> -> call function().",
226 .func = cmd_call0,
227 .argc = 1,
228 .argv = &call0_argv
229};
230
231/* Data and methods for 'mcall0' command. */
232static int cmd_mcall0(cmd_arg_t *argv);
233static cmd_arg_t mcall0_argv = {
234 .type = ARG_TYPE_STRING,
235 .buffer = call0_buf,
236 .len = sizeof(call0_buf)
237};
238static cmd_info_t mcall0_info = {
239 .name = "mcall0",
240 .description = "mcall0 <function> -> call function() on each CPU.",
241 .func = cmd_mcall0,
242 .argc = 1,
243 .argv = &mcall0_argv
244};
245
246/* Data and methods for 'call1' command. */
247static int cmd_call1(cmd_arg_t *argv);
248static cmd_arg_t call1_argv[] = {
249 {
250 .type = ARG_TYPE_STRING,
251 .buffer = call0_buf,
252 .len = sizeof(call0_buf)
253 },
254 {
255 .type = ARG_TYPE_VAR,
256 .buffer = carg1_buf,
257 .len = sizeof(carg1_buf)
258 }
259};
260static cmd_info_t call1_info = {
261 .name = "call1",
262 .description = "call1 <function> <arg1> -> call function(arg1).",
263 .func = cmd_call1,
264 .argc = 2,
265 .argv = call1_argv
266};
267
268/* Data and methods for 'call2' command. */
269static int cmd_call2(cmd_arg_t *argv);
270static cmd_arg_t call2_argv[] = {
271 {
272 .type = ARG_TYPE_STRING,
273 .buffer = call0_buf,
274 .len = sizeof(call0_buf)
275 },
276 {
277 .type = ARG_TYPE_VAR,
278 .buffer = carg1_buf,
279 .len = sizeof(carg1_buf)
280 },
281 {
282 .type = ARG_TYPE_VAR,
283 .buffer = carg2_buf,
284 .len = sizeof(carg2_buf)
285 }
286};
287static cmd_info_t call2_info = {
288 .name = "call2",
289 .description = "call2 <function> <arg1> <arg2> -> call function(arg1,arg2).",
290 .func = cmd_call2,
291 .argc = 3,
292 .argv = call2_argv
293};
294
295/* Data and methods for 'call3' command. */
296static int cmd_call3(cmd_arg_t *argv);
297static cmd_arg_t call3_argv[] = {
298 {
299 .type = ARG_TYPE_STRING,
300 .buffer = call0_buf,
301 .len = sizeof(call0_buf)
302 },
303 {
304 .type = ARG_TYPE_VAR,
305 .buffer = carg1_buf,
306 .len = sizeof(carg1_buf)
307 },
308 {
309 .type = ARG_TYPE_VAR,
310 .buffer = carg2_buf,
311 .len = sizeof(carg2_buf)
312 },
313 {
314 .type = ARG_TYPE_VAR,
315 .buffer = carg3_buf,
316 .len = sizeof(carg3_buf)
317 }
318
319};
320static cmd_info_t call3_info = {
321 .name = "call3",
322 .description = "call3 <function> <arg1> <arg2> <arg3> -> call function(arg1,arg2,arg3).",
323 .func = cmd_call3,
324 .argc = 4,
325 .argv = call3_argv
326};
327
328/* Data and methods for 'halt' command. */
329static int cmd_halt(cmd_arg_t *argv);
330static cmd_info_t halt_info = {
331 .name = "halt",
332 .description = "Halt the kernel.",
333 .func = cmd_halt,
334 .argc = 0
335};
336
337/* Data and methods for 'physmem' command. */
338static int cmd_physmem(cmd_arg_t *argv);
339cmd_info_t physmem_info = {
340 .name = "physmem",
341 .description = "Print physical memory configuration.",
342 .help = NULL,
343 .func = cmd_physmem,
344 .argc = 0,
345 .argv = NULL
346};
347
348/* Data and methods for 'tlb' command. */
349static int cmd_tlb(cmd_arg_t *argv);
350cmd_info_t tlb_info = {
351 .name = "tlb",
352 .description = "Print TLB of current processor.",
353 .help = NULL,
354 .func = cmd_tlb,
355 .argc = 0,
356 .argv = NULL
357};
358
359static int cmd_threads(cmd_arg_t *argv);
360static cmd_info_t threads_info = {
361 .name = "threads",
362 .description = "List all threads.",
363 .func = cmd_threads,
364 .argc = 0
365};
366
367static int cmd_tasks(cmd_arg_t *argv);
368static cmd_info_t tasks_info = {
369 .name = "tasks",
370 .description = "List all tasks.",
371 .func = cmd_tasks,
372 .argc = 0
373};
374
375
376static int cmd_sched(cmd_arg_t *argv);
377static cmd_info_t sched_info = {
378 .name = "scheduler",
379 .description = "List all scheduler information.",
380 .func = cmd_sched,
381 .argc = 0
382};
383
384static int cmd_slabs(cmd_arg_t *argv);
385static cmd_info_t slabs_info = {
386 .name = "slabs",
387 .description = "List slab caches.",
388 .func = cmd_slabs,
389 .argc = 0
390};
391
392/* Data and methods for 'zones' command */
393static int cmd_zones(cmd_arg_t *argv);
394static cmd_info_t zones_info = {
395 .name = "zones",
396 .description = "List of memory zones.",
397 .func = cmd_zones,
398 .argc = 0
399};
400
401/* Data and methods for 'ipc' command */
402static int cmd_ipc(cmd_arg_t *argv);
403static cmd_arg_t ipc_argv = {
404 .type = ARG_TYPE_INT,
405};
406static cmd_info_t ipc_info = {
407 .name = "ipc",
408 .description = "ipc <taskid> Show IPC information of given task.",
409 .func = cmd_ipc,
410 .argc = 1,
411 .argv = &ipc_argv
412};
413
414/* Data and methods for 'zone' command */
415static int cmd_zone(cmd_arg_t *argv);
416static cmd_arg_t zone_argv = {
417 .type = ARG_TYPE_INT,
418};
419
420static cmd_info_t zone_info = {
421 .name = "zone",
422 .description = "Show memory zone structure.",
423 .func = cmd_zone,
424 .argc = 1,
425 .argv = &zone_argv
426};
427
428/* Data and methods for 'cpus' command. */
429static int cmd_cpus(cmd_arg_t *argv);
430cmd_info_t cpus_info = {
431 .name = "cpus",
432 .description = "List all processors.",
433 .help = NULL,
434 .func = cmd_cpus,
435 .argc = 0,
436 .argv = NULL
437};
438
439/* Data and methods for 'version' command. */
440static int cmd_version(cmd_arg_t *argv);
441cmd_info_t version_info = {
442 .name = "version",
443 .description = "Print version information.",
444 .help = NULL,
445 .func = cmd_version,
446 .argc = 0,
447 .argv = NULL
448};
449
450static cmd_info_t *basic_commands[] = {
451 &call0_info,
452 &mcall0_info,
453 &call1_info,
454 &call2_info,
455 &call3_info,
456 &continue_info,
457 &cpus_info,
458 &desc_info,
459 &reboot_info,
460 &uptime_info,
461 &halt_info,
462 &help_info,
463 &ipc_info,
464 &set4_info,
465 &slabs_info,
466#ifdef CONFIG_SYMTAB
467 &symaddr_info,
468#endif
469 &sched_info,
470 &threads_info,
471 &tasks_info,
472 &physmem_info,
473 &tlb_info,
474 &version_info,
475 &zones_info,
476 &zone_info,
477#ifdef CONFIG_TEST
478 &tests_info,
479 &test_info,
480 &bench_info,
481#endif
482 NULL
483};
484
485
486/** Initialize command info structure.
487 *
488 * @param cmd Command info structure.
489 *
490 */
491void cmd_initialize(cmd_info_t *cmd)
492{
493 spinlock_initialize(&cmd->lock, "cmd");
494 link_initialize(&cmd->link);
495}
496
497/** Initialize and register commands. */
498void cmd_init(void)
499{
500 unsigned int i;
501
502 for (i = 0; basic_commands[i]; i++) {
503 cmd_initialize(basic_commands[i]);
504 if (!cmd_register(basic_commands[i]))
505 printf("Cannot register command %s\n", basic_commands[i]->name);
506 }
507}
508
509
510/** List supported commands.
511 *
512 * @param argv Argument vector.
513 *
514 * @return 0 on failure, 1 on success.
515 */
516int cmd_help(cmd_arg_t *argv)
517{
518 spinlock_lock(&cmd_lock);
519
520 link_t *cur;
521 size_t len = 0;
522 for (cur = cmd_head.next; cur != &cmd_head; cur = cur->next) {
523 cmd_info_t *hlp;
524 hlp = list_get_instance(cur, cmd_info_t, link);
525
526 spinlock_lock(&hlp->lock);
527 if (strlen(hlp->name) > len)
528 len = strlen(hlp->name);
529 spinlock_unlock(&hlp->lock);
530 }
531
532 for (cur = cmd_head.next; cur != &cmd_head; cur = cur->next) {
533 cmd_info_t *hlp;
534 hlp = list_get_instance(cur, cmd_info_t, link);
535
536 spinlock_lock(&hlp->lock);
537 printf("%-*s %s\n", len, hlp->name, hlp->description);
538 spinlock_unlock(&hlp->lock);
539 }
540
541 spinlock_unlock(&cmd_lock);
542
543 return 1;
544}
545
546
547/** Reboot the system.
548 *
549 * @param argv Argument vector.
550 *
551 * @return 0 on failure, 1 on success.
552 */
553int cmd_reboot(cmd_arg_t *argv)
554{
555 reboot();
556
557 /* Not reached */
558 return 1;
559}
560
561
562/** Print system uptime information.
563 *
564 * @param argv Argument vector.
565 *
566 * @return 0 on failure, 1 on success.
567 */
568int cmd_uptime(cmd_arg_t *argv)
569{
570 ASSERT(uptime);
571
572 /* This doesn't have to be very accurate */
573 unative_t sec = uptime->seconds1;
574
575 printf("Up %" PRIun " days, %" PRIun " hours, %" PRIun " minutes, %" PRIun " seconds\n",
576 sec / 86400, (sec % 86400) / 3600, (sec % 3600) / 60, sec % 60);
577
578 return 1;
579}
580
581/** Describe specified command.
582 *
583 * @param argv Argument vector.
584 *
585 * @return 0 on failure, 1 on success.
586 */
587int cmd_desc(cmd_arg_t *argv)
588{
589 link_t *cur;
590
591 spinlock_lock(&cmd_lock);
592
593 for (cur = cmd_head.next; cur != &cmd_head; cur = cur->next) {
594 cmd_info_t *hlp;
595
596 hlp = list_get_instance(cur, cmd_info_t, link);
597 spinlock_lock(&hlp->lock);
598
599 if (strncmp(hlp->name, (const char *) argv->buffer, strlen(hlp->name)) == 0) {
600 printf("%s - %s\n", hlp->name, hlp->description);
601 if (hlp->help)
602 hlp->help();
603 spinlock_unlock(&hlp->lock);
604 break;
605 }
606
607 spinlock_unlock(&hlp->lock);
608 }
609
610 spinlock_unlock(&cmd_lock);
611
612 return 1;
613}
614
615#ifdef CONFIG_SYMTAB
616
617/** Search symbol table */
618int cmd_symaddr(cmd_arg_t *argv)
619{
620 symtab_print_search((char *) argv->buffer);
621
622 return 1;
623}
624
625#endif
626
627/** Call function with zero parameters */
628int cmd_call0(cmd_arg_t *argv)
629{
630#ifdef CONFIG_SYMTAB
631 uintptr_t symaddr;
632 unative_t (*fnc)(void);
633 fncptr_t fptr;
634
635 symaddr = get_symbol_addr((char *) argv->buffer);
636 if (!symaddr)
637 printf("Symbol %s not found.\n", argv->buffer);
638 else if (symaddr == (uintptr_t) -1) {
639 symtab_print_search((char *) argv->buffer);
640 printf("Duplicate symbol, be more specific.\n");
641 } else {
642 fnc = (unative_t (*)(void)) arch_construct_function(&fptr, (void *) symaddr, (void *) cmd_call0);
643 printf("Calling %s() (%p)\n", argv->buffer, symaddr);
644 printf("Result: %#" PRIxn "\n", fnc());
645 }
646#endif
647 return 1;
648}
649
650/** Call function with zero parameters on each CPU */
651int cmd_mcall0(cmd_arg_t *argv)
652{
653 /*
654 * For each CPU, create a thread which will
655 * call the function.
656 */
657
658 count_t i;
659 for (i = 0; i < config.cpu_count; i++) {
660 if (!cpus[i].active)
661 continue;
662
663 thread_t *t;
664 if ((t = thread_create((void (*)(void *)) cmd_call0, (void *) argv, TASK, THREAD_FLAG_WIRED, "call0", false))) {
665 spinlock_lock(&t->lock);
666 t->cpu = &cpus[i];
667 spinlock_unlock(&t->lock);
668 printf("cpu%u: ", i);
669 thread_ready(t);
670 thread_join(t);
671 thread_detach(t);
672 } else
673 printf("Unable to create thread for cpu%u\n", i);
674 }
675
676 return 1;
677}
678
679/** Call function with one parameter */
680int cmd_call1(cmd_arg_t *argv)
681{
682#ifdef CONFIG_SYMTAB
683 uintptr_t symaddr;
684 char *symbol;
685 unative_t (*fnc)(unative_t, ...);
686 unative_t arg1 = argv[1].intval;
687 fncptr_t fptr;
688
689 symaddr = get_symbol_addr((char *) argv->buffer);
690
691 if (!symaddr)
692 printf("Symbol %s not found.\n", argv->buffer);
693 else if (symaddr == (uintptr_t) -1) {
694 symtab_print_search((char *) argv->buffer);
695 printf("Duplicate symbol, be more specific.\n");
696 } else {
697 symbol = get_symtab_entry(symaddr);
698 fnc = (unative_t (*)(unative_t, ...)) arch_construct_function(&fptr, (void *) symaddr, (void *) cmd_call1);
699 printf("Calling f(%#" PRIxn "): %p: %s\n", arg1, symaddr, symbol);
700 printf("Result: %#" PRIxn "\n", fnc(arg1));
701 }
702#endif
703 return 1;
704}
705
706/** Call function with two parameters */
707int cmd_call2(cmd_arg_t *argv)
708{
709#ifdef CONFIG_SYMTAB
710 uintptr_t symaddr;
711 char *symbol;
712 unative_t (*fnc)(unative_t, unative_t, ...);
713 unative_t arg1 = argv[1].intval;
714 unative_t arg2 = argv[2].intval;
715 fncptr_t fptr;
716
717 symaddr = get_symbol_addr((char *) argv->buffer);
718 if (!symaddr)
719 printf("Symbol %s not found.\n", argv->buffer);
720 else if (symaddr == (uintptr_t) -1) {
721 symtab_print_search((char *) argv->buffer);
722 printf("Duplicate symbol, be more specific.\n");
723 } else {
724 symbol = get_symtab_entry(symaddr);
725 fnc = (unative_t (*)(unative_t, unative_t, ...)) arch_construct_function(&fptr, (void *) symaddr, (void *) cmd_call2);
726 printf("Calling f(%#" PRIxn ", %#" PRIxn "): %p: %s\n",
727 arg1, arg2, symaddr, symbol);
728 printf("Result: %#" PRIxn "\n", fnc(arg1, arg2));
729 }
730#endif
731 return 1;
732}
733
734/** Call function with three parameters */
735int cmd_call3(cmd_arg_t *argv)
736{
737#ifdef CONFIG_SYMTAB
738 uintptr_t symaddr;
739 char *symbol;
740 unative_t (*fnc)(unative_t, unative_t, unative_t, ...);
741 unative_t arg1 = argv[1].intval;
742 unative_t arg2 = argv[2].intval;
743 unative_t arg3 = argv[3].intval;
744 fncptr_t fptr;
745
746 symaddr = get_symbol_addr((char *) argv->buffer);
747 if (!symaddr)
748 printf("Symbol %s not found.\n", argv->buffer);
749 else if (symaddr == (uintptr_t) -1) {
750 symtab_print_search((char *) argv->buffer);
751 printf("Duplicate symbol, be more specific.\n");
752 } else {
753 symbol = get_symtab_entry(symaddr);
754 fnc = (unative_t (*)(unative_t, unative_t, unative_t, ...)) arch_construct_function(&fptr, (void *) symaddr, (void *) cmd_call3);
755 printf("Calling f(%#" PRIxn ",%#" PRIxn ", %#" PRIxn "): %p: %s\n",
756 arg1, arg2, arg3, symaddr, symbol);
757 printf("Result: %#" PRIxn "\n", fnc(arg1, arg2, arg3));
758 }
759#endif
760 return 1;
761}
762
763
764/** Print detailed description of 'describe' command. */
765void desc_help(void)
766{
767 printf("Syntax: describe command_name\n");
768}
769
770/** Halt the kernel.
771 *
772 * @param argv Argument vector (ignored).
773 *
774 * @return 0 on failure, 1 on success (never returns).
775 */
776int cmd_halt(cmd_arg_t *argv)
777{
778 halt();
779 return 1;
780}
781
782/** Command for printing TLB contents.
783 *
784 * @param argv Not used.
785 *
786 * @return Always returns 1.
787 */
788int cmd_tlb(cmd_arg_t *argv)
789{
790 tlb_print();
791 return 1;
792}
793
794/** Command for printing physical memory configuration.
795 *
796 * @param argv Not used.
797 *
798 * @return Always returns 1.
799 */
800int cmd_physmem(cmd_arg_t *argv)
801{
802 physmem_print();
803 return 1;
804}
805
806/** Write 4 byte value to address */
807int cmd_set4(cmd_arg_t *argv)
808{
809 uint32_t *addr;
810 uint32_t arg1 = argv[1].intval;
811 bool pointer = false;
812
813 if (((char *)argv->buffer)[0] == '*') {
814#ifdef CONFIG_SYMTAB
815 addr = (uint32_t *) get_symbol_addr((char *) argv->buffer + 1);
816#else
817 addr = 0;
818#endif
819 pointer = true;
820 } else if (((char *) argv->buffer)[0] >= '0' &&
821 ((char *)argv->buffer)[0] <= '9') {
822 addr = (uint32_t *)atoi((char *)argv->buffer);
823 } else {
824#ifdef CONFIG_SYMTAB
825 addr = (uint32_t *)get_symbol_addr((char *) argv->buffer);
826#else
827 addr = 0;
828#endif
829 }
830
831 if (!addr)
832 printf("Symbol %s not found.\n", argv->buffer);
833 else if (addr == (uint32_t *) -1) {
834#ifdef CONFIG_SYMTAB
835 symtab_print_search((char *) argv->buffer);
836#endif
837 printf("Duplicate symbol, be more specific.\n");
838 } else {
839 if (pointer)
840 addr = (uint32_t *)(*(unative_t *)addr);
841 printf("Writing %#" PRIx64 " -> %p\n", arg1, addr);
842 *addr = arg1;
843
844 }
845
846 return 1;
847}
848
849/** Command for listings SLAB caches
850 *
851 * @param argv Ignores
852 *
853 * @return Always 1
854 */
855int cmd_slabs(cmd_arg_t * argv) {
856 slab_print_list();
857 return 1;
858}
859
860
861/** Command for listings Thread information
862 *
863 * @param argv Ignores
864 *
865 * @return Always 1
866 */
867int cmd_threads(cmd_arg_t * argv) {
868 thread_print_list();
869 return 1;
870}
871
872/** Command for listings Task information
873 *
874 * @param argv Ignores
875 *
876 * @return Always 1
877 */
878int cmd_tasks(cmd_arg_t * argv) {
879 task_print_list();
880 return 1;
881}
882
883/** Command for listings Thread information
884 *
885 * @param argv Ignores
886 *
887 * @return Always 1
888 */
889int cmd_sched(cmd_arg_t * argv) {
890 sched_print_list();
891 return 1;
892}
893
894/** Command for listing memory zones
895 *
896 * @param argv Ignored
897 *
898 * return Always 1
899 */
900int cmd_zones(cmd_arg_t * argv) {
901 zone_print_list();
902 return 1;
903}
904
905/** Command for memory zone details
906 *
907 * @param argv Integer argument from cmdline expected
908 *
909 * return Always 1
910 */
911int cmd_zone(cmd_arg_t * argv) {
912 zone_print_one(argv[0].intval);
913 return 1;
914}
915
916/** Command for printing task ipc details
917 *
918 * @param argv Integer argument from cmdline expected
919 *
920 * return Always 1
921 */
922int cmd_ipc(cmd_arg_t * argv) {
923 ipc_print_task(argv[0].intval);
924 return 1;
925}
926
927
928/** Command for listing processors.
929 *
930 * @param argv Ignored.
931 *
932 * return Always 1.
933 */
934int cmd_cpus(cmd_arg_t *argv)
935{
936 cpu_list();
937 return 1;
938}
939
940/** Command for printing kernel version.
941 *
942 * @param argv Ignored.
943 *
944 * return Always 1.
945 */
946int cmd_version(cmd_arg_t *argv)
947{
948 version_print();
949 return 1;
950}
951
952/** Command for returning console back to userspace.
953 *
954 * @param argv Ignored.
955 *
956 * return Always 1.
957 */
958int cmd_continue(cmd_arg_t *argv)
959{
960 printf("The kernel will now relinquish the console.\n");
961 release_console();
962
963 if ((kconsole_notify) && (kconsole_irq.notif_cfg.notify))
964 ipc_irq_send_msg_0(&kconsole_irq);
965
966 return 1;
967}
968
969#ifdef CONFIG_TEST
970/** Command for printing kernel tests list.
971 *
972 * @param argv Ignored.
973 *
974 * return Always 1.
975 */
976int cmd_tests(cmd_arg_t *argv)
977{
978 size_t len = 0;
979 test_t *test;
980 for (test = tests; test->name != NULL; test++) {
981 if (strlen(test->name) > len)
982 len = strlen(test->name);
983 }
984
985 for (test = tests; test->name != NULL; test++)
986 printf("%-*s %s%s\n", len, test->name, test->desc, (test->safe ? "" : " (unsafe)"));
987
988 printf("%-*s Run all safe tests\n", len, "*");
989 return 1;
990}
991
992static bool run_test(const test_t *test)
993{
994 printf("%s (%s)\n", test->name, test->desc);
995
996 /* Update and read thread accounting
997 for benchmarking */
998 ipl_t ipl = interrupts_disable();
999 spinlock_lock(&TASK->lock);
1000 uint64_t t0 = task_get_accounting(TASK);
1001 spinlock_unlock(&TASK->lock);
1002 interrupts_restore(ipl);
1003
1004 /* Execute the test */
1005 char * ret = test->entry(false);
1006
1007 /* Update and read thread accounting */
1008 ipl = interrupts_disable();
1009 spinlock_lock(&TASK->lock);
1010 uint64_t dt = task_get_accounting(TASK) - t0;
1011 spinlock_unlock(&TASK->lock);
1012 interrupts_restore(ipl);
1013
1014 uint64_t cycles;
1015 char suffix;
1016 order(dt, &cycles, &suffix);
1017
1018 printf("Time: %" PRIu64 "%c cycles\n", cycles, suffix);
1019
1020 if (ret == NULL) {
1021 printf("Test passed\n");
1022 return true;
1023 }
1024
1025 printf("%s\n", ret);
1026 return false;
1027}
1028
1029static bool run_bench(const test_t *test, const uint32_t cnt)
1030{
1031 uint32_t i;
1032 bool ret = true;
1033 uint64_t cycles;
1034 char suffix;
1035
1036 if (cnt < 1)
1037 return true;
1038
1039 uint64_t *data = (uint64_t *) malloc(sizeof(uint64_t) * cnt, 0);
1040 if (data == NULL) {
1041 printf("Error allocating memory for statistics\n");
1042 return false;
1043 }
1044
1045 for (i = 0; i < cnt; i++) {
1046 printf("%s (%u/%u) ... ", test->name, i + 1, cnt);
1047
1048 /* Update and read thread accounting
1049 for benchmarking */
1050 ipl_t ipl = interrupts_disable();
1051 spinlock_lock(&TASK->lock);
1052 uint64_t t0 = task_get_accounting(TASK);
1053 spinlock_unlock(&TASK->lock);
1054 interrupts_restore(ipl);
1055
1056 /* Execute the test */
1057 char * ret = test->entry(true);
1058
1059 /* Update and read thread accounting */
1060 ipl = interrupts_disable();
1061 spinlock_lock(&TASK->lock);
1062 uint64_t dt = task_get_accounting(TASK) - t0;
1063 spinlock_unlock(&TASK->lock);
1064 interrupts_restore(ipl);
1065
1066 if (ret != NULL) {
1067 printf("%s\n", ret);
1068 ret = false;
1069 break;
1070 }
1071
1072 data[i] = dt;
1073 order(dt, &cycles, &suffix);
1074 printf("OK (%" PRIu64 "%c cycles)\n", cycles, suffix);
1075 }
1076
1077 if (ret) {
1078 printf("\n");
1079
1080 uint64_t sum = 0;
1081
1082 for (i = 0; i < cnt; i++) {
1083 sum += data[i];
1084 }
1085
1086 order(sum / (uint64_t) cnt, &cycles, &suffix);
1087 printf("Average\t\t%" PRIu64 "%c\n", cycles, suffix);
1088 }
1089
1090 free(data);
1091
1092 return ret;
1093}
1094
1095/** Command for returning kernel tests
1096 *
1097 * @param argv Argument vector.
1098 *
1099 * return Always 1.
1100 */
1101int cmd_test(cmd_arg_t *argv)
1102{
1103 test_t *test;
1104
1105 if (strcmp((char *) argv->buffer, "*") == 0) {
1106 for (test = tests; test->name != NULL; test++) {
1107 if (test->safe) {
1108 printf("\n");
1109 if (!run_test(test))
1110 break;
1111 }
1112 }
1113 } else {
1114 bool fnd = false;
1115
1116 for (test = tests; test->name != NULL; test++) {
1117 if (strcmp(test->name, (char *) argv->buffer) == 0) {
1118 fnd = true;
1119 run_test(test);
1120 break;
1121 }
1122 }
1123
1124 if (!fnd)
1125 printf("Unknown test\n");
1126 }
1127
1128 return 1;
1129}
1130
1131/** Command for returning kernel tests as benchmarks
1132 *
1133 * @param argv Argument vector.
1134 *
1135 * return Always 1.
1136 */
1137int cmd_bench(cmd_arg_t *argv)
1138{
1139 test_t *test;
1140 uint32_t cnt = argv[1].intval;
1141
1142 bool fnd = false;
1143
1144 for (test = tests; test->name != NULL; test++) {
1145 if (strcmp(test->name, (char *) argv->buffer) == 0) {
1146 fnd = true;
1147
1148 if (test->safe)
1149 run_bench(test, cnt);
1150 else
1151 printf("Unsafe test\n");
1152
1153 break;
1154 }
1155 }
1156
1157 if (!fnd)
1158 printf("Unknown test\n");
1159
1160 return 1;
1161}
1162
1163#endif
1164
1165/** @}
1166 */
Note: See TracBrowser for help on using the repository browser.