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