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

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

major code revision

  • replace spinlocks taken with interrupts disabled with irq_spinlocks
  • change spacing (not indendation) to be tab-size independent
  • use unsigned integer types where appropriate (especially bit flags)
  • visual separation
  • remove argument names in function prototypes
  • string changes
  • correct some formating directives
  • replace various cryptic single-character variables (t, a, m, c, b, etc.) with proper identifiers (thread, task, timeout, as, itm, itc, etc.)
  • unify some assembler constructs
  • unused page table levels are now optimized out in compile time
  • replace several ints (with boolean semantics) with bools
  • use specifically sized types instead of generic types where appropriate (size_t, uint32_t, btree_key_t)
  • improve comments
  • split asserts with conjuction into multiple independent asserts
  • Property mode set to 100644
File size: 25.8 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/**
[cb01e1e]34 * @file cmd.c
35 * @brief Kernel console command wrappers.
[cf26ba9]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>
[d99c1d2]48#include <typedefs.h>
[5c9a08b]49#include <adt/list.h>
[442d0ae]50#include <arch.h>
[f74bbaf]51#include <config.h>
[442d0ae]52#include <func.h>
[19f857a]53#include <str.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>
[13a638d]67#include <ipc/event.h>
[b3631bc]68#include <sysinfo/sysinfo.h>
[e2b762ec]69#include <symtab.h>
[e16e0d59]70#include <errno.h>
[e2b762ec]71
[319e60e]72#ifdef CONFIG_TEST
73#include <test.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
[f74bbaf]85static int cmd_reboot(cmd_arg_t *argv);
86static cmd_info_t reboot_info = {
87 .name = "reboot",
88 .description = "Reboot.",
89 .func = cmd_reboot,
[e07fe0c]90 .argc = 0
91};
92
[4b662f8c]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
[41d33ac]101static int cmd_continue(cmd_arg_t *argv);
102static cmd_info_t continue_info = {
103 .name = "continue",
[319e60e]104 .description = "Return console back to userspace.",
[41d33ac]105 .func = cmd_continue,
106 .argc = 0
107};
108
[319e60e]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};
[95155b0c]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};
[319e60e]153#endif
154
[b45c443]155/* Data and methods for 'description' command. */
[442d0ae]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
[b45c443]173/* Data and methods for 'symaddr' command. */
[442d0ae]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
[ba276f7]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
[b45c443]209/* Data and methods for 'call0' command. */
[e5dbbe5]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];
[442d0ae]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
[e5dbbe5]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
[b45c443]244/* Data and methods for 'call1' command. */
[442d0ae]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
[b45c443]266/* Data and methods for 'call2' command. */
[442d0ae]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
[b45c443]293/* Data and methods for 'call3' command. */
[442d0ae]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
[b45c443]326/* Data and methods for 'halt' command. */
[442d0ae]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
[b07c332]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
[b45c443]346/* Data and methods for 'tlb' command. */
[0132630]347static int cmd_tlb(cmd_arg_t *argv);
348cmd_info_t tlb_info = {
349 .name = "tlb",
[442d0ae]350 .description = "Print TLB of current processor.",
351 .help = NULL,
[0132630]352 .func = cmd_tlb,
[442d0ae]353 .argc = 0,
354 .argv = NULL
355};
356
[55ab0f1]357static int cmd_threads(cmd_arg_t *argv);
358static cmd_info_t threads_info = {
359 .name = "threads",
[dd054bc2]360 .description = "List all threads.",
[55ab0f1]361 .func = cmd_threads,
362 .argc = 0
363};
364
[37c57f2]365static int cmd_tasks(cmd_arg_t *argv);
366static cmd_info_t tasks_info = {
367 .name = "tasks",
[dd054bc2]368 .description = "List all tasks.",
[37c57f2]369 .func = cmd_tasks,
370 .argc = 0
371};
372
[80bff342]373
[10e16a7]374static int cmd_sched(cmd_arg_t *argv);
375static cmd_info_t sched_info = {
376 .name = "scheduler",
[dd054bc2]377 .description = "List all scheduler information.",
[10e16a7]378 .func = cmd_sched,
379 .argc = 0
380};
381
[4e147a6]382static int cmd_slabs(cmd_arg_t *argv);
383static cmd_info_t slabs_info = {
384 .name = "slabs",
[dd054bc2]385 .description = "List slab caches.",
[4e147a6]386 .func = cmd_slabs,
387 .argc = 0
388};
389
[b3631bc]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
[b45c443]398/* Data and methods for 'zones' command */
[80bff342]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
[073c9e6]407/* Data and methods for 'ipc' command */
408static int cmd_ipc(cmd_arg_t *argv);
409static cmd_arg_t ipc_argv = {
[c4e4507]410 .type = ARG_TYPE_INT,
411};
[073c9e6]412static cmd_info_t ipc_info = {
413 .name = "ipc",
414 .description = "ipc <taskid> Show IPC information of given task.",
415 .func = cmd_ipc,
[c4e4507]416 .argc = 1,
[073c9e6]417 .argv = &ipc_argv
[c4e4507]418};
419
[2a75302]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
[b45c443]433/* Data and methods for 'zone' command */
[80bff342]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
[b45c443]447/* Data and methods for 'cpus' command. */
[0132630]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
[b45c443]458/* Data and methods for 'version' command. */
[0132630]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
[10e16a7]469static cmd_info_t *basic_commands[] = {
470 &call0_info,
[e5dbbe5]471 &mcall0_info,
[10e16a7]472 &call1_info,
473 &call2_info,
474 &call3_info,
[41d33ac]475 &continue_info,
[10e16a7]476 &cpus_info,
477 &desc_info,
[f74bbaf]478 &reboot_info,
[4b662f8c]479 &uptime_info,
[10e16a7]480 &halt_info,
481 &help_info,
[073c9e6]482 &ipc_info,
[2a75302]483 &kill_info,
[10e16a7]484 &set4_info,
485 &slabs_info,
[b3631bc]486 &sysinfo_info,
[10e16a7]487 &symaddr_info,
488 &sched_info,
[55ab0f1]489 &threads_info,
[37c57f2]490 &tasks_info,
[b07c332]491 &physmem_info,
[10e16a7]492 &tlb_info,
493 &version_info,
494 &zones_info,
495 &zone_info,
[319e60e]496#ifdef CONFIG_TEST
497 &tests_info,
498 &test_info,
[95155b0c]499 &bench_info,
[319e60e]500#endif
[10e16a7]501 NULL
502};
[80bff342]503
504
[442d0ae]505/** Initialize command info structure.
506 *
507 * @param cmd Command info structure.
508 *
509 */
510void cmd_initialize(cmd_info_t *cmd)
511{
[da1bafb]512 spinlock_initialize(&cmd->lock, "cmd.lock");
[442d0ae]513 link_initialize(&cmd->link);
514}
515
516/** Initialize and register commands. */
517void cmd_init(void)
518{
[b07c332]519 unsigned int i;
[80bff342]520
[b07c332]521 for (i = 0; basic_commands[i]; i++) {
[10e16a7]522 cmd_initialize(basic_commands[i]);
523 if (!cmd_register(basic_commands[i]))
[76fca31]524 printf("Cannot register command %s\n", basic_commands[i]->name);
[10e16a7]525 }
[442d0ae]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
[c1f7f6ea]539 link_t *cur;
[98000fb]540 size_t len = 0;
[442d0ae]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);
[c1f7f6ea]544
[442d0ae]545 spinlock_lock(&hlp->lock);
[20cc877]546 if (str_length(hlp->name) > len)
547 len = str_length(hlp->name);
[c1f7f6ea]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);
[442d0ae]554
[c1f7f6ea]555 spinlock_lock(&hlp->lock);
556 printf("%-*s %s\n", len, hlp->name, hlp->description);
[442d0ae]557 spinlock_unlock(&hlp->lock);
558 }
559
[ae318d3]560 spinlock_unlock(&cmd_lock);
[c1f7f6ea]561
[442d0ae]562 return 1;
563}
564
[f74bbaf]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
[4b662f8c]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
[c859753]594 printf("Up %" PRIun " days, %" PRIun " hours, %" PRIun " minutes, %" PRIun " seconds\n",
[4b662f8c]595 sec / 86400, (sec % 86400) / 3600, (sec % 3600) / 60, sec % 60);
596
597 return 1;
598}
599
[442d0ae]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;
[20cc877]609
[442d0ae]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);
[20cc877]617
618 if (str_lcmp(hlp->name, (const char *) argv->buffer, str_length(hlp->name)) == 0) {
[442d0ae]619 printf("%s - %s\n", hlp->name, hlp->description);
620 if (hlp->help)
621 hlp->help();
622 spinlock_unlock(&hlp->lock);
623 break;
624 }
[20cc877]625
[442d0ae]626 spinlock_unlock(&hlp->lock);
627 }
628
629 spinlock_unlock(&cmd_lock);
[20cc877]630
[442d0ae]631 return 1;
632}
633
634/** Search symbol table */
635int cmd_symaddr(cmd_arg_t *argv)
636{
[828aa05]637 symtab_print_search((char *) argv->buffer);
[442d0ae]638
639 return 1;
640}
641
642/** Call function with zero parameters */
643int cmd_call0(cmd_arg_t *argv)
644{
[7f1c620]645 uintptr_t symaddr;
[e16e0d59]646 char *symbol;
[0f81ceb7]647 unative_t (*fnc)(void);
648 fncptr_t fptr;
[e16e0d59]649 int rc;
[e2b762ec]650
[e16e0d59]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);
[442d0ae]658 printf("Duplicate symbol, be more specific.\n");
[e16e0d59]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);
[0f81ceb7]663 printf("Result: %#" PRIxn "\n", fnc());
[e16e0d59]664 } else {
665 printf("No symbol information available.\n");
[442d0ae]666 }
667 return 1;
668}
669
[e5dbbe5]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
[98000fb]678 size_t i;
[e5dbbe5]679 for (i = 0; i < config.cpu_count; i++) {
[b8f11baa]680 if (!cpus[i].active)
681 continue;
682
[da1bafb]683 thread_t *thread;
684 if ((thread = thread_create((void (*)(void *)) cmd_call0,
685 (void *) argv, TASK, THREAD_FLAG_WIRED, "call0", false))) {
686 irq_spinlock_lock(&thread->lock, true);
687 thread->cpu = &cpus[i];
688 irq_spinlock_unlock(&thread->lock, true);
689
690 printf("cpu%" PRIs ": ", i);
691
692 thread_ready(thread);
693 thread_join(thread);
694 thread_detach(thread);
[e5dbbe5]695 } else
[da1bafb]696 printf("Unable to create thread for cpu%" PRIs "\n", i);
[e5dbbe5]697 }
698
699 return 1;
700}
701
[442d0ae]702/** Call function with one parameter */
703int cmd_call1(cmd_arg_t *argv)
704{
[7f1c620]705 uintptr_t symaddr;
[442d0ae]706 char *symbol;
[0f81ceb7]707 unative_t (*fnc)(unative_t, ...);
[7f1c620]708 unative_t arg1 = argv[1].intval;
[0f81ceb7]709 fncptr_t fptr;
[e16e0d59]710 int rc;
[e2b762ec]711
[e16e0d59]712 symbol = (char *) argv->buffer;
713 rc = symtab_addr_lookup(symbol, &symaddr);
714
715 if (rc == ENOENT) {
716 printf("Symbol %s not found.\n", symbol);
717 } else if (rc == EOVERFLOW) {
718 symtab_print_search(symbol);
[442d0ae]719 printf("Duplicate symbol, be more specific.\n");
[e16e0d59]720 } else if (rc == EOK) {
[0f81ceb7]721 fnc = (unative_t (*)(unative_t, ...)) arch_construct_function(&fptr, (void *) symaddr, (void *) cmd_call1);
[c859753]722 printf("Calling f(%#" PRIxn "): %p: %s\n", arg1, symaddr, symbol);
[0f81ceb7]723 printf("Result: %#" PRIxn "\n", fnc(arg1));
[e16e0d59]724 } else {
725 printf("No symbol information available.\n");
[442d0ae]726 }
[e16e0d59]727
[442d0ae]728 return 1;
729}
730
731/** Call function with two parameters */
732int cmd_call2(cmd_arg_t *argv)
733{
[7f1c620]734 uintptr_t symaddr;
[442d0ae]735 char *symbol;
[0f81ceb7]736 unative_t (*fnc)(unative_t, unative_t, ...);
[7f1c620]737 unative_t arg1 = argv[1].intval;
738 unative_t arg2 = argv[2].intval;
[0f81ceb7]739 fncptr_t fptr;
[e16e0d59]740 int rc;
741
742 symbol = (char *) argv->buffer;
743 rc = symtab_addr_lookup(symbol, &symaddr);
744
745 if (rc == ENOENT) {
746 printf("Symbol %s not found.\n", symbol);
747 } else if (rc == EOVERFLOW) {
748 symtab_print_search(symbol);
[442d0ae]749 printf("Duplicate symbol, be more specific.\n");
[e16e0d59]750 } else if (rc == EOK) {
[0f81ceb7]751 fnc = (unative_t (*)(unative_t, unative_t, ...)) arch_construct_function(&fptr, (void *) symaddr, (void *) cmd_call2);
[c859753]752 printf("Calling f(%#" PRIxn ", %#" PRIxn "): %p: %s\n",
753 arg1, arg2, symaddr, symbol);
[0f81ceb7]754 printf("Result: %#" PRIxn "\n", fnc(arg1, arg2));
[e16e0d59]755 } else {
756 printf("No symbol information available.\n");
757 }
[442d0ae]758 return 1;
759}
760
761/** Call function with three parameters */
762int cmd_call3(cmd_arg_t *argv)
763{
[7f1c620]764 uintptr_t symaddr;
[442d0ae]765 char *symbol;
[0f81ceb7]766 unative_t (*fnc)(unative_t, unative_t, unative_t, ...);
[7f1c620]767 unative_t arg1 = argv[1].intval;
768 unative_t arg2 = argv[2].intval;
769 unative_t arg3 = argv[3].intval;
[0f81ceb7]770 fncptr_t fptr;
[e16e0d59]771 int rc;
[0f81ceb7]772
[e16e0d59]773 symbol = (char *) argv->buffer;
774 rc = symtab_addr_lookup(symbol, &symaddr);
775
776 if (rc == ENOENT) {
777 printf("Symbol %s not found.\n", symbol);
778 } else if (rc == EOVERFLOW) {
779 symtab_print_search(symbol);
[442d0ae]780 printf("Duplicate symbol, be more specific.\n");
[e16e0d59]781 } else if (rc == EOK) {
[0f81ceb7]782 fnc = (unative_t (*)(unative_t, unative_t, unative_t, ...)) arch_construct_function(&fptr, (void *) symaddr, (void *) cmd_call3);
[c859753]783 printf("Calling f(%#" PRIxn ",%#" PRIxn ", %#" PRIxn "): %p: %s\n",
784 arg1, arg2, arg3, symaddr, symbol);
[0f81ceb7]785 printf("Result: %#" PRIxn "\n", fnc(arg1, arg2, arg3));
[e16e0d59]786 } else {
787 printf("No symbol information available.\n");
[442d0ae]788 }
789 return 1;
790}
791
792
793/** Print detailed description of 'describe' command. */
794void desc_help(void)
795{
796 printf("Syntax: describe command_name\n");
797}
798
799/** Halt the kernel.
800 *
801 * @param argv Argument vector (ignored).
802 *
803 * @return 0 on failure, 1 on success (never returns).
804 */
805int cmd_halt(cmd_arg_t *argv)
806{
807 halt();
808 return 1;
809}
810
811/** Command for printing TLB contents.
812 *
813 * @param argv Not used.
814 *
815 * @return Always returns 1.
816 */
[0132630]817int cmd_tlb(cmd_arg_t *argv)
[442d0ae]818{
819 tlb_print();
820 return 1;
821}
[ba276f7]822
[b07c332]823/** Command for printing physical memory configuration.
824 *
825 * @param argv Not used.
826 *
827 * @return Always returns 1.
828 */
829int cmd_physmem(cmd_arg_t *argv)
830{
831 physmem_print();
832 return 1;
833}
834
[ba276f7]835/** Write 4 byte value to address */
836int cmd_set4(cmd_arg_t *argv)
837{
[e16e0d59]838 uintptr_t addr;
[7f1c620]839 uint32_t arg1 = argv[1].intval;
[ba276f7]840 bool pointer = false;
[e16e0d59]841 int rc;
[4ce914d4]842
843 if (((char *) argv->buffer)[0] == '*') {
[e16e0d59]844 rc = symtab_addr_lookup((char *) argv->buffer + 1, &addr);
[ba276f7]845 pointer = true;
[4ce914d4]846 } else if (((char *) argv->buffer)[0] >= '0' &&
847 ((char *) argv->buffer)[0] <= '9') {
848 uint64_t value;
849 rc = str_uint64((char *) argv->buffer, NULL, 0, true, &value);
850 if (rc == EOK)
851 addr = (uintptr_t) value;
852 } else
[e16e0d59]853 rc = symtab_addr_lookup((char *) argv->buffer, &addr);
[4ce914d4]854
[e16e0d59]855 if (rc == ENOENT)
[ba276f7]856 printf("Symbol %s not found.\n", argv->buffer);
[4ce914d4]857 else if (rc == EINVAL)
858 printf("Invalid address.\n");
[e16e0d59]859 else if (rc == EOVERFLOW) {
[828aa05]860 symtab_print_search((char *) argv->buffer);
[4ce914d4]861 printf("Duplicate symbol (be more specific) or address overflow.\n");
[e16e0d59]862 } else if (rc == EOK) {
[ba276f7]863 if (pointer)
[e16e0d59]864 addr = *(uintptr_t *) addr;
[c859753]865 printf("Writing %#" PRIx64 " -> %p\n", arg1, addr);
[e16e0d59]866 *(uint32_t *) addr = arg1;
[4ce914d4]867 } else
[e16e0d59]868 printf("No symbol information available.\n");
[ba276f7]869
870 return 1;
871}
[80bff342]872
[4e147a6]873/** Command for listings SLAB caches
874 *
875 * @param argv Ignores
876 *
877 * @return Always 1
878 */
[095b1534]879int cmd_slabs(cmd_arg_t * argv)
880{
[4e147a6]881 slab_print_list();
882 return 1;
883}
884
[b3631bc]885/** Command for dumping sysinfo
886 *
887 * @param argv Ignores
888 *
889 * @return Always 1
890 */
891int cmd_sysinfo(cmd_arg_t * argv)
892{
[9dae191e]893 sysinfo_dump(NULL);
[b3631bc]894 return 1;
895}
896
[55ab0f1]897
898/** Command for listings Thread information
899 *
900 * @param argv Ignores
901 *
902 * @return Always 1
903 */
[095b1534]904int cmd_threads(cmd_arg_t * argv)
905{
[55ab0f1]906 thread_print_list();
907 return 1;
908}
909
[37c57f2]910/** Command for listings Task information
911 *
912 * @param argv Ignores
913 *
914 * @return Always 1
915 */
[095b1534]916int cmd_tasks(cmd_arg_t * argv)
917{
[37c57f2]918 task_print_list();
919 return 1;
920}
921
[10e16a7]922/** Command for listings Thread information
923 *
924 * @param argv Ignores
925 *
926 * @return Always 1
927 */
[095b1534]928int cmd_sched(cmd_arg_t * argv)
929{
[10e16a7]930 sched_print_list();
931 return 1;
932}
933
[96cacc1]934/** Command for listing memory zones
935 *
936 * @param argv Ignored
937 *
938 * return Always 1
939 */
[095b1534]940int cmd_zones(cmd_arg_t * argv)
941{
[9dae191e]942 zones_print_list();
[80bff342]943 return 1;
944}
[0132630]945
[96cacc1]946/** Command for memory zone details
947 *
948 * @param argv Integer argument from cmdline expected
949 *
950 * return Always 1
951 */
[095b1534]952int cmd_zone(cmd_arg_t * argv)
953{
[dfd9186]954 zone_print_one(argv[0].intval);
[80bff342]955 return 1;
956}
957
[c4e4507]958/** Command for printing task ipc details
959 *
960 * @param argv Integer argument from cmdline expected
961 *
962 * return Always 1
963 */
[095b1534]964int cmd_ipc(cmd_arg_t * argv)
965{
[c4e4507]966 ipc_print_task(argv[0].intval);
967 return 1;
968}
969
[cb3d641a]970/** Command for killing a task
[2a75302]971 *
972 * @param argv Integer argument from cmdline expected
973 *
[cb3d641a]974 * return 0 on failure, 1 on success.
[2a75302]975 */
976int cmd_kill(cmd_arg_t * argv)
977{
978 if (task_kill(argv[0].intval) != EOK)
979 return 0;
980
981 return 1;
982}
[c4e4507]983
[0132630]984/** Command for listing processors.
985 *
986 * @param argv Ignored.
987 *
988 * return Always 1.
989 */
990int cmd_cpus(cmd_arg_t *argv)
991{
992 cpu_list();
993 return 1;
994}
995
996/** Command for printing kernel version.
997 *
998 * @param argv Ignored.
999 *
1000 * return Always 1.
1001 */
1002int cmd_version(cmd_arg_t *argv)
1003{
1004 version_print();
1005 return 1;
1006}
[41d33ac]1007
1008/** Command for returning console back to userspace.
1009 *
1010 * @param argv Ignored.
1011 *
1012 * return Always 1.
1013 */
1014int cmd_continue(cmd_arg_t *argv)
1015{
[dd054bc2]1016 printf("The kernel will now relinquish the console.\n");
[516ff92]1017 release_console();
[3ad953c]1018
[05641a9e]1019 event_notify_0(EVENT_KCONSOLE);
[821cc93]1020 indev_pop_character(stdin);
[3ad953c]1021
[41d33ac]1022 return 1;
1023}
[b45c443]1024
[50661ab]1025#ifdef CONFIG_TEST
[319e60e]1026/** Command for printing kernel tests list.
1027 *
1028 * @param argv Ignored.
1029 *
1030 * return Always 1.
1031 */
1032int cmd_tests(cmd_arg_t *argv)
1033{
[98000fb]1034 size_t len = 0;
[319e60e]1035 test_t *test;
[c1f7f6ea]1036 for (test = tests; test->name != NULL; test++) {
[20cc877]1037 if (str_length(test->name) > len)
1038 len = str_length(test->name);
[c1f7f6ea]1039 }
[319e60e]1040
1041 for (test = tests; test->name != NULL; test++)
[c1f7f6ea]1042 printf("%-*s %s%s\n", len, test->name, test->desc, (test->safe ? "" : " (unsafe)"));
[319e60e]1043
[c1f7f6ea]1044 printf("%-*s Run all safe tests\n", len, "*");
[319e60e]1045 return 1;
1046}
1047
[62b6d17]1048static bool run_test(const test_t *test)
[34db7fa]1049{
[c1f7f6ea]1050 printf("%s (%s)\n", test->name, test->desc);
[cce6acf]1051
1052 /* Update and read thread accounting
1053 for benchmarking */
[da1bafb]1054 irq_spinlock_lock(&TASK->lock, true);
[1ba37fa]1055 uint64_t ucycles0, kcycles0;
1056 task_get_accounting(TASK, &ucycles0, &kcycles0);
[da1bafb]1057 irq_spinlock_unlock(&TASK->lock, true);
[cce6acf]1058
1059 /* Execute the test */
[cb01e1e]1060 test_quiet = false;
[a000878c]1061 const char *ret = test->entry();
[cce6acf]1062
1063 /* Update and read thread accounting */
[da1bafb]1064 uint64_t ucycles1, kcycles1;
1065 irq_spinlock_lock(&TASK->lock, true);
[1ba37fa]1066 task_get_accounting(TASK, &ucycles1, &kcycles1);
[da1bafb]1067 irq_spinlock_unlock(&TASK->lock, true);
[cce6acf]1068
[1ba37fa]1069 uint64_t ucycles, kcycles;
1070 char usuffix, ksuffix;
[e535eeb]1071 order_suffix(ucycles1 - ucycles0, &ucycles, &usuffix);
1072 order_suffix(kcycles1 - kcycles0, &kcycles, &ksuffix);
[da1bafb]1073
[1ba37fa]1074 printf("Time: %" PRIu64 "%c user cycles, %" PRIu64 "%c kernel cycles\n",
[da1bafb]1075 ucycles, usuffix, kcycles, ksuffix);
[34db7fa]1076
1077 if (ret == NULL) {
1078 printf("Test passed\n");
[62b6d17]1079 return true;
[34db7fa]1080 }
[da1bafb]1081
[34db7fa]1082 printf("%s\n", ret);
[62b6d17]1083 return false;
[34db7fa]1084}
1085
[95155b0c]1086static bool run_bench(const test_t *test, const uint32_t cnt)
1087{
1088 uint32_t i;
1089 bool ret = true;
[1ba37fa]1090 uint64_t ucycles, kcycles;
1091 char usuffix, ksuffix;
[95155b0c]1092
1093 if (cnt < 1)
1094 return true;
1095
[828aa05]1096 uint64_t *data = (uint64_t *) malloc(sizeof(uint64_t) * cnt, 0);
[95155b0c]1097 if (data == NULL) {
1098 printf("Error allocating memory for statistics\n");
1099 return false;
1100 }
1101
1102 for (i = 0; i < cnt; i++) {
[c859753]1103 printf("%s (%u/%u) ... ", test->name, i + 1, cnt);
[95155b0c]1104
1105 /* Update and read thread accounting
1106 for benchmarking */
[da1bafb]1107 irq_spinlock_lock(&TASK->lock, true);
[1ba37fa]1108 uint64_t ucycles0, kcycles0;
1109 task_get_accounting(TASK, &ucycles0, &kcycles0);
[da1bafb]1110 irq_spinlock_unlock(&TASK->lock, true);
[95155b0c]1111
1112 /* Execute the test */
[cb01e1e]1113 test_quiet = true;
[a000878c]1114 const char *ret = test->entry();
[95155b0c]1115
1116 /* Update and read thread accounting */
[da1bafb]1117 irq_spinlock_lock(&TASK->lock, true);
[1ba37fa]1118 uint64_t ucycles1, kcycles1;
1119 task_get_accounting(TASK, &ucycles1, &kcycles1);
[da1bafb]1120 irq_spinlock_unlock(&TASK->lock, true);
1121
[95155b0c]1122 if (ret != NULL) {
1123 printf("%s\n", ret);
1124 ret = false;
1125 break;
1126 }
1127
[1ba37fa]1128 data[i] = ucycles1 - ucycles0 + kcycles1 - kcycles0;
[e535eeb]1129 order_suffix(ucycles1 - ucycles0, &ucycles, &usuffix);
1130 order_suffix(kcycles1 - kcycles0, &kcycles, &ksuffix);
[1ba37fa]1131 printf("OK (%" PRIu64 "%c user cycles, %" PRIu64 "%c kernel cycles)\n",
[da1bafb]1132 ucycles, usuffix, kcycles, ksuffix);
[95155b0c]1133 }
1134
1135 if (ret) {
1136 printf("\n");
1137
1138 uint64_t sum = 0;
1139
1140 for (i = 0; i < cnt; i++) {
1141 sum += data[i];
1142 }
1143
[e535eeb]1144 order_suffix(sum / (uint64_t) cnt, &ucycles, &usuffix);
[1ba37fa]1145 printf("Average\t\t%" PRIu64 "%c\n", ucycles, usuffix);
[95155b0c]1146 }
1147
1148 free(data);
1149
1150 return ret;
1151}
1152
[319e60e]1153/** Command for returning kernel tests
1154 *
1155 * @param argv Argument vector.
1156 *
1157 * return Always 1.
1158 */
1159int cmd_test(cmd_arg_t *argv)
1160{
1161 test_t *test;
1162
[20cc877]1163 if (str_cmp((char *) argv->buffer, "*") == 0) {
[50661ab]1164 for (test = tests; test->name != NULL; test++) {
1165 if (test->safe) {
[34db7fa]1166 printf("\n");
1167 if (!run_test(test))
1168 break;
[50661ab]1169 }
1170 }
1171 } else {
1172 bool fnd = false;
1173
1174 for (test = tests; test->name != NULL; test++) {
[20cc877]1175 if (str_cmp(test->name, (char *) argv->buffer) == 0) {
[50661ab]1176 fnd = true;
[34db7fa]1177 run_test(test);
[50661ab]1178 break;
1179 }
[319e60e]1180 }
[50661ab]1181
1182 if (!fnd)
[34db7fa]1183 printf("Unknown test\n");
[319e60e]1184 }
1185
1186 return 1;
1187}
[95155b0c]1188
1189/** Command for returning kernel tests as benchmarks
1190 *
1191 * @param argv Argument vector.
1192 *
1193 * return Always 1.
1194 */
1195int cmd_bench(cmd_arg_t *argv)
1196{
1197 test_t *test;
1198 uint32_t cnt = argv[1].intval;
1199
[3f2177e]1200 if (str_cmp((char *) argv->buffer, "*") == 0) {
1201 for (test = tests; test->name != NULL; test++) {
1202 if (test->safe) {
1203 if (!run_bench(test, cnt))
1204 break;
1205 }
[95155b0c]1206 }
[3f2177e]1207 } else {
1208 bool fnd = false;
[95155b0c]1209
[3f2177e]1210 for (test = tests; test->name != NULL; test++) {
1211 if (str_cmp(test->name, (char *) argv->buffer) == 0) {
1212 fnd = true;
1213
1214 if (test->safe)
1215 run_bench(test, cnt);
1216 else
1217 printf("Unsafe test\n");
1218
1219 break;
1220 }
1221 }
1222
1223 if (!fnd)
1224 printf("Unknown test\n");
1225 }
[cb01e1e]1226
[95155b0c]1227 return 1;
1228}
1229
[50661ab]1230#endif
[319e60e]1231
[06e1e95]1232/** @}
[b45c443]1233 */
Note: See TracBrowser for help on using the repository browser.