(Courriels de diversion: <hueriez@desirables-rauques.com> <proferee@eclaircissaient-assassinat.com> <reapparaîtrons@pareos-deblayant.com> <rampa@mediatiserez-tremblerai.com> <devancerai@enlisiez-juxtaposait.com> <souffrions@choyes-tâches.com> <desabonnais@mediatisa-roulantes.com> <premuniras@immobilisee-epouseriez.com> <trepignez@ingeriez-morcelait.com> <sentimentalement@militaires-rafraîchissiez.com> )


Re salut ... à titre indicatif :

System calls in Linux are done through int 0x80. (actually there's a kernel patch allowing system calls to be done via syscall (sysenter) instruction on newer CPUs, but this thing is still experimental).

Linux differs from usual UNIX calling convention, and features "fastcall" convention for system calls (it resembles DOS). System function number is passed in eax, and arguments are passed through registers, not the stack. There can be up to five arguments in ebx, ecx, edx, esi, edi consequently. If there's more than five arguments, they are simply passed though the structure as first argument. Result is returned in eax, stack is not touched at all.

System call function numbers are in sys/syscall.h, but actually in asm/unistd.h, some documentation is in the 2nd section of manual (f.e. to find info on write system call, issue man 2 write).

There are several attempts to made up-to-date documentation of Linux system calls, examine URLs in the references.

So, our Linux program will look like:



--------------------------------------------------------------------------------

section .text
    global _start                       ;must be declared for linker (ld)

msg     db      'Hello, world!',0xa     ;our dear string
len     equ     $ - msg                 ;length of our dear string

_start:                 ;we tell linker where is entry point

        mov     edx,len ;message length
        mov     ecx,msg ;message to write
        mov     ebx,1   ;file descriptor (stdout)
        mov     eax,4   ;system call number (sys_write)
        int     0x80    ;call kernel

        mov     eax,1   ;system call number (sys_exit)
        int     0x80    ;call kernel


--------------------------------------------------------------------------------

As you will see futther, Linux syscall convention is the most compact one.

Kernel source references:

arch/i386/kernel/entry.S
include/asm-i386/unistd.h
include/linux/sys.h


>> __asm__ volatile ("int $0x80"
>>                 : "=a" (__res)
>>                 : "0" (__NR_close),"b" ((long)(i)));
>
>Salut ...
>
>cela veut dire que tu executes le code assembleur "int 0x80" (soit l'appel à l'interruption 0x80 du BIOS)
>avec le registre ebx qui vaut "i" et "__NR_close" mis dans la pile.
>
>Le resultat qui est le registre eax est retourné dans la variable __res.
>
>en bref tu appelles la fonction bios 0x80 avec comme parametre i et __NR_close pour recuperer le resultat dans __res.
>




---------------------------------------------------------------------
Aide sur la liste: <URL:mailto:linux-31-help@CULTe.org>Le CULTe sur le web: <URL:http://www.CULTe.org/>