Rev 579 | Rev 585 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 579 | Rev 582 | ||
|---|---|---|---|
| Line 36... | Line 36... | ||
| 36 | #include <list.h> |
36 | #include <list.h> |
| 37 | #include <arch.h> |
37 | #include <arch.h> |
| 38 | #include <func.h> |
38 | #include <func.h> |
| 39 | #include <macros.h> |
39 | #include <macros.h> |
| 40 | #include <debug.h> |
40 | #include <debug.h> |
| - | 41 | #include <symtab.h> |
|
| 41 | 42 | ||
| 42 | #define MAX_CMDLINE 256 |
43 | #define MAX_CMDLINE 256 |
| 43 | 44 | ||
| 44 | /** Simple kernel console. |
45 | /** Simple kernel console. |
| 45 | * |
46 | * |
| Line 70... | Line 71... | ||
| 70 | static cmd_info_t *parse_cmdline(char *cmdline, size_t len); |
71 | static cmd_info_t *parse_cmdline(char *cmdline, size_t len); |
| 71 | static bool parse_argument(char *cmdline, size_t len, index_t *start, index_t *end); |
72 | static bool parse_argument(char *cmdline, size_t len, index_t *start, index_t *end); |
| 72 | 73 | ||
| 73 | /** Data and methods for 'help' command. */ |
74 | /** Data and methods for 'help' command. */ |
| 74 | static int cmd_help(cmd_arg_t *argv); |
75 | static int cmd_help(cmd_arg_t *argv); |
| 75 | static cmd_info_t help_info; |
76 | static cmd_info_t help_info = { |
| - | 77 | .name = "help", |
|
| - | 78 | .description = "List of supported commands.", |
|
| - | 79 | .func = cmd_help, |
|
| - | 80 | .argc = 0 |
|
| - | 81 | }; |
|
| 76 | 82 | ||
| 77 | /** Data and methods for 'description' command. */ |
83 | /** Data and methods for 'description' command. */ |
| 78 | static int cmd_desc(cmd_arg_t *argv); |
84 | static int cmd_desc(cmd_arg_t *argv); |
| 79 | static void desc_help(void); |
85 | static void desc_help(void); |
| 80 | static cmd_info_t desc_info; |
- | |
| 81 | static char desc_buf[MAX_CMDLINE+1]; |
86 | static char desc_buf[MAX_CMDLINE+1]; |
| 82 | static cmd_arg_t desc_argv = { |
87 | static cmd_arg_t desc_argv = { |
| 83 | .type = ARG_TYPE_STRING, |
88 | .type = ARG_TYPE_STRING, |
| 84 | .buffer = desc_buf, |
89 | .buffer = desc_buf, |
| 85 | .len = sizeof(desc_buf) |
90 | .len = sizeof(desc_buf) |
| 86 | }; |
91 | }; |
| - | 92 | static cmd_info_t desc_info = { |
|
| - | 93 | .name = "describe", |
|
| - | 94 | .description = "Describe specified command.", |
|
| - | 95 | .help = desc_help, |
|
| - | 96 | .func = cmd_desc, |
|
| - | 97 | .argc = 1, |
|
| - | 98 | .argv = &desc_argv |
|
| - | 99 | }; |
|
| - | 100 | ||
| - | 101 | /** Data and methods for 'symaddr' command. */ |
|
| - | 102 | static int cmd_symaddr(cmd_arg_t *argv); |
|
| - | 103 | static char symaddr_buf[MAX_CMDLINE+1]; |
|
| - | 104 | static cmd_arg_t symaddr_argv = { |
|
| - | 105 | .type = ARG_TYPE_STRING, |
|
| - | 106 | .buffer = symaddr_buf, |
|
| - | 107 | .len = sizeof(symaddr_buf) |
|
| - | 108 | }; |
|
| - | 109 | static cmd_info_t symaddr_info = { |
|
| - | 110 | .name = "symaddr", |
|
| - | 111 | .description = "Return symbol address.", |
|
| - | 112 | .func = cmd_symaddr, |
|
| - | 113 | .argc = 1, |
|
| - | 114 | .argv = &symaddr_argv |
|
| - | 115 | }; |
|
| - | 116 | ||
| - | 117 | /** Call0 - call function with no parameters */ |
|
| - | 118 | static char call0_buf[MAX_CMDLINE+1]; |
|
| - | 119 | ||
| - | 120 | static int cmd_call0(cmd_arg_t *argv); |
|
| - | 121 | static cmd_arg_t call0_argv = { |
|
| - | 122 | .type = ARG_TYPE_STRING, |
|
| - | 123 | .buffer = call0_buf, |
|
| - | 124 | .len = sizeof(call0_buf) |
|
| - | 125 | }; |
|
| - | 126 | static cmd_info_t call0_info = { |
|
| - | 127 | .name = "call0", |
|
| - | 128 | .description = "call0 <function> -> call function().", |
|
| - | 129 | .func = cmd_call0, |
|
| - | 130 | .argc = 1, |
|
| - | 131 | .argv = &call0_argv |
|
| - | 132 | }; |
|
| - | 133 | ||
| - | 134 | static int cmd_call1(cmd_arg_t *argv); |
|
| - | 135 | static cmd_arg_t call1_argv[] = { |
|
| - | 136 | { |
|
| - | 137 | .type = ARG_TYPE_STRING, |
|
| - | 138 | .buffer = call0_buf, |
|
| - | 139 | .len = sizeof(call0_buf) |
|
| - | 140 | }, |
|
| - | 141 | { .type = ARG_TYPE_INT } |
|
| - | 142 | }; |
|
| - | 143 | static cmd_info_t call1_info = { |
|
| - | 144 | .name = "call1", |
|
| - | 145 | .description = "call1 <function> <arg1> -> call function(arg1).", |
|
| - | 146 | .func = cmd_call1, |
|
| - | 147 | .argc = 2, |
|
| - | 148 | .argv = call1_argv |
|
| - | 149 | }; |
|
| - | 150 | ||
| - | 151 | static int cmd_call2(cmd_arg_t *argv); |
|
| - | 152 | static cmd_arg_t call2_argv[] = { |
|
| - | 153 | { |
|
| - | 154 | .type = ARG_TYPE_STRING, |
|
| - | 155 | .buffer = call0_buf, |
|
| - | 156 | .len = sizeof(call0_buf) |
|
| - | 157 | }, |
|
| - | 158 | { .type = ARG_TYPE_INT }, |
|
| - | 159 | { .type = ARG_TYPE_INT } |
|
| - | 160 | }; |
|
| - | 161 | static cmd_info_t call2_info = { |
|
| - | 162 | .name = "call2", |
|
| - | 163 | .description = "call2 <function> <arg1> <arg2> -> call function(arg1,arg2).", |
|
| - | 164 | .func = cmd_call2, |
|
| - | 165 | .argc = 3, |
|
| - | 166 | .argv = call2_argv |
|
| - | 167 | }; |
|
| - | 168 | ||
| 87 | 169 | ||
| 88 | /** Data and methods for 'halt' command. */ |
170 | /** Data and methods for 'halt' command. */ |
| 89 | static int cmd_halt(cmd_arg_t *argv); |
171 | static int cmd_halt(cmd_arg_t *argv); |
| 90 | static cmd_info_t halt_info; |
172 | static cmd_info_t halt_info = { |
| - | 173 | .name = "halt", |
|
| - | 174 | .description = "Halt the kernel.", |
|
| - | 175 | .func = cmd_halt, |
|
| - | 176 | .argc = 0 |
|
| - | 177 | }; |
|
| 91 | 178 | ||
| 92 | /** Initialize kconsole data structures. */ |
179 | /** Initialize kconsole data structures. */ |
| 93 | void kconsole_init(void) |
180 | void kconsole_init(void) |
| 94 | { |
181 | { |
| 95 | spinlock_initialize(&cmd_lock, "kconsole_cmd"); |
182 | spinlock_initialize(&cmd_lock, "kconsole_cmd"); |
| 96 | list_initialize(&cmd_head); |
183 | list_initialize(&cmd_head); |
| 97 | 184 | ||
| 98 | help_info.name = "help"; |
- | |
| 99 | help_info.description = "List supported commands."; |
- | |
| 100 | help_info.func = cmd_help; |
- | |
| 101 | help_info.help = NULL; |
- | |
| 102 | help_info.argc = 0; |
- | |
| 103 | help_info.argv = NULL; |
- | |
| 104 | - | ||
| 105 | spinlock_initialize(&help_info.lock, "kconsole_help"); |
185 | spinlock_initialize(&help_info.lock, "kconsole_help"); |
| 106 | link_initialize(&help_info.link); |
186 | link_initialize(&help_info.link); |
| 107 | - | ||
| 108 | if (!cmd_register(&help_info)) |
187 | if (!cmd_register(&help_info)) |
| 109 | panic("could not register command %s\n", help_info.name); |
188 | panic("could not register command %s\n", help_info.name); |
| 110 | 189 | ||
| 111 | 190 | ||
| 112 | desc_info.name = "describe"; |
- | |
| 113 | desc_info.description = "Describe specified command."; |
- | |
| 114 | desc_info.help = desc_help; |
- | |
| 115 | desc_info.func = cmd_desc; |
- | |
| 116 | desc_info.argc = 1; |
- | |
| 117 | desc_info.argv = &desc_argv; |
- | |
| 118 | - | ||
| 119 | spinlock_initialize(&desc_info.lock, "kconsole_desc"); |
191 | spinlock_initialize(&desc_info.lock, "kconsole_desc"); |
| 120 | link_initialize(&desc_info.link); |
192 | link_initialize(&desc_info.link); |
| 121 | - | ||
| 122 | if (!cmd_register(&desc_info)) |
193 | if (!cmd_register(&desc_info)) |
| 123 | panic("could not register command %s\n", desc_info.name); |
194 | panic("could not register command %s\n", desc_info.name); |
| 124 | 195 | ||
| - | 196 | spinlock_initialize(&symaddr_info.lock, "kconsole_symaddr"); |
|
| - | 197 | link_initialize(&symaddr_info.link); |
|
| - | 198 | if (!cmd_register(&symaddr_info)) |
|
| - | 199 | panic("could not register command %s\n", symaddr_info.name); |
|
| - | 200 | ||
| - | 201 | spinlock_initialize(&call0_info.lock, "kconsole_call0"); |
|
| - | 202 | link_initialize(&call0_info.link); |
|
| - | 203 | if (!cmd_register(&call0_info)) |
|
| - | 204 | panic("could not register command %s\n", call0_info.name); |
|
| - | 205 | ||
| - | 206 | spinlock_initialize(&call1_info.lock, "kconsole_call1"); |
|
| - | 207 | link_initialize(&call1_info.link); |
|
| - | 208 | if (!cmd_register(&call1_info)) |
|
| - | 209 | panic("could not register command %s\n", call1_info.name); |
|
| - | 210 | ||
| - | 211 | ||
| - | 212 | spinlock_initialize(&call2_info.lock, "kconsole_call2"); |
|
| - | 213 | link_initialize(&call2_info.link); |
|
| - | 214 | if (!cmd_register(&call2_info)) |
|
| - | 215 | panic("could not register command %s\n", call2_info.name); |
|
| 125 | 216 | ||
| 126 | halt_info.name = "halt"; |
- | |
| 127 | halt_info.description = "Halt the kernel."; |
- | |
| 128 | halt_info.func = cmd_halt; |
- | |
| 129 | halt_info.help = NULL; |
- | |
| 130 | halt_info.argc = 0; |
- | |
| 131 | halt_info.argv = NULL; |
- | |
| 132 | - | ||
| 133 | spinlock_initialize(&halt_info.lock, "kconsole_halt"); |
217 | spinlock_initialize(&halt_info.lock, "kconsole_halt"); |
| 134 | link_initialize(&halt_info.link); |
218 | link_initialize(&halt_info.link); |
| 135 | - | ||
| 136 | if (!cmd_register(&halt_info)) |
219 | if (!cmd_register(&halt_info)) |
| 137 | panic("could not register command %s\n", halt_info.name); |
220 | panic("could not register command %s\n", halt_info.name); |
| 138 | } |
221 | } |
| 139 | 222 | ||
| 140 | 223 | ||
| Line 283... | Line 366... | ||
| 283 | spinlock_unlock(&cmd->lock); |
366 | spinlock_unlock(&cmd->lock); |
| 284 | return NULL; |
367 | return NULL; |
| 285 | } |
368 | } |
| 286 | 369 | ||
| 287 | switch (cmd->argv[i].type) { |
370 | switch (cmd->argv[i].type) { |
| 288 | case ARG_TYPE_STRING: |
371 | case ARG_TYPE_STRING: |
| 289 | buf = cmd->argv[i].buffer; |
372 | buf = cmd->argv[i].buffer; |
| 290 | strncpy(buf, (const char *) &cmdline[start], min((end - start) + 1, cmd->argv[i].len - 1)); |
373 | strncpy(buf, (const char *) &cmdline[start], min((end - start) + 1, cmd->argv[i].len - 1)); |
| 291 | buf[min((end - start) + 1, cmd->argv[i].len - 1)] = '\0'; |
374 | buf[min((end - start) + 1, cmd->argv[i].len - 1)] = '\0'; |
| 292 | break; |
375 | break; |
| 293 | case ARG_TYPE_INT: |
376 | case ARG_TYPE_INT: { |
| - | 377 | char symname[MAX_SYMBOL_NAME]; |
|
| - | 378 | __address symaddr; |
|
| - | 379 | ||
| - | 380 | /* If we get a name, try to find it in symbol table */ |
|
| - | 381 | if (cmdline[start] < '0' | cmdline[start] > '9') { |
|
| - | 382 | strncpy(symname, cmdline+start, min((end-start) + 1, MAX_SYMBOL_NAME -1 )); |
|
| - | 383 | symaddr = get_symbol_addr(symname); |
|
| - | 384 | if (!symaddr) { |
|
| - | 385 | printf("Symbol %s not found.\n",symname); |
|
| - | 386 | return NULL; |
|
| - | 387 | } |
|
| - | 388 | if (symaddr == (__address) -1) { |
|
| - | 389 | printf("Duplicate symbol %s.\n",symname); |
|
| - | 390 | symtab_print_search(symname); |
|
| - | 391 | return NULL; |
|
| - | 392 | } |
|
| - | 393 | cmd->argv[i].intval = *((__native *)symaddr); |
|
| - | 394 | } else /* It's a number - convert it */ |
|
| - | 395 | cmd->argv[i].intval = atoi(cmdline+start); |
|
| - | 396 | break; |
|
| - | 397 | } |
|
| 294 | case ARG_TYPE_INVALID: |
398 | case ARG_TYPE_INVALID: |
| 295 | default: |
399 | default: |
| 296 | panic("invalid argument type\n"); |
400 | printf("invalid argument type\n"); |
| - | 401 | return NULL; |
|
| 297 | break; |
402 | break; |
| 298 | } |
403 | } |
| 299 | } |
404 | } |
| 300 | 405 | ||
| 301 | start = end + 1; |
406 | start = end + 1; |
| Line 410... | Line 515... | ||
| 410 | spinlock_unlock(&cmd_lock); |
515 | spinlock_unlock(&cmd_lock); |
| 411 | 516 | ||
| 412 | return 1; |
517 | return 1; |
| 413 | } |
518 | } |
| 414 | 519 | ||
| - | 520 | /** Search symbol table */ |
|
| - | 521 | int cmd_symaddr(cmd_arg_t *argv) |
|
| - | 522 | { |
|
| - | 523 | __address symaddr; |
|
| - | 524 | char *symbol; |
|
| - | 525 | ||
| - | 526 | symtab_print_search(argv->buffer); |
|
| - | 527 | ||
| - | 528 | return 1; |
|
| - | 529 | } |
|
| - | 530 | ||
| - | 531 | /** Call function with zero parameters */ |
|
| - | 532 | int cmd_call0(cmd_arg_t *argv) |
|
| - | 533 | { |
|
| - | 534 | __address symaddr; |
|
| - | 535 | char *symbol; |
|
| - | 536 | __native (*f)(void); |
|
| - | 537 | ||
| - | 538 | symaddr = get_symbol_addr(argv->buffer); |
|
| - | 539 | if (!symaddr) |
|
| - | 540 | printf("Symbol not found.\n"); |
|
| - | 541 | else if (symaddr == (__address) -1) { |
|
| - | 542 | symtab_print_search(argv->buffer); |
|
| - | 543 | printf("Duplicate symbol, be more specific.\n"); |
|
| - | 544 | } else { |
|
| - | 545 | symbol = get_symtab_entry(symaddr); |
|
| - | 546 | printf("Calling f(): 0x%p: %s\n", symaddr, symbol); |
|
| - | 547 | f = (__native (*)(void)) symaddr; |
|
| - | 548 | printf("Result: 0x%X\n", f()); |
|
| - | 549 | } |
|
| - | 550 | ||
| - | 551 | return 1; |
|
| - | 552 | } |
|
| - | 553 | ||
| - | 554 | /** Call function with one parameter */ |
|
| - | 555 | int cmd_call1(cmd_arg_t *argv) |
|
| - | 556 | { |
|
| - | 557 | __address symaddr; |
|
| - | 558 | char *symbol; |
|
| - | 559 | __native (*f)(__native); |
|
| - | 560 | __native arg1 = argv[1].intval; |
|
| - | 561 | ||
| - | 562 | symaddr = get_symbol_addr(argv->buffer); |
|
| - | 563 | if (!symaddr) |
|
| - | 564 | printf("Symbol not found.\n"); |
|
| - | 565 | else if (symaddr == (__address) -1) { |
|
| - | 566 | symtab_print_search(argv->buffer); |
|
| - | 567 | printf("Duplicate symbol, be more specific.\n"); |
|
| - | 568 | } else { |
|
| - | 569 | symbol = get_symtab_entry(symaddr); |
|
| - | 570 | printf("Calling f(0x%x): 0x%p: %s\n", arg1, symaddr, symbol); |
|
| - | 571 | f = (__native (*)(__native)) symaddr; |
|
| - | 572 | printf("Result: 0x%x\n", f(arg1)); |
|
| - | 573 | } |
|
| - | 574 | ||
| - | 575 | return 1; |
|
| - | 576 | } |
|
| - | 577 | ||
| - | 578 | /** Call function with two parameters */ |
|
| - | 579 | int cmd_call2(cmd_arg_t *argv) |
|
| - | 580 | { |
|
| - | 581 | __address symaddr; |
|
| - | 582 | char *symbol; |
|
| - | 583 | __native (*f)(__native); |
|
| - | 584 | __native arg1 = argv[1].intval; |
|
| - | 585 | __native arg2 = argv[2].intval; |
|
| - | 586 | ||
| - | 587 | symaddr = get_symbol_addr(argv->buffer); |
|
| - | 588 | if (!symaddr) |
|
| - | 589 | printf("Symbol not found.\n"); |
|
| - | 590 | else if (symaddr == (__address) -1) { |
|
| - | 591 | symtab_print_search(argv->buffer); |
|
| - | 592 | printf("Duplicate symbol, be more specific.\n"); |
|
| - | 593 | } else { |
|
| - | 594 | symbol = get_symtab_entry(symaddr); |
|
| - | 595 | printf("Calling f(0x%x,0x%x): 0x%p: %s\n", |
|
| - | 596 | arg1, arg2, symaddr, symbol); |
|
| - | 597 | f = (__native (*)(__native)) symaddr; |
|
| - | 598 | printf("Result: 0x%x\n", f(arg1)); |
|
| - | 599 | } |
|
| - | 600 | ||
| - | 601 | return 1; |
|
| - | 602 | } |
|
| - | 603 | ||
| - | 604 | ||
| 415 | /** Print detailed description of 'describe' command. */ |
605 | /** Print detailed description of 'describe' command. */ |
| 416 | void desc_help(void) |
606 | void desc_help(void) |
| 417 | { |
607 | { |
| 418 | printf("Syntax: describe command_name\n"); |
608 | printf("Syntax: describe command_name\n"); |
| 419 | } |
609 | } |