i386 asm tutorial [was Re: copy_from_user() fix]

Andrea Arcangeli (arcangeli@mbox.queen.it)
Fri, 28 Aug 1998 13:12:11 +0200 (CEST)


On Sun, 23 Aug 1998, Savochkin Andrey Vladimirovich wrote:

>I've reimplemented the fix according to Richard's suggestions.

I have some questions about your code that I don' t understand very well.
Please answer me only if you have the time ;-).

diff -ruN linux-2.1.117.orig/include/asm-i386/uaccess.h linux-2.1.117/include/asm-i386/uaccess.h
--- linux-2.1.117.orig/include/asm-i386/uaccess.h Mon Aug 3 23:38:10 1998
+++ linux-2.1.117/include/asm-i386/uaccess.h Sun Aug 23 13:24:06 1998
@@ -268,13 +268,38 @@
: "r"(size & 3), "0"(size / 4), "D"(to), "S"(from) \
: "di", "si", "memory")

+#define __copy_user_zeroing(to,from,size) \
+ __asm__ __volatile__( \
+ "0: rep; movsl\n" \
+ " movl %1,%0\n" \
+ "1: rep; movsb\n" \

I understand this perfectly.

+ "2:\n" \
+ ".section .fixup,\"ax\"\n" \

Why to change section? And has it to be called fixup? And what does it
mean ,"ax" at the end of the section declaration?

+ "3: lea 0(%1,%0,4),%0\n" \

Is this the addressing mode with base - index - scale - displacement
explained at pag 90 of the Intel document 24319881?

+ "4: pushl %0\n" \
+ " pushl %%eax\n" \
+ " xorl %%eax,%%eax\n" \
+ " rep; stosb\n" \

This should continue zeroing the memory pointed by edi (but we have just
written size bytes?) and btw I don' t know what ecx contains...

+ " popl %%eax\n" \
+ " popl %0\n" \
+ " jmp 2b\n" \
+ ".previous\n" \
+ ".section __ex_table,\"a\"\n" \
+ " .align 4\n" \
+ " .long 0b,3b\n" \
+ " .long 1b,4b\n" \

And where does we use these numbers? Maybe in the unknown instruction
(3:)?

+ ".previous" \
+ : "=&c"(size) \
^ This is needed because we use string operation that
autoread/autowrite ecx?

+ : "r"(size & 3), "0"(size / 4), "D"(to), "S"(from) \
+ : "di", "si", "memory");
+
/* We let the __ versions of copy_from/to_user inline, because they're often
* used in fast paths and have only a small space overhead.
*/

Andrea[s] Arcangeli

-
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.altern.org/andrebalsa/doc/lkml-faq.html