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