From: Kevin Lawton <kevinlawton2001@yahoo.com>
To: linux-kernel@vger.kernel.org
Subject: Simple patches for Linux as a guest OS in a plex86 VM (please consider)
Date: Wed, 22 Jan 2003 10:23:41 -0800 (PST) [thread overview]
Message-ID: <20030122182341.66324.qmail@web80309.mail.yahoo.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 946 bytes --]
Hello all,
I'm working on running Linux as a guest OS inside a
lightweight cut-down plex86 environment. My goal is to
run a stock Linux kernel, which can be slimmed down to
the essentials via kernel configuration, since a guest
OS doesn't need to drive much hardware.
For this, there's a few critical but simple diffs to
macro'ize the use of the PUSHF and POPF instructions,
due to broken semantics of running stuff using
PVI (protected mode virtual interrupts). The rest of
the stuff I believe can be monitored effectively by
the VM monitor.
Would you please consider integrating these diffs before 2.6?
There's only one new header file, and macro substitution for
a few cases where these instructions are used. For a normal
compile, there are zero logic changes. Just 1:1 macros.
Thanks much,
-Kevin Lawton
__________________________________________________
Do you Yahoo!?
New DSL Internet Access from SBC & Yahoo!
http://sbc.yahoo.com
[-- Attachment #2: linux-2.5.59-hal.diffs --]
[-- Type: application/octet-stream, Size: 14344 bytes --]
diff -urN linux-2.5.59/arch/i386/Kconfig linux-2.5.59-hal/arch/i386/Kconfig
--- linux-2.5.59/arch/i386/Kconfig Wed Jan 22 12:25:59 2003
+++ linux-2.5.59-hal/arch/i386/Kconfig Tue Jan 21 17:23:41 2003
@@ -1661,3 +1661,18 @@
bool
depends on SMP
default y
+
+menu "Hardware Abstraction Layer"
+
+config X86_HAL
+ bool "Compile for HAL (experimental)"
+ depends on !HIGHMEM && !SMP && !M486 && !M386 && !X86_UP_APIC && !X86_UP_IOAPIC
+ help
+ Say Y here _only_ if you are compiling Linux to run inside an
+ experimental Hardware Abstraction Layer. Say N here unless
+ you absolutely know what this is for. This will break Linux
+ running on a real machine for sure. This option has the
+ following configuration constraints: Pentium or higher,
+ uniprocessor mode, no apic support.
+
+endmenu
diff -urN linux-2.5.59/arch/i386/kernel/acpi_wakeup.S linux-2.5.59-hal/arch/i386/kernel/acpi_wakeup.S
--- linux-2.5.59/arch/i386/kernel/acpi_wakeup.S Tue Jan 14 00:58:23 2003
+++ linux-2.5.59-hal/arch/i386/kernel/acpi_wakeup.S Tue Jan 21 18:35:48 2003
@@ -2,6 +2,7 @@
#include <linux/linkage.h>
#include <asm/segment.h>
#include <asm/page.h>
+#include <asm/if.h>
#
# wakeup_code runs in real mode, and at unknown address (determined at run-time).
@@ -35,7 +36,7 @@
movw $0x0e00 + 'S', %fs:(0x12)
pushl $0 # Kill any dangerous flags
- popfl
+ POPFL
movl real_magic - wakeup_code, %eax
cmpl $0x12345678, %eax
@@ -283,7 +284,7 @@
movl %ebp, saved_context_ebp
movl %esi, saved_context_esi
movl %edi, saved_context_edi
- pushfl ; popl saved_context_eflags
+ PUSHFL ; popl saved_context_eflags
movl $.L1432,saved_eip
movl %esp,saved_esp
@@ -309,7 +310,7 @@
movl saved_context_esi, %esi
movl saved_context_edi, %edi
call restore_processor_state
- pushl saved_context_eflags ; popfl
+ pushl saved_context_eflags ; POPFL
ret
ALIGN
diff -urN linux-2.5.59/arch/i386/kernel/cpu/common.c linux-2.5.59-hal/arch/i386/kernel/cpu/common.c
--- linux-2.5.59/arch/i386/kernel/cpu/common.c Tue Jan 14 00:58:04 2003
+++ linux-2.5.59-hal/arch/i386/kernel/cpu/common.c Wed Jan 22 02:01:26 2003
@@ -7,6 +7,7 @@
#include <asm/msr.h>
#include <asm/io.h>
#include <asm/mmu_context.h>
+#include <asm/if.h>
#include "cpu.h"
@@ -170,16 +171,16 @@
{
u32 f1, f2;
- asm("pushfl\n\t"
- "pushfl\n\t"
+ asm( PUSHFL
+ PUSHFL
"popl %0\n\t"
"movl %0,%1\n\t"
"xorl %2,%0\n\t"
"pushl %0\n\t"
- "popfl\n\t"
- "pushfl\n\t"
+ POPFL
+ PUSHFL
"popl %0\n\t"
- "popfl\n\t"
+ POPFL
: "=&r" (f1), "=&r" (f2)
: "ir" (flag));
@@ -473,7 +474,7 @@
/*
* Delete NT
*/
- __asm__("pushfl ; andl $0xffffbfff,(%esp) ; popfl");
+ __asm__(PUSHFL " ; andl $0xffffbfff,(%%esp) ; " POPFL : );
/*
* Set up and load the per-CPU TSS and LDT
diff -urN linux-2.5.59/arch/i386/kernel/entry.S linux-2.5.59-hal/arch/i386/kernel/entry.S
--- linux-2.5.59/arch/i386/kernel/entry.S Wed Jan 22 12:25:59 2003
+++ linux-2.5.59-hal/arch/i386/kernel/entry.S Tue Jan 21 18:36:16 2003
@@ -48,6 +48,7 @@
#include <asm/segment.h>
#include <asm/smp.h>
#include <asm/page.h>
+#include <asm/if.h>
#include "irq_vectors.h"
EBX = 0x00
@@ -141,7 +142,7 @@
ENTRY(lcall7)
- pushfl # We get a different stack layout with call
+ PUSHFL # We get a different stack layout with call
# gates, which has to be cleaned up later..
pushl %eax
SAVE_ALL
@@ -163,7 +164,7 @@
jmp resume_userspace
ENTRY(lcall27)
- pushfl # We get a different stack layout with call
+ PUSHFL # We get a different stack layout with call
# gates, which has to be cleaned up later..
pushl %eax
SAVE_ALL
@@ -233,7 +234,7 @@
sti
pushl $(__USER_DS)
pushl %ebp
- pushfl
+ PUSHFL
pushl $(__USER_CS)
pushl $SYSENTER_RETURN
diff -urN linux-2.5.59/arch/i386/kernel/head.S linux-2.5.59-hal/arch/i386/kernel/head.S
--- linux-2.5.59/arch/i386/kernel/head.S Tue Jan 14 00:58:06 2003
+++ linux-2.5.59-hal/arch/i386/kernel/head.S Tue Jan 21 18:35:07 2003
@@ -16,6 +16,7 @@
#include <asm/pgtable.h>
#include <asm/desc.h>
#include <asm/cache.h>
+#include <asm/if.h>
#define OLD_CL_MAGIC_ADDR 0x90020
#define OLD_CL_MAGIC 0xA33F
@@ -111,7 +112,7 @@
orw %bx,%bx
jz 1f /* Initial CPU cleans BSS */
pushl $0
- popfl
+ POPFL
jmp checkCPUtype
1:
#endif CONFIG_SMP
@@ -138,7 +139,7 @@
* XXX - best to initialize before switching to protected mode.
*/
pushl $0
- popfl
+ POPFL
/*
* Copy bootup parameters out of the way. First 2kB of
* _empty_zero_page is for boot parameters, second 2kB
@@ -180,17 +181,17 @@
*/
movb $3,X86 # at least 386
- pushfl # push EFLAGS
+ PUSHFL # push EFLAGS
popl %eax # get EFLAGS
movl %eax,%ecx # save original EFLAGS
xorl $0x240000,%eax # flip AC and ID bits in EFLAGS
pushl %eax # copy to EFLAGS
- popfl # set EFLAGS
- pushfl # get new EFLAGS
+ POPFL # set EFLAGS
+ PUSHFL # get new EFLAGS
popl %eax # put it in eax
xorl %ecx,%eax # change in flags
pushl %ecx # restore original EFLAGS
- popfl
+ POPFL
testl $0x40000,%eax # check if AC bit changed
je is386
diff -urN linux-2.5.59/arch/i386/kernel/suspend_asm.S linux-2.5.59-hal/arch/i386/kernel/suspend_asm.S
--- linux-2.5.59/arch/i386/kernel/suspend_asm.S Tue Jan 14 00:58:33 2003
+++ linux-2.5.59-hal/arch/i386/kernel/suspend_asm.S Tue Jan 21 18:36:31 2003
@@ -5,6 +5,7 @@
#include <linux/linkage.h>
#include <asm/segment.h>
#include <asm/page.h>
+#include <asm/if.h>
ENTRY(do_magic)
pushl %ebx
@@ -21,7 +22,7 @@
movl %ebp, saved_context_ebp
movl %esi, saved_context_esi
movl %edi, saved_context_edi
- pushfl ; popl saved_context_eflags
+ PUSHFL ; popl saved_context_eflags
call do_magic_suspend_2
jmp .L1449
@@ -77,7 +78,7 @@
movl saved_context_esi, %esi
movl saved_context_edi, %edi
call restore_processor_state
- pushl saved_context_eflags ; popfl
+ pushl saved_context_eflags ; POPFL
call do_magic_resume_2
.L1449:
popl %ebx
@@ -89,4 +90,4 @@
loop2:
.quad 0
.previous
-
\ No newline at end of file
+
diff -urN linux-2.5.59/drivers/hotplug/cpqphp_nvram.c linux-2.5.59-hal/drivers/hotplug/cpqphp_nvram.c
--- linux-2.5.59/drivers/hotplug/cpqphp_nvram.c Tue Jan 14 00:59:15 2003
+++ linux-2.5.59-hal/drivers/hotplug/cpqphp_nvram.c Tue Jan 21 18:25:57 2003
@@ -37,6 +37,7 @@
#include <linux/pci.h>
#include <linux/init.h>
#include <asm/uaccess.h>
+#include <asm/if.h>
#include "cpqphp.h"
#include "cpqphp_nvram.h"
@@ -179,7 +180,7 @@
__asm__ (
"xorl %%ebx,%%ebx\n" \
"xorl %%edx,%%edx\n" \
- "pushf\n" \
+ PUSHFL \
"push %%cs\n" \
"cli\n" \
"call *%6\n"
diff -urN linux-2.5.59/drivers/pnp/pnpbios/core.c linux-2.5.59-hal/drivers/pnp/pnpbios/core.c
--- linux-2.5.59/drivers/pnp/pnpbios/core.c Tue Jan 14 00:58:04 2003
+++ linux-2.5.59-hal/drivers/pnp/pnpbios/core.c Tue Jan 21 18:31:26 2003
@@ -54,6 +54,7 @@
#include <linux/spinlock.h>
#include <asm/system.h>
#include <asm/byteorder.h>
+#include <asm/if.h>
/*
@@ -185,11 +186,11 @@
"pushl %%es\n\t"
"pushl %%fs\n\t"
"pushl %%gs\n\t"
- "pushfl\n\t"
+ PUSHFL
"movl %%esp, pnp_bios_fault_esp\n\t"
"movl $1f, pnp_bios_fault_eip\n\t"
"lcall %5,%6\n\t"
- "1:popfl\n\t"
+ "1:" POPFL
"popl %%gs\n\t"
"popl %%fs\n\t"
"popl %%es\n\t"
diff -urN linux-2.5.59/include/asm-i386/if.h linux-2.5.59-hal/include/asm-i386/if.h
--- linux-2.5.59/include/asm-i386/if.h Wed Dec 31 19:00:00 1969
+++ linux-2.5.59-hal/include/asm-i386/if.h Wed Jan 22 11:26:59 2003
@@ -0,0 +1,139 @@
+/*
+ * Routines to manipulate the interrupt flag (EFLAGS.IF). Abstracting
+ * them, makes it easier to compile for a hardware abstraction layer (HAL).
+ *
+ * (c) 2003 Kevin P. Lawton <kevinlawton2001@yahoo.com>
+ */
+
+#ifndef _LINUX_ASM_IF_H_
+#define _LINUX_ASM_IF_H_
+
+
+#ifndef CONFIG_X86_HAL
+
+/* For a standard compile, just use the native instructions. */
+
+#ifdef __ASSEMBLY__ /* For *.S assembly. */
+#define STI sti
+#define CLI cli
+#define PUSHFL pushfl
+#define POPFL popfl
+#else /* For *.C assembly. */
+#define STI "sti \n\t"
+#define CLI "cli \n\t"
+#define PUSHFL "pushfl \n\t"
+#define POPFL "popfl \n\t"
+#endif
+
+
+#else /* CONFIG_X86_HAL */
+
+/* For a HAL (Hardware Abstraction Layer) compile, the kernel is executed
+ * at PL=3 using PVI (Protected mode Virtual Interrupts), which are the
+ * analog to VME for v86 code. For some reason, The Creators stopped short of
+ * implementing proper IF handling for PUSHF/POPF for PVI, but STI/CLI are
+ * fine. So we have to complete the PVI semantics using the following
+ * sequences.
+ */
+
+/* cli/sti both work in PVI */
+#ifdef __ASSEMBLY__ /* For *.S assembly. */
+#define STI sti
+#define CLI cli
+#else /* For *.C assembly. */
+#define STI "sti \n\t"
+#define CLI "cli \n\t"
+#endif
+
+
+/* PUSHFL:
+ * When execution is monitored using PVI (Protected mode Virtual Interrupts),
+ * we have to complete the PVI semantics of the PUSHFL instruction, as
+ * per behaviour of VME.
+ *
+ * b19 b9
+ * CPU image of eflags: VIF IF
+ * |
+ * +------------+
+ * |
+ * v
+ * Stack image of eflags: VIF IF
+ *
+ * Notes: VIF on the stack image could be cleared, if it matters.
+ */
+
+#ifdef __ASSEMBLY__ /* For *.S assembly. */
+#define PUSHFL \
+ pushfl ; \
+ pushfl ; \
+ testl $(1<<19), 4(%esp) ; \
+ jz 69001f ; \
+ orl $(1<<9), 4(%esp) ; \
+ jmp 69002f ; \
+ 69001: ; \
+ andl $~(1<<9), 4(%esp) ; \
+ 69002: ; \
+ popfl
+#else /* For *.C assembly. */
+#define PUSHFL \
+ "pushfl \n\t" /* Final eflags stack image. */ \
+ "pushfl \n\t" /* For restoring arithmetic flags. */ \
+ "testl $(1<<19), 4(%%esp) \n\t" /* Was VIF bit set? */ \
+ "jz 69001f \n\t" \
+ "orl $(1<<9), 4(%%esp) \n\t" /* Yes: set stack image of IF. */ \
+ "jmp 69002f \n\t" \
+ "69001: \n\t" /* Use the zip of Lyon France :^) */ \
+ "andl $~(1<<9), 4(%%esp) \n\t" /* No: clear stack image of IF. */ \
+ "69002: \n\t" \
+ "popfl \n\t" /* Restore arithmetic flags. */
+#endif
+
+
+
+/* POPFL:
+ * When execution is monitored using PVI (Protected mode Virtual Interrupts),
+ * we have to complete the PVI semantics of the POPFL instruction, as
+ * per behaviour of VME.
+ *
+ * b19 b9
+ * Stack image of eflags: VIF IF
+ * |
+ * +------------+
+ * |
+ * v
+ * CPU image of eflags: VIF IF
+ *
+ * Notes: IF of the eflags register retains its previous value, which
+ * should be 1 (when monitored down to PL3, the processor ignores this
+ * bit in a POPF).
+ */
+
+#ifdef __ASSEMBLY__ /* For *.S assembly. */
+#define POPFL \
+ testl $(1<<9), 0(%esp) ; \
+ jz 69003f ; \
+ popfl ; \
+ sti ; \
+ jmp 69004f ; \
+ 69003: ; \
+ popfl ; \
+ cli ; \
+ 69004:
+#else /* For *.C assembly. */
+#define POPFL \
+ "testl $(1<<9), 0(%%esp) \n\t" /* Is IF set on stack image? */ \
+ "jz 69003f \n\t" \
+ "popfl \n\t" /* Yes: restore from stack and */ \
+ "sti \n\t" /* force VIF=1. */ \
+ "jmp 69004f \n\t" \
+ "69003: \n\t" \
+ "popfl \n\t" /* No: restore from stack and */ \
+ "cli \n\t" /* force VIF=0. */ \
+ "69004: \n\t"
+#endif
+
+
+#endif /* CONFIG_X86_HAL */
+
+
+#endif /* _LINUX_ASM_IF_H_ */
diff -urN linux-2.5.59/include/asm-i386/system.h linux-2.5.59-hal/include/asm-i386/system.h
--- linux-2.5.59/include/asm-i386/system.h Tue Jan 14 00:58:03 2003
+++ linux-2.5.59-hal/include/asm-i386/system.h Tue Jan 21 18:34:08 2003
@@ -5,6 +5,7 @@
#include <linux/kernel.h>
#include <asm/segment.h>
#include <linux/bitops.h> /* for LOCK_PREFIX */
+#include <asm/if.h>
#ifdef __KERNEL__
@@ -12,7 +13,7 @@
extern void FASTCALL(__switch_to(struct task_struct *prev, struct task_struct *next));
#define switch_to(prev,next,last) do { \
- asm volatile("pushfl\n\t" \
+ asm volatile(PUSHFL \
"pushl %%esi\n\t" \
"pushl %%edi\n\t" \
"pushl %%ebp\n\t" \
@@ -25,7 +26,7 @@
"popl %%ebp\n\t" \
"popl %%edi\n\t" \
"popl %%esi\n\t" \
- "popfl\n\t" \
+ POPFL \
:"=m" (prev->thread.esp),"=m" (prev->thread.eip) \
:"m" (next->thread.esp),"m" (next->thread.eip), \
"a" (prev), "d" (next)); \
@@ -380,8 +381,8 @@
#define set_wmb(var, value) do { var = value; wmb(); } while (0)
/* interrupt control.. */
-#define local_save_flags(x) __asm__ __volatile__("pushfl ; popl %0":"=g" (x): /* no input */)
-#define local_irq_restore(x) __asm__ __volatile__("pushl %0 ; popfl": /* no output */ :"g" (x):"memory", "cc")
+#define local_save_flags(x) __asm__ __volatile__(PUSHFL " ; popl %0":"=g" (x): /* no input */)
+#define local_irq_restore(x) __asm__ __volatile__("pushl %0 ; " POPFL : /* no output */ :"g" (x):"memory", "cc")
#define local_irq_disable() __asm__ __volatile__("cli": : :"memory")
#define local_irq_enable() __asm__ __volatile__("sti": : :"memory")
/* used in the idle loop; sti takes one instruction cycle to complete */
@@ -395,7 +396,7 @@
})
/* For spinlocks etc */
-#define local_irq_save(x) __asm__ __volatile__("pushfl ; popl %0 ; cli":"=g" (x): /* no input */ :"memory")
+#define local_irq_save(x) __asm__ __volatile__(PUSHFL " ; popl %0 ; cli":"=g" (x): /* no input */ :"memory")
/*
* disable hlt during certain critical i/o operations
next reply other threads:[~2003-01-22 18:14 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-01-22 18:23 Kevin Lawton [this message]
2003-01-22 19:56 ` Andrew Morton
2003-01-22 20:11 ` Kevin Lawton
2003-01-22 20:17 ` Andrew Morton
2003-01-22 20:35 ` Kai Germaschewski
2003-01-23 18:28 ` Ingo Oeser
2003-01-23 22:26 ` Jamie Lokier
2003-01-24 3:21 ` Kevin Lawton
2003-01-24 15:46 ` Pavel Machek
2003-01-24 16:52 ` Kevin Lawton
2003-01-24 19:01 ` Valdis.Kletnieks
2003-01-24 19:09 ` Kevin Lawton
2003-01-24 20:18 ` Derek Fawcus
2003-01-24 20:56 ` Kevin Lawton
2003-01-24 21:00 ` David Lang
2003-01-24 22:02 ` Kevin Lawton
[not found] <20030122182341.66324.qmail@web80309.mail.yahoo.com.suse.lists.linux.kernel>
2003-01-22 19:16 ` Andi Kleen
2003-01-22 19:30 ` Kevin Lawton
2003-01-23 5:11 ` Kevin Lawton
2003-01-23 5:50 ` Kai Germaschewski
2003-01-23 7:00 ` Kevin Lawton
2003-01-23 7:24 ` Andrew Morton
2003-01-23 15:41 ` Kevin Lawton
2003-01-24 15:49 ` Pavel Machek
2003-01-24 17:14 ` Kevin Lawton
2003-01-24 18:02 ` Lars Marowsky-Bree
2003-01-25 1:46 ` David Wagner
2003-01-25 12:00 ` Jan Hudec
2003-01-27 12:42 ` Pavel Machek
2003-01-26 20:00 ` Pavel Machek
2003-01-26 20:05 ` Lars Marowsky-Bree
2003-01-27 5:42 ` Nuno Silva
2003-01-24 3:32 Kevin Lawton
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20030122182341.66324.qmail@web80309.mail.yahoo.com \
--to=kevinlawton2001@yahoo.com \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome