asm (lidt) question
In arch/i386/kernel, inline asm for loading IDT (lidt) is used a few times, but with slightly different constraints and output/input definitions. Are these OK, equivalent, or what?
[rddunlap@dragon kernel]$ findc lidt./cpu/common.c:484: __asm__ __volatile__("lidt %0": "=m" (idt_descr));
./traps.c:783: __asm__ __volatile__("lidt %0": "=m" (idt_descr));
vs.
./reboot.c:186: __asm__ __volatile__ ("lidt %0" : : "m" (real_mode_idt));
./reboot.c:261: __asm__ __volatile__("lidt %0": :"m" (no_idt));
./suspend.c:95: asm volatile ("lidt %0" :: "m" (saved_context.idt_limit));
Thanks,
--
~Randy [yes, i've looked at the inline asm docs]
For Linux-2.6:
http://www.codemonkey.org.uk/post-halloween-2.5.txt
or http://lwn.net/Articles/39901/
http://www.kernel.org/pub/linux/kernel/people/rusty/modules/
Quoted 9 lines · Randy.Dunlap
In
arch/i386/kernel, inline asm for loading IDT (lidt) is used a few times, but with slightly different constraints and output/input definitions. Are these OK, equivalent, or what?[rddunlap@dragon kernel]$ findc lidt
./cpu/common.c:484:__asm____volatile__("lidt %0": "=m" (idt_descr));
./traps.c:783:__asm____volatile__("lidt %0": "=m" (idt_descr));
Quoted 5 lines
vs.
./reboot.c:186:
__asm____volatile__("lidt %0" : : "m" (real_mode_idt));
./reboot.c:261:__asm____volatile__("lidt %0": :"m" (no_idt));
./suspend.c:95: asm volatile ("lidt %0" :: "m" (saved_context.idt_limit));
I'd have said no looking at the syntax (input/output), but they indeed generate the same code (just checked).
- Davide
Quoted 11 lines · Davide Libenzi
Quoted 9 lines · Randy.Dunlap
In
arch/i386/kernel, inline asm for loading IDT (lidt) is used a few times, but with slightly different constraints and output/input definitions. Are these OK, equivalent, or what?[rddunlap@dragon kernel]$ findc lidt
./cpu/common.c:484:__asm____volatile__("lidt %0": "=m" (idt_descr));
./traps.c:783:__asm____volatile__("lidt %0": "=m" (idt_descr));
Quoted 8 lines
Quoted 5 lines
vs.
./reboot.c:186:
__asm____volatile__("lidt %0" : : "m" (real_mode_idt));
./reboot.c:261:__asm____volatile__("lidt %0": :"m" (no_idt));
./suspend.c:95: asm volatile ("lidt %0" :: "m" (saved_context.idt_limit));I'd have said no looking at the syntax (input/output), but they indeed generate the same code (just checked).
Randy, I'd say that this :
__asm__ __volatile__("lidt %0": "=m" (var));
is better then :
__asm__ __volatile__("lidt %0": :"m" (var));
IMHO, since "var" is really an output parameter.
- Davide
On Thu, 17 Jul 2003 16:18:06 -0700 (PDT) Davide Libenzi <[email protected]> wrote:
| On Thu, 17 Jul 2003, Davide Libenzi wrote:
|
| > On Thu, 17 Jul 2003, Randy.Dunlap wrote:
| >
| > >
| > > In arch/i386/kernel, inline asm for loading IDT (lidt) is used a few
| > > times, but with slightly different constraints and output/input
| > > definitions. Are these OK, equivalent, or what?
| > >
| > > [rddunlap@dragon kernel]$ findc lidt
| > > ./cpu/common.c:484: __asm__ __volatile__("lidt %0": "=m" (idt_descr));
| > > ./traps.c:783: __asm__ __volatile__("lidt %0": "=m" (idt_descr));
| > >
| > > vs.
| > >
| > > ./reboot.c:186: __asm__ __volatile__ ("lidt %0" : : "m" (real_mode_idt));
| > > ./reboot.c:261: __asm__ __volatile__("lidt %0": :"m" (no_idt));
| > > ./suspend.c:95: asm volatile ("lidt %0" :: "m" (saved_context.idt_limit));
| >
| > I'd have said no looking at the syntax (input/output), but they indeed
| > generate the same code (just checked).
|
| Randy, I'd say that this :
|
| __asm__ __volatile__("lidt %0": "=m" (var));
|
| is better then :
|
| __asm__ __volatile__("lidt %0": :"m" (var));
|
| IMHO, since "var" is really an output parameter.Yes, I agree, var is output and should be listed after the first ':' IMHO also.
Thanks for checking that they generate the same code, though.
I'll buy you a beer... No, wait, I already did that. :)
--
~Randy
Quoted 10 lines · Randy.Dunlap
| Randy, I'd say that this :
|
| __asm__ __volatile__("lidt %0": "=m" (var));
|
| is better then :
|
| __asm__ __volatile__("lidt %0": :"m" (var));
|
| IMHO, since "var" is really an output parameter.Quoted 2 lines
Yes, I agree, var is output and should be listed after the first ':' IMHO also.
BF (Brain Farting) is contagious ;) I need a vacation, a long one (and you too so maybe OSDL will hire someone else meanwhile :)
- Davide
Quoted 1 line · Davide Libenzi
IMHO, since "var" is really an output parameter.
"var" is read, not written.
I think you are confusing "lidt" with "sidt".
Therefore
Quoted 1 line
__asm____volatile__("lidt %0": :"m" (var));
is the better choice, and that's why I wrote it in reboot.c :)
-- Jamie
Quoted 5 lines · Jamie Lokier
Quoted 1 line · Davide Libenzi
IMHO, since "var" is really an output parameter.
"var" is read, not written.
I think you are confusing "lidt" with "sidt".
Actually I don't even know what I was confusing, since L and S are not there for nothing ;) And yes, the form with =m as input parameter should be corrected, even if it generates the same code.
- Davide
Quoted 8 lines · Davide Libenzi
Quoted 5 lines · Jamie Lokier
Quoted 1 line · Davide Libenzi
IMHO, since "var" is really an output parameter.
"var" is read, not written.
I think you are confusing "lidt" with "sidt".
Quoted 7 lines
Actually I don't even know what I was confusing, since L and S are not there for nothing ;) And yes, the form with =m as input parameter should be corrected, even if it generates the same code.
- Davide
LIDT is "load interrupt descriptor table". SIDT is "store interrupt descriptor table". Only SIDT modifies memory. LIDT reads from memory and puts the result into a special CPU register, therefore doesn't modify memory.
Cheers,
Dick Johnson
Penguin : Linux version 2.4.20 on an i686 machine (797.90 BogoMips).
Note 96.31% of all statistics are fiction.
Quoted 4 lines · Richard B. Johnson
LIDT is "load interrupt descriptor table". SIDT is "store interrupt descriptor table". Only SIDT modifies memory. LIDT reads from memory and puts the result into a special CPU register, therefore doesn't modify memory.
Indeed, that why this is not really correct :
__asm__ __volatile__("lidt %0": "=m" (var));
even if it generates the same code of :
__asm__ __volatile__("lidt %0": : "m" (var));
- Davide
On Tue, 22 Jul 2003 10:31:37 -0700 (PDT) Davide Libenzi <[email protected]> wrote:
| On Tue, 22 Jul 2003, Jamie Lokier wrote: | | > Davide Libenzi wrote: | > > IMHO, since "var" is really an output parameter. | > | > "var" is read, not written. | > I think you are confusing "lidt" with "sidt". | | Actually I don't even know what I was confusing, since L and S are not | there for nothing ;) And yes, the form with =m as input parameter should | be corrected, even if it generates the same code.
Yes, less confusion is better, so here's a patch to use the same reasonable syntax in all places.
Look OK? Generates the same code, as Davide pointed out.
--
~Randy
patch_name: lidt_norm.patchpatch_version: 2003-07-22.11:47:21
author: Randy.Dunlap <[email protected]>
description: normalize lidt/lgdt syntax usage
product: Linuxproduct_versions: 2.6.0-test1
diffstat: =
arch/i386/kernel/cpu/common.c | 4 ++-- arch/i386/kernel/traps.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-)
arch/i386/kernel/cpu/common.c renamed from arch/i386/kernel/cpu/common.c~lidt +2 -2
@@ -480,8 +480,8 @@*/ memcpy (thread->tls_array, cpu_gdt_table[cpu],GDT_ENTRY_TLS_ENTRIES *8 ); - __asm__ __volatile__("lgdt %0" :"=m" (cpu_gdt_descr[cpu])); - __asm__ __volatile__("lidt %0" :"=m" (idt_descr)); + __asm__ __volatile__("lgdt %0" : :"m" (cpu_gdt_descr[cpu])); + __asm__ __volatile__("lidt %0" : :"m" (idt_descr));/* * Delete NT
arch/i386/kernel/traps.c renamed from arch/i386/kernel/traps.c~lidt +1 -1
@@ -780,7 +780,7 @@* it uses the read-only mapped virtual address. */ idt_descr.address =fix_to_virt (FIX_F00F_IDT ); - __asm__ __volatile__("lidt %0": "=m" (idt_descr)); + __asm__ __volatile__("lidt %0": :"m" (idt_descr)); }#endif
Quoted 14 lines · Randy.Dunlap
On Tue, 22 Jul 2003 10:31:37 -0700 (PDT) Davide Libenzi <[email protected]> wrote:
| On Tue, 22 Jul 2003, Jamie Lokier wrote: | | > Davide Libenzi wrote: | > > IMHO, since "var" is really an output parameter. | > | > "var" is read, not written. | > I think you are confusing "lidt" with "sidt". | | Actually I don't even know what I was confusing, since L and S are not | there for nothing ;) And yes, the form with =m as input parameter should | be corrected, even if it generates the same code.
Quoted 4 lines
Yes, less confusion is better, so here's a patch to use the same reasonable syntax in all places.
Look OK? Generates the same code, as Davide pointed out.
Yep, that's the right syntax (pls push to Andrew or Linus) ;)
- Davide
On Tue, 22 Jul 2003 11:58:16 -0700 (PDT) Davide Libenzi <[email protected]> wrote:
| > Yes, less confusion is better, so here's a patch to use the | > same reasonable syntax in all places. | > | > Look OK? Generates the same code, as Davide pointed out. | | Yep, that's the right syntax (pls push to Andrew or Linus) ;) |
Yes, planning to.
~Randy