diff --git a/hypervisor/debug/shell_internal.c b/hypervisor/debug/shell_internal.c index 371018600..85f71b2d9 100644 --- a/hypervisor/debug/shell_internal.c +++ b/hypervisor/debug/shell_internal.c @@ -1040,6 +1040,34 @@ int shell_set_loglevel(struct shell *p_shell, int argc, char **argv) return status; } +int shell_cpuid(struct shell *p_shell, int argc, char **argv) +{ + char str[MAX_STR_SIZE] = {0}; + uint32_t leaf, subleaf = 0; + uint32_t eax, ebx, ecx, edx; + + if (argc == 2) { + leaf = strtoul(argv[1], NULL, 16); + } else if (argc == 3) { + leaf = strtoul(argv[1], NULL, 16); + subleaf = strtoul(argv[2], NULL, 16); + } else { + shell_puts(p_shell, + "Please enter correct cmd with " + "cpuid [subleaf]\r\n"); + return -EINVAL; + } + + cpuid_subleaf(leaf, subleaf, &eax, &ebx, &ecx, &edx); + snprintf(str, MAX_STR_SIZE, + "cpuid leaf: 0x%x, subleaf: 0x%x, 0x%x:0x%x:0x%x:0x%x\r\n", + leaf, subleaf, eax, ebx, ecx, edx); + + shell_puts(p_shell, str); + + return 0; +} + int shell_terminate_serial(struct shell *p_shell) { /* Shell shouldn't own the serial port handle anymore. */ diff --git a/hypervisor/debug/shell_internal.h b/hypervisor/debug/shell_internal.h index 3f584dca3..e12668649 100644 --- a/hypervisor/debug/shell_internal.h +++ b/hypervisor/debug/shell_internal.h @@ -149,6 +149,10 @@ struct shell_cmd { #define SHELL_CMD_SET_LOG_LVL_PARAM " [mem_loglevel]" #define SHELL_CMD_SET_LOG_LVL_HELP "Set loglevel [0-6]" +#define SHELL_CMD_CPUID "cpuid" +#define SHELL_CMD_CPUID_PARAM " [subleaf]" +#define SHELL_CMD_CPUID_HELP "cpuid leaf [subleaf], in hexadecimal" + /* Global function prototypes */ int shell_show_req_info(struct shell *p_shell, int argc, char **argv); @@ -172,6 +176,7 @@ int shell_show_vmexit_profile(struct shell *p_shell, int argc, char **argv); int shell_dump_logbuf(struct shell *p_shell, int argc, char **argv); int shell_get_loglevel(struct shell *p_shell, int argc, char **argv); int shell_set_loglevel(struct shell *p_shell, int argc, char **argv); +int shell_cpuid(struct shell *p_shell, int argc, char **argv); struct shell_cmd *shell_find_cmd(struct shell *p_shell, const char *cmd); int shell_process_cmd(struct shell *p_shell, char *p_input_line); int shell_terminate_serial(struct shell *p_shell); diff --git a/hypervisor/debug/shell_public.c b/hypervisor/debug/shell_public.c index 095084649..66f43f844 100644 --- a/hypervisor/debug/shell_public.c +++ b/hypervisor/debug/shell_public.c @@ -356,6 +356,17 @@ int shell_init(void) pr_err("Error: Command \"%s\" registration failed.", SHELL_CMD_SET_LOG_LVL); } + + status = shell_register_cmd(serial_session, + SHELL_CMD_CPUID, + SHELL_CMD_CPUID_PARAM, + SHELL_CMD_CPUID_HELP, + shell_cpuid); + + if (status != 0) { + pr_err("Error: Command \"%s\" registration failed.", + SHELL_CMD_CPUID); + } } return status;