-2

I am reading the copy_from_user function, in copy_from_user function, the macro __get_user_asm is used.

there is a mmap syscall in linux, mmap syscall will call function copy_from_user. this function will use the macro __get_user_asm if the size is constant. the content of __get_user_asm is

#define __get_user_asm(x, addr, err, itype, rtype, ltype, errret)   \
asm volatile("1:    mov"itype" %2,%"rtype"1\n"      \
         "2:\n"                     \
         ".section .fixup,\"ax\"\n"             \
         "3:    mov %3,%0\n"                \
         "  xor"itype" %"rtype"1,%"rtype"1\n"       \
         "  jmp 2b\n"                   \
         ".previous\n"                  \
         _ASM_EXTABLE(1b, 3b)               \
         : "=r" (err), ltype(x)             \
         : "m" (__m(addr)), "i" (errret), "0" (err))

when i try to translate __get_user_asm(*(u8 *)dst, (u8 __user *)src, ret, "b", "b", "=q", 1); to the real source,

1: movb %2,%b1\n
2:\n
.section .fixup, "ax" \n
3: mov %3, %0 \n
 **xorb %b1, %b1\n**
 jmp 2b\n
.previous\n

: "=r" (ret), =q(dst)
:"m"(dst), "i"(1), "0"(ret)

.quad "1b", "2b"\n
.previous\n```

, there are somewhere i can't understand.

1, in xorb %b1, %b1, what's %b1(b one, not b L)?

2, in jmp 2b, is 2b a label or a memroy address? if 2b is a label, how can i find this lable?

3, what's the function of .quad "1b", "2b"?

where can i get the knowledge that make me to understand the linux kernel source in semantics layer?

too honest for this site
  • 12,050
  • 4
  • 30
  • 52
  • [`xorb %b1, %b1` just sets `%b1` to 0.](http://stackoverflow.com/questions/33666617/what-is-the-best-way-to-set-a-register-to-zero-in-x86-assembly-xor-mov-or-and) – Cornstalks Oct 01 '16 at 01:24
  • yeah, i know the thing that sentence do. but i don't know what's %b1? – peasantspring Oct 01 '16 at 01:28

2 Answers2

2

Reading the docs for gcc's extended asm, we see that %1 refers to the second parameter (because parameter numbers are zero based). In your example, that's dst.

Adding b (ie %b1) is described here:

Modifier Description                             Operand  masm=att  masm=intel
b        Print the QImode name of the register.  %b0      %al       al

jmp 2b means look backward for a label named 2.

The .quad directive is defined here:

.quad expects zero or more bignums, separated by commas. For each bignum, it emits an 8-byte integer. If the bignum won't fit in 8 bytes, it prints a warning message; and just takes the lowest order 8 bytes of the bignum.

As for where to get info, hopefully the links I have provided help.

David Wohlferd
  • 7,110
  • 2
  • 29
  • 56
0

XOR any register with itself sets it to zero. So %B1 = 0.

nrabbit
  • 181
  • 2
  • 9