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