From: ut000745 <wangyou...@uniontech.com> Signed-off-by: wangyouwan <wangyou...@uniontech.com> --- grub-core/Makefile.core.def | 1 + grub-core/kern/i386/coreboot/init.c | 5 ++ grub-core/kern/i386/cpumodelname.c | 73 +++++++++++++++++++++++++++++ grub-core/kern/i386/efi/init.c | 3 ++ grub-core/kern/i386/pc/init.c | 3 ++ include/grub/i386/cpumodelname.h | 24 ++++++++++ 6 files changed, 109 insertions(+) create mode 100644 grub-core/kern/i386/cpumodelname.c create mode 100644 include/grub/i386/cpumodelname.h
diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def index 8022e1c0a..2d46b945a 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def @@ -214,6 +214,7 @@ kernel = { x86 = kern/i386/tsc.c; x86 = kern/i386/tsc_pit.c; + x86 = kern/i386/cpumodelname.c; i386_efi = kern/i386/efi/tsc.c; x86_64_efi = kern/i386/efi/tsc.c; i386_efi = kern/i386/tsc_pmtimer.c; diff --git a/grub-core/kern/i386/coreboot/init.c b/grub-core/kern/i386/coreboot/init.c index 3314f027f..68675ac66 100644 --- a/grub-core/kern/i386/coreboot/init.c +++ b/grub-core/kern/i386/coreboot/init.c @@ -35,6 +35,7 @@ #include <grub/cpu/floppy.h> #include <grub/cpu/tsc.h> #include <grub/video.h> +#include <grub/cpu/cpumodelname.h> extern grub_uint8_t _start[]; extern grub_uint8_t _end[]; @@ -109,6 +110,8 @@ grub_machine_init (void) grub_gfxterm_init (); grub_tsc_init (); + + grub_cpu_model_name_init (); } #else @@ -124,6 +127,8 @@ grub_machine_init (void) grub_machine_mmap_iterate (heap_init, NULL); grub_tsc_init (); + + grub_cpu_model_name_init (); } #endif diff --git a/grub-core/kern/i386/cpumodelname.c b/grub-core/kern/i386/cpumodelname.c new file mode 100644 index 000000000..49adbcf14 --- /dev/null +++ b/grub-core/kern/i386/cpumodelname.c @@ -0,0 +1,73 @@ +/* kern/i386/cpumodelname.c - x86 get cpu model name + * + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2008 Free Software Foundation, Inc. + * + * GRUB is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see <http://www.gnu.org/licenses/>. + */ +#include <grub/mm.h> +#include <grub/dl.h> +#include <grub/env.h> +#include <grub/i386/cpuid.h> +#include <grub/i386/cpumodelname.h> + +GRUB_MOD_LICENSE ("GPLv3+"); + +static void +grub_get_model_name (void) +{ + char *ret = NULL; + grub_uint32_t x86_model_id[12]; + + char cpumodelname[6] = {0}; + const char *list[] = {"Intel","AMD","zhaoxin"}; + unsigned i; + + grub_cpuid (0x80000002, x86_model_id[0], x86_model_id[1], x86_model_id[2], x86_model_id[3]); + grub_cpuid (0x80000003, x86_model_id[4], x86_model_id[5], x86_model_id[6], x86_model_id[7]); + grub_cpuid (0x80000004, x86_model_id[8], x86_model_id[9], x86_model_id[10], x86_model_id[11]); + + for (i = 0; i < sizeof(list)/sizeof(list[0]); i++) + { + ret = grub_strstr ((char *)x86_model_id, list[i]); + if (ret != NULL) + { + grub_strncpy (cpumodelname, list[i], grub_strlen(list[i]) + 1); + break; + } + } + + grub_env_set ("cpu_model_name", cpumodelname); + grub_env_export ("cpu_model_name"); + +} + +void +grub_cpu_model_name_init (void) +{ + unsigned int ext_level; + unsigned int eax, ebx, ecx, edx; + + if (!grub_cpu_is_cpuid_supported ()) + return; + + grub_cpuid (0x80000000, eax, ebx, ecx, edx); + ext_level = eax; + + if (ext_level < 0x80000004) + return; + + grub_get_model_name (); + +} diff --git a/grub-core/kern/i386/efi/init.c b/grub-core/kern/i386/efi/init.c index 46476e27e..099265140 100644 --- a/grub-core/kern/i386/efi/init.c +++ b/grub-core/kern/i386/efi/init.c @@ -27,12 +27,15 @@ #include <grub/efi/efi.h> #include <grub/i386/tsc.h> #include <grub/loader.h> +#include <grub/i386/cpumodelname.h> void grub_machine_init (void) { grub_efi_init (); grub_tsc_init (); + + grub_cpu_model_name_init (); } void diff --git a/grub-core/kern/i386/pc/init.c b/grub-core/kern/i386/pc/init.c index 27bc68b8a..b8251be8a 100644 --- a/grub-core/kern/i386/pc/init.c +++ b/grub-core/kern/i386/pc/init.c @@ -35,6 +35,7 @@ #include <grub/cpu/cpuid.h> #include <grub/cpu/tsc.h> #include <grub/machine/time.h> +#include <grub/cpu/cpumodelname.h> struct mem_region { @@ -260,6 +261,8 @@ grub_machine_init (void) } grub_tsc_init (); + + grub_cpu_model_name_init (); } void diff --git a/include/grub/i386/cpumodelname.h b/include/grub/i386/cpumodelname.h new file mode 100644 index 000000000..838fe1603 --- /dev/null +++ b/include/grub/i386/cpumodelname.h @@ -0,0 +1,24 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2019 Free Software Foundation, Inc. + * + * GRUB is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef GRUB_CPUMODENAME_H +#define GRUB_CPUMODENAME_H 1 + +void grub_cpu_model_name_init (void); + +#endif /* GRUB_CPUMODENAME_H */ -- 2.20.1 _______________________________________________ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel