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

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

cleanup kernel tests infrastructure

  • Property mode set to 100644
File size: 19.0 KB
RevLine 
[442d0ae]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
[06e1e95]29/** @addtogroup genericconsole
[b45c443]30 * @{
31 */
32
[442d0ae]33/**
[cf26ba9]34 * @file cmd.c
35 * @brief Kernel console command wrappers.
36 *
[442d0ae]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>
[41d33ac]44#include <console/console.h>
[442d0ae]45#include <console/kconsole.h>
46#include <print.h>
47#include <panic.h>
48#include <typedefs.h>
49#include <arch/types.h>
[5c9a08b]50#include <adt/list.h>
[442d0ae]51#include <arch.h>
52#include <func.h>
53#include <macros.h>
54#include <debug.h>
55#include <symtab.h>
[0132630]56#include <cpu.h>
[442d0ae]57#include <mm/tlb.h>
58#include <arch/mm/tlb.h>
[80bff342]59#include <mm/frame.h>
[0132630]60#include <main/version.h>
[4e147a6]61#include <mm/slab.h>
[10e16a7]62#include <proc/scheduler.h>
[55ab0f1]63#include <proc/thread.h>
[37c57f2]64#include <proc/task.h>
[c4e4507]65#include <ipc/ipc.h>
[62939f7]66#include <ipc/irq.h>
[442d0ae]67
[319e60e]68#ifdef CONFIG_TEST
69#include <test.h>
70#endif
71
[34db7fa]72#ifdef CONFIG_BENCH
73#include <arch/cycle.h>
74#endif
75
[b45c443]76/* Data and methods for 'help' command. */
[442d0ae]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
[e07fe0c]85static cmd_info_t exit_info = {
86 .name = "exit",
[319e60e]87 .description = "Exit kconsole",
[e07fe0c]88 .argc = 0
89};
90
[41d33ac]91static int cmd_continue(cmd_arg_t *argv);
92static cmd_info_t continue_info = {
93 .name = "continue",
[319e60e]94 .description = "Return console back to userspace.",
[41d33ac]95 .func = cmd_continue,
96 .argc = 0
97};
98
[319e60e]99#ifdef CONFIG_TEST
100static int cmd_tests(cmd_arg_t *argv);
101static cmd_info_t tests_info = {
102 .name = "tests",
103 .description = "Print available kernel tests.",
104 .func = cmd_tests,
105 .argc = 0
106};
107
108static char test_buf[MAX_CMDLINE + 1];
109static int cmd_test(cmd_arg_t *argv);
110static cmd_arg_t test_argv[] = {
111 {
112 .type = ARG_TYPE_STRING,
113 .buffer = test_buf,
114 .len = sizeof(test_buf)
115 }
116};
117static cmd_info_t test_info = {
118 .name = "test",
119 .description = "Run kernel test.",
120 .func = cmd_test,
121 .argc = 1,
122 .argv = test_argv
123};
124#endif
125
[b45c443]126/* Data and methods for 'description' command. */
[442d0ae]127static int cmd_desc(cmd_arg_t *argv);
128static void desc_help(void);
129static char desc_buf[MAX_CMDLINE+1];
130static cmd_arg_t desc_argv = {
131 .type = ARG_TYPE_STRING,
132 .buffer = desc_buf,
133 .len = sizeof(desc_buf)
134};
135static cmd_info_t desc_info = {
136 .name = "describe",
137 .description = "Describe specified command.",
138 .help = desc_help,
139 .func = cmd_desc,
140 .argc = 1,
141 .argv = &desc_argv
142};
143
[b45c443]144/* Data and methods for 'symaddr' command. */
[442d0ae]145static int cmd_symaddr(cmd_arg_t *argv);
146static char symaddr_buf[MAX_CMDLINE+1];
147static cmd_arg_t symaddr_argv = {
148 .type = ARG_TYPE_STRING,
149 .buffer = symaddr_buf,
150 .len = sizeof(symaddr_buf)
151};
152static cmd_info_t symaddr_info = {
153 .name = "symaddr",
154 .description = "Return symbol address.",
155 .func = cmd_symaddr,
156 .argc = 1,
157 .argv = &symaddr_argv
158};
159
[ba276f7]160static char set_buf[MAX_CMDLINE+1];
161static int cmd_set4(cmd_arg_t *argv);
162static cmd_arg_t set4_argv[] = {
163 {
164 .type = ARG_TYPE_STRING,
165 .buffer = set_buf,
166 .len = sizeof(set_buf)
167 },
168 {
169 .type = ARG_TYPE_INT
170 }
171};
172static cmd_info_t set4_info = {
173 .name = "set4",
174 .description = "set <dest_addr> <value> - 4byte version",
175 .func = cmd_set4,
176 .argc = 2,
177 .argv = set4_argv
178};
179
[b45c443]180/* Data and methods for 'call0' command. */
[442d0ae]181static char call0_buf[MAX_CMDLINE+1];
182static char carg1_buf[MAX_CMDLINE+1];
183static char carg2_buf[MAX_CMDLINE+1];
184static char carg3_buf[MAX_CMDLINE+1];
185
186static int cmd_call0(cmd_arg_t *argv);
187static cmd_arg_t call0_argv = {
188 .type = ARG_TYPE_STRING,
189 .buffer = call0_buf,
190 .len = sizeof(call0_buf)
191};
192static cmd_info_t call0_info = {
193 .name = "call0",
194 .description = "call0 <function> -> call function().",
195 .func = cmd_call0,
196 .argc = 1,
197 .argv = &call0_argv
198};
199
[b45c443]200/* Data and methods for 'call1' command. */
[442d0ae]201static int cmd_call1(cmd_arg_t *argv);
202static cmd_arg_t call1_argv[] = {
203 {
204 .type = ARG_TYPE_STRING,
205 .buffer = call0_buf,
206 .len = sizeof(call0_buf)
207 },
208 {
209 .type = ARG_TYPE_VAR,
210 .buffer = carg1_buf,
211 .len = sizeof(carg1_buf)
212 }
213};
214static cmd_info_t call1_info = {
215 .name = "call1",
216 .description = "call1 <function> <arg1> -> call function(arg1).",
217 .func = cmd_call1,
218 .argc = 2,
219 .argv = call1_argv
220};
221
[b45c443]222/* Data and methods for 'call2' command. */
[442d0ae]223static int cmd_call2(cmd_arg_t *argv);
224static cmd_arg_t call2_argv[] = {
225 {
226 .type = ARG_TYPE_STRING,
227 .buffer = call0_buf,
228 .len = sizeof(call0_buf)
229 },
230 {
231 .type = ARG_TYPE_VAR,
232 .buffer = carg1_buf,
233 .len = sizeof(carg1_buf)
234 },
235 {
236 .type = ARG_TYPE_VAR,
237 .buffer = carg2_buf,
238 .len = sizeof(carg2_buf)
239 }
240};
241static cmd_info_t call2_info = {
242 .name = "call2",
243 .description = "call2 <function> <arg1> <arg2> -> call function(arg1,arg2).",
244 .func = cmd_call2,
245 .argc = 3,
246 .argv = call2_argv
247};
248
[b45c443]249/* Data and methods for 'call3' command. */
[442d0ae]250static int cmd_call3(cmd_arg_t *argv);
251static cmd_arg_t call3_argv[] = {
252 {
253 .type = ARG_TYPE_STRING,
254 .buffer = call0_buf,
255 .len = sizeof(call0_buf)
256 },
257 {
258 .type = ARG_TYPE_VAR,
259 .buffer = carg1_buf,
260 .len = sizeof(carg1_buf)
261 },
262 {
263 .type = ARG_TYPE_VAR,
264 .buffer = carg2_buf,
265 .len = sizeof(carg2_buf)
266 },
267 {
268 .type = ARG_TYPE_VAR,
269 .buffer = carg3_buf,
270 .len = sizeof(carg3_buf)
271 }
272
273};
274static cmd_info_t call3_info = {
275 .name = "call3",
276 .description = "call3 <function> <arg1> <arg2> <arg3> -> call function(arg1,arg2,arg3).",
277 .func = cmd_call3,
278 .argc = 4,
279 .argv = call3_argv
280};
281
[b45c443]282/* Data and methods for 'halt' command. */
[442d0ae]283static int cmd_halt(cmd_arg_t *argv);
284static cmd_info_t halt_info = {
285 .name = "halt",
286 .description = "Halt the kernel.",
287 .func = cmd_halt,
288 .argc = 0
289};
290
[b45c443]291/* Data and methods for 'tlb' command. */
[0132630]292static int cmd_tlb(cmd_arg_t *argv);
293cmd_info_t tlb_info = {
294 .name = "tlb",
[442d0ae]295 .description = "Print TLB of current processor.",
296 .help = NULL,
[0132630]297 .func = cmd_tlb,
[442d0ae]298 .argc = 0,
299 .argv = NULL
300};
301
[55ab0f1]302static int cmd_threads(cmd_arg_t *argv);
303static cmd_info_t threads_info = {
304 .name = "threads",
[dd054bc2]305 .description = "List all threads.",
[55ab0f1]306 .func = cmd_threads,
307 .argc = 0
308};
309
[37c57f2]310static int cmd_tasks(cmd_arg_t *argv);
311static cmd_info_t tasks_info = {
312 .name = "tasks",
[dd054bc2]313 .description = "List all tasks.",
[37c57f2]314 .func = cmd_tasks,
315 .argc = 0
316};
317
[80bff342]318
[10e16a7]319static int cmd_sched(cmd_arg_t *argv);
320static cmd_info_t sched_info = {
321 .name = "scheduler",
[dd054bc2]322 .description = "List all scheduler information.",
[10e16a7]323 .func = cmd_sched,
324 .argc = 0
325};
326
[4e147a6]327static int cmd_slabs(cmd_arg_t *argv);
328static cmd_info_t slabs_info = {
329 .name = "slabs",
[dd054bc2]330 .description = "List slab caches.",
[4e147a6]331 .func = cmd_slabs,
332 .argc = 0
333};
334
[b45c443]335/* Data and methods for 'zones' command */
[80bff342]336static int cmd_zones(cmd_arg_t *argv);
337static cmd_info_t zones_info = {
338 .name = "zones",
339 .description = "List of memory zones.",
340 .func = cmd_zones,
341 .argc = 0
342};
343
[b45c443]344/* Data and methods for 'ipc_task' command */
[c4e4507]345static int cmd_ipc_task(cmd_arg_t *argv);
346static cmd_arg_t ipc_task_argv = {
347 .type = ARG_TYPE_INT,
348};
349static cmd_info_t ipc_task_info = {
350 .name = "ipc_task",
[dd054bc2]351 .description = "ipc_task <taskid> Show IPC information of given task.",
[c4e4507]352 .func = cmd_ipc_task,
353 .argc = 1,
354 .argv = &ipc_task_argv
355};
356
[b45c443]357/* Data and methods for 'zone' command */
[80bff342]358static int cmd_zone(cmd_arg_t *argv);
359static cmd_arg_t zone_argv = {
360 .type = ARG_TYPE_INT,
361};
362
363static cmd_info_t zone_info = {
364 .name = "zone",
365 .description = "Show memory zone structure.",
366 .func = cmd_zone,
367 .argc = 1,
368 .argv = &zone_argv
369};
370
[b45c443]371/* Data and methods for 'cpus' command. */
[0132630]372static int cmd_cpus(cmd_arg_t *argv);
373cmd_info_t cpus_info = {
374 .name = "cpus",
375 .description = "List all processors.",
376 .help = NULL,
377 .func = cmd_cpus,
378 .argc = 0,
379 .argv = NULL
380};
381
[b45c443]382/* Data and methods for 'version' command. */
[0132630]383static int cmd_version(cmd_arg_t *argv);
384cmd_info_t version_info = {
385 .name = "version",
386 .description = "Print version information.",
387 .help = NULL,
388 .func = cmd_version,
389 .argc = 0,
390 .argv = NULL
391};
392
[10e16a7]393static cmd_info_t *basic_commands[] = {
394 &call0_info,
395 &call1_info,
396 &call2_info,
397 &call3_info,
[41d33ac]398 &continue_info,
[10e16a7]399 &cpus_info,
400 &desc_info,
401 &exit_info,
402 &halt_info,
403 &help_info,
[c4e4507]404 &ipc_task_info,
[10e16a7]405 &set4_info,
406 &slabs_info,
407 &symaddr_info,
408 &sched_info,
[55ab0f1]409 &threads_info,
[37c57f2]410 &tasks_info,
[10e16a7]411 &tlb_info,
412 &version_info,
413 &zones_info,
414 &zone_info,
[319e60e]415#ifdef CONFIG_TEST
416 &tests_info,
417 &test_info,
418#endif
[10e16a7]419 NULL
420};
[80bff342]421
422
[442d0ae]423/** Initialize command info structure.
424 *
425 * @param cmd Command info structure.
426 *
427 */
428void cmd_initialize(cmd_info_t *cmd)
429{
430 spinlock_initialize(&cmd->lock, "cmd");
431 link_initialize(&cmd->link);
432}
433
434/** Initialize and register commands. */
435void cmd_init(void)
436{
[10e16a7]437 int i;
[80bff342]438
[10e16a7]439 for (i=0;basic_commands[i]; i++) {
440 cmd_initialize(basic_commands[i]);
441 if (!cmd_register(basic_commands[i]))
442 panic("could not register command %s\n",
443 basic_commands[i]->name);
444 }
[442d0ae]445}
446
447
448/** List supported commands.
449 *
450 * @param argv Argument vector.
451 *
452 * @return 0 on failure, 1 on success.
453 */
454int cmd_help(cmd_arg_t *argv)
455{
456 link_t *cur;
457
458 spinlock_lock(&cmd_lock);
459
460 for (cur = cmd_head.next; cur != &cmd_head; cur = cur->next) {
461 cmd_info_t *hlp;
462
463 hlp = list_get_instance(cur, cmd_info_t, link);
464 spinlock_lock(&hlp->lock);
465
466 printf("%s - %s\n", hlp->name, hlp->description);
467
468 spinlock_unlock(&hlp->lock);
469 }
470
471 spinlock_unlock(&cmd_lock);
472
473 return 1;
474}
475
476/** Describe specified command.
477 *
478 * @param argv Argument vector.
479 *
480 * @return 0 on failure, 1 on success.
481 */
482int cmd_desc(cmd_arg_t *argv)
483{
484 link_t *cur;
485
486 spinlock_lock(&cmd_lock);
487
488 for (cur = cmd_head.next; cur != &cmd_head; cur = cur->next) {
489 cmd_info_t *hlp;
490
491 hlp = list_get_instance(cur, cmd_info_t, link);
492 spinlock_lock(&hlp->lock);
493
494 if (strncmp(hlp->name, (const char *) argv->buffer, strlen(hlp->name)) == 0) {
495 printf("%s - %s\n", hlp->name, hlp->description);
496 if (hlp->help)
497 hlp->help();
498 spinlock_unlock(&hlp->lock);
499 break;
500 }
501
502 spinlock_unlock(&hlp->lock);
503 }
504
505 spinlock_unlock(&cmd_lock);
506
507 return 1;
508}
509
510/** Search symbol table */
511int cmd_symaddr(cmd_arg_t *argv)
512{
513 symtab_print_search(argv->buffer);
514
515 return 1;
516}
517
518/** Call function with zero parameters */
519int cmd_call0(cmd_arg_t *argv)
520{
[7f1c620]521 uintptr_t symaddr;
[442d0ae]522 char *symbol;
[7f1c620]523 unative_t (*f)(void);
[3701250]524#ifdef ia64
525 struct {
[7f1c620]526 unative_t f;
527 unative_t gp;
[3701250]528 }fptr;
529#endif
[442d0ae]530
531 symaddr = get_symbol_addr(argv->buffer);
532 if (!symaddr)
533 printf("Symbol %s not found.\n", argv->buffer);
[7f1c620]534 else if (symaddr == (uintptr_t) -1) {
[442d0ae]535 symtab_print_search(argv->buffer);
536 printf("Duplicate symbol, be more specific.\n");
537 } else {
538 symbol = get_symtab_entry(symaddr);
[7f1c620]539 printf("Calling f(): %.*p: %s\n", sizeof(uintptr_t) * 2, symaddr, symbol);
[3701250]540#ifdef ia64
541 fptr.f = symaddr;
[7f1c620]542 fptr.gp = ((unative_t *)cmd_call2)[1];
543 f = (unative_t (*)(void)) &fptr;
[3701250]544#else
[7f1c620]545 f = (unative_t (*)(void)) symaddr;
[3701250]546#endif
[ad45bde9]547 printf("Result: %#zx\n", f());
[442d0ae]548 }
549
550 return 1;
551}
552
553/** Call function with one parameter */
554int cmd_call1(cmd_arg_t *argv)
555{
[7f1c620]556 uintptr_t symaddr;
[442d0ae]557 char *symbol;
[7f1c620]558 unative_t (*f)(unative_t,...);
559 unative_t arg1 = argv[1].intval;
[3701250]560#ifdef ia64
561 struct {
[7f1c620]562 unative_t f;
563 unative_t gp;
[3701250]564 }fptr;
565#endif
[442d0ae]566
567 symaddr = get_symbol_addr(argv->buffer);
568 if (!symaddr)
569 printf("Symbol %s not found.\n", argv->buffer);
[7f1c620]570 else if (symaddr == (uintptr_t) -1) {
[442d0ae]571 symtab_print_search(argv->buffer);
572 printf("Duplicate symbol, be more specific.\n");
573 } else {
574 symbol = get_symtab_entry(symaddr);
[3701250]575
[7f1c620]576 printf("Calling f(%#zx): %.*p: %s\n", arg1, sizeof(uintptr_t) * 2, symaddr, symbol);
[3701250]577#ifdef ia64
578 fptr.f = symaddr;
[7f1c620]579 fptr.gp = ((unative_t *)cmd_call2)[1];
580 f = (unative_t (*)(unative_t,...)) &fptr;
[3701250]581#else
[7f1c620]582 f = (unative_t (*)(unative_t,...)) symaddr;
[3701250]583#endif
[ad45bde9]584 printf("Result: %#zx\n", f(arg1));
[442d0ae]585 }
586
587 return 1;
588}
589
590/** Call function with two parameters */
591int cmd_call2(cmd_arg_t *argv)
592{
[7f1c620]593 uintptr_t symaddr;
[442d0ae]594 char *symbol;
[7f1c620]595 unative_t (*f)(unative_t,unative_t,...);
596 unative_t arg1 = argv[1].intval;
597 unative_t arg2 = argv[2].intval;
[3701250]598#ifdef ia64
599 struct {
[7f1c620]600 unative_t f;
601 unative_t gp;
[3701250]602 }fptr;
603#endif
[442d0ae]604
605 symaddr = get_symbol_addr(argv->buffer);
606 if (!symaddr)
607 printf("Symbol %s not found.\n", argv->buffer);
[7f1c620]608 else if (symaddr == (uintptr_t) -1) {
[442d0ae]609 symtab_print_search(argv->buffer);
610 printf("Duplicate symbol, be more specific.\n");
611 } else {
612 symbol = get_symtab_entry(symaddr);
[ad45bde9]613 printf("Calling f(0x%zx,0x%zx): %.*p: %s\n",
[7f1c620]614 arg1, arg2, sizeof(uintptr_t) * 2, symaddr, symbol);
[3701250]615#ifdef ia64
616 fptr.f = symaddr;
[7f1c620]617 fptr.gp = ((unative_t *)cmd_call2)[1];
618 f = (unative_t (*)(unative_t,unative_t,...)) &fptr;
[3701250]619#else
[7f1c620]620 f = (unative_t (*)(unative_t,unative_t,...)) symaddr;
[3701250]621#endif
[ad45bde9]622 printf("Result: %#zx\n", f(arg1, arg2));
[442d0ae]623 }
624
625 return 1;
626}
627
628/** Call function with three parameters */
629int cmd_call3(cmd_arg_t *argv)
630{
[7f1c620]631 uintptr_t symaddr;
[442d0ae]632 char *symbol;
[7f1c620]633 unative_t (*f)(unative_t,unative_t,unative_t,...);
634 unative_t arg1 = argv[1].intval;
635 unative_t arg2 = argv[2].intval;
636 unative_t arg3 = argv[3].intval;
[3701250]637#ifdef ia64
638 struct {
[7f1c620]639 unative_t f;
640 unative_t gp;
[3701250]641 }fptr;
642#endif
[442d0ae]643
644 symaddr = get_symbol_addr(argv->buffer);
645 if (!symaddr)
646 printf("Symbol %s not found.\n", argv->buffer);
[7f1c620]647 else if (symaddr == (uintptr_t) -1) {
[442d0ae]648 symtab_print_search(argv->buffer);
649 printf("Duplicate symbol, be more specific.\n");
650 } else {
651 symbol = get_symtab_entry(symaddr);
[ad45bde9]652 printf("Calling f(0x%zx,0x%zx, 0x%zx): %.*p: %s\n",
[7f1c620]653 arg1, arg2, arg3, sizeof(uintptr_t) * 2, symaddr, symbol);
[3701250]654#ifdef ia64
655 fptr.f = symaddr;
[7f1c620]656 fptr.gp = ((unative_t *)cmd_call2)[1];
657 f = (unative_t (*)(unative_t,unative_t,unative_t,...)) &fptr;
[3701250]658#else
[7f1c620]659 f = (unative_t (*)(unative_t,unative_t,unative_t,...)) symaddr;
[3701250]660#endif
[ad45bde9]661 printf("Result: %#zx\n", f(arg1, arg2, arg3));
[442d0ae]662 }
663
664 return 1;
665}
666
667
668/** Print detailed description of 'describe' command. */
669void desc_help(void)
670{
671 printf("Syntax: describe command_name\n");
672}
673
674/** Halt the kernel.
675 *
676 * @param argv Argument vector (ignored).
677 *
678 * @return 0 on failure, 1 on success (never returns).
679 */
680int cmd_halt(cmd_arg_t *argv)
681{
682 halt();
683 return 1;
684}
685
686/** Command for printing TLB contents.
687 *
688 * @param argv Not used.
689 *
690 * @return Always returns 1.
691 */
[0132630]692int cmd_tlb(cmd_arg_t *argv)
[442d0ae]693{
694 tlb_print();
695 return 1;
696}
[ba276f7]697
698/** Write 4 byte value to address */
699int cmd_set4(cmd_arg_t *argv)
700{
[7f1c620]701 uint32_t *addr ;
702 uint32_t arg1 = argv[1].intval;
[ba276f7]703 bool pointer = false;
704
705 if (((char *)argv->buffer)[0] == '*') {
[7f1c620]706 addr = (uint32_t *) get_symbol_addr(argv->buffer+1);
[ba276f7]707 pointer = true;
708 } else if (((char *)argv->buffer)[0] >= '0' &&
709 ((char *)argv->buffer)[0] <= '9')
[7f1c620]710 addr = (uint32_t *)atoi((char *)argv->buffer);
[ba276f7]711 else
[7f1c620]712 addr = (uint32_t *)get_symbol_addr(argv->buffer);
[ba276f7]713
714 if (!addr)
715 printf("Symbol %s not found.\n", argv->buffer);
[7f1c620]716 else if (addr == (uint32_t *) -1) {
[ba276f7]717 symtab_print_search(argv->buffer);
718 printf("Duplicate symbol, be more specific.\n");
719 } else {
720 if (pointer)
[7f1c620]721 addr = (uint32_t *)(*(unative_t *)addr);
722 printf("Writing 0x%x -> %.*p\n", arg1, sizeof(uintptr_t) * 2, addr);
[ba276f7]723 *addr = arg1;
724
725 }
726
727 return 1;
728}
[80bff342]729
[4e147a6]730/** Command for listings SLAB caches
731 *
732 * @param argv Ignores
733 *
734 * @return Always 1
735 */
736int cmd_slabs(cmd_arg_t * argv) {
737 slab_print_list();
738 return 1;
739}
740
[55ab0f1]741
742/** Command for listings Thread information
743 *
744 * @param argv Ignores
745 *
746 * @return Always 1
747 */
748int cmd_threads(cmd_arg_t * argv) {
749 thread_print_list();
750 return 1;
751}
752
[37c57f2]753/** Command for listings Task information
754 *
755 * @param argv Ignores
756 *
757 * @return Always 1
758 */
759int cmd_tasks(cmd_arg_t * argv) {
760 task_print_list();
761 return 1;
762}
763
[10e16a7]764/** Command for listings Thread information
765 *
766 * @param argv Ignores
767 *
768 * @return Always 1
769 */
770int cmd_sched(cmd_arg_t * argv) {
771 sched_print_list();
772 return 1;
773}
774
[96cacc1]775/** Command for listing memory zones
776 *
777 * @param argv Ignored
778 *
779 * return Always 1
780 */
[80bff342]781int cmd_zones(cmd_arg_t * argv) {
[dfd9186]782 zone_print_list();
[80bff342]783 return 1;
784}
[0132630]785
[96cacc1]786/** Command for memory zone details
787 *
788 * @param argv Integer argument from cmdline expected
789 *
790 * return Always 1
791 */
[80bff342]792int cmd_zone(cmd_arg_t * argv) {
[dfd9186]793 zone_print_one(argv[0].intval);
[80bff342]794 return 1;
795}
796
[c4e4507]797/** Command for printing task ipc details
798 *
799 * @param argv Integer argument from cmdline expected
800 *
801 * return Always 1
802 */
803int cmd_ipc_task(cmd_arg_t * argv) {
804 ipc_print_task(argv[0].intval);
805 return 1;
806}
807
808
[0132630]809/** Command for listing processors.
810 *
811 * @param argv Ignored.
812 *
813 * return Always 1.
814 */
815int cmd_cpus(cmd_arg_t *argv)
816{
817 cpu_list();
818 return 1;
819}
820
821/** Command for printing kernel version.
822 *
823 * @param argv Ignored.
824 *
825 * return Always 1.
826 */
827int cmd_version(cmd_arg_t *argv)
828{
829 version_print();
830 return 1;
831}
[41d33ac]832
833/** Command for returning console back to userspace.
834 *
835 * @param argv Ignored.
836 *
837 * return Always 1.
838 */
839int cmd_continue(cmd_arg_t *argv)
840{
[dd054bc2]841 printf("The kernel will now relinquish the console.\n");
842 printf("Use userspace controls to redraw the screen.\n");
[41d33ac]843 arch_release_console();
844 return 1;
845}
[b45c443]846
[50661ab]847#ifdef CONFIG_TEST
[319e60e]848/** Command for printing kernel tests list.
849 *
850 * @param argv Ignored.
851 *
852 * return Always 1.
853 */
854int cmd_tests(cmd_arg_t *argv)
855{
856 test_t *test;
857
858 for (test = tests; test->name != NULL; test++)
[50661ab]859 printf("%s\t\t%s%s\n", test->name, test->desc, (test->safe ? "" : " (unsafe)"));
[319e60e]860
[50661ab]861 printf("*\t\tRun all safe tests\n");
[319e60e]862 return 1;
863}
864
[34db7fa]865static bool run_test(const test_t * test)
866{
867 printf("%s\t\t%s\n", test->name, test->desc);
868#ifdef CONFIG_BENCH
869 uint64_t t0 = get_cycle();
870#endif
871 char * ret = test->entry();
872#ifdef CONFIG_BENCH
873 uint64_t dt = get_cycle() - t0;
874 printf("Time: %llu cycles\n", dt);
875#endif
876
877 if (ret == NULL) {
878 printf("Test passed\n");
879 return true;
880 }
881
882 printf("%s\n", ret);
883 return false;
884}
885
[319e60e]886/** Command for returning kernel tests
887 *
888 * @param argv Argument vector.
889 *
890 * return Always 1.
891 */
892int cmd_test(cmd_arg_t *argv)
893{
894 test_t *test;
895
[50661ab]896 if (strcmp(argv->buffer, "*") == 0) {
897 for (test = tests; test->name != NULL; test++) {
898 if (test->safe) {
[34db7fa]899 printf("\n");
900 if (!run_test(test))
901 break;
[50661ab]902 }
903 }
904 } else {
905 bool fnd = false;
906
907 for (test = tests; test->name != NULL; test++) {
908 if (strcmp(test->name, argv->buffer) == 0) {
909 fnd = true;
[34db7fa]910 run_test(test);
[50661ab]911 break;
912 }
[319e60e]913 }
[50661ab]914
915 if (!fnd)
[34db7fa]916 printf("Unknown test\n");
[319e60e]917 }
918
919 return 1;
920}
[50661ab]921#endif
[319e60e]922
[06e1e95]923/** @}
[b45c443]924 */
Note: See TracBrowser for help on using the repository browser.