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