[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Minios-devel] [UNIKRAFT PATCH 2/6] plat/common: Provide cpuid macro for x86


  • To: Simon Kuenzer <simon.kuenzer@xxxxxxxxx>
  • From: gaulthier.gain@xxxxxxxxx
  • Date: Thu, 12 Dec 2019 14:37:15 +0100 (CET)
  • Cc: Felipe Huici <felipe.huici@xxxxxxxxx>, minios-devel@xxxxxxxxxxxxx
  • Delivery-date: Thu, 12 Dec 2019 13:37:30 +0000
  • Dkim-filter: OpenDKIM Filter v2.11.0 serv108.segi.ulg.ac.be 048A1200F4B0
  • List-id: Mini-os development list <minios-devel.lists.xenproject.org>
  • Thread-index: vJDgC/Mt4lHcY3At5+3+iYzxXedPgw==
  • Thread-topic: plat/common: Provide cpuid macro for x86

Reviewed-by: Gaulthier Gain <gaulthier.gain@xxxxxxxxx>

----- Mail original -----
De: "Simon Kuenzer" <simon.kuenzer@xxxxxxxxx>
À: minios-devel@xxxxxxxxxxxxx
Cc: "Gaulthier Gain" <gaulthier.gain@xxxxxxxxx>, "Felipe Huici" 
<felipe.huici@xxxxxxxxx>, "Simon Kuenzer" <simon.kuenzer@xxxxxxxxx>
Envoyé: Jeudi 5 Décembre 2019 15:02:18
Objet: [UNIKRAFT PATCH 2/6] plat/common: Provide cpuid macro for x86

The `cpuid` instruction is used to query and retrieve information
about supported CPU features.

Signed-off-by: Simon Kuenzer <simon.kuenzer@xxxxxxxxx>
---
 plat/common/include/x86/cpu.h | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/plat/common/include/x86/cpu.h b/plat/common/include/x86/cpu.h
index 4a3f65d4..3bec2b58 100644
--- a/plat/common/include/x86/cpu.h
+++ b/plat/common/include/x86/cpu.h
@@ -59,6 +59,15 @@ struct _x86_features {
 
 extern struct _x86_features x86_cpu_features;
 
+static inline void cpuid(__u32 fn, __u32 subfn,
+                        __u32 *eax, __u32 *ebx,
+                        __u32 *ecx, __u32 *edx)
+{
+       asm volatile("cpuid"
+                    : "=a"(*eax), "=b"(*ebx), "=c"(*ecx), "=d"(*edx)
+                    : "a"(fn), "c" (subfn));
+}
+
 static inline void save_extregs(struct sw_ctx *ctx)
 {
        switch (x86_cpu_features.save) {
@@ -132,17 +141,14 @@ static inline void _init_cpufeatures(void)
         * contains "1" after this asm expression. See the "Warning" note at
         * https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html#InputOperands
         */
-       asm volatile("cpuid" : "=a"(eax), "=c"(ecx), "=d"(edx) : "a"(1)
-                       : "ebx");
+       cpuid(1, 0, &eax, &ebx, &ecx, &edx);
        if (ecx & X86_CPUID1_ECX_OSXSAVE) {
-               asm volatile("cpuid" : "=a"(eax), "=c"(ecx) : "a"(0xd), "c"(1)
-                               : "ebx", "edx");
+               cpuid(0xd, 1, &eax, &ebx, &ecx, &edx);
                if (eax & X86_CPUIDD1_EAX_XSAVEOPT)
                        x86_cpu_features.save = X86_SAVE_XSAVEOPT;
                else
                        x86_cpu_features.save = X86_SAVE_XSAVE;
-               asm volatile("cpuid" : "=a"(eax), "=b"(ebx), "=c"(ecx)
-                               : "a"(0xd), "c"(0) : "edx");
+               cpuid(0xd, 0, &eax, &ebx, &ecx, &edx);
                x86_cpu_features.extregs_size = ebx;
                x86_cpu_features.extregs_align = 64;
        } else if (edx & X86_CPUID1_EDX_FXSR) {
-- 
2.20.1

_______________________________________________
Minios-devel mailing list
Minios-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/minios-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.