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

Last change on this file since a064d4f was a064d4f, checked in by Jiří Zárevúcky <zarevucky.jiri@…>, 18 months ago

Make thread_join() imply thread_put()

This makes the function more similar to traditional threading APIs.

  • Property mode set to 100644
File size: 35.9 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
[174156fd]29/** @addtogroup kernel_generic_console
[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
[63e27ef]43#include <assert.h>
[442d0ae]44#include <console/cmd.h>
[41d33ac]45#include <console/console.h>
[442d0ae]46#include <console/kconsole.h>
[bab75df6]47#include <stdio.h>
[b2fa1204]48#include <log.h>
[442d0ae]49#include <panic.h>
[d99c1d2]50#include <typedefs.h>
[5c9a08b]51#include <adt/list.h>
[442d0ae]52#include <arch.h>
[f74bbaf]53#include <config.h>
[b2e121a]54#include <halt.h>
[19f857a]55#include <str.h>
[442d0ae]56#include <macros.h>
[0132630]57#include <cpu.h>
[442d0ae]58#include <mm/tlb.h>
[e8a1530]59#include <mm/km.h>
[442d0ae]60#include <arch/mm/tlb.h>
[80bff342]61#include <mm/frame.h>
[0132630]62#include <main/version.h>
[4e147a6]63#include <mm/slab.h>
[10e16a7]64#include <proc/scheduler.h>
[55ab0f1]65#include <proc/thread.h>
[37c57f2]66#include <proc/task.h>
[c4e4507]67#include <ipc/ipc.h>
[62939f7]68#include <ipc/irq.h>
[13a638d]69#include <ipc/event.h>
[b3631bc]70#include <sysinfo/sysinfo.h>
[e2b762ec]71#include <symtab.h>
[e16e0d59]72#include <errno.h>
[aafed15]73#include <stdlib.h>
[e2b762ec]74
[319e60e]75#ifdef CONFIG_TEST
76#include <test.h>
77#endif
78
[b45c443]79/* Data and methods for 'help' command. */
[442d0ae]80static int cmd_help(cmd_arg_t *argv);
81static cmd_info_t help_info = {
82 .name = "help",
[df58e44]83 .description = "List supported commands.",
[442d0ae]84 .func = cmd_help,
85 .argc = 0
86};
87
[e8a1530]88/* Data and methods for pio_read_8 command */
89static int cmd_pio_read_8(cmd_arg_t *argv);
90static cmd_arg_t pio_read_8_argv[] = { { .type = ARG_TYPE_INT } };
91static cmd_info_t pio_read_8_info = {
92 .name = "pio_read_8",
93 .description = "pio_read_8 <address> Read 1 byte from memory (or port).",
94 .func = cmd_pio_read_8,
95 .argc = 1,
96 .argv = pio_read_8_argv
97};
98
99/* Data and methods for pio_read_16 command */
100static int cmd_pio_read_16(cmd_arg_t *argv);
101static cmd_arg_t pio_read_16_argv[] = { { .type = ARG_TYPE_INT } };
102static cmd_info_t pio_read_16_info = {
103 .name = "pio_read_16",
104 .description = "pio_read_16 <address> Read 2 bytes from memory (or port).",
105 .func = cmd_pio_read_16,
106 .argc = 1,
107 .argv = pio_read_16_argv
108};
109
110/* Data and methods for pio_read_32 command */
111static int cmd_pio_read_32(cmd_arg_t *argv);
112static cmd_arg_t pio_read_32_argv[] = { { .type = ARG_TYPE_INT } };
113static cmd_info_t pio_read_32_info = {
114 .name = "pio_read_32",
115 .description = "pio_read_32 <address> Read 4 bytes from memory (or port).",
116 .func = cmd_pio_read_32,
117 .argc = 1,
118 .argv = pio_read_32_argv
119};
120
121/* Data and methods for pio_write_8 command */
122static int cmd_pio_write_8(cmd_arg_t *argv);
123static cmd_arg_t pio_write_8_argv[] = {
124 { .type = ARG_TYPE_INT },
125 { .type = ARG_TYPE_INT }
126};
127static cmd_info_t pio_write_8_info = {
128 .name = "pio_write_8",
129 .description = "pio_write_8 <address> <value> Write 1 byte to memory (or port).",
130 .func = cmd_pio_write_8,
131 .argc = 2,
132 .argv = pio_write_8_argv
133};
134
135/* Data and methods for pio_write_16 command */
136static int cmd_pio_write_16(cmd_arg_t *argv);
137static cmd_arg_t pio_write_16_argv[] = {
138 { .type = ARG_TYPE_INT },
139 { .type = ARG_TYPE_INT }
140};
141static cmd_info_t pio_write_16_info = {
142 .name = "pio_write_16",
143 .description = "pio_write_16 <address> <value> Write 2 bytes to memory (or port).",
144 .func = cmd_pio_write_16,
145 .argc = 2,
146 .argv = pio_write_16_argv
147};
148
149/* Data and methods for pio_write_32 command */
150static int cmd_pio_write_32(cmd_arg_t *argv);
151static cmd_arg_t pio_write_32_argv[] = {
152 { .type = ARG_TYPE_INT },
153 { .type = ARG_TYPE_INT }
154};
155static cmd_info_t pio_write_32_info = {
156 .name = "pio_write_32",
157 .description = "pio_write_32 <address> <value> Write 4 bytes to memory (or port).",
158 .func = cmd_pio_write_32,
159 .argc = 2,
160 .argv = pio_write_32_argv
161};
162
[df58e44]163/* Data and methods for 'reboot' command. */
[f74bbaf]164static int cmd_reboot(cmd_arg_t *argv);
165static cmd_info_t reboot_info = {
166 .name = "reboot",
[df58e44]167 .description = "Reboot system.",
[f74bbaf]168 .func = cmd_reboot,
[e07fe0c]169 .argc = 0
170};
171
[df58e44]172/* Data and methods for 'uptime' command. */
[4b662f8c]173static int cmd_uptime(cmd_arg_t *argv);
174static cmd_info_t uptime_info = {
175 .name = "uptime",
[df58e44]176 .description = "Show system uptime.",
[4b662f8c]177 .func = cmd_uptime,
178 .argc = 0
179};
180
[df58e44]181/* Data and methods for 'continue' command. */
[41d33ac]182static int cmd_continue(cmd_arg_t *argv);
183static cmd_info_t continue_info = {
184 .name = "continue",
[319e60e]185 .description = "Return console back to userspace.",
[41d33ac]186 .func = cmd_continue,
187 .argc = 0
188};
189
[319e60e]190#ifdef CONFIG_TEST
[5b7a107]191
[df58e44]192/* Data and methods for 'test' command. */
[319e60e]193static char test_buf[MAX_CMDLINE + 1];
194static int cmd_test(cmd_arg_t *argv);
195static cmd_arg_t test_argv[] = {
196 {
[851f33a]197 .type = ARG_TYPE_STRING_OPTIONAL,
[319e60e]198 .buffer = test_buf,
199 .len = sizeof(test_buf)
200 }
201};
202static cmd_info_t test_info = {
203 .name = "test",
[df58e44]204 .description = "<test> List kernel tests or run a test.",
[319e60e]205 .func = cmd_test,
206 .argc = 1,
[e8d48d2]207 .argv = test_argv,
208 .hints_enum = tests_hints_enum
[319e60e]209};
[95155b0c]210
[df58e44]211/* Data and methods for 'bench' command. */
[95155b0c]212static int cmd_bench(cmd_arg_t *argv);
213static cmd_arg_t bench_argv[] = {
214 {
215 .type = ARG_TYPE_STRING,
216 .buffer = test_buf,
217 .len = sizeof(test_buf)
218 },
219 {
220 .type = ARG_TYPE_INT,
221 }
222};
223static cmd_info_t bench_info = {
224 .name = "bench",
[df58e44]225 .description = "<test> <count> Run kernel test as benchmark.",
[95155b0c]226 .func = cmd_bench,
227 .argc = 2,
228 .argv = bench_argv
229};
[5b7a107]230
[7130754]231/* Data and methods for 'printbench' command. */
232static int cmd_printbench(cmd_arg_t *argv);
233
234static cmd_info_t printbench_info = {
235 .name = "printbench",
236 .description = "Run a printing benchmark.",
237 .func = cmd_printbench,
238 .argc = 0,
239};
240
[5b7a107]241#endif /* CONFIG_TEST */
[319e60e]242
[b45c443]243/* Data and methods for 'description' command. */
[442d0ae]244static int cmd_desc(cmd_arg_t *argv);
245static void desc_help(void);
[df58e44]246static char desc_buf[MAX_CMDLINE + 1];
[442d0ae]247static cmd_arg_t desc_argv = {
248 .type = ARG_TYPE_STRING,
249 .buffer = desc_buf,
250 .len = sizeof(desc_buf)
251};
252static cmd_info_t desc_info = {
253 .name = "describe",
[df58e44]254 .description = "<command> Describe specified command.",
[442d0ae]255 .help = desc_help,
256 .func = cmd_desc,
257 .argc = 1,
[3266412]258 .argv = &desc_argv,
259 .hints_enum = cmdtab_enum
[442d0ae]260};
261
[b45c443]262/* Data and methods for 'symaddr' command. */
[442d0ae]263static int cmd_symaddr(cmd_arg_t *argv);
[df58e44]264static char symaddr_buf[MAX_CMDLINE + 1];
[442d0ae]265static cmd_arg_t symaddr_argv = {
266 .type = ARG_TYPE_STRING,
267 .buffer = symaddr_buf,
268 .len = sizeof(symaddr_buf)
269};
270static cmd_info_t symaddr_info = {
271 .name = "symaddr",
[df58e44]272 .description = "<symbol> Return symbol address.",
[442d0ae]273 .func = cmd_symaddr,
274 .argc = 1,
[3266412]275 .argv = &symaddr_argv,
276 .hints_enum = symtab_hints_enum,
[442d0ae]277};
278
[df58e44]279/* Data and methods for 'set4' command. */
280static char set_buf[MAX_CMDLINE + 1];
[ba276f7]281static int cmd_set4(cmd_arg_t *argv);
282static cmd_arg_t set4_argv[] = {
283 {
284 .type = ARG_TYPE_STRING,
285 .buffer = set_buf,
286 .len = sizeof(set_buf)
287 },
[1b20da0]288 {
[ba276f7]289 .type = ARG_TYPE_INT
290 }
291};
292static cmd_info_t set4_info = {
293 .name = "set4",
[df58e44]294 .description = "<addr> <value> Set 4B memory location to a value.",
[ba276f7]295 .func = cmd_set4,
296 .argc = 2,
297 .argv = set4_argv
298};
299
[c0f13d2]300/* Data and methods for 'call0' and 'mcall0' command. */
[e5dbbe5]301static char call0_buf[MAX_CMDLINE + 1];
302static char carg1_buf[MAX_CMDLINE + 1];
303static char carg2_buf[MAX_CMDLINE + 1];
304static char carg3_buf[MAX_CMDLINE + 1];
[442d0ae]305
306static int cmd_call0(cmd_arg_t *argv);
307static cmd_arg_t call0_argv = {
308 .type = ARG_TYPE_STRING,
309 .buffer = call0_buf,
310 .len = sizeof(call0_buf)
311};
312static cmd_info_t call0_info = {
313 .name = "call0",
[df58e44]314 .description = "<function> Call function().",
[442d0ae]315 .func = cmd_call0,
316 .argc = 1,
[a363016]317 .argv = &call0_argv,
318 .hints_enum = symtab_hints_enum
[442d0ae]319};
320
[e5dbbe5]321/* Data and methods for 'mcall0' command. */
322static int cmd_mcall0(cmd_arg_t *argv);
323static cmd_arg_t mcall0_argv = {
324 .type = ARG_TYPE_STRING,
325 .buffer = call0_buf,
326 .len = sizeof(call0_buf)
327};
328static cmd_info_t mcall0_info = {
329 .name = "mcall0",
[df58e44]330 .description = "<function> Call function() on each CPU.",
[e5dbbe5]331 .func = cmd_mcall0,
332 .argc = 1,
[a363016]333 .argv = &mcall0_argv,
334 .hints_enum = symtab_hints_enum
[e5dbbe5]335};
336
[b45c443]337/* Data and methods for 'call1' command. */
[442d0ae]338static int cmd_call1(cmd_arg_t *argv);
339static cmd_arg_t call1_argv[] = {
340 {
341 .type = ARG_TYPE_STRING,
342 .buffer = call0_buf,
343 .len = sizeof(call0_buf)
344 },
[1b20da0]345 {
[442d0ae]346 .type = ARG_TYPE_VAR,
347 .buffer = carg1_buf,
348 .len = sizeof(carg1_buf)
349 }
350};
351static cmd_info_t call1_info = {
352 .name = "call1",
[df58e44]353 .description = "<function> <arg1> Call function(arg1).",
[442d0ae]354 .func = cmd_call1,
355 .argc = 2,
[a363016]356 .argv = call1_argv,
357 .hints_enum = symtab_hints_enum
[442d0ae]358};
359
[b45c443]360/* Data and methods for 'call2' command. */
[442d0ae]361static int cmd_call2(cmd_arg_t *argv);
362static cmd_arg_t call2_argv[] = {
363 {
364 .type = ARG_TYPE_STRING,
365 .buffer = call0_buf,
366 .len = sizeof(call0_buf)
367 },
[1b20da0]368 {
[442d0ae]369 .type = ARG_TYPE_VAR,
370 .buffer = carg1_buf,
371 .len = sizeof(carg1_buf)
372 },
[1b20da0]373 {
[442d0ae]374 .type = ARG_TYPE_VAR,
375 .buffer = carg2_buf,
376 .len = sizeof(carg2_buf)
377 }
378};
379static cmd_info_t call2_info = {
380 .name = "call2",
[df58e44]381 .description = "<function> <arg1> <arg2> Call function(arg1, arg2).",
[442d0ae]382 .func = cmd_call2,
383 .argc = 3,
[a363016]384 .argv = call2_argv,
385 .hints_enum = symtab_hints_enum
[442d0ae]386};
387
[b45c443]388/* Data and methods for 'call3' command. */
[442d0ae]389static int cmd_call3(cmd_arg_t *argv);
390static cmd_arg_t call3_argv[] = {
391 {
392 .type = ARG_TYPE_STRING,
393 .buffer = call0_buf,
394 .len = sizeof(call0_buf)
395 },
[1b20da0]396 {
[442d0ae]397 .type = ARG_TYPE_VAR,
398 .buffer = carg1_buf,
399 .len = sizeof(carg1_buf)
400 },
[1b20da0]401 {
[442d0ae]402 .type = ARG_TYPE_VAR,
403 .buffer = carg2_buf,
404 .len = sizeof(carg2_buf)
405 },
[1b20da0]406 {
[442d0ae]407 .type = ARG_TYPE_VAR,
408 .buffer = carg3_buf,
409 .len = sizeof(carg3_buf)
410 }
411
412};
413static cmd_info_t call3_info = {
414 .name = "call3",
[df58e44]415 .description = "<function> <arg1> <arg2> <arg3> Call function(arg1, arg2, arg3).",
[442d0ae]416 .func = cmd_call3,
417 .argc = 4,
[a363016]418 .argv = call3_argv,
419 .hints_enum = symtab_hints_enum
[442d0ae]420};
421
[b45c443]422/* Data and methods for 'halt' command. */
[442d0ae]423static int cmd_halt(cmd_arg_t *argv);
424static cmd_info_t halt_info = {
425 .name = "halt",
426 .description = "Halt the kernel.",
427 .func = cmd_halt,
428 .argc = 0
429};
430
[b07c332]431/* Data and methods for 'physmem' command. */
432static int cmd_physmem(cmd_arg_t *argv);
433cmd_info_t physmem_info = {
434 .name = "physmem",
435 .description = "Print physical memory configuration.",
436 .help = NULL,
437 .func = cmd_physmem,
438 .argc = 0,
439 .argv = NULL
440};
441
[b45c443]442/* Data and methods for 'tlb' command. */
[0132630]443static int cmd_tlb(cmd_arg_t *argv);
444cmd_info_t tlb_info = {
445 .name = "tlb",
[df58e44]446 .description = "Print TLB of the current CPU.",
[442d0ae]447 .help = NULL,
[0132630]448 .func = cmd_tlb,
[442d0ae]449 .argc = 0,
450 .argv = NULL
451};
452
[48dcc69]453static char flag_buf[MAX_CMDLINE + 1];
454
[55ab0f1]455static int cmd_threads(cmd_arg_t *argv);
[48dcc69]456static cmd_arg_t threads_argv = {
457 .type = ARG_TYPE_STRING_OPTIONAL,
458 .buffer = flag_buf,
459 .len = sizeof(flag_buf)
460};
[55ab0f1]461static cmd_info_t threads_info = {
462 .name = "threads",
[48dcc69]463 .description = "List all threads (use -a for additional information).",
[55ab0f1]464 .func = cmd_threads,
[48dcc69]465 .argc = 1,
466 .argv = &threads_argv
[55ab0f1]467};
468
[37c57f2]469static int cmd_tasks(cmd_arg_t *argv);
[c0f13d2]470static cmd_arg_t tasks_argv = {
471 .type = ARG_TYPE_STRING_OPTIONAL,
[48dcc69]472 .buffer = flag_buf,
473 .len = sizeof(flag_buf)
[c0f13d2]474};
[37c57f2]475static cmd_info_t tasks_info = {
476 .name = "tasks",
[c0f13d2]477 .description = "List all tasks (use -a for additional information).",
[37c57f2]478 .func = cmd_tasks,
[c0f13d2]479 .argc = 1,
480 .argv = &tasks_argv
[37c57f2]481};
482
[5b7a107]483#ifdef CONFIG_UDEBUG
484
[df58e44]485/* Data and methods for 'btrace' command */
486static int cmd_btrace(cmd_arg_t *argv);
487static cmd_arg_t btrace_argv = {
488 .type = ARG_TYPE_INT,
489};
490static cmd_info_t btrace_info = {
491 .name = "btrace",
492 .description = "<threadid> Show thread stack trace.",
493 .func = cmd_btrace,
494 .argc = 1,
495 .argv = &btrace_argv
496};
[80bff342]497
[5b7a107]498#endif /* CONFIG_UDEBUG */
[80bff342]499
[10e16a7]500static int cmd_sched(cmd_arg_t *argv);
501static cmd_info_t sched_info = {
502 .name = "scheduler",
[df58e44]503 .description = "Show scheduler information.",
[10e16a7]504 .func = cmd_sched,
505 .argc = 0
506};
507
[82d515e9]508static int cmd_caches(cmd_arg_t *argv);
509static cmd_info_t caches_info = {
510 .name = "caches",
[dd054bc2]511 .description = "List slab caches.",
[82d515e9]512 .func = cmd_caches,
[4e147a6]513 .argc = 0
514};
515
[b3631bc]516static int cmd_sysinfo(cmd_arg_t *argv);
517static cmd_info_t sysinfo_info = {
518 .name = "sysinfo",
519 .description = "Dump sysinfo.",
520 .func = cmd_sysinfo,
521 .argc = 0
522};
523
[b45c443]524/* Data and methods for 'zones' command */
[80bff342]525static int cmd_zones(cmd_arg_t *argv);
526static cmd_info_t zones_info = {
527 .name = "zones",
[df58e44]528 .description = "List memory zones.",
[80bff342]529 .func = cmd_zones,
530 .argc = 0
531};
532
[df58e44]533/* Data and methods for 'zone' command */
534static int cmd_zone(cmd_arg_t *argv);
535static cmd_arg_t zone_argv = {
536 .type = ARG_TYPE_INT,
537};
538
539static cmd_info_t zone_info = {
540 .name = "zone",
541 .description = "<zone> Show memory zone structure.",
542 .func = cmd_zone,
543 .argc = 1,
544 .argv = &zone_argv
545};
546
[073c9e6]547/* Data and methods for 'ipc' command */
548static int cmd_ipc(cmd_arg_t *argv);
549static cmd_arg_t ipc_argv = {
[c4e4507]550 .type = ARG_TYPE_INT,
551};
[073c9e6]552static cmd_info_t ipc_info = {
553 .name = "ipc",
[df58e44]554 .description = "<taskid> Show IPC information of a task.",
[073c9e6]555 .func = cmd_ipc,
[c4e4507]556 .argc = 1,
[073c9e6]557 .argv = &ipc_argv
[c4e4507]558};
559
[2a75302]560/* Data and methods for 'kill' command */
561static int cmd_kill(cmd_arg_t *argv);
562static cmd_arg_t kill_argv = {
563 .type = ARG_TYPE_INT,
564};
565static cmd_info_t kill_info = {
566 .name = "kill",
[df58e44]567 .description = "<taskid> Kill a task.",
[2a75302]568 .func = cmd_kill,
569 .argc = 1,
570 .argv = &kill_argv
571};
572
[b45c443]573/* Data and methods for 'cpus' command. */
[0132630]574static int cmd_cpus(cmd_arg_t *argv);
575cmd_info_t cpus_info = {
576 .name = "cpus",
577 .description = "List all processors.",
578 .help = NULL,
579 .func = cmd_cpus,
580 .argc = 0,
581 .argv = NULL
582};
583
[b45c443]584/* Data and methods for 'version' command. */
[0132630]585static int cmd_version(cmd_arg_t *argv);
586cmd_info_t version_info = {
587 .name = "version",
588 .description = "Print version information.",
589 .help = NULL,
590 .func = cmd_version,
591 .argc = 0,
592 .argv = NULL
593};
594
[10e16a7]595static cmd_info_t *basic_commands[] = {
596 &call0_info,
[e5dbbe5]597 &mcall0_info,
[82d515e9]598 &caches_info,
[10e16a7]599 &call1_info,
600 &call2_info,
601 &call3_info,
[41d33ac]602 &continue_info,
[10e16a7]603 &cpus_info,
604 &desc_info,
605 &halt_info,
606 &help_info,
[073c9e6]607 &ipc_info,
[2a75302]608 &kill_info,
[df58e44]609 &physmem_info,
610 &reboot_info,
611 &sched_info,
[10e16a7]612 &set4_info,
613 &symaddr_info,
[df58e44]614 &sysinfo_info,
[37c57f2]615 &tasks_info,
[df58e44]616 &threads_info,
[10e16a7]617 &tlb_info,
[df58e44]618 &uptime_info,
[10e16a7]619 &version_info,
620 &zones_info,
621 &zone_info,
[319e60e]622#ifdef CONFIG_TEST
623 &test_info,
[95155b0c]624 &bench_info,
[7130754]625 &printbench_info,
[5b7a107]626#endif
627#ifdef CONFIG_UDEBUG
628 &btrace_info,
[319e60e]629#endif
[e8a1530]630 &pio_read_8_info,
631 &pio_read_16_info,
632 &pio_read_32_info,
633 &pio_write_8_info,
634 &pio_write_16_info,
635 &pio_write_32_info,
[10e16a7]636 NULL
637};
[80bff342]638
[442d0ae]639/** Initialize command info structure.
640 *
641 * @param cmd Command info structure.
642 *
643 */
644void cmd_initialize(cmd_info_t *cmd)
645{
[da1bafb]646 spinlock_initialize(&cmd->lock, "cmd.lock");
[442d0ae]647 link_initialize(&cmd->link);
648}
649
650/** Initialize and register commands. */
651void cmd_init(void)
652{
[b07c332]653 unsigned int i;
[80bff342]654
[b07c332]655 for (i = 0; basic_commands[i]; i++) {
[10e16a7]656 cmd_initialize(basic_commands[i]);
[40fb017]657 }
658
659 for (i = 0; basic_commands[i]; i++) {
660 if (!cmd_register(basic_commands[i])) {
[b2fa1204]661 log(LF_OTHER, LVL_ERROR,
662 "Cannot register command %s",
[40fb017]663 basic_commands[i]->name);
664 }
[10e16a7]665 }
[442d0ae]666}
667
668/** List supported commands.
669 *
670 * @param argv Argument vector.
671 *
672 * @return 0 on failure, 1 on success.
673 */
674int cmd_help(cmd_arg_t *argv)
675{
676 spinlock_lock(&cmd_lock);
[a35b458]677
[98000fb]678 size_t len = 0;
[feeac0d]679 list_foreach(cmd_list, link, cmd_info_t, hlp) {
[442d0ae]680 spinlock_lock(&hlp->lock);
[20cc877]681 if (str_length(hlp->name) > len)
682 len = str_length(hlp->name);
[c1f7f6ea]683 spinlock_unlock(&hlp->lock);
684 }
[a35b458]685
[0b0f4bb]686 unsigned int _len = (unsigned int) len;
687 if ((_len != len) || (((int) _len) < 0)) {
[b2fa1204]688 log(LF_OTHER, LVL_ERROR, "Command length overflow");
[0b0f4bb]689 return 1;
690 }
[a35b458]691
[feeac0d]692 list_foreach(cmd_list, link, cmd_info_t, hlp) {
[c1f7f6ea]693 spinlock_lock(&hlp->lock);
[0b0f4bb]694 printf("%-*s %s\n", _len, hlp->name, hlp->description);
[442d0ae]695 spinlock_unlock(&hlp->lock);
696 }
[a35b458]697
[ae318d3]698 spinlock_unlock(&cmd_lock);
[a35b458]699
[442d0ae]700 return 1;
701}
702
[e8a1530]703/** Read 1 byte from phys memory or io port.
704 *
705 * @param argv Argument vector.
706 *
707 * @return 0 on failure, 1 on success.
708 */
709static int cmd_pio_read_8(cmd_arg_t *argv)
710{
711 uint8_t *ptr = NULL;
[a35b458]712
[e8a1530]713#ifdef IO_SPACE_BOUNDARY
[3f6c16fe]714 if ((void *) argv->intval < IO_SPACE_BOUNDARY)
715 ptr = (void *) argv[0].intval;
[e8a1530]716 else
717#endif
[2f33fbc]718 ptr = (uint8_t *) km_map(argv[0].intval, sizeof(uint8_t),
[a1b9f63]719 PAGE_SIZE, PAGE_NOT_CACHEABLE);
[a35b458]720
[e8a1530]721 const uint8_t val = pio_read_8(ptr);
[2f33fbc]722 printf("read %" PRIxn ": %" PRIx8 "\n", argv[0].intval, val);
[a35b458]723
[e8a1530]724#ifdef IO_SPACE_BOUNDARY
[3f6c16fe]725 if ((void *) argv->intval < IO_SPACE_BOUNDARY)
[e8a1530]726 return 1;
727#endif
[a35b458]728
[2f33fbc]729 km_unmap((uintptr_t) ptr, sizeof(uint8_t));
[e8a1530]730 return 1;
731}
732
733/** Read 2 bytes from phys memory or io port.
734 *
735 * @param argv Argument vector.
736 *
737 * @return 0 on failure, 1 on success.
738 */
739static int cmd_pio_read_16(cmd_arg_t *argv)
740{
741 uint16_t *ptr = NULL;
[a35b458]742
[e8a1530]743#ifdef IO_SPACE_BOUNDARY
[3f6c16fe]744 if ((void *) argv->intval < IO_SPACE_BOUNDARY)
[2f33fbc]745 ptr = (void *) argv[0].intval;
[e8a1530]746 else
747#endif
[2f33fbc]748 ptr = (uint16_t *) km_map(argv[0].intval, sizeof(uint16_t),
[a1b9f63]749 PAGE_SIZE, PAGE_NOT_CACHEABLE);
[a35b458]750
[e8a1530]751 const uint16_t val = pio_read_16(ptr);
[2f33fbc]752 printf("read %" PRIxn ": %" PRIx16 "\n", argv[0].intval, val);
[a35b458]753
[e8a1530]754#ifdef IO_SPACE_BOUNDARY
[3f6c16fe]755 if ((void *) argv->intval < IO_SPACE_BOUNDARY)
[e8a1530]756 return 1;
757#endif
[a35b458]758
[2f33fbc]759 km_unmap((uintptr_t) ptr, sizeof(uint16_t));
[e8a1530]760 return 1;
761}
762
763/** Read 4 bytes from phys memory or io port.
764 *
765 * @param argv Argument vector.
766 *
767 * @return 0 on failure, 1 on success.
768 */
769static int cmd_pio_read_32(cmd_arg_t *argv)
770{
771 uint32_t *ptr = NULL;
[a35b458]772
[e8a1530]773#ifdef IO_SPACE_BOUNDARY
[3f6c16fe]774 if ((void *) argv->intval < IO_SPACE_BOUNDARY)
775 ptr = (void *) argv[0].intval;
[e8a1530]776 else
777#endif
[2f33fbc]778 ptr = (uint32_t *) km_map(argv[0].intval, sizeof(uint32_t),
[a1b9f63]779 PAGE_SIZE, PAGE_NOT_CACHEABLE);
[a35b458]780
[e8a1530]781 const uint32_t val = pio_read_32(ptr);
[2f33fbc]782 printf("read %" PRIxn ": %" PRIx32 "\n", argv[0].intval, val);
[a35b458]783
[e8a1530]784#ifdef IO_SPACE_BOUNDARY
[3f6c16fe]785 if ((void *) argv->intval < IO_SPACE_BOUNDARY)
[e8a1530]786 return 1;
787#endif
[a35b458]788
[2f33fbc]789 km_unmap((uintptr_t) ptr, sizeof(uint32_t));
[e8a1530]790 return 1;
791}
792
793/** Write 1 byte to phys memory or io port.
794 *
795 * @param argv Argument vector.
796 *
797 * @return 0 on failure, 1 on success.
798 */
799static int cmd_pio_write_8(cmd_arg_t *argv)
800{
801 uint8_t *ptr = NULL;
[a35b458]802
[e8a1530]803#ifdef IO_SPACE_BOUNDARY
[3f6c16fe]804 if ((void *) argv->intval < IO_SPACE_BOUNDARY)
805 ptr = (void *) argv[0].intval;
[e8a1530]806 else
807#endif
[2f33fbc]808 ptr = (uint8_t *) km_map(argv[0].intval, sizeof(uint8_t),
[a1b9f63]809 PAGE_SIZE, PAGE_NOT_CACHEABLE);
[a35b458]810
[2f33fbc]811 printf("write %" PRIxn ": %" PRIx8 "\n", argv[0].intval,
812 (uint8_t) argv[1].intval);
813 pio_write_8(ptr, (uint8_t) argv[1].intval);
[a35b458]814
[e8a1530]815#ifdef IO_SPACE_BOUNDARY
[3f6c16fe]816 if ((void *) argv->intval < IO_SPACE_BOUNDARY)
[e8a1530]817 return 1;
818#endif
[a35b458]819
[2f33fbc]820 km_unmap((uintptr_t) ptr, sizeof(uint8_t));
[e8a1530]821 return 1;
822}
823
824/** Write 2 bytes to phys memory or io port.
825 *
826 * @param argv Argument vector.
827 *
828 * @return 0 on failure, 1 on success.
829 */
830static int cmd_pio_write_16(cmd_arg_t *argv)
831{
832 uint16_t *ptr = NULL;
[a35b458]833
[e8a1530]834#ifdef IO_SPACE_BOUNDARY
[3f6c16fe]835 if ((void *) argv->intval < IO_SPACE_BOUNDARY)
836 ptr = (void *) argv[0].intval;
[e8a1530]837 else
838#endif
[2f33fbc]839 ptr = (uint16_t *) km_map(argv[0].intval, sizeof(uint16_t),
[a1b9f63]840 PAGE_SIZE, PAGE_NOT_CACHEABLE);
[a35b458]841
[2f33fbc]842 printf("write %" PRIxn ": %" PRIx16 "\n", argv[0].intval,
843 (uint16_t) argv[1].intval);
844 pio_write_16(ptr, (uint16_t) argv[1].intval);
[a35b458]845
[e8a1530]846#ifdef IO_SPACE_BOUNDARY
[3f6c16fe]847 if ((void *) argv->intval < IO_SPACE_BOUNDARY)
[e8a1530]848 return 1;
849#endif
[a35b458]850
[2f33fbc]851 km_unmap((uintptr_t) ptr, sizeof(uint16_t));
[e8a1530]852 return 1;
853}
854
855/** Write 4 bytes to phys memory or io port.
856 *
857 * @param argv Argument vector.
858 *
859 * @return 0 on failure, 1 on success.
860 */
861static int cmd_pio_write_32(cmd_arg_t *argv)
862{
863 uint32_t *ptr = NULL;
[a35b458]864
[e8a1530]865#ifdef IO_SPACE_BOUNDARY
[3f6c16fe]866 if ((void *) argv->intval < IO_SPACE_BOUNDARY)
867 ptr = (void *) argv[0].intval;
[e8a1530]868 else
869#endif
[2f33fbc]870 ptr = (uint32_t *) km_map(argv[0].intval, sizeof(uint32_t),
[a1b9f63]871 PAGE_SIZE, PAGE_NOT_CACHEABLE);
[a35b458]872
[2f33fbc]873 printf("write %" PRIxn ": %" PRIx32 "\n", argv[0].intval,
874 (uint32_t) argv[1].intval);
875 pio_write_32(ptr, (uint32_t) argv[1].intval);
[a35b458]876
[e8a1530]877#ifdef IO_SPACE_BOUNDARY
[3f6c16fe]878 if ((void *) argv->intval < IO_SPACE_BOUNDARY)
[e8a1530]879 return 1;
880#endif
[a35b458]881
[2f33fbc]882 km_unmap((uintptr_t) ptr, sizeof(uint32_t));
[e8a1530]883 return 1;
884}
885
[f74bbaf]886/** Reboot the system.
887 *
888 * @param argv Argument vector.
889 *
890 * @return 0 on failure, 1 on success.
891 */
892int cmd_reboot(cmd_arg_t *argv)
893{
894 reboot();
[a35b458]895
[f74bbaf]896 /* Not reached */
897 return 1;
898}
899
[4b662f8c]900/** Print system uptime information.
901 *
902 * @param argv Argument vector.
903 *
904 * @return 0 on failure, 1 on success.
905 */
906int cmd_uptime(cmd_arg_t *argv)
907{
[63e27ef]908 assert(uptime);
[a35b458]909
[4b662f8c]910 /* This doesn't have to be very accurate */
[96b02eb9]911 sysarg_t sec = uptime->seconds1;
[a35b458]912
[c859753]913 printf("Up %" PRIun " days, %" PRIun " hours, %" PRIun " minutes, %" PRIun " seconds\n",
[3bacee1]914 sec / 86400, (sec % 86400) / 3600, (sec % 3600) / 60, sec % 60);
[a35b458]915
[4b662f8c]916 return 1;
917}
918
[442d0ae]919/** Describe specified command.
920 *
921 * @param argv Argument vector.
922 *
923 * @return 0 on failure, 1 on success.
924 */
925int cmd_desc(cmd_arg_t *argv)
926{
927 spinlock_lock(&cmd_lock);
[a35b458]928
[feeac0d]929 list_foreach(cmd_list, link, cmd_info_t, hlp) {
[442d0ae]930 spinlock_lock(&hlp->lock);
[a35b458]931
[20cc877]932 if (str_lcmp(hlp->name, (const char *) argv->buffer, str_length(hlp->name)) == 0) {
[442d0ae]933 printf("%s - %s\n", hlp->name, hlp->description);
934 if (hlp->help)
935 hlp->help();
936 spinlock_unlock(&hlp->lock);
937 break;
938 }
[a35b458]939
[442d0ae]940 spinlock_unlock(&hlp->lock);
941 }
[a35b458]942
[1b20da0]943 spinlock_unlock(&cmd_lock);
[a35b458]944
[442d0ae]945 return 1;
946}
947
948/** Search symbol table */
949int cmd_symaddr(cmd_arg_t *argv)
950{
[828aa05]951 symtab_print_search((char *) argv->buffer);
[a35b458]952
[442d0ae]953 return 1;
954}
955
956/** Call function with zero parameters */
957int cmd_call0(cmd_arg_t *argv)
958{
[7f1c620]959 uintptr_t symaddr;
[e16e0d59]960 char *symbol;
[96b02eb9]961 sysarg_t (*fnc)(void);
[0f81ceb7]962 fncptr_t fptr;
[b7fd2a0]963 errno_t rc;
[e2b762ec]964
[e16e0d59]965 symbol = (char *) argv->buffer;
966 rc = symtab_addr_lookup(symbol, &symaddr);
967
968 if (rc == ENOENT)
969 printf("Symbol %s not found.\n", symbol);
970 else if (rc == EOVERFLOW) {
971 symtab_print_search(symbol);
[442d0ae]972 printf("Duplicate symbol, be more specific.\n");
[e16e0d59]973 } else if (rc == EOK) {
[c992538a]974 ipl_t ipl;
975
976 ipl = interrupts_disable();
[96b02eb9]977 fnc = (sysarg_t (*)(void)) arch_construct_function(&fptr,
[e16e0d59]978 (void *) symaddr, (void *) cmd_call0);
[0b0f4bb]979 printf("Calling %s() (%p)\n", symbol, (void *) symaddr);
[0f81ceb7]980 printf("Result: %#" PRIxn "\n", fnc());
[c992538a]981 interrupts_restore(ipl);
[e16e0d59]982 } else {
983 printf("No symbol information available.\n");
[442d0ae]984 }
985 return 1;
986}
987
[e5dbbe5]988/** Call function with zero parameters on each CPU */
989int cmd_mcall0(cmd_arg_t *argv)
990{
991 /*
992 * For each CPU, create a thread which will
993 * call the function.
994 */
[a35b458]995
[0b0f4bb]996 unsigned int i;
[e5dbbe5]997 for (i = 0; i < config.cpu_count; i++) {
[b8f11baa]998 if (!cpus[i].active)
999 continue;
[a35b458]1000
[da1bafb]1001 thread_t *thread;
1002 if ((thread = thread_create((void (*)(void *)) cmd_call0,
[6eef3c4]1003 (void *) argv, TASK, THREAD_FLAG_NONE, "call0"))) {
[0b0f4bb]1004 printf("cpu%u: ", i);
[6eef3c4]1005 thread_wire(thread, &cpus[i]);
[1871118]1006 thread_ready(thread_ref(thread));
[da1bafb]1007 thread_join(thread);
[e5dbbe5]1008 } else
[0b0f4bb]1009 printf("Unable to create thread for cpu%u\n", i);
[e5dbbe5]1010 }
[a35b458]1011
[e5dbbe5]1012 return 1;
1013}
1014
[442d0ae]1015/** Call function with one parameter */
1016int cmd_call1(cmd_arg_t *argv)
1017{
[7f1c620]1018 uintptr_t symaddr;
[442d0ae]1019 char *symbol;
[96b02eb9]1020 sysarg_t (*fnc)(sysarg_t, ...);
1021 sysarg_t arg1 = argv[1].intval;
[0f81ceb7]1022 fncptr_t fptr;
[b7fd2a0]1023 errno_t rc;
[e2b762ec]1024
[e16e0d59]1025 symbol = (char *) argv->buffer;
1026 rc = symtab_addr_lookup(symbol, &symaddr);
1027
1028 if (rc == ENOENT) {
1029 printf("Symbol %s not found.\n", symbol);
1030 } else if (rc == EOVERFLOW) {
1031 symtab_print_search(symbol);
[442d0ae]1032 printf("Duplicate symbol, be more specific.\n");
[e16e0d59]1033 } else if (rc == EOK) {
[c992538a]1034 ipl_t ipl;
1035
1036 ipl = interrupts_disable();
[96b02eb9]1037 fnc = (sysarg_t (*)(sysarg_t, ...))
[0b0f4bb]1038 arch_construct_function(&fptr, (void *) symaddr,
1039 (void *) cmd_call1);
1040 printf("Calling f(%#" PRIxn "): %p: %s\n", arg1,
1041 (void *) symaddr, symbol);
[0f81ceb7]1042 printf("Result: %#" PRIxn "\n", fnc(arg1));
[c992538a]1043 interrupts_restore(ipl);
[e16e0d59]1044 } else {
1045 printf("No symbol information available.\n");
[442d0ae]1046 }
[e16e0d59]1047
[442d0ae]1048 return 1;
1049}
1050
1051/** Call function with two parameters */
1052int cmd_call2(cmd_arg_t *argv)
1053{
[7f1c620]1054 uintptr_t symaddr;
[442d0ae]1055 char *symbol;
[96b02eb9]1056 sysarg_t (*fnc)(sysarg_t, sysarg_t, ...);
1057 sysarg_t arg1 = argv[1].intval;
1058 sysarg_t arg2 = argv[2].intval;
[0f81ceb7]1059 fncptr_t fptr;
[b7fd2a0]1060 errno_t rc;
[e16e0d59]1061
1062 symbol = (char *) argv->buffer;
1063 rc = symtab_addr_lookup(symbol, &symaddr);
1064
1065 if (rc == ENOENT) {
1066 printf("Symbol %s not found.\n", symbol);
1067 } else if (rc == EOVERFLOW) {
1068 symtab_print_search(symbol);
[442d0ae]1069 printf("Duplicate symbol, be more specific.\n");
[e16e0d59]1070 } else if (rc == EOK) {
[c992538a]1071 ipl_t ipl;
1072
1073 ipl = interrupts_disable();
[96b02eb9]1074 fnc = (sysarg_t (*)(sysarg_t, sysarg_t, ...))
[0b0f4bb]1075 arch_construct_function(&fptr, (void *) symaddr,
1076 (void *) cmd_call2);
[1b20da0]1077 printf("Calling f(%#" PRIxn ", %#" PRIxn "): %p: %s\n",
[3bacee1]1078 arg1, arg2, (void *) symaddr, symbol);
[0f81ceb7]1079 printf("Result: %#" PRIxn "\n", fnc(arg1, arg2));
[c992538a]1080 interrupts_restore(ipl);
[e16e0d59]1081 } else {
1082 printf("No symbol information available.\n");
1083 }
[442d0ae]1084 return 1;
1085}
1086
1087/** Call function with three parameters */
1088int cmd_call3(cmd_arg_t *argv)
1089{
[7f1c620]1090 uintptr_t symaddr;
[442d0ae]1091 char *symbol;
[96b02eb9]1092 sysarg_t (*fnc)(sysarg_t, sysarg_t, sysarg_t, ...);
1093 sysarg_t arg1 = argv[1].intval;
1094 sysarg_t arg2 = argv[2].intval;
1095 sysarg_t arg3 = argv[3].intval;
[0f81ceb7]1096 fncptr_t fptr;
[b7fd2a0]1097 errno_t rc;
[a35b458]1098
[e16e0d59]1099 symbol = (char *) argv->buffer;
1100 rc = symtab_addr_lookup(symbol, &symaddr);
1101
1102 if (rc == ENOENT) {
1103 printf("Symbol %s not found.\n", symbol);
1104 } else if (rc == EOVERFLOW) {
1105 symtab_print_search(symbol);
[442d0ae]1106 printf("Duplicate symbol, be more specific.\n");
[e16e0d59]1107 } else if (rc == EOK) {
[c992538a]1108 ipl_t ipl;
1109
1110 ipl = interrupts_disable();
[96b02eb9]1111 fnc = (sysarg_t (*)(sysarg_t, sysarg_t, sysarg_t, ...))
[0b0f4bb]1112 arch_construct_function(&fptr, (void *) symaddr,
1113 (void *) cmd_call3);
1114 printf("Calling f(%#" PRIxn ",%#" PRIxn ", %#" PRIxn "): %p: %s\n",
[3bacee1]1115 arg1, arg2, arg3, (void *) symaddr, symbol);
[0f81ceb7]1116 printf("Result: %#" PRIxn "\n", fnc(arg1, arg2, arg3));
[c992538a]1117 interrupts_restore(ipl);
[e16e0d59]1118 } else {
1119 printf("No symbol information available.\n");
[442d0ae]1120 }
1121 return 1;
1122}
1123
1124/** Print detailed description of 'describe' command. */
1125void desc_help(void)
1126{
1127 printf("Syntax: describe command_name\n");
1128}
1129
1130/** Halt the kernel.
1131 *
1132 * @param argv Argument vector (ignored).
1133 *
1134 * @return 0 on failure, 1 on success (never returns).
1135 */
1136int cmd_halt(cmd_arg_t *argv)
1137{
1138 halt();
1139 return 1;
1140}
1141
1142/** Command for printing TLB contents.
1143 *
1144 * @param argv Not used.
1145 *
1146 * @return Always returns 1.
1147 */
[0132630]1148int cmd_tlb(cmd_arg_t *argv)
[442d0ae]1149{
1150 tlb_print();
1151 return 1;
1152}
[ba276f7]1153
[b07c332]1154/** Command for printing physical memory configuration.
1155 *
1156 * @param argv Not used.
1157 *
1158 * @return Always returns 1.
1159 */
1160int cmd_physmem(cmd_arg_t *argv)
1161{
1162 physmem_print();
1163 return 1;
1164}
1165
[ba276f7]1166/** Write 4 byte value to address */
1167int cmd_set4(cmd_arg_t *argv)
1168{
[566da7f8]1169 uintptr_t addr = 0; // Prevent -Werror=maybe-uninitialized
[7f1c620]1170 uint32_t arg1 = argv[1].intval;
[ba276f7]1171 bool pointer = false;
[b7fd2a0]1172 errno_t rc;
[a35b458]1173
[4ce914d4]1174 if (((char *) argv->buffer)[0] == '*') {
[e16e0d59]1175 rc = symtab_addr_lookup((char *) argv->buffer + 1, &addr);
[ba276f7]1176 pointer = true;
[4ce914d4]1177 } else if (((char *) argv->buffer)[0] >= '0' &&
[3bacee1]1178 ((char *) argv->buffer)[0] <= '9') {
[4ce914d4]1179 uint64_t value;
[059a8e4]1180 rc = str_uint64_t((char *) argv->buffer, NULL, 0, true, &value);
[4ce914d4]1181 if (rc == EOK)
1182 addr = (uintptr_t) value;
1183 } else
[e16e0d59]1184 rc = symtab_addr_lookup((char *) argv->buffer, &addr);
[a35b458]1185
[e16e0d59]1186 if (rc == ENOENT)
[0b0f4bb]1187 printf("Symbol %s not found.\n", (char *) argv->buffer);
[4ce914d4]1188 else if (rc == EINVAL)
1189 printf("Invalid address.\n");
[e16e0d59]1190 else if (rc == EOVERFLOW) {
[828aa05]1191 symtab_print_search((char *) argv->buffer);
[4ce914d4]1192 printf("Duplicate symbol (be more specific) or address overflow.\n");
[e16e0d59]1193 } else if (rc == EOK) {
[ba276f7]1194 if (pointer)
[e16e0d59]1195 addr = *(uintptr_t *) addr;
[3bacee1]1196 printf("Writing %#" PRIx32 " -> %p\n", arg1, (void *) addr);
[e16e0d59]1197 *(uint32_t *) addr = arg1;
[4ce914d4]1198 } else
[e16e0d59]1199 printf("No symbol information available.\n");
[a35b458]1200
[ba276f7]1201 return 1;
1202}
[80bff342]1203
[82d515e9]1204/** Command for listing slab allocator caches
[4e147a6]1205 *
[82d515e9]1206 * @param argv Ignored
[4e147a6]1207 *
1208 * @return Always 1
1209 */
[82d515e9]1210int cmd_caches(cmd_arg_t *argv)
[095b1534]1211{
[4e147a6]1212 slab_print_list();
1213 return 1;
1214}
1215
[b3631bc]1216/** Command for dumping sysinfo
1217 *
1218 * @param argv Ignores
1219 *
1220 * @return Always 1
1221 */
[df58e44]1222int cmd_sysinfo(cmd_arg_t *argv)
[b3631bc]1223{
[9dae191e]1224 sysinfo_dump(NULL);
[b3631bc]1225 return 1;
1226}
1227
[df58e44]1228/** Command for listing thread information
[55ab0f1]1229 *
[48dcc69]1230 * @param argv Ignored
[55ab0f1]1231 *
1232 * @return Always 1
1233 */
[48dcc69]1234int cmd_threads(cmd_arg_t *argv)
[095b1534]1235{
[48dcc69]1236 if (str_cmp(flag_buf, "-a") == 0)
1237 thread_print_list(true);
1238 else if (str_cmp(flag_buf, "") == 0)
1239 thread_print_list(false);
1240 else
1241 printf("Unknown argument \"%s\".\n", flag_buf);
[a35b458]1242
[55ab0f1]1243 return 1;
1244}
1245
[df58e44]1246/** Command for listing task information
[37c57f2]1247 *
[48dcc69]1248 * @param argv Ignored
[37c57f2]1249 *
1250 * @return Always 1
1251 */
[c0f13d2]1252int cmd_tasks(cmd_arg_t *argv)
[095b1534]1253{
[48dcc69]1254 if (str_cmp(flag_buf, "-a") == 0)
[c0f13d2]1255 task_print_list(true);
[48dcc69]1256 else if (str_cmp(flag_buf, "") == 0)
[c0f13d2]1257 task_print_list(false);
1258 else
[48dcc69]1259 printf("Unknown argument \"%s\".\n", flag_buf);
[a35b458]1260
[37c57f2]1261 return 1;
1262}
1263
[5b7a107]1264#ifdef CONFIG_UDEBUG
1265
[df58e44]1266/** Command for printing thread stack trace
1267 *
1268 * @param argv Integer argument from cmdline expected
1269 *
1270 * return Always 1
1271 *
1272 */
1273int cmd_btrace(cmd_arg_t *argv)
1274{
1275 thread_stack_trace(argv[0].intval);
1276 return 1;
1277}
1278
[5b7a107]1279#endif /* CONFIG_UDEBUG */
1280
[df58e44]1281/** Command for printing scheduler information
[10e16a7]1282 *
1283 * @param argv Ignores
1284 *
1285 * @return Always 1
1286 */
[df58e44]1287int cmd_sched(cmd_arg_t *argv)
[095b1534]1288{
[10e16a7]1289 sched_print_list();
1290 return 1;
1291}
1292
[96cacc1]1293/** Command for listing memory zones
1294 *
1295 * @param argv Ignored
1296 *
1297 * return Always 1
1298 */
[df58e44]1299int cmd_zones(cmd_arg_t *argv)
[095b1534]1300{
[9dae191e]1301 zones_print_list();
[80bff342]1302 return 1;
1303}
[0132630]1304
[96cacc1]1305/** Command for memory zone details
1306 *
1307 * @param argv Integer argument from cmdline expected
1308 *
1309 * return Always 1
1310 */
[df58e44]1311int cmd_zone(cmd_arg_t *argv)
[095b1534]1312{
[dfd9186]1313 zone_print_one(argv[0].intval);
[80bff342]1314 return 1;
1315}
1316
[df58e44]1317/** Command for printing task IPC details
[c4e4507]1318 *
1319 * @param argv Integer argument from cmdline expected
1320 *
1321 * return Always 1
1322 */
[df58e44]1323int cmd_ipc(cmd_arg_t *argv)
[095b1534]1324{
[c4e4507]1325 ipc_print_task(argv[0].intval);
1326 return 1;
1327}
1328
[cb3d641a]1329/** Command for killing a task
[2a75302]1330 *
1331 * @param argv Integer argument from cmdline expected
1332 *
[cb3d641a]1333 * return 0 on failure, 1 on success.
[2a75302]1334 */
[df58e44]1335int cmd_kill(cmd_arg_t *argv)
[2a75302]1336{
1337 if (task_kill(argv[0].intval) != EOK)
1338 return 0;
1339
1340 return 1;
1341}
[c4e4507]1342
[0132630]1343/** Command for listing processors.
1344 *
1345 * @param argv Ignored.
1346 *
1347 * return Always 1.
1348 */
1349int cmd_cpus(cmd_arg_t *argv)
1350{
1351 cpu_list();
1352 return 1;
1353}
1354
1355/** Command for printing kernel version.
1356 *
1357 * @param argv Ignored.
1358 *
1359 * return Always 1.
1360 */
1361int cmd_version(cmd_arg_t *argv)
1362{
1363 version_print();
1364 return 1;
1365}
[41d33ac]1366
1367/** Command for returning console back to userspace.
1368 *
1369 * @param argv Ignored.
1370 *
1371 * return Always 1.
1372 */
1373int cmd_continue(cmd_arg_t *argv)
1374{
[dd054bc2]1375 printf("The kernel will now relinquish the console.\n");
[516ff92]1376 release_console();
[821cc93]1377 indev_pop_character(stdin);
[a35b458]1378
[41d33ac]1379 return 1;
1380}
[b45c443]1381
[50661ab]1382#ifdef CONFIG_TEST
[62b6d17]1383static bool run_test(const test_t *test)
[34db7fa]1384{
[c1f7f6ea]1385 printf("%s (%s)\n", test->name, test->desc);
[a35b458]1386
[7c3fb9b]1387 /*
1388 * Update and read thread accounting
1389 * for benchmarking
1390 */
[da1bafb]1391 irq_spinlock_lock(&TASK->lock, true);
[1ba37fa]1392 uint64_t ucycles0, kcycles0;
1393 task_get_accounting(TASK, &ucycles0, &kcycles0);
[da1bafb]1394 irq_spinlock_unlock(&TASK->lock, true);
[a35b458]1395
[cce6acf]1396 /* Execute the test */
[cb01e1e]1397 test_quiet = false;
[a000878c]1398 const char *ret = test->entry();
[a35b458]1399
[cce6acf]1400 /* Update and read thread accounting */
[da1bafb]1401 uint64_t ucycles1, kcycles1;
1402 irq_spinlock_lock(&TASK->lock, true);
[1ba37fa]1403 task_get_accounting(TASK, &ucycles1, &kcycles1);
[da1bafb]1404 irq_spinlock_unlock(&TASK->lock, true);
[a35b458]1405
[1ba37fa]1406 uint64_t ucycles, kcycles;
1407 char usuffix, ksuffix;
[e535eeb]1408 order_suffix(ucycles1 - ucycles0, &ucycles, &usuffix);
1409 order_suffix(kcycles1 - kcycles0, &kcycles, &ksuffix);
[a35b458]1410
[1ba37fa]1411 printf("Time: %" PRIu64 "%c user cycles, %" PRIu64 "%c kernel cycles\n",
[da1bafb]1412 ucycles, usuffix, kcycles, ksuffix);
[a35b458]1413
[34db7fa]1414 if (ret == NULL) {
1415 printf("Test passed\n");
[62b6d17]1416 return true;
[34db7fa]1417 }
[a35b458]1418
[34db7fa]1419 printf("%s\n", ret);
[62b6d17]1420 return false;
[34db7fa]1421}
1422
[95155b0c]1423static bool run_bench(const test_t *test, const uint32_t cnt)
1424{
1425 uint32_t i;
1426 bool ret = true;
[1ba37fa]1427 uint64_t ucycles, kcycles;
1428 char usuffix, ksuffix;
[a35b458]1429
[95155b0c]1430 if (cnt < 1)
1431 return true;
[a35b458]1432
[11b285d]1433 uint64_t *data = (uint64_t *) malloc(sizeof(uint64_t) * cnt);
[95155b0c]1434 if (data == NULL) {
1435 printf("Error allocating memory for statistics\n");
1436 return false;
1437 }
[a35b458]1438
[95155b0c]1439 for (i = 0; i < cnt; i++) {
[c859753]1440 printf("%s (%u/%u) ... ", test->name, i + 1, cnt);
[a35b458]1441
[7c3fb9b]1442 /*
1443 * Update and read thread accounting
1444 * for benchmarking
1445 */
[da1bafb]1446 irq_spinlock_lock(&TASK->lock, true);
[1ba37fa]1447 uint64_t ucycles0, kcycles0;
1448 task_get_accounting(TASK, &ucycles0, &kcycles0);
[da1bafb]1449 irq_spinlock_unlock(&TASK->lock, true);
[a35b458]1450
[95155b0c]1451 /* Execute the test */
[cb01e1e]1452 test_quiet = true;
[21881bd8]1453 const char *test_ret = test->entry();
[a35b458]1454
[95155b0c]1455 /* Update and read thread accounting */
[da1bafb]1456 irq_spinlock_lock(&TASK->lock, true);
[1ba37fa]1457 uint64_t ucycles1, kcycles1;
1458 task_get_accounting(TASK, &ucycles1, &kcycles1);
[da1bafb]1459 irq_spinlock_unlock(&TASK->lock, true);
[a35b458]1460
[21881bd8]1461 if (test_ret != NULL) {
1462 printf("%s\n", test_ret);
[95155b0c]1463 ret = false;
1464 break;
1465 }
[a35b458]1466
[1ba37fa]1467 data[i] = ucycles1 - ucycles0 + kcycles1 - kcycles0;
[e535eeb]1468 order_suffix(ucycles1 - ucycles0, &ucycles, &usuffix);
1469 order_suffix(kcycles1 - kcycles0, &kcycles, &ksuffix);
[1ba37fa]1470 printf("OK (%" PRIu64 "%c user cycles, %" PRIu64 "%c kernel cycles)\n",
[da1bafb]1471 ucycles, usuffix, kcycles, ksuffix);
[95155b0c]1472 }
[a35b458]1473
[95155b0c]1474 if (ret) {
1475 printf("\n");
[a35b458]1476
[95155b0c]1477 uint64_t sum = 0;
[a35b458]1478
[95155b0c]1479 for (i = 0; i < cnt; i++) {
1480 sum += data[i];
1481 }
[a35b458]1482
[e535eeb]1483 order_suffix(sum / (uint64_t) cnt, &ucycles, &usuffix);
[1ba37fa]1484 printf("Average\t\t%" PRIu64 "%c\n", ucycles, usuffix);
[95155b0c]1485 }
[a35b458]1486
[95155b0c]1487 free(data);
[a35b458]1488
[95155b0c]1489 return ret;
1490}
1491
[851f33a]1492static void list_tests(void)
1493{
1494 size_t len = 0;
1495 test_t *test;
[a35b458]1496
[851f33a]1497 for (test = tests; test->name != NULL; test++) {
1498 if (str_length(test->name) > len)
1499 len = str_length(test->name);
1500 }
[a35b458]1501
[0b0f4bb]1502 unsigned int _len = (unsigned int) len;
1503 if ((_len != len) || (((int) _len) < 0)) {
1504 printf("Command length overflow\n");
1505 return;
1506 }
[a35b458]1507
[851f33a]1508 for (test = tests; test->name != NULL; test++)
[0b0f4bb]1509 printf("%-*s %s%s\n", _len, test->name, test->desc,
1510 (test->safe ? "" : " (unsafe)"));
[a35b458]1511
[0b0f4bb]1512 printf("%-*s Run all safe tests\n", _len, "*");
[851f33a]1513}
1514
1515/** Command for listing and running kernel tests
[319e60e]1516 *
1517 * @param argv Argument vector.
1518 *
1519 * return Always 1.
[851f33a]1520 *
[319e60e]1521 */
1522int cmd_test(cmd_arg_t *argv)
1523{
1524 test_t *test;
[a35b458]1525
[20cc877]1526 if (str_cmp((char *) argv->buffer, "*") == 0) {
[50661ab]1527 for (test = tests; test->name != NULL; test++) {
1528 if (test->safe) {
[34db7fa]1529 printf("\n");
1530 if (!run_test(test))
1531 break;
[50661ab]1532 }
1533 }
[851f33a]1534 } else if (str_cmp((char *) argv->buffer, "") != 0) {
[50661ab]1535 bool fnd = false;
[a35b458]1536
[50661ab]1537 for (test = tests; test->name != NULL; test++) {
[20cc877]1538 if (str_cmp(test->name, (char *) argv->buffer) == 0) {
[50661ab]1539 fnd = true;
[34db7fa]1540 run_test(test);
[50661ab]1541 break;
1542 }
[319e60e]1543 }
[a35b458]1544
[50661ab]1545 if (!fnd)
[34db7fa]1546 printf("Unknown test\n");
[851f33a]1547 } else
1548 list_tests();
[a35b458]1549
[319e60e]1550 return 1;
1551}
[95155b0c]1552
1553/** Command for returning kernel tests as benchmarks
1554 *
1555 * @param argv Argument vector.
1556 *
1557 * return Always 1.
1558 */
1559int cmd_bench(cmd_arg_t *argv)
1560{
1561 test_t *test;
1562 uint32_t cnt = argv[1].intval;
[a35b458]1563
[3f2177e]1564 if (str_cmp((char *) argv->buffer, "*") == 0) {
1565 for (test = tests; test->name != NULL; test++) {
1566 if (test->safe) {
1567 if (!run_bench(test, cnt))
1568 break;
1569 }
[95155b0c]1570 }
[3f2177e]1571 } else {
1572 bool fnd = false;
[a35b458]1573
[3f2177e]1574 for (test = tests; test->name != NULL; test++) {
1575 if (str_cmp(test->name, (char *) argv->buffer) == 0) {
1576 fnd = true;
[a35b458]1577
[3f2177e]1578 if (test->safe)
1579 run_bench(test, cnt);
1580 else
1581 printf("Unsafe test\n");
[a35b458]1582
[3f2177e]1583 break;
1584 }
1585 }
[a35b458]1586
[3f2177e]1587 if (!fnd)
1588 printf("Unknown test\n");
1589 }
[a35b458]1590
[95155b0c]1591 return 1;
1592}
1593
[7130754]1594int cmd_printbench(cmd_arg_t *argv)
1595{
1596 int cnt = 20;
1597
1598 uint64_t *data = malloc(sizeof(uint64_t) * cnt);
1599 if (data == NULL) {
1600 printf("Error allocating memory for statistics\n");
1601 return false;
1602 }
1603
1604 for (int i = 0; i < cnt; i++) {
1605 /*
1606 * Update and read thread accounting
1607 * for benchmarking
1608 */
1609 irq_spinlock_lock(&TASK->lock, true);
1610 uint64_t ucycles0, kcycles0;
1611 task_get_accounting(TASK, &ucycles0, &kcycles0);
1612 irq_spinlock_unlock(&TASK->lock, true);
1613
1614 /* Execute the test */
1615 for (int j = 0; j < 20; j++) {
1616 printf("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ěščřžýáíéú!@#$%%^&*(){}+\n");
1617 printf("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ěščřžýáíéú!@#$%%^&*(){}+abcdefghijklmnopqrstuvwxyz\n");
1618 printf("0123456789ěščřžýáíéú!@#$%%^&*(){}+abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\n");
1619 }
1620
1621 /* Update and read thread accounting */
1622 irq_spinlock_lock(&TASK->lock, true);
1623 uint64_t ucycles1, kcycles1;
1624 task_get_accounting(TASK, &ucycles1, &kcycles1);
1625 irq_spinlock_unlock(&TASK->lock, true);
1626
1627 data[i] = ucycles1 - ucycles0 + kcycles1 - kcycles0;
1628 }
1629
1630 printf("\n");
1631
1632 uint64_t cycles;
1633 char suffix;
1634 uint64_t sum = 0;
1635
1636 for (int i = 0; i < cnt; i++) {
1637 sum += data[i];
1638 }
1639
1640 order_suffix(sum / (uint64_t) cnt, &cycles, &suffix);
1641 printf("Average\t\t%" PRIu64 "%c\n", cycles, suffix);
1642
1643 free(data);
1644
1645 return true;
1646}
1647
[50661ab]1648#endif
[319e60e]1649
[06e1e95]1650/** @}
[b45c443]1651 */
Note: See TracBrowser for help on using the repository browser.