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

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

Make optionality of symbol information less intrusive per Jakub's request. Also, improve symtab function names and update their semantics.

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