Alan Modra wrote:
> gcc can generate code that accesses parameters like prev->tss.esp
> indexed from registers other than %esp, since switch_to is passed
> prev, next, and last in registers. If this were not so, gcc might
> access task_struct fields via %esp in the asm, which breaks as %esp is
> altered by the pushes.
>
> Hmm, actually I don't think there's anything to prohibit gcc from using
> %esp anyway. Maybe I should rewrite switch_to to make sure of this.
Fwiw, you can reduce the number of pushes & pops to 1 and, in principle,
generate shorter code. Attached is a patch I used from the 2.2.8 days.
Back then it actually generated slightly larger code: GCC did a worse
job register allocation when told they're clobbered then when saving
them explicitly. I don't know what it's like nowadays.
enjoy,
-- Jamie
diff -u linux-2.2.8/include/asm-i386/system.h.devel linux-2.2.8/include/asm-i386/system.h
--- linux-2.2.8/include/asm-i386/system.h.devel Wed May 12 00:44:17 1999
+++ linux-2.2.8/include/asm-i386/system.h Wed May 12 00:50:44 1999
@@ -9,24 +9,25 @@
struct task_struct; /* one of the stranger aspects of C forward declarations.. */
extern void FASTCALL(__switch_to(struct task_struct *prev, struct task_struct *next));
+/*
+ * EBP must be the last thing pushed for get_wchan() [see fs/proc/array.c].
+ * Anyway GCC ignores EBP in a clobber list.
+ */
#define switch_to(prev,next,last) do { \
- asm volatile("pushl %%esi\n\t" \
- "pushl %%edi\n\t" \
- "pushl %%ebp\n\t" \
+ asm volatile("pushl %%ebp\n\t" \
"movl %%esp,%0\n\t" /* save ESP */ \
"movl %3,%%esp\n\t" /* restore ESP */ \
"movl $1f,%1\n\t" /* save EIP */ \
"pushl %4\n\t" /* restore EIP */ \
"jmp __switch_to\n" \
"1:\t" \
- "popl %%ebp\n\t" \
- "popl %%edi\n\t" \
- "popl %%esi\n\t" \
+ "popl %%ebp" \
:"=m" (prev->tss.esp),"=m" (prev->tss.eip), \
"=b" (last) \
:"m" (next->tss.esp),"m" (next->tss.eip), \
"a" (prev), "d" (next), \
- "b" (prev)); \
+ "b" (prev) \
+ :"esi", "edi"); \
} while (0)
#define _set_base(addr,base) do { unsigned long __pr; \
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/
This archive was generated by hypermail 2b29 : Mon May 15 2000 - 21:00:17 EST