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