This is the mail archive of the ecos-discuss@sources.redhat.com mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Interprocess communication


On Tue, Mar 05, 2002 at 11:33:08AM -0600, Alfredo Carrillo wrote:
> I modified the next file:    syscall-i386-linux-1.0.S
> adding the entry for shmget function, as follows:
> 
>          .
>          .
> #ifndef _SYS_SYSCALL_H
> #define _SYS_SYSCALL_H
> 
> #define SYS_setup               0 // Used only by init, to get system going.
> #define SYS_exit                1
> #define SYS_fork                2
> #define SYS_read                3
> #define SYS_write               4
> #define SYS_open                5
>          .
>          .
>          .
> #define SYS_nanosleep    162
> #define SYS_mremap      163
> #define SYS_shmget        164  /***    I added this line    ***/

Nope. That will not work. These are the system call numbers used to
call into the Linux Kernel. These are well defined numbers. You cannot
add your own, or not without editing the Linux kernel as well!

First off you need to study a little how Linux system calls
work. Basically, to invoke something inside the linux kernel, you set
the CPU register eax to the number of the system call you want to make
and then do an int 0x80 trap. This causes a jump into the kernel. It
then looks at the contents of eax to work out what you asked it to
do. You can pass parameters using the registers ebx, ecx, edx & esi.

So, a little example. The read system call takes three parameters, fd,
buf and count. In that file you will see SYSCALL3(read). This is a bit
of macro magic. The Macro is

#define SYSCALL3(x)                             \
        .globl NAME(x) ;                        \
                                                \
NAME(x):                                        \
                                                \
        push %ebx;                              \
        mov 8(%esp), %ebx;                      \
        mov 12(%esp), %ecx;                     \
        mov 16(%esp), %edx;                     \
        lea     SYS_##x, %eax;                  \
        int $0x80;                              \
        pop %ebx;                               \
        ret;                                    \
        END(x)

It puts the parameters into ebx, ecx and edx. It loads eax with
SYS_read, ie 3, and then does and int 0x80 into the kernel.

Now, you want to use share memory system calls. If you look at the
linux kernel sources, you will find the comment i posted this
morning. The file linux/arch/i386/kernel/sys_i386.c in the linux
sources contains code for all funny system calls. It seems that all
SysV IPC calls go through a single system call, sys_ipc. They are
multiplexed and it looks like the first parameter to the system call
is which IPC function you want the kernel to do. You need to
understand this system call and write some C code in eCos which does
the multiplexing in userspace in the same way the kernel understands
it.

        Andrew

-- 
Before posting, please read the FAQ: http://sources.redhat.com/fom/ecos
and search the list archive: http://sources.redhat.com/ml/ecos-discuss


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]