* AMD Geode i686
@ 2010-03-01 22:03 Matteo Croce
2010-03-01 23:43 ` Brian Gerst
2010-04-15 17:11 ` Lennart Sorensen
0 siblings, 2 replies; 7+ messages in thread
From: Matteo Croce @ 2010-03-01 22:03 UTC (permalink / raw)
To: linux-kernel; +Cc: Alan Cox, H. Peter Anvin
Hi,
I have refreshed my AMD Geode i686 patch with NOPL and I have added a
new nice feature.
When a NOPL is found the parser looks for any NOPL after the current
one, so they are emulated in bulk.
Tested ok on a Pcengines Alix.
Signed-off-by: Matteo Croce <technoboy85@gmail.com>
--- a/arch/x86/kernel/Makefile 2010-03-01 01:18:51.697166322 +0100
+++ b/arch/x86/kernel/Makefile 2010-03-01 01:19:45.727095700 +0100
@@ -89,6 +89,8 @@
obj-$(CONFIG_HPET_TIMER) += hpet.o
obj-$(CONFIG_K8_NB) += k8.o
+obj-$(CONFIG_MGEODEGX1) += nopl_emu.o
+obj-$(CONFIG_MGEODE_LX) += nopl_emu.o
obj-$(CONFIG_DEBUG_RODATA_TEST) += test_rodata.o
obj-$(CONFIG_DEBUG_NX_TEST) += test_nx.o
--- a/arch/x86/kernel/cpu/amd.c 2010-03-01 01:18:51.737097341 +0100
+++ b/arch/x86/kernel/cpu/amd.c 2010-03-01 01:19:27.867865836 +0100
@@ -138,8 +138,10 @@
}
if (c->x86_model == 10) {
- /Index: linux-2.6.33/arch/x86/kernel/Makefile
===================================================================
* AMD Geode LX is model 10 */
- /* placeholder for any needed mods */
+ /* Geode only lacks the NOPL instruction to be i686,
+ but we can emulate it in the exception handler
+ and promote it to a class 6 cpu */
+ boot_cpu_data.x86 = 6;
return;
}
}
--- a/arch/x86/kernel/entry_32.S 2010-03-01 01:18:51.717096708 +0100
+++ b/arch/x86/kernel/entry_32.S 2010-03-01 01:19:27.867865836 +0100
@@ -960,7 +960,11 @@
RING0_INT_FRAME
pushl $0
CFI_ADJUST_CFA_OFFSET 4
+#ifdef CONFIG_MGEODE_LX
+ pushl $do_nopl_emu
+#else
pushl $do_invalid_op
+#endif
CFI_ADJUST_CFA_OFFSET 4
jmp error_code
CFI_ENDPROC
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ b/arch/x86/kernel/nopl_emu.c 2010-03-01 02:40:44.324595733 +0100
@@ -0,0 +1,107 @@
+/*
+ * linux/arch/x86/kernel/nopl_emu.c
+ *
+ * Copyright (C) 2002 Willy Tarreau
+ * Copyright (C) 2010 Matteo Croce
+ */
+
+#include <asm/processor.h>
+#include <asm/traps.h>
+
+/* This code can be used to allow the AMD Geode to hopefully correctly execute
+ * some code which was originally compiled for an i686, by emulating NOPL,
+ * the only missing i686 instruction in the CPU
+ *
+ * Willy Tarreau <willy@meta-x.org>
+ * Matteo Croce <technoboy85@gmail.com>
+ */
+
+static inline int do_1f(u8 *ip)
+{
+ int length = 3;
+ switch (*ip) {
+ case 0x84:
+ if (!ip[5])
+ length++;
+ else
+ return 0;
+ case 0x80:
+ if (!ip[4] && !ip[3])
+ length += 2;
+ else
+ return 0;
+ case 0x44:
+ if (!ip[2])
+ length++;
+ else
+ return 0;
+ case 0x40:
+ if (!ip[1])
+ length++;
+ else
+ return 0;
+ case 0x00:
+ return length;
+ }
+ return 0;
+}
+
+static inline int do_0f(u8 *ip)
+{
+ if (*ip == 0x1f)
+ return do_1f(ip + 1);
+ return 0;
+}
+
+static inline int do_66(u8 *ip)
+{
+ if (*ip == 0x90)
+ return 2;
+ if (*ip == 0x0f) {
+ int res = do_0f(ip + 1);
+ if (res)
+ return res + 1;
+ else
+ return 0;
+ }
+ return 0;
+}
+
+static inline int do_start(u8 *ip)
+{
+ if (*ip == 0x0f)
+ return do_0f(ip + 1);
+ if (*ip == 0x66)
+ return do_66(ip + 1);
+ return 0;
+}
+
+/* [do_nopl_emu] is called by exception 6 after an invalid opcode has been
+ * encountered. It will try to emulate it by doing nothing,
+ * and will send a SIGILL or SIGSEGV to the process if not possible.
+ * the NOPL can have variable length opcodes:
+
+bytes number opcode
+ 2 66 90
+ 3 0f 1f 00
+ 4 0f 1f 40 00
+ 5 0f 1f 44 00 00
+ 6 66 0f 1f 44 00 00
+ 7 0f 1f 80 00 00 00 00
+ 8 0f 1f 84 00 00 00 00 00
+ 9 66 0f 1f 84 00 00 00 00 00
+*/
+void do_nopl_emu(struct pt_regs *regs, long error_code)
+{
+ u8 *ip = (u8 *)instruction_pointer(regs);
+ int res = do_start(ip);
+
+ if (res) {
+ do {
+ ip += res;
+ res = do_start(ip);
+ } while (res);
+ regs->ip = (typeof(regs->ip))ip;
+ } else
+ do_invalid_op(regs, error_code);
+}
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: AMD Geode i686
2010-03-01 22:03 AMD Geode i686 Matteo Croce
@ 2010-03-01 23:43 ` Brian Gerst
2010-03-01 23:49 ` H. Peter Anvin
2010-04-15 17:11 ` Lennart Sorensen
1 sibling, 1 reply; 7+ messages in thread
From: Brian Gerst @ 2010-03-01 23:43 UTC (permalink / raw)
To: Matteo Croce; +Cc: linux-kernel, Alan Cox, H. Peter Anvin
On Mon, Mar 1, 2010 at 5:03 PM, Matteo Croce <technoboy85@gmail.com> wrote:
> Hi,
> I have refreshed my AMD Geode i686 patch with NOPL and I have added a
> new nice feature.
> When a NOPL is found the parser looks for any NOPL after the current
> one, so they are emulated in bulk.
> Tested ok on a Pcengines Alix.
>
> Signed-off-by: Matteo Croce <technoboy85@gmail.com>
1. Since this can possibly touch userspace, you must use get_user() to
read the instruction bytes.
2. This parser is too simple to cover all the possible encodings, not
just the recommended ones from the Intel manual. You really should be
decoding:
- all prefixes (like segment overrides), which can be repeated.
- the 0f 1f opcode.
- the Mod R/M byte.
- the SIB byte (if present).
- the displacement.
This should probably be part of a more general instruction emulator.
--
Brian Gerst
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: AMD Geode i686
2010-03-01 23:43 ` Brian Gerst
@ 2010-03-01 23:49 ` H. Peter Anvin
0 siblings, 0 replies; 7+ messages in thread
From: H. Peter Anvin @ 2010-03-01 23:49 UTC (permalink / raw)
To: Brian Gerst; +Cc: Matteo Croce, linux-kernel, Alan Cox
On 03/01/2010 03:43 PM, Brian Gerst wrote:
>
> This should probably be part of a more general instruction emulator.
>
... as is being developed; see other thread.
-hpa
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: AMD Geode i686
2010-03-01 22:03 AMD Geode i686 Matteo Croce
2010-03-01 23:43 ` Brian Gerst
@ 2010-04-15 17:11 ` Lennart Sorensen
2010-04-15 17:20 ` Matteo Croce
1 sibling, 1 reply; 7+ messages in thread
From: Lennart Sorensen @ 2010-04-15 17:11 UTC (permalink / raw)
To: Matteo Croce; +Cc: linux-kernel, Alan Cox, H. Peter Anvin
On Mon, Mar 01, 2010 at 11:03:09PM +0100, Matteo Croce wrote:
> Hi,
> I have refreshed my AMD Geode i686 patch with NOPL and I have added a
> new nice feature.
> When a NOPL is found the parser looks for any NOPL after the current
> one, so they are emulated in bulk.
> Tested ok on a Pcengines Alix.
>
> Signed-off-by: Matteo Croce <technoboy85@gmail.com>
>
> --- a/arch/x86/kernel/Makefile 2010-03-01 01:18:51.697166322 +0100
> +++ b/arch/x86/kernel/Makefile 2010-03-01 01:19:45.727095700 +0100
> @@ -89,6 +89,8 @@
> obj-$(CONFIG_HPET_TIMER) += hpet.o
>
> obj-$(CONFIG_K8_NB) += k8.o
> +obj-$(CONFIG_MGEODEGX1) += nopl_emu.o
> +obj-$(CONFIG_MGEODE_LX) += nopl_emu.o
> obj-$(CONFIG_DEBUG_RODATA_TEST) += test_rodata.o
> obj-$(CONFIG_DEBUG_NX_TEST) += test_nx.o
>
> --- a/arch/x86/kernel/cpu/amd.c 2010-03-01 01:18:51.737097341 +0100
> +++ b/arch/x86/kernel/cpu/amd.c 2010-03-01 01:19:27.867865836 +0100
> @@ -138,8 +138,10 @@
> }
>
> if (c->x86_model == 10) {
> - /Index: linux-2.6.33/arch/x86/kernel/Makefile
> ===================================================================
> * AMD Geode LX is model 10 */
> - /* placeholder for any needed mods */
> + /* Geode only lacks the NOPL instruction to be i686,
> + but we can emulate it in the exception handler
> + and promote it to a class 6 cpu */
> + boot_cpu_data.x86 = 6;
> return;
> }
> }
> --- a/arch/x86/kernel/entry_32.S 2010-03-01 01:18:51.717096708 +0100
> +++ b/arch/x86/kernel/entry_32.S 2010-03-01 01:19:27.867865836 +0100
> @@ -960,7 +960,11 @@
> RING0_INT_FRAME
> pushl $0
> CFI_ADJUST_CFA_OFFSET 4
> +#ifdef CONFIG_MGEODE_LX
> + pushl $do_nopl_emu
> +#else
> pushl $do_invalid_op
> +#endif
How does this work for MGEODEGX1 when it looks for MGEODE_LX? It seems
you made both link against the code above after all. Is this wrong or
the above?
Can it not work if you want to run a generic kernel on your Geode rather
than one built explicitly for the LX? I build one kernel to run on
Geode SC1200 and Geode LX.
--
Len Sorensen
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: AMD Geode i686
2010-04-15 17:11 ` Lennart Sorensen
@ 2010-04-15 17:20 ` Matteo Croce
2010-04-15 17:32 ` Lennart Sorensen
0 siblings, 1 reply; 7+ messages in thread
From: Matteo Croce @ 2010-04-15 17:20 UTC (permalink / raw)
To: Lennart Sorensen; +Cc: linux-kernel, Alan Cox, H. Peter Anvin
On Thu, Apr 15, 2010 at 7:11 PM, Lennart Sorensen
<lsorense@csclub.uwaterloo.ca> wrote:
> On Mon, Mar 01, 2010 at 11:03:09PM +0100, Matteo Croce wrote:
>> Hi,
>> I have refreshed my AMD Geode i686 patch with NOPL and I have added a
>> new nice feature.
>> When a NOPL is found the parser looks for any NOPL after the current
>> one, so they are emulated in bulk.
>> Tested ok on a Pcengines Alix.
>>
>> Signed-off-by: Matteo Croce <technoboy85@gmail.com>
>>
>> --- a/arch/x86/kernel/Makefile 2010-03-01 01:18:51.697166322 +0100
>> +++ b/arch/x86/kernel/Makefile 2010-03-01 01:19:45.727095700 +0100
>> @@ -89,6 +89,8 @@
>> obj-$(CONFIG_HPET_TIMER) += hpet.o
>>
>> obj-$(CONFIG_K8_NB) += k8.o
>> +obj-$(CONFIG_MGEODEGX1) += nopl_emu.o
>> +obj-$(CONFIG_MGEODE_LX) += nopl_emu.o
>> obj-$(CONFIG_DEBUG_RODATA_TEST) += test_rodata.o
>> obj-$(CONFIG_DEBUG_NX_TEST) += test_nx.o
>>
>> --- a/arch/x86/kernel/cpu/amd.c 2010-03-01 01:18:51.737097341 +0100
>> +++ b/arch/x86/kernel/cpu/amd.c 2010-03-01 01:19:27.867865836 +0100
>> @@ -138,8 +138,10 @@
>> }
>>
>> if (c->x86_model == 10) {
>> - /Index: linux-2.6.33/arch/x86/kernel/Makefile
>> ===================================================================
>> * AMD Geode LX is model 10 */
>> - /* placeholder for any needed mods */
>> + /* Geode only lacks the NOPL instruction to be i686,
>> + but we can emulate it in the exception handler
>> + and promote it to a class 6 cpu */
>> + boot_cpu_data.x86 = 6;
>> return;
>> }
>> }
>> --- a/arch/x86/kernel/entry_32.S 2010-03-01 01:18:51.717096708 +0100
>> +++ b/arch/x86/kernel/entry_32.S 2010-03-01 01:19:27.867865836 +0100
>> @@ -960,7 +960,11 @@
>> RING0_INT_FRAME
>> pushl $0
>> CFI_ADJUST_CFA_OFFSET 4
>> +#ifdef CONFIG_MGEODE_LX
>> + pushl $do_nopl_emu
>> +#else
>> pushl $do_invalid_op
>> +#endif
>
> How does this work for MGEODEGX1 when it looks for MGEODE_LX? It seems
> you made both link against the code above after all. Is this wrong or
> the above?
>
> Can it not work if you want to run a generic kernel on your Geode rather
> than one built explicitly for the LX? I build one kernel to run on
> Geode SC1200 and Geode LX.
>
> --
> Len Sorensen
>
This code should work for Geode GX too.
Try it and report success please
--
Matteo Croce
OpenWrt developer
_______ ________ __
| |.-----.-----.-----.| | | |.----.| |_
| - || _ | -__| || | | || _|| _|
|_______|| __|_____|__|__||________||__| |____|
|__| W I R E L E S S F R E E D O M
KAMIKAZE (bleeding edge) ------------------
* 10 oz Vodka Shake well with ice and strain
* 10 oz Triple sec mixture into 10 shot glasses.
* 10 oz lime juice Salute!
---------------------------------------------------
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: AMD Geode i686
2010-04-15 17:20 ` Matteo Croce
@ 2010-04-15 17:32 ` Lennart Sorensen
2010-04-15 17:36 ` Matteo Croce
0 siblings, 1 reply; 7+ messages in thread
From: Lennart Sorensen @ 2010-04-15 17:32 UTC (permalink / raw)
To: Matteo Croce; +Cc: Lennart Sorensen, linux-kernel, Alan Cox, H. Peter Anvin
On Thu, Apr 15, 2010 at 07:20:27PM +0200, Matteo Croce wrote:
> On Thu, Apr 15, 2010 at 7:11 PM, Lennart Sorensen
> <lsorense@csclub.uwaterloo.ca> wrote:
> > On Mon, Mar 01, 2010 at 11:03:09PM +0100, Matteo Croce wrote:
> >> Hi,
> >> I have refreshed my AMD Geode i686 patch with NOPL and I have added a
> >> new nice feature.
> >> When a NOPL is found the parser looks for any NOPL after the current
> >> one, so they are emulated in bulk.
> >> Tested ok on a Pcengines Alix.
> >>
> >> Signed-off-by: Matteo Croce <technoboy85@gmail.com>
> >>
> >> --- a/arch/x86/kernel/Makefile 2010-03-01 01:18:51.697166322 +0100
> >> +++ b/arch/x86/kernel/Makefile 2010-03-01 01:19:45.727095700 +0100
> >> @@ -89,6 +89,8 @@
> >> obj-$(CONFIG_HPET_TIMER) += hpet.o
> >>
> >> obj-$(CONFIG_K8_NB) += k8.o
> >> +obj-$(CONFIG_MGEODEGX1) += nopl_emu.o
> >> +obj-$(CONFIG_MGEODE_LX) += nopl_emu.o
> >> obj-$(CONFIG_DEBUG_RODATA_TEST) += test_rodata.o
> >> obj-$(CONFIG_DEBUG_NX_TEST) += test_nx.o
> >>
> >> --- a/arch/x86/kernel/cpu/amd.c 2010-03-01 01:18:51.737097341 +0100
> >> +++ b/arch/x86/kernel/cpu/amd.c 2010-03-01 01:19:27.867865836 +0100
> >> @@ -138,8 +138,10 @@
> >> }
> >>
> >> if (c->x86_model == 10) {
> >> - /Index: linux-2.6.33/arch/x86/kernel/Makefile
> >> ===================================================================
> >> * AMD Geode LX is model 10 */
> >> - /* placeholder for any needed mods */
> >> + /* Geode only lacks the NOPL instruction to be i686,
> >> + but we can emulate it in the exception handler
> >> + and promote it to a class 6 cpu */
> >> + boot_cpu_data.x86 = 6;
> >> return;
> >> }
> >> }
> >> --- a/arch/x86/kernel/entry_32.S 2010-03-01 01:18:51.717096708 +0100
> >> +++ b/arch/x86/kernel/entry_32.S 2010-03-01 01:19:27.867865836 +0100
> >> @@ -960,7 +960,11 @@
> >> RING0_INT_FRAME
> >> pushl $0
> >> CFI_ADJUST_CFA_OFFSET 4
> >> +#ifdef CONFIG_MGEODE_LX
> >> + pushl $do_nopl_emu
> >> +#else
> >> pushl $do_invalid_op
> >> +#endif
> >
> > How does this work for MGEODEGX1 when it looks for MGEODE_LX? It seems
> > you made both link against the code above after all. Is this wrong or
> > the above?
> >
> > Can it not work if you want to run a generic kernel on your Geode rather
> > than one built explicitly for the LX? I build one kernel to run on
> > Geode SC1200 and Geode LX.
> >
> > --
> > Len Sorensen
> >
>
> This code should work for Geode GX too.
> Try it and report success please
But if I don't have CONFIG_MGEODE_LX then what is going to call the
$do_nopl_emu in entry_32.S?
--
Len Sorensen
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: AMD Geode i686
2010-04-15 17:32 ` Lennart Sorensen
@ 2010-04-15 17:36 ` Matteo Croce
0 siblings, 0 replies; 7+ messages in thread
From: Matteo Croce @ 2010-04-15 17:36 UTC (permalink / raw)
To: Lennart Sorensen; +Cc: linux-kernel, Alan Cox, H. Peter Anvin
On Thu, Apr 15, 2010 at 7:32 PM, Lennart Sorensen
<lsorense@csclub.uwaterloo.ca> wrote:
> On Thu, Apr 15, 2010 at 07:20:27PM +0200, Matteo Croce wrote:
>> On Thu, Apr 15, 2010 at 7:11 PM, Lennart Sorensen
>> <lsorense@csclub.uwaterloo.ca> wrote:
>> > On Mon, Mar 01, 2010 at 11:03:09PM +0100, Matteo Croce wrote:
>> >> Hi,
>> >> I have refreshed my AMD Geode i686 patch with NOPL and I have added a
>> >> new nice feature.
>> >> When a NOPL is found the parser looks for any NOPL after the current
>> >> one, so they are emulated in bulk.
>> >> Tested ok on a Pcengines Alix.
>> >>
>> >> Signed-off-by: Matteo Croce <technoboy85@gmail.com>
>> >>
>> >> --- a/arch/x86/kernel/Makefile 2010-03-01 01:18:51.697166322 +0100
>> >> +++ b/arch/x86/kernel/Makefile 2010-03-01 01:19:45.727095700 +0100
>> >> @@ -89,6 +89,8 @@
>> >> obj-$(CONFIG_HPET_TIMER) += hpet.o
>> >>
>> >> obj-$(CONFIG_K8_NB) += k8.o
>> >> +obj-$(CONFIG_MGEODEGX1) += nopl_emu.o
>> >> +obj-$(CONFIG_MGEODE_LX) += nopl_emu.o
>> >> obj-$(CONFIG_DEBUG_RODATA_TEST) += test_rodata.o
>> >> obj-$(CONFIG_DEBUG_NX_TEST) += test_nx.o
>> >>
>> >> --- a/arch/x86/kernel/cpu/amd.c 2010-03-01 01:18:51.737097341 +0100
>> >> +++ b/arch/x86/kernel/cpu/amd.c 2010-03-01 01:19:27.867865836 +0100
>> >> @@ -138,8 +138,10 @@
>> >> }
>> >>
>> >> if (c->x86_model == 10) {
>> >> - /Index: linux-2.6.33/arch/x86/kernel/Makefile
>> >> ===================================================================
>> >> * AMD Geode LX is model 10 */
>> >> - /* placeholder for any needed mods */
>> >> + /* Geode only lacks the NOPL instruction to be i686,
>> >> + but we can emulate it in the exception handler
>> >> + and promote it to a class 6 cpu */
>> >> + boot_cpu_data.x86 = 6;
>> >> return;
>> >> }
>> >> }
>> >> --- a/arch/x86/kernel/entry_32.S 2010-03-01 01:18:51.717096708 +0100
>> >> +++ b/arch/x86/kernel/entry_32.S 2010-03-01 01:19:27.867865836 +0100
>> >> @@ -960,7 +960,11 @@
>> >> RING0_INT_FRAME
>> >> pushl $0
>> >> CFI_ADJUST_CFA_OFFSET 4
>> >> +#ifdef CONFIG_MGEODE_LX
>> >> + pushl $do_nopl_emu
>> >> +#else
>> >> pushl $do_invalid_op
>> >> +#endif
>> >
>> > How does this work for MGEODEGX1 when it looks for MGEODE_LX? It seems
>> > you made both link against the code above after all. Is this wrong or
>> > the above?
>> >
>> > Can it not work if you want to run a generic kernel on your Geode rather
>> > than one built explicitly for the LX? I build one kernel to run on
>> > Geode SC1200 and Geode LX.
>> >
>> > --
>> > Len Sorensen
>> >
>>
>> This code should work for Geode GX too.
>> Try it and report success please
>
> But if I don't have CONFIG_MGEODE_LX then what is going to call the
> $do_nopl_emu in entry_32.S?
>
> --
> Len Sorensen
>
#if defined(CONFIG_MGEODE_LX) || defined(MGEODEGX1)
sort of..
--
Matteo Croce
OpenWrt developer
_______ ________ __
| |.-----.-----.-----.| | | |.----.| |_
| - || _ | -__| || | | || _|| _|
|_______|| __|_____|__|__||________||__| |____|
|__| W I R E L E S S F R E E D O M
KAMIKAZE (bleeding edge) ------------------
* 10 oz Vodka Shake well with ice and strain
* 10 oz Triple sec mixture into 10 shot glasses.
* 10 oz lime juice Salute!
---------------------------------------------------
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2010-04-15 17:36 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-03-01 22:03 AMD Geode i686 Matteo Croce
2010-03-01 23:43 ` Brian Gerst
2010-03-01 23:49 ` H. Peter Anvin
2010-04-15 17:11 ` Lennart Sorensen
2010-04-15 17:20 ` Matteo Croce
2010-04-15 17:32 ` Lennart Sorensen
2010-04-15 17:36 ` Matteo Croce
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).