Subversion Repositories HelenOS-historic

Rev

Rev 591 | Rev 596 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. /*
  2.  * Copyright (C) 2005 Jakub 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.  
  29. #include <console/kconsole.h>
  30. #include <console/console.h>
  31. #include <console/chardev.h>
  32. #include <print.h>
  33. #include <panic.h>
  34. #include <typedefs.h>
  35. #include <arch/types.h>
  36. #include <list.h>
  37. #include <arch.h>
  38. #include <func.h>
  39. #include <macros.h>
  40. #include <debug.h>
  41. #include <symtab.h>
  42.  
  43. #include <mm/tlb_cmd.h>
  44.  
  45. #define MAX_CMDLINE 256
  46.  
  47. /** Simple kernel console.
  48.  *
  49.  * The console is realized by kernel thread kconsole.
  50.  * It doesn't understand any useful command on its own,
  51.  * but makes it possible for other kernel subsystems to
  52.  * register their own commands.
  53.  */
  54.  
  55. /** Locking.
  56.  *
  57.  * There is a list of cmd_info_t structures. This list
  58.  * is protected by cmd_lock spinlock. Note that specially
  59.  * the link elements of cmd_info_t are protected by
  60.  * this lock.
  61.  *
  62.  * Each cmd_info_t also has its own lock, which protects
  63.  * all elements thereof except the link element.
  64.  *
  65.  * cmd_lock must be acquired before any cmd_info lock.
  66.  * When locking two cmd info structures, structure with
  67.  * lower address must be locked first.
  68.  */
  69.  
  70. spinlock_t cmd_lock;    /**< Lock protecting command list. */
  71. link_t cmd_head;    /**< Command list. */
  72.  
  73. static cmd_info_t *parse_cmdline(char *cmdline, size_t len);
  74. static bool parse_argument(char *cmdline, size_t len, index_t *start, index_t *end);
  75.  
  76. /** Data and methods for 'help' command. */
  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.  
  85. /** Data and methods for 'description' command. */
  86. static int cmd_desc(cmd_arg_t *argv);
  87. static void desc_help(void);
  88. static char desc_buf[MAX_CMDLINE+1];
  89. static cmd_arg_t desc_argv = {
  90.     .type = ARG_TYPE_STRING,
  91.     .buffer = desc_buf,
  92.     .len = sizeof(desc_buf)
  93. };
  94. static cmd_info_t desc_info = {
  95.     .name = "describe",
  96.     .description = "Describe specified command.",
  97.     .help = desc_help,
  98.     .func = cmd_desc,
  99.     .argc = 1,
  100.     .argv = &desc_argv
  101. };
  102.  
  103. /** Data and methods for 'symaddr' command. */
  104. static int cmd_symaddr(cmd_arg_t *argv);
  105. static char symaddr_buf[MAX_CMDLINE+1];
  106. static cmd_arg_t symaddr_argv = {
  107.     .type = ARG_TYPE_STRING,
  108.     .buffer = symaddr_buf,
  109.     .len = sizeof(symaddr_buf)
  110. };
  111. static cmd_info_t symaddr_info = {
  112.     .name = "symaddr",
  113.     .description = "Return symbol address.",
  114.     .func = cmd_symaddr,
  115.     .argc = 1,
  116.     .argv = &symaddr_argv
  117. };
  118.  
  119. /** Call0 - call function with no parameters */
  120. static char call0_buf[MAX_CMDLINE+1];
  121. static char carg1_buf[MAX_CMDLINE+1];
  122. static char carg2_buf[MAX_CMDLINE+1];
  123. static char carg3_buf[MAX_CMDLINE+1];
  124.  
  125. static int cmd_call0(cmd_arg_t *argv);
  126. static cmd_arg_t call0_argv = {
  127.     .type = ARG_TYPE_STRING,
  128.     .buffer = call0_buf,
  129.     .len = sizeof(call0_buf)
  130. };
  131. static cmd_info_t call0_info = {
  132.     .name = "call0",
  133.     .description = "call0 <function> -> call function().",
  134.     .func = cmd_call0,
  135.     .argc = 1,
  136.     .argv = &call0_argv
  137. };
  138.  
  139. static int cmd_call1(cmd_arg_t *argv);
  140. static cmd_arg_t call1_argv[] = {
  141.     {
  142.         .type = ARG_TYPE_STRING,
  143.         .buffer = call0_buf,
  144.         .len = sizeof(call0_buf)
  145.     },
  146.     {
  147.         .type = ARG_TYPE_VAR,
  148.         .buffer = carg1_buf,
  149.         .len = sizeof(carg1_buf)
  150.     }
  151. };
  152. static cmd_info_t call1_info = {
  153.     .name = "call1",
  154.     .description = "call1 <function> <arg1> -> call function(arg1).",
  155.     .func = cmd_call1,
  156.     .argc = 2,
  157.     .argv = call1_argv
  158. };
  159.  
  160. static int cmd_call2(cmd_arg_t *argv);
  161. static cmd_arg_t call2_argv[] = {
  162.     {
  163.         .type = ARG_TYPE_STRING,
  164.         .buffer = call0_buf,
  165.         .len = sizeof(call0_buf)
  166.     },
  167.     {
  168.         .type = ARG_TYPE_VAR,
  169.         .buffer = carg1_buf,
  170.         .len = sizeof(carg1_buf)
  171.     },
  172.     {
  173.         .type = ARG_TYPE_VAR,
  174.         .buffer = carg2_buf,
  175.         .len = sizeof(carg2_buf)
  176.     }
  177. };
  178. static cmd_info_t call2_info = {
  179.     .name = "call2",
  180.     .description = "call2 <function> <arg1> <arg2> -> call function(arg1,arg2).",
  181.     .func = cmd_call2,
  182.     .argc = 3,
  183.     .argv = call2_argv
  184. };
  185.  
  186. static int cmd_call3(cmd_arg_t *argv);
  187. static cmd_arg_t call3_argv[] = {
  188.     {
  189.         .type = ARG_TYPE_STRING,
  190.         .buffer = call0_buf,
  191.         .len = sizeof(call0_buf)
  192.     },
  193.     {
  194.         .type = ARG_TYPE_VAR,
  195.         .buffer = carg1_buf,
  196.         .len = sizeof(carg1_buf)
  197.     },
  198.     {
  199.         .type = ARG_TYPE_VAR,
  200.         .buffer = carg2_buf,
  201.         .len = sizeof(carg2_buf)
  202.     },
  203.     {
  204.         .type = ARG_TYPE_VAR,
  205.         .buffer = carg3_buf,
  206.         .len = sizeof(carg3_buf)
  207.     }
  208.  
  209. };
  210. static cmd_info_t call3_info = {
  211.     .name = "call3",
  212.     .description = "call3 <function> <arg1> <arg2> <arg3> -> call function(arg1,arg2,arg3).",
  213.     .func = cmd_call3,
  214.     .argc = 4,
  215.     .argv = call3_argv
  216. };
  217.  
  218. /** Data and methods for 'halt' command. */
  219. static int cmd_halt(cmd_arg_t *argv);
  220. static cmd_info_t halt_info = {
  221.     .name = "halt",
  222.     .description = "Halt the kernel.",
  223.     .func = cmd_halt,
  224.     .argc = 0
  225. };
  226.  
  227. /** Initialize kconsole data structures. */
  228. void kconsole_init(void)
  229. {
  230.     spinlock_initialize(&cmd_lock, "kconsole_cmd");
  231.     list_initialize(&cmd_head);
  232.    
  233.     spinlock_initialize(&help_info.lock, "kconsole_help");
  234.     link_initialize(&help_info.link);
  235.     if (!cmd_register(&help_info))
  236.         panic("could not register command %s\n", help_info.name);
  237.  
  238.  
  239.     spinlock_initialize(&desc_info.lock, "kconsole_desc");
  240.     link_initialize(&desc_info.link);
  241.     if (!cmd_register(&desc_info))
  242.         panic("could not register command %s\n", desc_info.name);
  243.    
  244.     spinlock_initialize(&symaddr_info.lock, "kconsole_symaddr");
  245.     link_initialize(&symaddr_info.link);
  246.     if (!cmd_register(&symaddr_info))
  247.         panic("could not register command %s\n", symaddr_info.name);
  248.  
  249.     spinlock_initialize(&call0_info.lock, "kconsole_call0");
  250.     link_initialize(&call0_info.link);
  251.     if (!cmd_register(&call0_info))
  252.         panic("could not register command %s\n", call0_info.name);
  253.  
  254.     spinlock_initialize(&call1_info.lock, "kconsole_call1");
  255.     link_initialize(&call1_info.link);
  256.     if (!cmd_register(&call1_info))
  257.         panic("could not register command %s\n", call1_info.name);
  258.  
  259.  
  260.     spinlock_initialize(&call2_info.lock, "kconsole_call2");
  261.     link_initialize(&call2_info.link);
  262.     if (!cmd_register(&call2_info))
  263.         panic("could not register command %s\n", call2_info.name);
  264.  
  265.     spinlock_initialize(&call3_info.lock, "kconsole_call3");
  266.     link_initialize(&call3_info.link);
  267.     if (!cmd_register(&call3_info))
  268.         panic("could not register command %s\n", call3_info.name);
  269.    
  270.     spinlock_initialize(&halt_info.lock, "kconsole_halt");
  271.     link_initialize(&halt_info.link);
  272.     if (!cmd_register(&halt_info))
  273.         panic("could not register command %s\n", halt_info.name);
  274.  
  275.     spinlock_initialize(&desc_ptlb.lock, "kconsole_ptlb");
  276.     link_initialize(&desc_ptlb.link);
  277.     if (!cmd_register(&desc_ptlb))
  278.         panic("could not register command %s\n", desc_ptlb.name);
  279. }
  280.  
  281.  
  282. /** Register kconsole command.
  283.  *
  284.  * @param cmd Structure describing the command.
  285.  *
  286.  * @return 0 on failure, 1 on success.
  287.  */
  288. int cmd_register(cmd_info_t *cmd)
  289. {
  290.     ipl_t ipl;
  291.     link_t *cur;
  292.    
  293.     spinlock_lock(&cmd_lock);
  294.    
  295.     /*
  296.      * Make sure the command is not already listed.
  297.      */
  298.     for (cur = cmd_head.next; cur != &cmd_head; cur = cur->next) {
  299.         cmd_info_t *hlp;
  300.        
  301.         hlp = list_get_instance(cur, cmd_info_t, link);
  302.  
  303.         if (hlp == cmd) {
  304.             /* The command is already there. */
  305.             spinlock_unlock(&cmd_lock);
  306.             return 0;
  307.         }
  308.  
  309.         /* Avoid deadlock. */
  310.         if (hlp < cmd) {
  311.             spinlock_lock(&hlp->lock);
  312.             spinlock_lock(&cmd->lock);
  313.         } else {
  314.             spinlock_lock(&cmd->lock);
  315.             spinlock_lock(&hlp->lock);
  316.         }
  317.        
  318.         if ((strncmp(hlp->name, cmd->name, strlen(cmd->name)) == 0)) {
  319.             /* The command is already there. */
  320.             spinlock_unlock(&hlp->lock);
  321.             spinlock_unlock(&cmd->lock);
  322.             spinlock_unlock(&cmd_lock);
  323.             return 0;
  324.         }
  325.        
  326.         spinlock_unlock(&hlp->lock);
  327.         spinlock_unlock(&cmd->lock);
  328.     }
  329.    
  330.     /*
  331.      * Now the command can be added.
  332.      */
  333.     list_append(&cmd->link, &cmd_head);
  334.    
  335.     spinlock_unlock(&cmd_lock);
  336.     return 1;
  337. }
  338.  
  339. /** Kernel console managing thread.
  340.  *
  341.  * @param arg Not used.
  342.  */
  343. void kconsole(void *arg)
  344. {
  345.     char cmdline[MAX_CMDLINE+1];
  346.     cmd_info_t *cmd_info;
  347.     count_t len;
  348.  
  349.     if (!stdin) {
  350.         printf("%s: no stdin\n", __FUNCTION__);
  351.         return;
  352.     }
  353.    
  354.     while (true) {
  355.         printf("%s> ", __FUNCTION__);
  356.         if (!(len = gets(stdin, cmdline, sizeof(cmdline))))
  357.             continue;
  358.         cmdline[len] = '\0';
  359.         cmd_info = parse_cmdline(cmdline, len);
  360.         if (!cmd_info)
  361.             continue;
  362.         (void) cmd_info->func(cmd_info->argv);
  363.     }
  364. }
  365.  
  366. static int parse_int_arg(char *text, size_t len, __native *result)
  367. {
  368.     char symname[MAX_SYMBOL_NAME];
  369.     __address symaddr;
  370.     bool isaddr = false;
  371.     bool isptr = false;
  372.    
  373.     /* If we get a name, try to find it in symbol table */
  374.     if (text[0] < '0' | text[0] > '9') {
  375.         if (text[0] == '&') {
  376.             isaddr = true;
  377.             text++;len--;
  378.         } else if (text[0] == '*') {
  379.             isptr = true;
  380.             text++;len--;
  381.         }
  382.         strncpy(symname, text, min(len+1, MAX_SYMBOL_NAME));
  383.         symaddr = get_symbol_addr(symname);
  384.         if (!symaddr) {
  385.             printf("Symbol %s not found.\n",symname);
  386.             return -1;
  387.         }
  388.         if (symaddr == (__address) -1) {
  389.             printf("Duplicate symbol %s.\n",symname);
  390.             symtab_print_search(symname);
  391.             return -1;
  392.         }
  393.         if (isaddr)
  394.             *result = (__native)symaddr;
  395.         else if (isptr)
  396.             *result = **((__native **)symaddr);
  397.         else
  398.             *result = *((__native *)symaddr);
  399.     } else /* It's a number - convert it */
  400.         *result = atoi(text);
  401.     return 0;
  402. }
  403.  
  404. /** Parse command line.
  405.  *
  406.  * @param cmdline Command line as read from input device.
  407.  * @param len Command line length.
  408.  *
  409.  * @return Structure describing the command.
  410.  */
  411. cmd_info_t *parse_cmdline(char *cmdline, size_t len)
  412. {
  413.     index_t start = 0, end = 0;
  414.     cmd_info_t *cmd = NULL;
  415.     link_t *cur;
  416.     ipl_t ipl;
  417.     int i;
  418.    
  419.     if (!parse_argument(cmdline, len, &start, &end)) {
  420.         /* Command line did not contain alphanumeric word. */
  421.         return NULL;
  422.     }
  423.  
  424.     spinlock_lock(&cmd_lock);
  425.    
  426.     for (cur = cmd_head.next; cur != &cmd_head; cur = cur->next) {
  427.         cmd_info_t *hlp;
  428.        
  429.         hlp = list_get_instance(cur, cmd_info_t, link);
  430.         spinlock_lock(&hlp->lock);
  431.        
  432.         if (strncmp(hlp->name, &cmdline[start], (end - start) + 1) == 0) {
  433.             cmd = hlp;
  434.             break;
  435.         }
  436.        
  437.         spinlock_unlock(&hlp->lock);
  438.     }
  439.    
  440.     spinlock_unlock(&cmd_lock);
  441.    
  442.     if (!cmd) {
  443.         /* Unknown command. */
  444.         printf("Unknown command.\n");
  445.         return NULL;
  446.     }
  447.  
  448.     /* cmd == hlp is locked */
  449.    
  450.     /*
  451.      * The command line must be further analyzed and
  452.      * the parameters therefrom must be matched and
  453.      * converted to those specified in the cmd info
  454.      * structure.
  455.      */
  456.  
  457.     for (i = 0; i < cmd->argc; i++) {
  458.         char *buf;
  459.         start = end + 1;
  460.         if (!parse_argument(cmdline, len, &start, &end)) {
  461.             printf("Too few arguments.\n");
  462.             spinlock_unlock(&cmd->lock);
  463.             return NULL;
  464.         }
  465.        
  466.         switch (cmd->argv[i].type) {
  467.         case ARG_TYPE_STRING:
  468.                 buf = cmd->argv[i].buffer;
  469.                 strncpy(buf, (const char *) &cmdline[start], min((end - start) + 2, cmd->argv[i].len));
  470.             buf[min((end - start) + 1, cmd->argv[i].len - 1)] = '\0';
  471.             break;
  472.         case ARG_TYPE_INT:
  473.             if (parse_int_arg(cmdline+start, end-start+1,
  474.                       &cmd->argv[i].intval))
  475.                 return NULL;
  476.             break;
  477.         case ARG_TYPE_VAR:
  478.             if (start != end && cmdline[start] == '"' && cmdline[end] == '"') {
  479.                 buf = cmd->argv[i].buffer;
  480.                 strncpy(buf, (const char *) &cmdline[start+1],
  481.                     min((end-start), cmd->argv[i].len));
  482.                 buf[min((end - start), cmd->argv[i].len - 1)] = '\0';
  483.                 cmd->argv[i].intval = (__native) buf;
  484.                 cmd->argv[i].vartype = ARG_TYPE_STRING;
  485.             } else if (!parse_int_arg(cmdline+start, end-start+1,
  486.                          &cmd->argv[i].intval))
  487.                 cmd->argv[i].vartype = ARG_TYPE_INT;
  488.             else {
  489.                 printf("Unrecognized variable argument.\n");
  490.                 return NULL;
  491.             }
  492.             break;
  493.         case ARG_TYPE_INVALID:
  494.         default:
  495.             printf("invalid argument type\n");
  496.             return NULL;
  497.             break;
  498.         }
  499.     }
  500.    
  501.     start = end + 1;
  502.     if (parse_argument(cmdline, len, &start, &end)) {
  503.         printf("Too many arguments.\n");
  504.         spinlock_unlock(&cmd->lock);
  505.         return NULL;
  506.     }
  507.    
  508.     spinlock_unlock(&cmd->lock);
  509.     return cmd;
  510. }
  511.  
  512. /** Parse argument.
  513.  *
  514.  * Find start and end positions of command line argument.
  515.  *
  516.  * @param cmdline Command line as read from the input device.
  517.  * @param len Number of characters in cmdline.
  518.  * @param start On entry, 'start' contains pointer to the index
  519.  *        of first unprocessed character of cmdline.
  520.  *        On successful exit, it marks beginning of the next argument.
  521.  * @param end Undefined on entry. On exit, 'end' points to the last character
  522.  *        of the next argument.
  523.  *
  524.  * @return false on failure, true on success.
  525.  */
  526. bool parse_argument(char *cmdline, size_t len, index_t *start, index_t *end)
  527. {
  528.     int i;
  529.     bool found_start = false;
  530.    
  531.     ASSERT(start != NULL);
  532.     ASSERT(end != NULL);
  533.    
  534.     for (i = *start; i < len; i++) {
  535.         if (!found_start) {
  536.             if (is_white(cmdline[i]))
  537.                 (*start)++;
  538.             else
  539.                 found_start = true;
  540.         } else {
  541.             if (is_white(cmdline[i]))
  542.                 break;
  543.         }
  544.     }
  545.     *end = i - 1;
  546.  
  547.     return found_start;
  548. }
  549.  
  550.  
  551. /** List supported commands.
  552.  *
  553.  * @param argv Argument vector.
  554.  *
  555.  * @return 0 on failure, 1 on success.
  556.  */
  557. int cmd_help(cmd_arg_t *argv)
  558. {
  559.     link_t *cur;
  560.     ipl_t ipl;
  561.  
  562.     spinlock_lock(&cmd_lock);
  563.    
  564.     for (cur = cmd_head.next; cur != &cmd_head; cur = cur->next) {
  565.         cmd_info_t *hlp;
  566.        
  567.         hlp = list_get_instance(cur, cmd_info_t, link);
  568.         spinlock_lock(&hlp->lock);
  569.        
  570.         printf("%s - %s\n", hlp->name, hlp->description);
  571.  
  572.         spinlock_unlock(&hlp->lock);
  573.     }
  574.    
  575.     spinlock_unlock(&cmd_lock);
  576.  
  577.     return 1;
  578. }
  579.  
  580. /** Describe specified command.
  581.  *
  582.  * @param argv Argument vector.
  583.  *
  584.  * @return 0 on failure, 1 on success.
  585.  */
  586. int cmd_desc(cmd_arg_t *argv)
  587. {
  588.     link_t *cur;
  589.     ipl_t ipl;
  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.  
  615. /** Search symbol table */
  616. int cmd_symaddr(cmd_arg_t *argv)
  617. {
  618.     __address symaddr;
  619.     char *symbol;
  620.  
  621.     symtab_print_search(argv->buffer);
  622.    
  623.     return 1;
  624. }
  625.  
  626. /** Call function with zero parameters */
  627. int cmd_call0(cmd_arg_t *argv)
  628. {
  629.     __address symaddr;
  630.     char *symbol;
  631.     __native (*f)(void);
  632.  
  633.     symaddr = get_symbol_addr(argv->buffer);
  634.     if (!symaddr)
  635.         printf("Symbol %s not found.\n", argv->buffer);
  636.     else if (symaddr == (__address) -1) {
  637.         symtab_print_search(argv->buffer);
  638.         printf("Duplicate symbol, be more specific.\n");
  639.     } else {
  640.         symbol = get_symtab_entry(symaddr);
  641.         printf("Calling f(): 0x%p: %s\n", symaddr, symbol);
  642.         f =  (__native (*)(void)) symaddr;
  643.         printf("Result: 0x%X\n", f());
  644.     }
  645.    
  646.     return 1;
  647. }
  648.  
  649. /** Call function with one parameter */
  650. int cmd_call1(cmd_arg_t *argv)
  651. {
  652.     __address symaddr;
  653.     char *symbol;
  654.     __native (*f)(__native);
  655.     __native arg1 = argv[1].intval;
  656.  
  657.     symaddr = get_symbol_addr(argv->buffer);
  658.     if (!symaddr)
  659.         printf("Symbol %s not found.\n", argv->buffer);
  660.     else if (symaddr == (__address) -1) {
  661.         symtab_print_search(argv->buffer);
  662.         printf("Duplicate symbol, be more specific.\n");
  663.     } else {
  664.         symbol = get_symtab_entry(symaddr);
  665.         printf("Calling f(0x%x): 0x%p: %s\n", arg1, symaddr, symbol);
  666.         f =  (__native (*)(__native)) symaddr;
  667.         printf("Result: 0x%x\n", f(arg1));
  668.     }
  669.    
  670.     return 1;
  671. }
  672.  
  673. /** Call function with two parameters */
  674. int cmd_call2(cmd_arg_t *argv)
  675. {
  676.     __address symaddr;
  677.     char *symbol;
  678.     __native (*f)(__native,__native);
  679.     __native arg1 = argv[1].intval;
  680.     __native arg2 = argv[2].intval;
  681.  
  682.     symaddr = get_symbol_addr(argv->buffer);
  683.     if (!symaddr)
  684.         printf("Symbol %s not found.\n", argv->buffer);
  685.     else if (symaddr == (__address) -1) {
  686.         symtab_print_search(argv->buffer);
  687.         printf("Duplicate symbol, be more specific.\n");
  688.     } else {
  689.         symbol = get_symtab_entry(symaddr);
  690.         printf("Calling f(0x%x,0x%x): 0x%p: %s\n",
  691.                arg1, arg2, symaddr, symbol);
  692.         f =  (__native (*)(__native,__native)) symaddr;
  693.         printf("Result: 0x%x\n", f(arg1, arg2));
  694.     }
  695.    
  696.     return 1;
  697. }
  698.  
  699. /** Call function with three parameters */
  700. int cmd_call3(cmd_arg_t *argv)
  701. {
  702.     __address symaddr;
  703.     char *symbol;
  704.     __native (*f)(__native,__native,__native);
  705.     __native arg1 = argv[1].intval;
  706.     __native arg2 = argv[2].intval;
  707.     __native arg3 = argv[3].intval;
  708.  
  709.     symaddr = get_symbol_addr(argv->buffer);
  710.     if (!symaddr)
  711.         printf("Symbol %s not found.\n", argv->buffer);
  712.     else if (symaddr == (__address) -1) {
  713.         symtab_print_search(argv->buffer);
  714.         printf("Duplicate symbol, be more specific.\n");
  715.     } else {
  716.         symbol = get_symtab_entry(symaddr);
  717.         printf("Calling f(0x%x,0x%x, 0x%x): 0x%p: %s\n",
  718.                arg1, arg2, arg3, symaddr, symbol);
  719.         f =  (__native (*)(__native,__native,__native)) symaddr;
  720.         printf("Result: 0x%x\n", f(arg1, arg2, arg3));
  721.     }
  722.    
  723.     return 1;
  724. }
  725.  
  726.  
  727. /** Print detailed description of 'describe' command. */
  728. void desc_help(void)
  729. {
  730.     printf("Syntax: describe command_name\n");
  731. }
  732.  
  733. /** Halt the kernel.
  734.  *
  735.  * @param argv Argument vector (ignored).
  736.  *
  737.  * @return 0 on failure, 1 on success (never returns).
  738.  */
  739. int cmd_halt(cmd_arg_t *argv)
  740. {
  741.     halt();
  742.     return 1;
  743. }
  744.