Skip to content

Commit a6bc36f

Browse files
yonghuahwenlingz
authored andcommitted
HV: refine shell.c & shell_priv.h
- move local functions declarations to shell.c - remove 'name' field in 'struct shell' as i/o session s/w layer is deprecated. Signed-off-by: Yonghua Huang <yonghua.huang@intel.com> Acked-by: Eddie Dong <eddie.dong@intel.com>
1 parent 28c8923 commit a6bc36f

File tree

2 files changed

+109
-123
lines changed

2 files changed

+109
-123
lines changed

hypervisor/debug/shell.c

Lines changed: 97 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,22 @@
1616
*/
1717
#define SHELL_INPUT_LINE_OTHER(v) (((v) + 1U) % 2U)
1818

19+
static int shell_cmd_help(__unused int argc, __unused char **argv);
20+
static int shell_list_vm(__unused int argc, __unused char **argv);
21+
static int shell_list_vcpu(__unused int argc, __unused char **argv);
22+
static int shell_vcpu_dumpreg(int argc, char **argv);
23+
static int shell_dumpmem(int argc, char **argv);
24+
static int shell_to_sos_console(int argc, char **argv);
25+
static int shell_show_cpu_int(__unused int argc, __unused char **argv);
26+
static int shell_show_ptdev_info(__unused int argc, __unused char **argv);
27+
static int shell_show_vioapic_info(int argc, char **argv);
28+
static int shell_show_ioapic_info(__unused int argc, __unused char **argv);
29+
static int shell_show_vmexit_profile(__unused int argc, __unused char **argv);
30+
static int shell_dump_logbuf(int argc, char **argv);
31+
static int shell_loglevel(int argc, char **argv);
32+
static int shell_cpuid(int argc, char **argv);
33+
static int shell_trigger_crash(int argc, char **argv);
34+
1935
static struct shell_cmd shell_cmds[] = {
2036
{
2137
.str = SHELL_CMD_HELP,
@@ -179,11 +195,32 @@ static int string_to_argv(char *argv_str, void *p_argv_mem,
179195
return 0;
180196
}
181197

198+
static struct shell_cmd *shell_find_cmd(const char *cmd_str)
199+
{
200+
uint32_t i;
201+
struct shell_cmd *p_cmd = NULL;
202+
203+
for (i = 0U; i < p_shell->cmd_count; i++) {
204+
p_cmd = &p_shell->shell_cmd[i];
205+
if (strcmp(p_cmd->str, cmd_str) == 0) {
206+
return p_cmd;
207+
}
208+
}
209+
return NULL;
210+
}
211+
182212
static char shell_getc(void)
183213
{
184214
return console_getc();
185215
}
186216

217+
static void shell_puts(const char *string_ptr)
218+
{
219+
/* Output the string */
220+
(void)console_write(string_ptr, strnlen_s(string_ptr,
221+
SHELL_STRING_MAX_LEN));
222+
}
223+
187224
static void shell_handle_special_char(uint8_t ch)
188225
{
189226
switch (ch) {
@@ -289,6 +326,51 @@ static bool shell_input_line(void)
289326
return done;
290327
}
291328

329+
static int shell_process_cmd(char *p_input_line)
330+
{
331+
int status = -EINVAL;
332+
struct shell_cmd *p_cmd;
333+
char cmd_argv_str[SHELL_CMD_MAX_LEN + 1U];
334+
int cmd_argv_mem[sizeof(char *) * ((SHELL_CMD_MAX_LEN + 1U) / 2U)];
335+
int cmd_argc;
336+
char **cmd_argv;
337+
338+
/* Copy the input line INTo an argument string to become part of the
339+
* argument vector.
340+
*/
341+
(void)strcpy_s(&cmd_argv_str[0], SHELL_CMD_MAX_LEN, p_input_line);
342+
cmd_argv_str[SHELL_CMD_MAX_LEN] = 0;
343+
344+
/* Build the argv vector from the string. The first argument in the
345+
* resulting vector will be the command string itself.
346+
*/
347+
348+
/* NOTE: This process is destructive to the argument string! */
349+
350+
(void) string_to_argv(&cmd_argv_str[0],
351+
(void *) &cmd_argv_mem[0],
352+
sizeof(cmd_argv_mem), (void *)&cmd_argc, &cmd_argv);
353+
354+
/* Determine if there is a command to process. */
355+
if (cmd_argc != 0) {
356+
/* See if command is in cmds supported */
357+
p_cmd = shell_find_cmd(cmd_argv[0]);
358+
if (p_cmd == NULL) {
359+
shell_puts("\r\nError: Invalid command.\r\n");
360+
return -EINVAL;
361+
}
362+
363+
status = p_cmd->fcn(cmd_argc, &cmd_argv[0]);
364+
if (status == -EINVAL) {
365+
shell_puts("\r\nError: Invalid parameters.\r\n");
366+
} else if (status != 0) {
367+
shell_puts("\r\nCommand launch failed.\r\n");
368+
}
369+
}
370+
371+
return status;
372+
}
373+
292374
static int shell_process(void)
293375
{
294376
int status;
@@ -323,19 +405,6 @@ static int shell_process(void)
323405
return status;
324406
}
325407

326-
struct shell_cmd *shell_find_cmd(const char *cmd_str)
327-
{
328-
uint32_t i;
329-
struct shell_cmd *p_cmd = NULL;
330-
331-
for (i = 0U; i < p_shell->cmd_count; i++) {
332-
p_cmd = &p_shell->shell_cmd[i];
333-
if (strcmp(p_cmd->str, cmd_str) == 0) {
334-
return p_cmd;
335-
}
336-
}
337-
return NULL;
338-
}
339408

340409
void shell_kick(void)
341410
{
@@ -363,66 +432,20 @@ void shell_kick(void)
363432
}
364433
}
365434

366-
int shell_process_cmd(char *p_input_line)
367-
{
368-
int status = -EINVAL;
369-
struct shell_cmd *p_cmd;
370-
char cmd_argv_str[SHELL_CMD_MAX_LEN + 1U];
371-
int cmd_argv_mem[sizeof(char *) * ((SHELL_CMD_MAX_LEN + 1U) / 2U)];
372-
int cmd_argc;
373-
char **cmd_argv;
374-
375-
/* Copy the input line INTo an argument string to become part of the
376-
* argument vector.
377-
*/
378-
(void)strcpy_s(&cmd_argv_str[0], SHELL_CMD_MAX_LEN, p_input_line);
379-
cmd_argv_str[SHELL_CMD_MAX_LEN] = 0;
380-
381-
/* Build the argv vector from the string. The first argument in the
382-
* resulting vector will be the command string itself.
383-
*/
384-
385-
/* NOTE: This process is destructive to the argument string! */
386-
387-
(void) string_to_argv(&cmd_argv_str[0],
388-
(void *) &cmd_argv_mem[0],
389-
sizeof(cmd_argv_mem), (void *)&cmd_argc, &cmd_argv);
390-
391-
/* Determine if there is a command to process. */
392-
if (cmd_argc != 0) {
393-
/* See if command is in cmds supported */
394-
p_cmd = shell_find_cmd(cmd_argv[0]);
395-
if (p_cmd == NULL) {
396-
shell_puts("\r\nError: Invalid command.\r\n");
397-
return -EINVAL;
398-
}
399-
400-
status = p_cmd->fcn(cmd_argc, &cmd_argv[0]);
401-
if (status == -EINVAL) {
402-
shell_puts("\r\nError: Invalid parameters.\r\n");
403-
} else if (status != 0) {
404-
shell_puts("\r\nCommand launch failed.\r\n");
405-
}
406-
}
407-
408-
return status;
409-
}
410435

411436
void shell_init(void)
412437
{
413438
p_shell->shell_cmd = shell_cmds;
414439
p_shell->cmd_count = ARRAY_SIZE(shell_cmds);
415440

416-
(void)strcpy_s((void *)p_shell->name, SHELL_NAME_MAX_LEN, "Serial");
417-
418441
/* Zero fill the input buffer */
419442
(void)memset((void *)p_shell->input_line[p_shell->input_line_active], 0U,
420443
SHELL_CMD_MAX_LEN + 1U);
421444
}
422445

423446
#define SHELL_ROWS 10
424447
#define MAX_INDENT_LEN 16
425-
int shell_cmd_help(__unused int argc, __unused char **argv)
448+
static int shell_cmd_help(__unused int argc, __unused char **argv)
426449
{
427450
int spaces = 0;
428451
struct shell_cmd *p_cmd = NULL;
@@ -496,7 +519,7 @@ int shell_cmd_help(__unused int argc, __unused char **argv)
496519
return 0;
497520
}
498521

499-
int shell_list_vm(__unused int argc, __unused char **argv)
522+
static int shell_list_vm(__unused int argc, __unused char **argv)
500523
{
501524
char temp_str[MAX_STR_SIZE];
502525
struct list_head *pos;
@@ -534,7 +557,7 @@ int shell_list_vm(__unused int argc, __unused char **argv)
534557
return 0;
535558
}
536559

537-
int shell_list_vcpu(__unused int argc, __unused char **argv)
560+
static int shell_list_vcpu(__unused int argc, __unused char **argv)
538561
{
539562
char temp_str[MAX_STR_SIZE];
540563
struct list_head *pos;
@@ -584,7 +607,7 @@ int shell_list_vcpu(__unused int argc, __unused char **argv)
584607
}
585608

586609
#define DUMPREG_SP_SIZE 32
587-
int shell_vcpu_dumpreg(int argc, char **argv)
610+
static int shell_vcpu_dumpreg(int argc, char **argv)
588611
{
589612
int status = 0;
590613
uint16_t vm_id;
@@ -702,7 +725,7 @@ int shell_vcpu_dumpreg(int argc, char **argv)
702725
}
703726

704727
#define MAX_MEMDUMP_LEN (32U*8U)
705-
int shell_dumpmem(int argc, char **argv)
728+
static int shell_dumpmem(int argc, char **argv)
706729
{
707730
uint64_t addr;
708731
uint64_t *ptr;
@@ -746,7 +769,7 @@ int shell_dumpmem(int argc, char **argv)
746769
return 0;
747770
}
748771

749-
int shell_to_sos_console(__unused int argc, __unused char **argv)
772+
static int shell_to_sos_console(__unused int argc, __unused char **argv)
750773
{
751774
char temp_str[TEMP_STR_SIZE];
752775
uint16_t guest_no = 0U;
@@ -782,7 +805,7 @@ int shell_to_sos_console(__unused int argc, __unused char **argv)
782805
return 0;
783806
}
784807

785-
int shell_show_cpu_int(__unused int argc, __unused char **argv)
808+
static int shell_show_cpu_int(__unused int argc, __unused char **argv)
786809
{
787810
char *temp_str = alloc_page();
788811

@@ -798,7 +821,7 @@ int shell_show_cpu_int(__unused int argc, __unused char **argv)
798821
return 0;
799822
}
800823

801-
int shell_show_ptdev_info(__unused int argc, __unused char **argv)
824+
static int shell_show_ptdev_info(__unused int argc, __unused char **argv)
802825
{
803826
char *temp_str = alloc_page();
804827

@@ -814,7 +837,7 @@ int shell_show_ptdev_info(__unused int argc, __unused char **argv)
814837
return 0;
815838
}
816839

817-
int shell_show_vioapic_info(int argc, char **argv)
840+
static int shell_show_vioapic_info(int argc, char **argv)
818841
{
819842
char *temp_str = alloc_page();
820843
uint16_t vmid;
@@ -842,7 +865,7 @@ int shell_show_vioapic_info(int argc, char **argv)
842865
return -EINVAL;
843866
}
844867

845-
int shell_show_ioapic_info(__unused int argc, __unused char **argv)
868+
static int shell_show_ioapic_info(__unused int argc, __unused char **argv)
846869
{
847870
char *temp_str = alloc_pages(2U);
848871

@@ -858,7 +881,7 @@ int shell_show_ioapic_info(__unused int argc, __unused char **argv)
858881
return 0;
859882
}
860883

861-
int shell_show_vmexit_profile(__unused int argc, __unused char **argv)
884+
static int shell_show_vmexit_profile(__unused int argc, __unused char **argv)
862885
{
863886
char *temp_str = alloc_pages(2U);
864887

@@ -874,7 +897,7 @@ int shell_show_vmexit_profile(__unused int argc, __unused char **argv)
874897
return 0;
875898
}
876899

877-
int shell_dump_logbuf(int argc, char **argv)
900+
static int shell_dump_logbuf(int argc, char **argv)
878901
{
879902
uint16_t pcpu_id;
880903
int val;
@@ -891,7 +914,7 @@ int shell_dump_logbuf(int argc, char **argv)
891914
return -EINVAL;
892915
}
893916

894-
int shell_loglevel(int argc, char **argv)
917+
static int shell_loglevel(int argc, char **argv)
895918
{
896919
char str[MAX_STR_SIZE] = {0};
897920

@@ -912,7 +935,7 @@ int shell_loglevel(int argc, char **argv)
912935
return 0;
913936
}
914937

915-
int shell_cpuid(int argc, char **argv)
938+
static int shell_cpuid(int argc, char **argv)
916939
{
917940
char str[MAX_STR_SIZE] = {0};
918941
uint32_t leaf, subleaf = 0;
@@ -939,7 +962,7 @@ int shell_cpuid(int argc, char **argv)
939962
return 0;
940963
}
941964

942-
int shell_trigger_crash(int argc, char **argv)
965+
static int shell_trigger_crash(int argc, char **argv)
943966
{
944967
char str[MAX_STR_SIZE] = {0};
945968

@@ -951,12 +974,3 @@ int shell_trigger_crash(int argc, char **argv)
951974

952975
return 0;
953976
}
954-
955-
void shell_puts(const char *string_ptr)
956-
{
957-
/* Output the string */
958-
(void)console_write(string_ptr, strnlen_s(string_ptr,
959-
SHELL_STRING_MAX_LEN));
960-
}
961-
962-

0 commit comments

Comments
 (0)