Re: Switch from User space to Kernel space.

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

 




This is extended aseembly in gcc syntax.

the prototype is
asm ( assembler template


: output operands /* optional */

           : input operands                   /* optional */

           : list of clobbered registers      /* optional */

           );


The assembler prototype consists of assembly instructions. Each operand is described by an operand-constraint string followed by the C expression. First colon separates the assembler instruction from the first output operand and other separates the last output operand from the input. Commas separate the operands in the group.


The 'a' & 'b' are the registers
a  ==>   %eax, %ax, %al
b  ==>   %ebx, %bx, %bl

Read this http://www.ibiblio.org/gferg/ldp/GCC-Inline-Assembly-HOWTO.html#s3 to understand more about the syntax.

I hope you can now understand the code easily.

Ketan

At 10:10 PM 7/26/2004, Dhiman, Gaurav wrote:

Can any one tell me what's going on in following code (esp code in RED color) ?



#define <http://lxr.linux.no/ident?v=2.4.21;i=_syscall1>_syscall1(<http://lxr.linux.no/ident?v=2.4.21;i=type>type,<http://lxr.linux.no/ident?v=2.4.21;i=name>name,type1,<http://lxr.linux.no/ident?v=2.4.21;i=arg1>arg1) \
<http://lxr.linux.no/ident?v=2.4.21;i=type>type <http://lxr.linux.no/ident?v=2.4.21;i=name>name(type1 <http://lxr.linux.no/ident?v=2.4.21;i=arg1>arg1) \
{ \
long <http://lxr.linux.no/ident?v=2.4.21;i=__res>__res; \
__asm__ volatile ("int $0x80" \
: "=a" (<http://lxr.linux.no/ident?v=2.4.21;i=__res>__res) \
: "" (__NR_##name),"b" ((long)(<http://lxr.linux.no/ident?v=2.4.21;i=arg1>arg1))); \


<http://lxr.linux.no/ident?v=2.4.21;i=__syscall_return>__syscall_return(<http://lxr.linux.no/ident?v=2.4.21;i=type>type,<http://lxr.linux.no/ident?v=2.4.21;i=__res>__res); \
}
This has been taken from 'unistd.h' file in kernel sources. It's a code which actually creates a stub, so that user process can make a call to system call.


My question is for having an access this code (macro) user process or library function used by user program must include this file ('unistd.h'). Is it like this that this file is included by a library or user program which makes a call to system call. Actually it is the first time that I am studying about how the control switches from user space to kernel space. I want to know exact code which make this switch. I think that its this stub only which allow the control to switch from user space to kernel space.

One more thing, Please let me know what does the code in RED color is doing. Its an assembly code, please explain it.

Regards,
Gaurav




-- 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