aboutsummaryrefslogtreecommitdiffstats
path: root/com32/include
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2019-02-04 12:16:57 -0800
committerH. Peter Anvin <hpa@zytor.com>2019-02-04 12:16:57 -0800
commit35badfce1f4855a32d089e1a9d8c098e3ef343c7 (patch)
treeb114358b6bac8eb97d7b3bf395e7eaeb7a1de1e5 /com32/include
parent621770d33e6da95556ccfc4f08fd16edb8300c63 (diff)
downloadsyslinux-35badfce1f4855a32d089e1a9d8c098e3ef343c7.tar.gz
syslinux-35badfce1f4855a32d089e1a9d8c098e3ef343c7.tar.xz
syslinux-35badfce1f4855a32d089e1a9d8c098e3ef343c7.zip
Reorganize and clean up a bunch of the x86 code
We were doing a bunch of i386-specific things even on x86-64. Fix this, and merge x86 definitions where possible. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Diffstat (limited to 'com32/include')
-rw-r--r--com32/include/com32.h22
-rw-r--r--com32/include/sys/bitops.h31
-rw-r--r--com32/include/sys/cpu.h57
-rw-r--r--com32/include/sys/fpu.h2
-rw-r--r--com32/include/sys/i386/bitops.h54
-rw-r--r--com32/include/sys/i386/cpu.h114
-rw-r--r--com32/include/sys/module.h4
-rw-r--r--com32/include/sys/module32.h (renamed from com32/include/sys/i386/module.h)0
-rw-r--r--com32/include/sys/module64.h (renamed from com32/include/sys/x86_64/module.h)0
-rw-r--r--com32/include/sys/x86_64/cpu.h128
-rw-r--r--com32/include/x86/bitops.h (renamed from com32/include/sys/x86_64/bitops.h)27
-rw-r--r--com32/include/x86/cpu.h206
-rw-r--r--com32/include/x86/regs.h66
13 files changed, 322 insertions, 389 deletions
diff --git a/com32/include/com32.h b/com32/include/com32.h
index adef7126..1a843e0b 100644
--- a/com32/include/com32.h
+++ b/com32/include/com32.h
@@ -29,7 +29,7 @@
/*
* com32.h
*
- * Common declarations for com32 programs.
+ * Declarations for the BIOS call interface
*/
#ifndef _COM32_H
@@ -39,6 +39,7 @@
#include <stdbool.h>
#include <stddef.h>
#include <klibc/compiler.h> /* For __cdecl */
+#include <x86/regs.h>
/*
* This structure defines the register frame used by the
@@ -73,25 +74,6 @@ typedef struct {
reg32_t eflags; /* Offset 40 */
} com32sys_t;
-/* EFLAGS definitions */
-#define EFLAGS_CF 0x00000001
-#define EFLAGS_PF 0x00000004
-#define EFLAGS_AF 0x00000010
-#define EFLAGS_ZF 0x00000040
-#define EFLAGS_SF 0x00000080
-#define EFLAGS_TF 0x00000100
-#define EFLAGS_IF 0x00000200
-#define EFLAGS_DF 0x00000400
-#define EFLAGS_OF 0x00000800
-#define EFLAGS_IOPL 0x00003000
-#define EFLAGS_NT 0x00004000
-#define EFLAGS_RF 0x00010000
-#define EFLAGS_VM 0x00020000
-#define EFLAGS_AC 0x00040000
-#define EFLAGS_VIF 0x00080000
-#define EFLAGS_VIP 0x00100000
-#define EFLAGS_ID 0x00200000
-
struct com32_pmapi;
extern struct com32_sys_args {
diff --git a/com32/include/sys/bitops.h b/com32/include/sys/bitops.h
index de30d932..017f600d 100644
--- a/com32/include/sys/bitops.h
+++ b/com32/include/sys/bitops.h
@@ -1,6 +1,6 @@
/* ----------------------------------------------------------------------- *
*
- * Copyright 2010-2011 Intel Corporation; author: H. Peter Anvin
+ * Copyright 2010-2019 Intel Corporation; author: H. Peter Anvin
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
@@ -36,11 +36,30 @@
#include <klibc/compiler.h>
-#if __SIZEOF_POINTER__ == 4
-#include <i386/bitops.h>
-#elif __SIZEOF_POINTER__ == 8
-#include <x86_64/bitops.h>
+#if defined(__i386__) || defined(__x86_64__)
+# include <x86/bitops.h>
#else
-#error "Unable to build for to-be-defined architecture type"
+static inline void set_bit(long __bit, void *__bitmap)
+{
+ char *__cp = (char *)__bitmap;
+
+ __cp[__bit >> 3] |= 1 << (__bit & 7);
+}
+
+static inline void clr_bit(long __bit, void *__bitmap)
+{
+ char *__cp = (char *)__bitmap;
+
+ __cp[__bit >> 3] &= ~(1 << (__bit & 7));
+}
+
+static inline _Bool __purefunc test_bit(long __bit, const void *__bitmap)
+{
+ const char *__cp = (char *)__bitmap;
+
+ return (__cp[__bit >> 3] >> (__bit & 7)) & 1;
+}
+
#endif
+
#endif /* _BITOPS_H */
diff --git a/com32/include/sys/cpu.h b/com32/include/sys/cpu.h
deleted file mode 100644
index 76c45da0..00000000
--- a/com32/include/sys/cpu.h
+++ /dev/null
@@ -1,57 +0,0 @@
-#ifndef _CPU_H
-#define _CPU_H
-
-#include <stdbool.h>
-#include <stdint.h>
-#include <klibc/compiler.h>
-
-#if __SIZEOF_POINTER__ == 4
-#include <i386/cpu.h>
-#elif __SIZEOF_POINTER__ == 8
-#include <x86_64/cpu.h>
-#else
-#error "unsupported architecture"
-#endif
-
-typedef unsigned long irq_state_t;
-
-static inline irq_state_t irq_state(void)
-{
- irq_state_t __st;
-
- asm volatile("pushf ; pop %0" : "=rm" (__st) : : "memory");
- return __st;
-}
-
-static inline irq_state_t irq_save(void)
-{
- irq_state_t __st = irq_state();
- cli();
- return __st;
-}
-
-static inline void irq_restore(irq_state_t __st)
-{
- asm volatile("push %0 ; popf" : : "rm" (__st) : "memory");
-}
-
-/* Standard macro to see if a specific flag is changeable */
-static inline __constfunc bool cpu_has_eflag(unsigned long flag)
-{
- unsigned long f0, f1;
- asm("pushf ; "
- "pushf ; "
- "pop %0 ; "
- "mov %0,%1 ; "
- "xor %2,%1 ; "
- "push %1 ; "
- "popf ; "
- "pushf ; "
- "pop %1 ; "
- "popf"
- : "=&r" (f0), "=&r" (f1)
- : "ri" (flag));
- return !!((f0^f1) & flag);
-}
-
-#endif
diff --git a/com32/include/sys/fpu.h b/com32/include/sys/fpu.h
index 134ae596..7a69be5f 100644
--- a/com32/include/sys/fpu.h
+++ b/com32/include/sys/fpu.h
@@ -1,6 +1,6 @@
#ifndef _SYS_FPU_H
#define _SYS_FPU_H
-extern int x86_init_fpu(void);
+extern int init_fpu(void);
#endif /* _SYS_FPU_H */
diff --git a/com32/include/sys/i386/bitops.h b/com32/include/sys/i386/bitops.h
deleted file mode 100644
index 663b267a..00000000
--- a/com32/include/sys/i386/bitops.h
+++ /dev/null
@@ -1,54 +0,0 @@
-/* ----------------------------------------------------------------------- *
- *
- * Copyright 2010-2011 Intel Corporation; author: H. Peter Anvin
- *
- * Permission is hereby granted, free of charge, to any person
- * obtaining a copy of this software and associated documentation
- * files (the "Software"), to deal in the Software without
- * restriction, including without limitation the rights to use,
- * copy, modify, merge, publish, distribute, sublicense, and/or
- * sell copies of the Software, and to permit persons to whom
- * the Software is furnished to do so, subject to the following
- * conditions:
- *
- * The above copyright notice and this permission notice shall
- * be included in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
- * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
- * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
- * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- * OTHER DEALINGS IN THE SOFTWARE.
- *
- * ----------------------------------------------------------------------- */
-
-/*
- * i386 bitops.h
- *
- * Simple bitwise operations
- */
-static inline void set_bit(long __bit, void *__bitmap)
-{
- asm volatile("btsl %1,%0"
- : "+m" (*(unsigned char *)__bitmap)
- : "Ir" (__bit) : "memory");
-}
-
-static inline void clr_bit(long __bit, void *__bitmap)
-{
- asm volatile("btcl %1,%0"
- : "+m" (*(unsigned char *)__bitmap)
- : "Ir" (__bit) : "memory");
-}
-
-static inline int __purefunc test_bit(long __bit, const void *__bitmap)
-{
- unsigned char __r;
- asm("btl %2,%1; setc %0"
- : "=qm" (__r)
- : "m" (*(const unsigned char *)__bitmap), "Ir" (__bit));
- return __r;
-}
diff --git a/com32/include/sys/i386/cpu.h b/com32/include/sys/i386/cpu.h
deleted file mode 100644
index a0cedf20..00000000
--- a/com32/include/sys/i386/cpu.h
+++ /dev/null
@@ -1,114 +0,0 @@
-/* i386 cpu.h */
-
-static inline uint64_t rdtsc(void)
-{
- uint64_t v;
- asm volatile("rdtsc" : "=A" (v));
- return v;
-}
-
-static inline uint32_t rdtscl(void)
-{
- uint32_t v;
- asm volatile("rdtsc" : "=a" (v) : : "edx");
- return v;
-}
-
-static inline void cpuid_count(uint32_t op, uint32_t cnt,
- uint32_t * eax, uint32_t * ebx,
- uint32_t * ecx, uint32_t * edx)
-{
- asm volatile("movl %%ebx,%1 ; "
- "cpuid ; "
- "xchgl %1,%%ebx"
- : "=a" (*eax), "=SD" (*ebx), "=c" (*ecx), "=d" (*edx)
- : "a"(op), "c"(cnt));
-}
-
-static inline void cpuid(uint32_t op, uint32_t * eax, uint32_t * ebx,
- uint32_t * ecx, uint32_t * edx)
-{
- cpuid_count(op, 0, eax, ebx, ecx, edx);
-}
-
-static inline __constfunc uint32_t cpuid_eax(uint32_t level)
-{
- uint32_t v;
-
- asm volatile("pushl %%ebx ; "
- "cpuid ; "
- "popl %%ebx"
- : "=a" (v)
- : "a"(level)
- : "ecx", "edx");
- return v;
-}
-
-static inline __constfunc uint32_t cpuid_ebx(uint32_t level)
-{
- uint32_t v;
-
- asm volatile("movl %%ebx,%0 ; "
- "cpuid ; "
- "xchgl %0,%%ebx"
- : "=SD" (v), "+a" (level)
- : : "ecx", "edx");
- return v;
-}
-
-static inline __constfunc uint32_t cpuid_ecx(uint32_t level)
-{
- uint32_t v;
-
- asm volatile("pushl %%ebx ; "
- "cpuid ; "
- "popl %%ebx"
- : "=c" (v), "+a" (level)
- : : "edx");
- return v;
-}
-
-static inline __constfunc uint32_t cpuid_edx(uint32_t level)
-{
- uint32_t v;
-
- asm volatile("pushl %%ebx ; "
- "cpuid ; "
- "popl %%ebx"
- : "=d" (v), "+a" (level)
- : : "ecx");
- return v;
-}
-
-static inline uint64_t rdmsr(uint32_t msr)
-{
- uint64_t v;
-
- asm volatile("rdmsr" : "=A" (v) : "c"(msr));
- return v;
-}
-
-static inline void wrmsr(uint64_t v, uint32_t msr)
-{
- asm volatile("wrmsr" : : "A" (v), "c" (msr));
-}
-
-static inline void cpu_relax(void)
-{
- asm volatile("rep ; nop" : : : "memory");
-}
-
-static inline void hlt(void)
-{
- asm volatile("hlt" : : : "memory");
-}
-
-static inline void cli(void)
-{
- asm volatile("cli" : : : "memory");
-}
-
-static inline void sti(void)
-{
- asm volatile("sti" : : : "memory");
-}
diff --git a/com32/include/sys/module.h b/com32/include/sys/module.h
index 48d65b2a..8e48fb2d 100644
--- a/com32/include/sys/module.h
+++ b/com32/include/sys/module.h
@@ -15,9 +15,9 @@
#include <linux/list.h>
#if __SIZEOF_POINTER__ == 4
-#include <i386/module.h>
+#include "module32.h"
#elif __SIZEOF_POINTER__ == 8
-#include <x86_64/module.h>
+#include "module64.h"
#else
#error "unsupported architecture"
#endif
diff --git a/com32/include/sys/i386/module.h b/com32/include/sys/module32.h
index 21988ead..21988ead 100644
--- a/com32/include/sys/i386/module.h
+++ b/com32/include/sys/module32.h
diff --git a/com32/include/sys/x86_64/module.h b/com32/include/sys/module64.h
index 203a6cd0..203a6cd0 100644
--- a/com32/include/sys/x86_64/module.h
+++ b/com32/include/sys/module64.h
diff --git a/com32/include/sys/x86_64/cpu.h b/com32/include/sys/x86_64/cpu.h
deleted file mode 100644
index cbe968f5..00000000
--- a/com32/include/sys/x86_64/cpu.h
+++ /dev/null
@@ -1,128 +0,0 @@
-#ifndef _CPU_X86_64_H
-#define _CPU_X86_64_H
-
-/* x86_64 cpu.h */
-
-static inline uint64_t rdtsc(void)
-{
- uint64_t v;
- asm volatile("rdtsc" : "=A" (v));
- return v;
-}
-
-static inline uint32_t rdtscl(void)
-{
- uint32_t v;
- asm volatile("rdtsc" : "=a" (v) : : "edx");
- return v;
-}
-
-static inline void native_cpuid(unsigned int *eax, unsigned int *ebx,
- unsigned int *ecx, unsigned int *edx)
-{
- /* ecx is often an input as well as an output. */
- asm volatile("cpuid"
- : "=a" (*eax),
- "=b" (*ebx),
- "=c" (*ecx),
- "=d" (*edx)
- : "0" (*eax), "2" (*ecx)
- : "memory");
-}
-/*
- * Generic CPUID function
- * clear %ecx since some cpus (Cyrix MII) do not set or clear %ecx
- * resulting in stale register contents being returned.
- */
-static inline void cpuid(uint32_t op,
- uint32_t *eax, uint32_t *ebx,
- uint32_t *ecx, uint32_t *edx)
-{
- *eax = op;
- *ecx = 0;
- native_cpuid(eax, ebx, ecx, edx);
-}
-
-/*
- * CPUID functions returning a single datum
- */
-static inline uint32_t cpuid_eax(uint32_t op)
-{
- uint32_t eax, ebx, ecx, edx;
-
- cpuid(op, &eax, &ebx, &ecx, &edx);
-
- return eax;
-}
-
-static inline uint32_t cpuid_ebx(uint32_t op)
-{
- uint32_t eax, ebx, ecx, edx;
-
- cpuid(op, &eax, &ebx, &ecx, &edx);
-
- return ebx;
-}
-
-static inline uint32_t cpuid_ecx(uint32_t op)
-{
- uint32_t eax, ebx, ecx, edx;
-
- cpuid(op, &eax, &ebx, &ecx, &edx);
-
- return ecx;
-}
-
-static inline uint32_t cpuid_edx(uint32_t op)
-{
- uint32_t eax, ebx, ecx, edx;
-
- cpuid(op, &eax, &ebx, &ecx, &edx);
-
- return edx;
-}
-
-static inline void cpuid_count(uint32_t op, uint32_t cnt,
- uint32_t * eax, uint32_t * ebx,
- uint32_t * ecx, uint32_t * edx)
-{
- asm volatile("movl %%ebx,%1 ; "
- "cpuid ; "
- "xchgl %1,%%ebx"
- : "=a" (*eax), "=SD" (*ebx), "=c" (*ecx), "=d" (*edx)
- : "a"(op), "c"(cnt));
-}
-
-static inline uint64_t rdmsr(uint32_t msr)
-{
- uint64_t v;
-
- asm volatile("rdmsr" : "=A" (v) : "c"(msr));
- return v;
-}
-
-static inline void wrmsr(uint64_t v, uint32_t msr)
-{
- asm volatile("wrmsr" : : "A" (v), "c" (msr));
-}
-
-static inline void cpu_relax(void)
-{
- asm volatile("rep ; nop" : : : "memory");
-}
-
-static inline void hlt(void)
-{
- asm volatile("hlt" : : : "memory");
-}
-
-static inline void cli(void)
-{
- asm volatile("cli" : : : "memory");
-}
-
-static inline void sti(void)
-{
- asm volatile("sti" : : : "memory");
-}
-#endif
diff --git a/com32/include/sys/x86_64/bitops.h b/com32/include/x86/bitops.h
index 7b1cc2b6..7667b6bf 100644
--- a/com32/include/sys/x86_64/bitops.h
+++ b/com32/include/x86/bitops.h
@@ -1,5 +1,5 @@
/* ----------------------------------------------------------------------- *
- *
+ *
* Copyright 2010-2011 Intel Corporation; author: H. Peter Anvin
*
* Permission is hereby granted, free of charge, to any person
@@ -10,10 +10,10 @@
* sell copies of the Software, and to permit persons to whom
* the Software is furnished to do so, subject to the following
* conditions:
- *
+ *
* The above copyright notice and this permission notice shall
* be included in all copies or substantial portions of the Software.
- *
+ *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
@@ -26,11 +26,14 @@
* ----------------------------------------------------------------------- */
/*
- * bitops.h - i386
+ * x86/bitops.h
*
* Simple bitwise operations
*/
+#ifndef _X86_BITOPS_H
+#define _X86_BITOPS_H
+
static inline void set_bit(long __bit, void *__bitmap)
{
asm volatile("bts %1,%0"
@@ -40,16 +43,26 @@ static inline void set_bit(long __bit, void *__bitmap)
static inline void clr_bit(long __bit, void *__bitmap)
{
- asm volatile("btcl %1,%0"
+ asm volatile("btc %1,%0"
: "+m" (*(unsigned char *)__bitmap)
: "Ir" (__bit) : "memory");
}
-static inline int __purefunc test_bit(long __bit, const void *__bitmap)
+static inline _Bool __purefunc test_bit(long __bit, const void *__bitmap)
{
- unsigned char __r;
+ _Bool __r;
+
+#ifdef __GCC_ASM_FLAG_OUTPUTS__
+ asm("bt %2,%1"
+ : "=@ccc" (__r)
+ : "m" (*(const unsigned char *)__bitmap), "Ir" (__bit));
+#else
asm("bt %2,%1; setc %0"
: "=qm" (__r)
: "m" (*(const unsigned char *)__bitmap), "Ir" (__bit));
+#endif
+
return __r;
}
+
+#endif /* _X86_BITOPS_H */
diff --git a/com32/include/x86/cpu.h b/com32/include/x86/cpu.h
new file mode 100644
index 00000000..5bdc74de
--- /dev/null
+++ b/com32/include/x86/cpu.h
@@ -0,0 +1,206 @@
+#ifndef _X86_CPU_H
+#define _X86_CPU_H
+
+#include <klibc/compiler.h>
+#include <inttypes.h>
+#include <stdbool.h>
+
+static inline bool cpu_has_eflag(unsigned long flag)
+{
+ unsigned long f1, f2;
+
+ asm("pushf ; "
+ "pushf ; "
+ "pop %0 ; "
+ "mov %0,%1 ; "
+ "xor %2,%1 ; "
+ "push %1 ; "
+ "popf ; "
+ "pushf ; "
+ "pop %1 ; "
+ "popf"
+ : "=r" (f1), "=r" (f2) : "ri" (flag));
+
+ return !!((f1 ^ f2) & flag);
+}
+
+static inline uint64_t rdtsc(void)
+{
+ uint32_t eax, edx;
+ asm volatile("rdtsc" : "=a" (eax), "=d" (edx));
+ return eax + ((uint64_t)edx << 32);
+}
+
+static inline uint32_t rdtscl(void)
+{
+ uint32_t v;
+ asm volatile("rdtsc" : "=a" (v) : : "edx");
+ return v;
+}
+
+static inline void cpuid_count(uint32_t op, uint32_t cnt,
+ uint32_t *eax, uint32_t *ebx,
+ uint32_t *ecx, uint32_t *edx)
+{
+#if defined(__i386__) && defined(__PIC__)
+ asm volatile("movl %%ebx,%1 ; "
+ "cpuid ; "
+ "xchgl %1,%%ebx"
+ : "=a" (*eax), "=SD" (*ebx), "=c" (*ecx), "=d" (*edx)
+ : "a"(op), "c"(cnt));
+#else
+ asm volatile("cpuid"
+ : "=a" (*eax), "=b" (*ebx), "=c" (*ecx), "=d" (*edx)
+ : "a"(op), "c"(cnt));
+#endif
+}
+
+static inline void cpuid(uint32_t op,
+ uint32_t *eax, uint32_t *ebx,
+ uint32_t *ecx, uint32_t *edx)
+{
+ cpuid_count(op, 0, eax, ebx, ecx, edx);
+}
+
+static inline __constfunc uint32_t cpuid_eax(uint32_t level)
+{
+ uint32_t eax, ebx, ecx, edx;
+
+ cpuid_count(level, 0, &eax, &ebx, &ecx, &edx);
+ return eax;
+}
+
+static inline __constfunc uint32_t cpuid_ebx(uint32_t level)
+{
+ uint32_t eax, ebx, ecx, edx;
+
+ cpuid_count(level, 0, &eax, &ebx, &ecx, &edx);
+ return ebx;
+}
+
+static inline __constfunc uint32_t cpuid_ecx(uint32_t level)
+{
+ uint32_t eax, ebx, ecx, edx;
+
+ cpuid_count(level, 0, &eax, &ebx, &ecx, &edx);
+ return ecx;
+}
+
+static inline __constfunc uint32_t cpuid_edx(uint32_t level)
+{
+ uint32_t eax, ebx, ecx, edx;
+
+ cpuid_count(level, 0, &eax, &ebx, &ecx, &edx);
+ return edx;
+}
+
+static inline uint64_t rdmsr(uint32_t msr)
+{
+ uint32_t eax, edx;
+
+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (msr));
+ return eax + ((uint64_t)edx << 32);
+}
+
+static inline void wrmsr(uint64_t v, uint32_t msr)
+{
+ uint32_t eax = v;
+ uint32_t edx = v >> 32;
+
+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (msr));
+}
+
+static inline unsigned long long get_cr0(void)
+{
+ unsigned long v;
+ asm volatile("mov %%cr0,%0" : "=r" (v));
+ return v;
+}
+
+static inline void set_cr0(unsigned long v)
+{
+ asm volatile("mov %0,%%cr0" : : "r" (v));
+}
+
+static inline unsigned long get_cr4(void)
+{
+ unsigned long v;
+ asm volatile("mov %%cr4,%0" : "=r" (v));
+ return v;
+}
+
+static inline void set_cr4(unsigned long v)
+{
+ asm volatile("mov %0,%%cr4" : : "r" (v));
+}
+
+static inline uint32_t get_mxcsr(void)
+{
+ uint32_t v;
+ asm("stmxcsr %0" : "=m" (v));
+ return v;
+}
+
+static inline void set_mxcsr(uint32_t v)
+{
+ asm volatile("ldmxcsr %0" : : "m" (v));
+}
+
+static inline void fninit(void)
+{
+ asm volatile("fninit");
+}
+
+static inline void cpu_relax(void)
+{
+ asm volatile("rep ; nop");
+}
+
+static inline void hlt(void)
+{
+ asm volatile("hlt" : : : "memory");
+}
+
+static inline void cli(void)
+{
+ asm volatile("cli" : : : "memory");
+}
+
+static inline void sti(void)
+{
+ asm volatile("sti" : : : "memory");
+}
+
+static inline unsigned long get_eflags(void)
+{
+ unsigned long v;
+
+ asm volatile("pushf ; pop %0" : "=rm" (v));
+ return v;
+}
+
+static inline void set_eflags(unsigned long v)
+{
+ asm volatile("push %0 ; popf" : : "g" (v) : "memory");
+}
+
+typedef unsigned long irq_state_t;
+
+static inline irq_state_t irq_state(void)
+{
+ return get_eflags();
+}
+
+static inline irq_state_t irq_save(void)
+{
+ irq_state_t v = irq_state();
+ cli();
+ return v;
+}
+
+static inline void irq_restore(irq_state_t v)
+{
+ set_eflags(v);
+}
+
+#endif /* _X86_CPU_H */
diff --git a/com32/include/x86/regs.h b/com32/include/x86/regs.h
new file mode 100644
index 00000000..62f3a53d
--- /dev/null
+++ b/com32/include/x86/regs.h
@@ -0,0 +1,66 @@
+#ifndef _X86_REGS_H
+#define _X86_REGS_H
+
+/*
+ * Register definitions for x86 - should be assembly-safe
+ */
+
+/* EFLAGS definitions */
+#define EFLAGS_CF 0x00000001
+#define EFLAGS_PF 0x00000004
+#define EFLAGS_AF 0x00000010
+#define EFLAGS_ZF 0x00000040
+#define EFLAGS_SF 0x00000080
+#define EFLAGS_TF 0x00000100
+#define EFLAGS_IF 0x00000200
+#define EFLAGS_DF 0x00000400
+#define EFLAGS_OF 0x00000800
+#define EFLAGS_IOPL 0x00003000
+#define EFLAGS_NT 0x00004000
+#define EFLAGS_RF 0x00010000
+#define EFLAGS_VM 0x00020000
+#define EFLAGS_AC 0x00040000
+#define EFLAGS_VIF 0x00080000
+#define EFLAGS_VIP 0x00100000
+#define EFLAGS_ID 0x00200000
+
+/* CR0 definitions */
+#define CR0_PE 0x00000001
+#define CR0_MP 0x00000002
+#define CR0_EM 0x00000004
+#define CR0_TS 0x00000008
+#define CR0_ET 0x00000010
+#define CR0_NE 0x00000020
+#define CR0_WP 0x00010000
+#define CR0_AM 0x00040000
+#define CR0_NW 0x20000000
+#define CR0_CD 0x40000000
+#define CR0_PG 0x80000000
+
+/* CR4 definitions */
+#define CR4_VME 0x00000001
+#define CR4_PVI 0x00000002
+#define CR4_TSD 0x00000004
+#define CR4_DE 0x00000008
+#define CR4_PSE 0x00000010
+#define CR4_PAE 0x00000020
+#define CR4_MCE 0x00000040
+#define CR4_PGE 0x00000080
+#define CR4_PCE 0x00000100
+#define CR4_OSFXSR 0x00000200
+#define CR4_OSXMMEXCEPT 0x00000400
+#define CR4_UMIP 0x00000800
+#define CR4_VA57 0x00001000
+#define CR4_VMXE 0x00002000
+#define CR4_SMXE 0x00004000
+#define CR4_SEE 0x00008000
+#define CR4_FSGSBASE 0x00010000
+#define CR4_PCIDE 0x00020000
+#define CR4_OSXSAVE 0x00040000
+#define CR4_SMEP 0x00100000
+#define CR4_SMAP 0x00200000
+#define CR4_PKE 0x00400000
+#define CR4_CET 0x00800000
+
+#endif /* _X86_REGS_H */
+