question on inline assembly (kernel_thread)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello,

While studying the kernel_thread() function (2.4.8) for x86, which is written as inline assembly function, I came accross a question.

487 int kernel_thread(int (*fn)(void *), void * arg, unsigned long flags)
488 {
489         long retval, d0;
490 
491         __asm__ __volatile__(
492                 "movl %%esp,%%esi\n\t"
493                 "int $0x80\n\t"         /* Linux/i386 system call */
494                 "cmpl %%esp,%%esi\n\t"  /* child or parent? */
495                 "je 1f\n\t"             /* parent - jump */

.... /* Lines 496 to 501 are not relevant to my question */

502                 "movl %3,%0\n\t"        /* exit */
503                 "int $0x80\n"
504                 "1:\t"
505                 :"=&a" (retval), "=&S" (d0)
506                 :"" (__NR_clone), "i" (__NR_exit),
507                  "r" (arg), "r" (fn),
508                  "b" (flags | CLONE_VM)
509                 : "memory");
510         return retval;
511 }

In the above code listing, in line 493 I understand, that this is a programmed exception having vector 128 (0x80), which is used to trigger a system call, where the system
call is specified by the content of the eax register (from the context I guess that it should be the clone() system call, which is identified by __NR_clone).
What I don't understand is, how the correct system call number (__NR_clone(?)) gets into the eax register, before the programmed exception in line 493 - similar to lines
502, 503 I would have expected a "movl %2, %0\n\t" before line 493, to get __NR_clone into the eax register (by the way it is interesting to notice that __NR_clone is
specified as input operand %2, but that never used in the actual assembly code).
I am not very familiar with inline assembly, so I guess that that the answer to my question lies in the inline assembly syntax/features (e.g. I do not know what the ""
constraint for the output operand (__NR_clone) means).

thanks in advance for any help
with best regards
Martin

P.S. please put me on cc: in your reply, since I am not in the mailing list.

--
Supercomputing System AG          email: maletinsky@scs.ch
Martin Maletinsky                 phone: +41 (0)1 445 16 05
Technoparkstrasse 1               fax:   +41 (0)1 445 16 10
CH-8005 Zurich
--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux