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

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since af7a26b was b3631bc, checked in by Martin Decky <martin@…>, 15 years ago

add sysinfo kconsole command

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