[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>
|
---|
| 53 | #include <macros.h>
|
---|
| 54 | #include <debug.h>
|
---|
| 55 | #include <symtab.h>
|
---|
[0132630] | 56 | #include <cpu.h>
|
---|
[442d0ae] | 57 | #include <mm/tlb.h>
|
---|
| 58 | #include <arch/mm/tlb.h>
|
---|
[80bff342] | 59 | #include <mm/frame.h>
|
---|
[0132630] | 60 | #include <main/version.h>
|
---|
[4e147a6] | 61 | #include <mm/slab.h>
|
---|
[10e16a7] | 62 | #include <proc/scheduler.h>
|
---|
[55ab0f1] | 63 | #include <proc/thread.h>
|
---|
[37c57f2] | 64 | #include <proc/task.h>
|
---|
[c4e4507] | 65 | #include <ipc/ipc.h>
|
---|
[62939f7] | 66 | #include <ipc/irq.h>
|
---|
[442d0ae] | 67 |
|
---|
[319e60e] | 68 | #ifdef CONFIG_TEST
|
---|
| 69 | #include <test.h>
|
---|
| 70 | #endif
|
---|
| 71 |
|
---|
[b45c443] | 72 | /* Data and methods for 'help' command. */
|
---|
[442d0ae] | 73 | static int cmd_help(cmd_arg_t *argv);
|
---|
| 74 | static cmd_info_t help_info = {
|
---|
| 75 | .name = "help",
|
---|
| 76 | .description = "List of supported commands.",
|
---|
| 77 | .func = cmd_help,
|
---|
| 78 | .argc = 0
|
---|
| 79 | };
|
---|
| 80 |
|
---|
[e07fe0c] | 81 | static cmd_info_t exit_info = {
|
---|
| 82 | .name = "exit",
|
---|
[f74bbaf] | 83 | .description = "Exit kconsole.",
|
---|
| 84 | .argc = 0
|
---|
| 85 | };
|
---|
| 86 |
|
---|
| 87 | static int cmd_reboot(cmd_arg_t *argv);
|
---|
| 88 | static cmd_info_t reboot_info = {
|
---|
| 89 | .name = "reboot",
|
---|
| 90 | .description = "Reboot.",
|
---|
| 91 | .func = cmd_reboot,
|
---|
[e07fe0c] | 92 | .argc = 0
|
---|
| 93 | };
|
---|
| 94 |
|
---|
[4b662f8c] | 95 | static int cmd_uptime(cmd_arg_t *argv);
|
---|
| 96 | static cmd_info_t uptime_info = {
|
---|
| 97 | .name = "uptime",
|
---|
| 98 | .description = "Print uptime information.",
|
---|
| 99 | .func = cmd_uptime,
|
---|
| 100 | .argc = 0
|
---|
| 101 | };
|
---|
| 102 |
|
---|
[41d33ac] | 103 | static int cmd_continue(cmd_arg_t *argv);
|
---|
| 104 | static cmd_info_t continue_info = {
|
---|
| 105 | .name = "continue",
|
---|
[319e60e] | 106 | .description = "Return console back to userspace.",
|
---|
[41d33ac] | 107 | .func = cmd_continue,
|
---|
| 108 | .argc = 0
|
---|
| 109 | };
|
---|
| 110 |
|
---|
[319e60e] | 111 | #ifdef CONFIG_TEST
|
---|
| 112 | static int cmd_tests(cmd_arg_t *argv);
|
---|
| 113 | static cmd_info_t tests_info = {
|
---|
| 114 | .name = "tests",
|
---|
| 115 | .description = "Print available kernel tests.",
|
---|
| 116 | .func = cmd_tests,
|
---|
| 117 | .argc = 0
|
---|
| 118 | };
|
---|
| 119 |
|
---|
| 120 | static char test_buf[MAX_CMDLINE + 1];
|
---|
| 121 | static int cmd_test(cmd_arg_t *argv);
|
---|
| 122 | static cmd_arg_t test_argv[] = {
|
---|
| 123 | {
|
---|
| 124 | .type = ARG_TYPE_STRING,
|
---|
| 125 | .buffer = test_buf,
|
---|
| 126 | .len = sizeof(test_buf)
|
---|
| 127 | }
|
---|
| 128 | };
|
---|
| 129 | static cmd_info_t test_info = {
|
---|
| 130 | .name = "test",
|
---|
| 131 | .description = "Run kernel test.",
|
---|
| 132 | .func = cmd_test,
|
---|
| 133 | .argc = 1,
|
---|
| 134 | .argv = test_argv
|
---|
| 135 | };
|
---|
[95155b0c] | 136 |
|
---|
| 137 | static int cmd_bench(cmd_arg_t *argv);
|
---|
| 138 | static cmd_arg_t bench_argv[] = {
|
---|
| 139 | {
|
---|
| 140 | .type = ARG_TYPE_STRING,
|
---|
| 141 | .buffer = test_buf,
|
---|
| 142 | .len = sizeof(test_buf)
|
---|
| 143 | },
|
---|
| 144 | {
|
---|
| 145 | .type = ARG_TYPE_INT,
|
---|
| 146 | }
|
---|
| 147 | };
|
---|
| 148 | static cmd_info_t bench_info = {
|
---|
| 149 | .name = "bench",
|
---|
| 150 | .description = "Run kernel test as benchmark.",
|
---|
| 151 | .func = cmd_bench,
|
---|
| 152 | .argc = 2,
|
---|
| 153 | .argv = bench_argv
|
---|
| 154 | };
|
---|
[319e60e] | 155 | #endif
|
---|
| 156 |
|
---|
[b45c443] | 157 | /* Data and methods for 'description' command. */
|
---|
[442d0ae] | 158 | static int cmd_desc(cmd_arg_t *argv);
|
---|
| 159 | static void desc_help(void);
|
---|
| 160 | static char desc_buf[MAX_CMDLINE+1];
|
---|
| 161 | static cmd_arg_t desc_argv = {
|
---|
| 162 | .type = ARG_TYPE_STRING,
|
---|
| 163 | .buffer = desc_buf,
|
---|
| 164 | .len = sizeof(desc_buf)
|
---|
| 165 | };
|
---|
| 166 | static cmd_info_t desc_info = {
|
---|
| 167 | .name = "describe",
|
---|
| 168 | .description = "Describe specified command.",
|
---|
| 169 | .help = desc_help,
|
---|
| 170 | .func = cmd_desc,
|
---|
| 171 | .argc = 1,
|
---|
| 172 | .argv = &desc_argv
|
---|
| 173 | };
|
---|
| 174 |
|
---|
[b45c443] | 175 | /* Data and methods for 'symaddr' command. */
|
---|
[442d0ae] | 176 | static int cmd_symaddr(cmd_arg_t *argv);
|
---|
| 177 | static char symaddr_buf[MAX_CMDLINE+1];
|
---|
| 178 | static cmd_arg_t symaddr_argv = {
|
---|
| 179 | .type = ARG_TYPE_STRING,
|
---|
| 180 | .buffer = symaddr_buf,
|
---|
| 181 | .len = sizeof(symaddr_buf)
|
---|
| 182 | };
|
---|
| 183 | static cmd_info_t symaddr_info = {
|
---|
| 184 | .name = "symaddr",
|
---|
| 185 | .description = "Return symbol address.",
|
---|
| 186 | .func = cmd_symaddr,
|
---|
| 187 | .argc = 1,
|
---|
| 188 | .argv = &symaddr_argv
|
---|
| 189 | };
|
---|
| 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,
|
---|
| 459 | &exit_info,
|
---|
[f74bbaf] | 460 | &reboot_info,
|
---|
[4b662f8c] | 461 | &uptime_info,
|
---|
[10e16a7] | 462 | &halt_info,
|
---|
| 463 | &help_info,
|
---|
[073c9e6] | 464 | &ipc_info,
|
---|
[10e16a7] | 465 | &set4_info,
|
---|
| 466 | &slabs_info,
|
---|
| 467 | &symaddr_info,
|
---|
| 468 | &sched_info,
|
---|
[55ab0f1] | 469 | &threads_info,
|
---|
[37c57f2] | 470 | &tasks_info,
|
---|
[b07c332] | 471 | &physmem_info,
|
---|
[10e16a7] | 472 | &tlb_info,
|
---|
| 473 | &version_info,
|
---|
| 474 | &zones_info,
|
---|
| 475 | &zone_info,
|
---|
[319e60e] | 476 | #ifdef CONFIG_TEST
|
---|
| 477 | &tests_info,
|
---|
| 478 | &test_info,
|
---|
[95155b0c] | 479 | &bench_info,
|
---|
[319e60e] | 480 | #endif
|
---|
[10e16a7] | 481 | NULL
|
---|
| 482 | };
|
---|
[80bff342] | 483 |
|
---|
| 484 |
|
---|
[442d0ae] | 485 | /** Initialize command info structure.
|
---|
| 486 | *
|
---|
| 487 | * @param cmd Command info structure.
|
---|
| 488 | *
|
---|
| 489 | */
|
---|
| 490 | void cmd_initialize(cmd_info_t *cmd)
|
---|
| 491 | {
|
---|
| 492 | spinlock_initialize(&cmd->lock, "cmd");
|
---|
| 493 | link_initialize(&cmd->link);
|
---|
| 494 | }
|
---|
| 495 |
|
---|
| 496 | /** Initialize and register commands. */
|
---|
| 497 | void cmd_init(void)
|
---|
| 498 | {
|
---|
[b07c332] | 499 | unsigned int i;
|
---|
[80bff342] | 500 |
|
---|
[b07c332] | 501 | for (i = 0; basic_commands[i]; i++) {
|
---|
[10e16a7] | 502 | cmd_initialize(basic_commands[i]);
|
---|
| 503 | if (!cmd_register(basic_commands[i]))
|
---|
[b07c332] | 504 | panic("could not register command %s\n", basic_commands[i]->name);
|
---|
[10e16a7] | 505 | }
|
---|
[442d0ae] | 506 | }
|
---|
| 507 |
|
---|
| 508 |
|
---|
| 509 | /** List supported commands.
|
---|
| 510 | *
|
---|
| 511 | * @param argv Argument vector.
|
---|
| 512 | *
|
---|
| 513 | * @return 0 on failure, 1 on success.
|
---|
| 514 | */
|
---|
| 515 | int cmd_help(cmd_arg_t *argv)
|
---|
| 516 | {
|
---|
| 517 | link_t *cur;
|
---|
| 518 |
|
---|
| 519 | spinlock_lock(&cmd_lock);
|
---|
| 520 |
|
---|
| 521 | for (cur = cmd_head.next; cur != &cmd_head; cur = cur->next) {
|
---|
| 522 | cmd_info_t *hlp;
|
---|
| 523 |
|
---|
| 524 | hlp = list_get_instance(cur, cmd_info_t, link);
|
---|
| 525 | spinlock_lock(&hlp->lock);
|
---|
| 526 |
|
---|
| 527 | printf("%s - %s\n", hlp->name, hlp->description);
|
---|
| 528 |
|
---|
| 529 | spinlock_unlock(&hlp->lock);
|
---|
| 530 | }
|
---|
| 531 |
|
---|
| 532 | spinlock_unlock(&cmd_lock);
|
---|
| 533 |
|
---|
| 534 | return 1;
|
---|
| 535 | }
|
---|
| 536 |
|
---|
[f74bbaf] | 537 |
|
---|
| 538 | /** Reboot the system.
|
---|
| 539 | *
|
---|
| 540 | * @param argv Argument vector.
|
---|
| 541 | *
|
---|
| 542 | * @return 0 on failure, 1 on success.
|
---|
| 543 | */
|
---|
| 544 | int cmd_reboot(cmd_arg_t *argv)
|
---|
| 545 | {
|
---|
| 546 | reboot();
|
---|
| 547 |
|
---|
| 548 | /* Not reached */
|
---|
| 549 | return 1;
|
---|
| 550 | }
|
---|
| 551 |
|
---|
[4b662f8c] | 552 |
|
---|
| 553 | /** Print system uptime information.
|
---|
| 554 | *
|
---|
| 555 | * @param argv Argument vector.
|
---|
| 556 | *
|
---|
| 557 | * @return 0 on failure, 1 on success.
|
---|
| 558 | */
|
---|
| 559 | int cmd_uptime(cmd_arg_t *argv)
|
---|
| 560 | {
|
---|
| 561 | ASSERT(uptime);
|
---|
| 562 |
|
---|
| 563 | /* This doesn't have to be very accurate */
|
---|
| 564 | unative_t sec = uptime->seconds1;
|
---|
| 565 |
|
---|
[c859753] | 566 | printf("Up %" PRIun " days, %" PRIun " hours, %" PRIun " minutes, %" PRIun " seconds\n",
|
---|
[4b662f8c] | 567 | sec / 86400, (sec % 86400) / 3600, (sec % 3600) / 60, sec % 60);
|
---|
| 568 |
|
---|
| 569 | return 1;
|
---|
| 570 | }
|
---|
| 571 |
|
---|
[442d0ae] | 572 | /** Describe specified command.
|
---|
| 573 | *
|
---|
| 574 | * @param argv Argument vector.
|
---|
| 575 | *
|
---|
| 576 | * @return 0 on failure, 1 on success.
|
---|
| 577 | */
|
---|
| 578 | int cmd_desc(cmd_arg_t *argv)
|
---|
| 579 | {
|
---|
| 580 | link_t *cur;
|
---|
| 581 |
|
---|
| 582 | spinlock_lock(&cmd_lock);
|
---|
| 583 |
|
---|
| 584 | for (cur = cmd_head.next; cur != &cmd_head; cur = cur->next) {
|
---|
| 585 | cmd_info_t *hlp;
|
---|
| 586 |
|
---|
| 587 | hlp = list_get_instance(cur, cmd_info_t, link);
|
---|
| 588 | spinlock_lock(&hlp->lock);
|
---|
| 589 |
|
---|
| 590 | if (strncmp(hlp->name, (const char *) argv->buffer, strlen(hlp->name)) == 0) {
|
---|
| 591 | printf("%s - %s\n", hlp->name, hlp->description);
|
---|
| 592 | if (hlp->help)
|
---|
| 593 | hlp->help();
|
---|
| 594 | spinlock_unlock(&hlp->lock);
|
---|
| 595 | break;
|
---|
| 596 | }
|
---|
| 597 |
|
---|
| 598 | spinlock_unlock(&hlp->lock);
|
---|
| 599 | }
|
---|
| 600 |
|
---|
| 601 | spinlock_unlock(&cmd_lock);
|
---|
| 602 |
|
---|
| 603 | return 1;
|
---|
| 604 | }
|
---|
| 605 |
|
---|
| 606 | /** Search symbol table */
|
---|
| 607 | int cmd_symaddr(cmd_arg_t *argv)
|
---|
| 608 | {
|
---|
[828aa05] | 609 | symtab_print_search((char *) argv->buffer);
|
---|
[442d0ae] | 610 |
|
---|
| 611 | return 1;
|
---|
| 612 | }
|
---|
| 613 |
|
---|
| 614 | /** Call function with zero parameters */
|
---|
| 615 | int cmd_call0(cmd_arg_t *argv)
|
---|
| 616 | {
|
---|
[7f1c620] | 617 | uintptr_t symaddr;
|
---|
[442d0ae] | 618 | char *symbol;
|
---|
[7f1c620] | 619 | unative_t (*f)(void);
|
---|
[3701250] | 620 | #ifdef ia64
|
---|
| 621 | struct {
|
---|
[7f1c620] | 622 | unative_t f;
|
---|
| 623 | unative_t gp;
|
---|
[e5dbbe5] | 624 | } fptr;
|
---|
[3701250] | 625 | #endif
|
---|
[442d0ae] | 626 |
|
---|
[828aa05] | 627 | symaddr = get_symbol_addr((char *) argv->buffer);
|
---|
[442d0ae] | 628 | if (!symaddr)
|
---|
| 629 | printf("Symbol %s not found.\n", argv->buffer);
|
---|
[7f1c620] | 630 | else if (symaddr == (uintptr_t) -1) {
|
---|
[828aa05] | 631 | symtab_print_search((char *) argv->buffer);
|
---|
[442d0ae] | 632 | printf("Duplicate symbol, be more specific.\n");
|
---|
| 633 | } else {
|
---|
| 634 | symbol = get_symtab_entry(symaddr);
|
---|
[c859753] | 635 | printf("Calling %s() (%p)\n", symbol, symaddr);
|
---|
[3701250] | 636 | #ifdef ia64
|
---|
| 637 | fptr.f = symaddr;
|
---|
[7f1c620] | 638 | fptr.gp = ((unative_t *)cmd_call2)[1];
|
---|
| 639 | f = (unative_t (*)(void)) &fptr;
|
---|
[3701250] | 640 | #else
|
---|
[7f1c620] | 641 | f = (unative_t (*)(void)) symaddr;
|
---|
[3701250] | 642 | #endif
|
---|
[c859753] | 643 | printf("Result: %#" PRIxn "\n", f());
|
---|
[442d0ae] | 644 | }
|
---|
| 645 |
|
---|
| 646 | return 1;
|
---|
| 647 | }
|
---|
| 648 |
|
---|
[e5dbbe5] | 649 | /** Call function with zero parameters on each CPU */
|
---|
| 650 | int cmd_mcall0(cmd_arg_t *argv)
|
---|
| 651 | {
|
---|
| 652 | /*
|
---|
| 653 | * For each CPU, create a thread which will
|
---|
| 654 | * call the function.
|
---|
| 655 | */
|
---|
| 656 |
|
---|
| 657 | count_t i;
|
---|
| 658 | for (i = 0; i < config.cpu_count; i++) {
|
---|
[b8f11baa] | 659 | if (!cpus[i].active)
|
---|
| 660 | continue;
|
---|
| 661 |
|
---|
[e5dbbe5] | 662 | thread_t *t;
|
---|
| 663 | if ((t = thread_create((void (*)(void *)) cmd_call0, (void *) argv, TASK, THREAD_FLAG_WIRED, "call0", false))) {
|
---|
| 664 | spinlock_lock(&t->lock);
|
---|
| 665 | t->cpu = &cpus[i];
|
---|
| 666 | spinlock_unlock(&t->lock);
|
---|
| 667 | printf("cpu%u: ", i);
|
---|
| 668 | thread_ready(t);
|
---|
| 669 | thread_join(t);
|
---|
[72bcb25] | 670 | thread_detach(t);
|
---|
[e5dbbe5] | 671 | } else
|
---|
| 672 | printf("Unable to create thread for cpu%u\n", i);
|
---|
| 673 | }
|
---|
| 674 |
|
---|
| 675 | return 1;
|
---|
| 676 | }
|
---|
| 677 |
|
---|
[442d0ae] | 678 | /** Call function with one parameter */
|
---|
| 679 | int cmd_call1(cmd_arg_t *argv)
|
---|
| 680 | {
|
---|
[7f1c620] | 681 | uintptr_t symaddr;
|
---|
[442d0ae] | 682 | char *symbol;
|
---|
[7f1c620] | 683 | unative_t (*f)(unative_t,...);
|
---|
| 684 | unative_t arg1 = argv[1].intval;
|
---|
[3701250] | 685 | #ifdef ia64
|
---|
| 686 | struct {
|
---|
[7f1c620] | 687 | unative_t f;
|
---|
| 688 | unative_t gp;
|
---|
[c859753] | 689 | } fptr;
|
---|
[3701250] | 690 | #endif
|
---|
[442d0ae] | 691 |
|
---|
[828aa05] | 692 | symaddr = get_symbol_addr((char *) argv->buffer);
|
---|
[442d0ae] | 693 | if (!symaddr)
|
---|
| 694 | printf("Symbol %s not found.\n", argv->buffer);
|
---|
[7f1c620] | 695 | else if (symaddr == (uintptr_t) -1) {
|
---|
[828aa05] | 696 | symtab_print_search((char *) argv->buffer);
|
---|
[442d0ae] | 697 | printf("Duplicate symbol, be more specific.\n");
|
---|
| 698 | } else {
|
---|
| 699 | symbol = get_symtab_entry(symaddr);
|
---|
[3701250] | 700 |
|
---|
[c859753] | 701 | printf("Calling f(%#" PRIxn "): %p: %s\n", arg1, symaddr, symbol);
|
---|
[3701250] | 702 | #ifdef ia64
|
---|
| 703 | fptr.f = symaddr;
|
---|
[7f1c620] | 704 | fptr.gp = ((unative_t *)cmd_call2)[1];
|
---|
| 705 | f = (unative_t (*)(unative_t,...)) &fptr;
|
---|
[3701250] | 706 | #else
|
---|
[7f1c620] | 707 | f = (unative_t (*)(unative_t,...)) symaddr;
|
---|
[3701250] | 708 | #endif
|
---|
[c859753] | 709 | printf("Result: %#" PRIxn "\n", f(arg1));
|
---|
[442d0ae] | 710 | }
|
---|
| 711 |
|
---|
| 712 | return 1;
|
---|
| 713 | }
|
---|
| 714 |
|
---|
| 715 | /** Call function with two parameters */
|
---|
| 716 | int cmd_call2(cmd_arg_t *argv)
|
---|
| 717 | {
|
---|
[7f1c620] | 718 | uintptr_t symaddr;
|
---|
[442d0ae] | 719 | char *symbol;
|
---|
[7f1c620] | 720 | unative_t (*f)(unative_t,unative_t,...);
|
---|
| 721 | unative_t arg1 = argv[1].intval;
|
---|
| 722 | unative_t arg2 = argv[2].intval;
|
---|
[3701250] | 723 | #ifdef ia64
|
---|
| 724 | struct {
|
---|
[7f1c620] | 725 | unative_t f;
|
---|
| 726 | unative_t gp;
|
---|
[3701250] | 727 | }fptr;
|
---|
| 728 | #endif
|
---|
[442d0ae] | 729 |
|
---|
[828aa05] | 730 | symaddr = get_symbol_addr((char *) argv->buffer);
|
---|
[442d0ae] | 731 | if (!symaddr)
|
---|
| 732 | printf("Symbol %s not found.\n", argv->buffer);
|
---|
[7f1c620] | 733 | else if (symaddr == (uintptr_t) -1) {
|
---|
[828aa05] | 734 | symtab_print_search((char *) argv->buffer);
|
---|
[442d0ae] | 735 | printf("Duplicate symbol, be more specific.\n");
|
---|
| 736 | } else {
|
---|
| 737 | symbol = get_symtab_entry(symaddr);
|
---|
[c859753] | 738 | printf("Calling f(%#" PRIxn ", %#" PRIxn "): %p: %s\n",
|
---|
| 739 | arg1, arg2, symaddr, symbol);
|
---|
[3701250] | 740 | #ifdef ia64
|
---|
| 741 | fptr.f = symaddr;
|
---|
[7f1c620] | 742 | fptr.gp = ((unative_t *)cmd_call2)[1];
|
---|
| 743 | f = (unative_t (*)(unative_t,unative_t,...)) &fptr;
|
---|
[3701250] | 744 | #else
|
---|
[7f1c620] | 745 | f = (unative_t (*)(unative_t,unative_t,...)) symaddr;
|
---|
[3701250] | 746 | #endif
|
---|
[c859753] | 747 | printf("Result: %#" PRIxn "\n", f(arg1, arg2));
|
---|
[442d0ae] | 748 | }
|
---|
| 749 |
|
---|
| 750 | return 1;
|
---|
| 751 | }
|
---|
| 752 |
|
---|
| 753 | /** Call function with three parameters */
|
---|
| 754 | int cmd_call3(cmd_arg_t *argv)
|
---|
| 755 | {
|
---|
[7f1c620] | 756 | uintptr_t symaddr;
|
---|
[442d0ae] | 757 | char *symbol;
|
---|
[7f1c620] | 758 | unative_t (*f)(unative_t,unative_t,unative_t,...);
|
---|
| 759 | unative_t arg1 = argv[1].intval;
|
---|
| 760 | unative_t arg2 = argv[2].intval;
|
---|
| 761 | unative_t arg3 = argv[3].intval;
|
---|
[3701250] | 762 | #ifdef ia64
|
---|
| 763 | struct {
|
---|
[7f1c620] | 764 | unative_t f;
|
---|
| 765 | unative_t gp;
|
---|
[3701250] | 766 | }fptr;
|
---|
| 767 | #endif
|
---|
[442d0ae] | 768 |
|
---|
[828aa05] | 769 | symaddr = get_symbol_addr((char *) argv->buffer);
|
---|
[442d0ae] | 770 | if (!symaddr)
|
---|
| 771 | printf("Symbol %s not found.\n", argv->buffer);
|
---|
[7f1c620] | 772 | else if (symaddr == (uintptr_t) -1) {
|
---|
[828aa05] | 773 | symtab_print_search((char *) argv->buffer);
|
---|
[442d0ae] | 774 | printf("Duplicate symbol, be more specific.\n");
|
---|
| 775 | } else {
|
---|
| 776 | symbol = get_symtab_entry(symaddr);
|
---|
[c859753] | 777 | printf("Calling f(%#" PRIxn ",%#" PRIxn ", %#" PRIxn "): %p: %s\n",
|
---|
| 778 | arg1, arg2, arg3, symaddr, symbol);
|
---|
[3701250] | 779 | #ifdef ia64
|
---|
| 780 | fptr.f = symaddr;
|
---|
[7f1c620] | 781 | fptr.gp = ((unative_t *)cmd_call2)[1];
|
---|
| 782 | f = (unative_t (*)(unative_t,unative_t,unative_t,...)) &fptr;
|
---|
[3701250] | 783 | #else
|
---|
[7f1c620] | 784 | f = (unative_t (*)(unative_t,unative_t,unative_t,...)) symaddr;
|
---|
[3701250] | 785 | #endif
|
---|
[c859753] | 786 | printf("Result: %#" PRIxn "\n", f(arg1, arg2, arg3));
|
---|
[442d0ae] | 787 | }
|
---|
| 788 |
|
---|
| 789 | return 1;
|
---|
| 790 | }
|
---|
| 791 |
|
---|
| 792 |
|
---|
| 793 | /** Print detailed description of 'describe' command. */
|
---|
| 794 | void desc_help(void)
|
---|
| 795 | {
|
---|
| 796 | printf("Syntax: describe command_name\n");
|
---|
| 797 | }
|
---|
| 798 |
|
---|
| 799 | /** Halt the kernel.
|
---|
| 800 | *
|
---|
| 801 | * @param argv Argument vector (ignored).
|
---|
| 802 | *
|
---|
| 803 | * @return 0 on failure, 1 on success (never returns).
|
---|
| 804 | */
|
---|
| 805 | int cmd_halt(cmd_arg_t *argv)
|
---|
| 806 | {
|
---|
| 807 | halt();
|
---|
| 808 | return 1;
|
---|
| 809 | }
|
---|
| 810 |
|
---|
| 811 | /** Command for printing TLB contents.
|
---|
| 812 | *
|
---|
| 813 | * @param argv Not used.
|
---|
| 814 | *
|
---|
| 815 | * @return Always returns 1.
|
---|
| 816 | */
|
---|
[0132630] | 817 | int cmd_tlb(cmd_arg_t *argv)
|
---|
[442d0ae] | 818 | {
|
---|
| 819 | tlb_print();
|
---|
| 820 | return 1;
|
---|
| 821 | }
|
---|
[ba276f7] | 822 |
|
---|
[b07c332] | 823 | /** Command for printing physical memory configuration.
|
---|
| 824 | *
|
---|
| 825 | * @param argv Not used.
|
---|
| 826 | *
|
---|
| 827 | * @return Always returns 1.
|
---|
| 828 | */
|
---|
| 829 | int cmd_physmem(cmd_arg_t *argv)
|
---|
| 830 | {
|
---|
| 831 | physmem_print();
|
---|
| 832 | return 1;
|
---|
| 833 | }
|
---|
| 834 |
|
---|
[ba276f7] | 835 | /** Write 4 byte value to address */
|
---|
| 836 | int cmd_set4(cmd_arg_t *argv)
|
---|
| 837 | {
|
---|
[201abde] | 838 | uint32_t *addr;
|
---|
[7f1c620] | 839 | uint32_t arg1 = argv[1].intval;
|
---|
[ba276f7] | 840 | bool pointer = false;
|
---|
| 841 |
|
---|
| 842 | if (((char *)argv->buffer)[0] == '*') {
|
---|
[828aa05] | 843 | addr = (uint32_t *) get_symbol_addr((char *) argv->buffer + 1);
|
---|
[ba276f7] | 844 | pointer = true;
|
---|
[828aa05] | 845 | } else if (((char *) argv->buffer)[0] >= '0' &&
|
---|
[ba276f7] | 846 | ((char *)argv->buffer)[0] <= '9')
|
---|
[7f1c620] | 847 | addr = (uint32_t *)atoi((char *)argv->buffer);
|
---|
[ba276f7] | 848 | else
|
---|
[828aa05] | 849 | addr = (uint32_t *)get_symbol_addr((char *) argv->buffer);
|
---|
[ba276f7] | 850 |
|
---|
| 851 | if (!addr)
|
---|
| 852 | printf("Symbol %s not found.\n", argv->buffer);
|
---|
[7f1c620] | 853 | else if (addr == (uint32_t *) -1) {
|
---|
[828aa05] | 854 | symtab_print_search((char *) argv->buffer);
|
---|
[ba276f7] | 855 | printf("Duplicate symbol, be more specific.\n");
|
---|
| 856 | } else {
|
---|
| 857 | if (pointer)
|
---|
[7f1c620] | 858 | addr = (uint32_t *)(*(unative_t *)addr);
|
---|
[c859753] | 859 | printf("Writing %#" PRIx64 " -> %p\n", arg1, addr);
|
---|
[ba276f7] | 860 | *addr = arg1;
|
---|
| 861 |
|
---|
| 862 | }
|
---|
| 863 |
|
---|
| 864 | return 1;
|
---|
| 865 | }
|
---|
[80bff342] | 866 |
|
---|
[4e147a6] | 867 | /** Command for listings SLAB caches
|
---|
| 868 | *
|
---|
| 869 | * @param argv Ignores
|
---|
| 870 | *
|
---|
| 871 | * @return Always 1
|
---|
| 872 | */
|
---|
| 873 | int cmd_slabs(cmd_arg_t * argv) {
|
---|
| 874 | slab_print_list();
|
---|
| 875 | return 1;
|
---|
| 876 | }
|
---|
| 877 |
|
---|
[55ab0f1] | 878 |
|
---|
| 879 | /** Command for listings Thread information
|
---|
| 880 | *
|
---|
| 881 | * @param argv Ignores
|
---|
| 882 | *
|
---|
| 883 | * @return Always 1
|
---|
| 884 | */
|
---|
| 885 | int cmd_threads(cmd_arg_t * argv) {
|
---|
| 886 | thread_print_list();
|
---|
| 887 | return 1;
|
---|
| 888 | }
|
---|
| 889 |
|
---|
[37c57f2] | 890 | /** Command for listings Task information
|
---|
| 891 | *
|
---|
| 892 | * @param argv Ignores
|
---|
| 893 | *
|
---|
| 894 | * @return Always 1
|
---|
| 895 | */
|
---|
| 896 | int cmd_tasks(cmd_arg_t * argv) {
|
---|
| 897 | task_print_list();
|
---|
| 898 | return 1;
|
---|
| 899 | }
|
---|
| 900 |
|
---|
[10e16a7] | 901 | /** Command for listings Thread information
|
---|
| 902 | *
|
---|
| 903 | * @param argv Ignores
|
---|
| 904 | *
|
---|
| 905 | * @return Always 1
|
---|
| 906 | */
|
---|
| 907 | int cmd_sched(cmd_arg_t * argv) {
|
---|
| 908 | sched_print_list();
|
---|
| 909 | return 1;
|
---|
| 910 | }
|
---|
| 911 |
|
---|
[96cacc1] | 912 | /** Command for listing memory zones
|
---|
| 913 | *
|
---|
| 914 | * @param argv Ignored
|
---|
| 915 | *
|
---|
| 916 | * return Always 1
|
---|
| 917 | */
|
---|
[80bff342] | 918 | int cmd_zones(cmd_arg_t * argv) {
|
---|
[dfd9186] | 919 | zone_print_list();
|
---|
[80bff342] | 920 | return 1;
|
---|
| 921 | }
|
---|
[0132630] | 922 |
|
---|
[96cacc1] | 923 | /** Command for memory zone details
|
---|
| 924 | *
|
---|
| 925 | * @param argv Integer argument from cmdline expected
|
---|
| 926 | *
|
---|
| 927 | * return Always 1
|
---|
| 928 | */
|
---|
[80bff342] | 929 | int cmd_zone(cmd_arg_t * argv) {
|
---|
[dfd9186] | 930 | zone_print_one(argv[0].intval);
|
---|
[80bff342] | 931 | return 1;
|
---|
| 932 | }
|
---|
| 933 |
|
---|
[c4e4507] | 934 | /** Command for printing task ipc details
|
---|
| 935 | *
|
---|
| 936 | * @param argv Integer argument from cmdline expected
|
---|
| 937 | *
|
---|
| 938 | * return Always 1
|
---|
| 939 | */
|
---|
[073c9e6] | 940 | int cmd_ipc(cmd_arg_t * argv) {
|
---|
[c4e4507] | 941 | ipc_print_task(argv[0].intval);
|
---|
| 942 | return 1;
|
---|
| 943 | }
|
---|
| 944 |
|
---|
| 945 |
|
---|
[0132630] | 946 | /** Command for listing processors.
|
---|
| 947 | *
|
---|
| 948 | * @param argv Ignored.
|
---|
| 949 | *
|
---|
| 950 | * return Always 1.
|
---|
| 951 | */
|
---|
| 952 | int cmd_cpus(cmd_arg_t *argv)
|
---|
| 953 | {
|
---|
| 954 | cpu_list();
|
---|
| 955 | return 1;
|
---|
| 956 | }
|
---|
| 957 |
|
---|
| 958 | /** Command for printing kernel version.
|
---|
| 959 | *
|
---|
| 960 | * @param argv Ignored.
|
---|
| 961 | *
|
---|
| 962 | * return Always 1.
|
---|
| 963 | */
|
---|
| 964 | int cmd_version(cmd_arg_t *argv)
|
---|
| 965 | {
|
---|
| 966 | version_print();
|
---|
| 967 | return 1;
|
---|
| 968 | }
|
---|
[41d33ac] | 969 |
|
---|
| 970 | /** Command for returning console back to userspace.
|
---|
| 971 | *
|
---|
| 972 | * @param argv Ignored.
|
---|
| 973 | *
|
---|
| 974 | * return Always 1.
|
---|
| 975 | */
|
---|
| 976 | int cmd_continue(cmd_arg_t *argv)
|
---|
| 977 | {
|
---|
[dd054bc2] | 978 | printf("The kernel will now relinquish the console.\n");
|
---|
| 979 | printf("Use userspace controls to redraw the screen.\n");
|
---|
[41d33ac] | 980 | arch_release_console();
|
---|
| 981 | return 1;
|
---|
| 982 | }
|
---|
[b45c443] | 983 |
|
---|
[50661ab] | 984 | #ifdef CONFIG_TEST
|
---|
[319e60e] | 985 | /** Command for printing kernel tests list.
|
---|
| 986 | *
|
---|
| 987 | * @param argv Ignored.
|
---|
| 988 | *
|
---|
| 989 | * return Always 1.
|
---|
| 990 | */
|
---|
| 991 | int cmd_tests(cmd_arg_t *argv)
|
---|
| 992 | {
|
---|
| 993 | test_t *test;
|
---|
| 994 |
|
---|
| 995 | for (test = tests; test->name != NULL; test++)
|
---|
[50661ab] | 996 | printf("%s\t\t%s%s\n", test->name, test->desc, (test->safe ? "" : " (unsafe)"));
|
---|
[319e60e] | 997 |
|
---|
[50661ab] | 998 | printf("*\t\tRun all safe tests\n");
|
---|
[319e60e] | 999 | return 1;
|
---|
| 1000 | }
|
---|
| 1001 |
|
---|
[62b6d17] | 1002 | static bool run_test(const test_t *test)
|
---|
[34db7fa] | 1003 | {
|
---|
[62b6d17] | 1004 | printf("%s\t\t%s\n", test->name, test->desc);
|
---|
[cce6acf] | 1005 |
|
---|
| 1006 | /* Update and read thread accounting
|
---|
| 1007 | for benchmarking */
|
---|
| 1008 | ipl_t ipl = interrupts_disable();
|
---|
[0313ff0] | 1009 | spinlock_lock(&TASK->lock);
|
---|
| 1010 | uint64_t t0 = task_get_accounting(TASK);
|
---|
| 1011 | spinlock_unlock(&TASK->lock);
|
---|
[cce6acf] | 1012 | interrupts_restore(ipl);
|
---|
| 1013 |
|
---|
| 1014 | /* Execute the test */
|
---|
[95155b0c] | 1015 | char * ret = test->entry(false);
|
---|
[cce6acf] | 1016 |
|
---|
| 1017 | /* Update and read thread accounting */
|
---|
| 1018 | ipl = interrupts_disable();
|
---|
[0313ff0] | 1019 | spinlock_lock(&TASK->lock);
|
---|
| 1020 | uint64_t dt = task_get_accounting(TASK) - t0;
|
---|
| 1021 | spinlock_unlock(&TASK->lock);
|
---|
[cce6acf] | 1022 | interrupts_restore(ipl);
|
---|
| 1023 |
|
---|
[95155b0c] | 1024 | uint64_t cycles;
|
---|
| 1025 | char suffix;
|
---|
| 1026 | order(dt, &cycles, &suffix);
|
---|
| 1027 |
|
---|
[c859753] | 1028 | printf("Time: %" PRIu64 "%c cycles\n", cycles, suffix);
|
---|
[34db7fa] | 1029 |
|
---|
| 1030 | if (ret == NULL) {
|
---|
| 1031 | printf("Test passed\n");
|
---|
[62b6d17] | 1032 | return true;
|
---|
[34db7fa] | 1033 | }
|
---|
| 1034 |
|
---|
| 1035 | printf("%s\n", ret);
|
---|
[62b6d17] | 1036 | return false;
|
---|
[34db7fa] | 1037 | }
|
---|
| 1038 |
|
---|
[95155b0c] | 1039 | static bool run_bench(const test_t *test, const uint32_t cnt)
|
---|
| 1040 | {
|
---|
| 1041 | uint32_t i;
|
---|
| 1042 | bool ret = true;
|
---|
| 1043 | uint64_t cycles;
|
---|
| 1044 | char suffix;
|
---|
| 1045 |
|
---|
| 1046 | if (cnt < 1)
|
---|
| 1047 | return true;
|
---|
| 1048 |
|
---|
[828aa05] | 1049 | uint64_t *data = (uint64_t *) malloc(sizeof(uint64_t) * cnt, 0);
|
---|
[95155b0c] | 1050 | if (data == NULL) {
|
---|
| 1051 | printf("Error allocating memory for statistics\n");
|
---|
| 1052 | return false;
|
---|
| 1053 | }
|
---|
| 1054 |
|
---|
| 1055 | for (i = 0; i < cnt; i++) {
|
---|
[c859753] | 1056 | printf("%s (%u/%u) ... ", test->name, i + 1, cnt);
|
---|
[95155b0c] | 1057 |
|
---|
| 1058 | /* Update and read thread accounting
|
---|
| 1059 | for benchmarking */
|
---|
| 1060 | ipl_t ipl = interrupts_disable();
|
---|
| 1061 | spinlock_lock(&TASK->lock);
|
---|
| 1062 | uint64_t t0 = task_get_accounting(TASK);
|
---|
| 1063 | spinlock_unlock(&TASK->lock);
|
---|
| 1064 | interrupts_restore(ipl);
|
---|
| 1065 |
|
---|
| 1066 | /* Execute the test */
|
---|
| 1067 | char * ret = test->entry(true);
|
---|
| 1068 |
|
---|
| 1069 | /* Update and read thread accounting */
|
---|
| 1070 | ipl = interrupts_disable();
|
---|
| 1071 | spinlock_lock(&TASK->lock);
|
---|
| 1072 | uint64_t dt = task_get_accounting(TASK) - t0;
|
---|
| 1073 | spinlock_unlock(&TASK->lock);
|
---|
| 1074 | interrupts_restore(ipl);
|
---|
| 1075 |
|
---|
| 1076 | if (ret != NULL) {
|
---|
| 1077 | printf("%s\n", ret);
|
---|
| 1078 | ret = false;
|
---|
| 1079 | break;
|
---|
| 1080 | }
|
---|
| 1081 |
|
---|
| 1082 | data[i] = dt;
|
---|
| 1083 | order(dt, &cycles, &suffix);
|
---|
[c859753] | 1084 | printf("OK (%" PRIu64 "%c cycles)\n", cycles, suffix);
|
---|
[95155b0c] | 1085 | }
|
---|
| 1086 |
|
---|
| 1087 | if (ret) {
|
---|
| 1088 | printf("\n");
|
---|
| 1089 |
|
---|
| 1090 | uint64_t sum = 0;
|
---|
| 1091 |
|
---|
| 1092 | for (i = 0; i < cnt; i++) {
|
---|
| 1093 | sum += data[i];
|
---|
| 1094 | }
|
---|
| 1095 |
|
---|
| 1096 | order(sum / (uint64_t) cnt, &cycles, &suffix);
|
---|
[c859753] | 1097 | printf("Average\t\t%" PRIu64 "%c\n", cycles, suffix);
|
---|
[95155b0c] | 1098 | }
|
---|
| 1099 |
|
---|
| 1100 | free(data);
|
---|
| 1101 |
|
---|
| 1102 | return ret;
|
---|
| 1103 | }
|
---|
| 1104 |
|
---|
[319e60e] | 1105 | /** Command for returning kernel tests
|
---|
| 1106 | *
|
---|
| 1107 | * @param argv Argument vector.
|
---|
| 1108 | *
|
---|
| 1109 | * return Always 1.
|
---|
| 1110 | */
|
---|
| 1111 | int cmd_test(cmd_arg_t *argv)
|
---|
| 1112 | {
|
---|
| 1113 | test_t *test;
|
---|
| 1114 |
|
---|
[828aa05] | 1115 | if (strcmp((char *) argv->buffer, "*") == 0) {
|
---|
[50661ab] | 1116 | for (test = tests; test->name != NULL; test++) {
|
---|
| 1117 | if (test->safe) {
|
---|
[34db7fa] | 1118 | printf("\n");
|
---|
| 1119 | if (!run_test(test))
|
---|
| 1120 | break;
|
---|
[50661ab] | 1121 | }
|
---|
| 1122 | }
|
---|
| 1123 | } else {
|
---|
| 1124 | bool fnd = false;
|
---|
| 1125 |
|
---|
| 1126 | for (test = tests; test->name != NULL; test++) {
|
---|
[828aa05] | 1127 | if (strcmp(test->name, (char *) argv->buffer) == 0) {
|
---|
[50661ab] | 1128 | fnd = true;
|
---|
[34db7fa] | 1129 | run_test(test);
|
---|
[50661ab] | 1130 | break;
|
---|
| 1131 | }
|
---|
[319e60e] | 1132 | }
|
---|
[50661ab] | 1133 |
|
---|
| 1134 | if (!fnd)
|
---|
[34db7fa] | 1135 | printf("Unknown test\n");
|
---|
[319e60e] | 1136 | }
|
---|
| 1137 |
|
---|
| 1138 | return 1;
|
---|
| 1139 | }
|
---|
[95155b0c] | 1140 |
|
---|
| 1141 | /** Command for returning kernel tests as benchmarks
|
---|
| 1142 | *
|
---|
| 1143 | * @param argv Argument vector.
|
---|
| 1144 | *
|
---|
| 1145 | * return Always 1.
|
---|
| 1146 | */
|
---|
| 1147 | int cmd_bench(cmd_arg_t *argv)
|
---|
| 1148 | {
|
---|
| 1149 | test_t *test;
|
---|
| 1150 | uint32_t cnt = argv[1].intval;
|
---|
| 1151 |
|
---|
| 1152 | bool fnd = false;
|
---|
| 1153 |
|
---|
| 1154 | for (test = tests; test->name != NULL; test++) {
|
---|
[828aa05] | 1155 | if (strcmp(test->name, (char *) argv->buffer) == 0) {
|
---|
[95155b0c] | 1156 | fnd = true;
|
---|
[c8410ec9] | 1157 |
|
---|
| 1158 | if (test->safe)
|
---|
| 1159 | run_bench(test, cnt);
|
---|
| 1160 | else
|
---|
| 1161 | printf("Unsafe test\n");
|
---|
| 1162 |
|
---|
[95155b0c] | 1163 | break;
|
---|
| 1164 | }
|
---|
| 1165 | }
|
---|
| 1166 |
|
---|
| 1167 | if (!fnd)
|
---|
| 1168 | printf("Unknown test\n");
|
---|
| 1169 |
|
---|
| 1170 | return 1;
|
---|
| 1171 | }
|
---|
| 1172 |
|
---|
[50661ab] | 1173 | #endif
|
---|
[319e60e] | 1174 |
|
---|
[06e1e95] | 1175 | /** @}
|
---|
[b45c443] | 1176 | */
|
---|