summaryrefslogtreecommitdiffstats
path: root/include/grub/i386/cpuid.h
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 16:29:51 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 16:29:51 +0000
commit6e7a315eb67cb6c113cf37e1d66c4f11a51a2b3e (patch)
tree32451fa3cdd9321fb2591fada9891b2cb70a9cd1 /include/grub/i386/cpuid.h
parentInitial commit. (diff)
downloadgrub2-6e7a315eb67cb6c113cf37e1d66c4f11a51a2b3e.tar.xz
grub2-6e7a315eb67cb6c113cf37e1d66c4f11a51a2b3e.zip
Adding upstream version 2.06.upstream/2.06upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r--include/grub/i386/cpuid.h85
1 files changed, 85 insertions, 0 deletions
diff --git a/include/grub/i386/cpuid.h b/include/grub/i386/cpuid.h
new file mode 100644
index 0000000..f7ae4b0
--- /dev/null
+++ b/include/grub/i386/cpuid.h
@@ -0,0 +1,85 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2009 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_CPU_CPUID_HEADER
+#define GRUB_CPU_CPUID_HEADER 1
+
+extern unsigned char grub_cpuid_has_longmode;
+extern unsigned char grub_cpuid_has_pae;
+
+#ifdef __x86_64__
+
+static __inline int
+grub_cpu_is_cpuid_supported (void)
+{
+ grub_uint64_t id_supported;
+
+ __asm__ ("pushfq\n\t"
+ "popq %%rax /* Get EFLAGS into EAX */\n\t"
+ "movq %%rax, %%rcx /* Save original flags in ECX */\n\t"
+ "xorq $0x200000, %%rax /* Flip ID bit in EFLAGS */\n\t"
+ "pushq %%rax /* Store modified EFLAGS on stack */\n\t"
+ "popfq /* Replace current EFLAGS */\n\t"
+ "pushfq /* Read back the EFLAGS */\n\t"
+ "popq %%rax /* Get EFLAGS into EAX */\n\t"
+ "xorq %%rcx, %%rax /* Check if flag could be modified */\n\t"
+ : "=a" (id_supported)
+ : /* No inputs. */
+ : /* Clobbered: */ "%rcx");
+
+ return id_supported != 0;
+}
+
+#else
+
+static __inline int
+grub_cpu_is_cpuid_supported (void)
+{
+ grub_uint32_t id_supported;
+
+ __asm__ ("pushfl\n\t"
+ "popl %%eax /* Get EFLAGS into EAX */\n\t"
+ "movl %%eax, %%ecx /* Save original flags in ECX */\n\t"
+ "xorl $0x200000, %%eax /* Flip ID bit in EFLAGS */\n\t"
+ "pushl %%eax /* Store modified EFLAGS on stack */\n\t"
+ "popfl /* Replace current EFLAGS */\n\t"
+ "pushfl /* Read back the EFLAGS */\n\t"
+ "popl %%eax /* Get EFLAGS into EAX */\n\t"
+ "xorl %%ecx, %%eax /* Check if flag could be modified */\n\t"
+ : "=a" (id_supported)
+ : /* No inputs. */
+ : /* Clobbered: */ "%rcx");
+
+ return id_supported != 0;
+}
+
+#endif
+
+#ifdef __PIC__
+#define grub_cpuid(num,a,b,c,d) \
+ asm volatile ("xchgl %%ebx, %1; cpuid; xchgl %%ebx, %1" \
+ : "=a" (a), "=r" (b), "=c" (c), "=d" (d) \
+ : "0" (num))
+#else
+#define grub_cpuid(num,a,b,c,d) \
+ asm volatile ("cpuid" \
+ : "=a" (a), "=b" (b), "=c" (c), "=d" (d) \
+ : "0" (num))
+#endif
+
+#endif