Re: complicated inline assembly

Richard B. Johnson (root@chaos.analogic.com)
Mon, 23 Aug 1999 20:43:36 -0400 (EDT)


On Mon, 23 Aug 1999, Mehta, Hiren wrote:

> Can anybody explain the following complicated assembly that I found
> include/asm-i386/unistd.h file ?
>
> #define _syscall0(type,name) \
> type name(void) \
> { \
> long __res; \
> __asm__ volatile ("int $0x80" \
> : "=a" (__res) \
> : "0" (__NR_##name)); \
> if (__res >= 0) \
> return (type) __res; \
> errno = -__res; \
> return -1; \
> }
>

This is the user-to-kernel interface for the kernel system calls. It
takes the system-call number, puts it into register eax as a function code
and executes the software interrupt 80 hex. Upon return, it checks for
a negative value, also in eax. If it is negative, it puts the
negative of the return value (now positive) into global errno, and
returns -1.

Note that this is a MACRO so substitution rules apply for 'type' and
'name' Type would be typically 'int' and 'name' would be system-call
number.

Cheers,
Dick Johnson
**** FILE SYSTEM WAS MODIFIED ****
Penguin : Linux version 2.3.13 on an i686 machine (400.59 BogoMips).
Warning : It's hard to remain at the trailing edge of technology.

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