rtai-core/include/asm-i386/rtai_xncall.h

00001 /*
00002  * Copyright (C) 2001,2002,2003 Philippe Gerum <rpm@xenomai.org>.
00003  *
00004  * Xenomai is free software; you can redistribute it and/or modify it
00005  * under the terms of the GNU General Public License as published by
00006  * the Free Software Foundation; either version 2 of the License, or
00007  * (at your option) any later version.
00008  *
00009  * Xenomai is distributed in the hope that it will be useful, but
00010  * WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with Xenomai; if not, write to the Free Software Foundation,
00016  * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00017  *
00018  * As a special exception, the RTAI project gives permission
00019  * for additional uses of the text contained in its release of
00020  * Xenomai.
00021  *
00022  * The exception is that, if you link the Xenomai libraries with other
00023  * files to produce an executable, this does not by itself cause the
00024  * resulting executable to be covered by the GNU General Public License.
00025  * Your use of that executable is in no way restricted on account of
00026  * linking the Xenomai libraries code into it.
00027  *
00028  * This exception does not however invalidate any other reasons why
00029  * the executable file might be covered by the GNU General Public
00030  * License.
00031  *
00032  * This exception applies only to the code released by the
00033  * RTAI project under the name Xenomai.  If you copy code from other
00034  * RTAI project releases into a copy of Xenomai, as the General Public
00035  * License permits, the exception does not apply to the code that you
00036  * add in this way.  To avoid misleading anyone as to the status of
00037  * such modified files, you must delete this exception notice from
00038  * them.
00039  *
00040  * If you write modifications of your own for Xenomai, it is your
00041  * choice whether to permit this exception to apply to your
00042  * modifications. If you do not wish that, delete this exception
00043  * notice.
00044  */
00045 
00046 #ifndef _RTAI_ASM_I386_XNCALL_H
00047 #define _RTAI_ASM_I386_XNCALL_H
00048 
00049 #include <asm/ptrace.h>
00050 
00051 #ifdef __KERNEL__
00052 
00053 #include <asm/uaccess.h>
00054 #include <rtai_wrappers.h>
00055 
00056 #define __xn_copy_from_user(task,dstP,srcP,n)  __copy_from_user(dstP,srcP,n)
00057 #define __xn_copy_to_user(task,dstP,srcP,n)    __copy_to_user(dstP,srcP,n)
00058 #define __xn_put_user(task,src,dstP)           __put_user(src,dstP)
00059 #define __xn_get_user(task,dst,srcP)           __get_user(dst,srcP)
00060 
00061 #define __xn_range_ok(task,addr,size) ({ \
00062         unsigned long flag,sum; \
00063         asm("addl %3,%1 ; sbbl %0,%0; cmpl %1,%4; sbbl $0,%0" \
00064                 :"=&r" (flag), "=r" (sum) \
00065                 :"1" (addr),"g" ((int)(size)),"g" get_tsk_addr_limit(task)); \
00066         flag; })
00067 
00068 /* WP bit must work for using the shadow support, so we only need
00069    trivial range checking here. */
00070 #define __xn_access_ok(task,type,addr,size)    (__xn_range_ok(task,addr,size) == 0)
00071 
00072 #define XNARCH_MAX_SYSENT 255
00073 
00074 typedef struct _xnsysent {
00075 
00076     int (*svc)(struct task_struct *task,
00077                struct pt_regs *regs);
00078 
00079 #define __xn_flag_suspensive 0x1
00080 #define __xn_flag_anycontext 0x2
00081 
00082     u_long flags;
00083 
00084 } xnsysent_t;
00085 
00086 extern int nkgkptd;
00087 
00088 #define xnshadow_ptd(t)    ((t)->ptd[nkgkptd])
00089 #define xnshadow_thread(t) ((xnthread_t *)xnshadow_ptd(t))
00090 
00091 #endif /* __KERNEL__ */
00092 
00093 /*
00094  * Some of the following macros have been adapted from glibc's syscall
00095  * mechanism implementation:
00096  * Copyright (C) 1992,1993,1995-2000,2002,2003 Free Software Foundation, Inc.
00097  * Contributed by Ulrich Drepper, <drepper@gnu.org>, August 1995.
00098  *
00099  * The following code defines an inline syscall mechanism used by
00100  * Xenomai's real-time interfaces to invoke the skin module services
00101  * in kernel space.
00102  */
00103 
00104 /* Xenomai multiplexer syscall. */
00105 #define __xn_sys_mux    555
00106 /* Xenomai nucleus syscalls. */
00107 #define __xn_sys_attach  0      /* muxid = xnshadow_attach_skin(magic,infp) */
00108 #define __xn_sys_detach  1      /* xnshadow_detach_skin(muxid) */
00109 #define __xn_sys_sched   2      /* xnpod_schedule(void) */
00110 #define __xn_sys_sync    3      /* xnshadow_sync(&syncflag) */
00111 #define __xn_sys_migrate 4      /* switched = xnshadow_relax/harden() */
00112 
00113 asm (".L__X'%ebx = 1\n\t"
00114      ".L__X'%ecx = 2\n\t"
00115      ".L__X'%edx = 2\n\t"
00116      ".L__X'%eax = 3\n\t"
00117      ".L__X'%esi = 3\n\t"
00118      ".L__X'%edi = 3\n\t"
00119      ".L__X'%ebp = 3\n\t"
00120      ".L__X'%esp = 3\n\t"
00121      ".macro bpushl name reg\n\t"
00122      ".if 1 - \\name\n\t"
00123      ".if 2 - \\name\n\t"
00124      "pushl %ebx\n\t"
00125      ".else\n\t"
00126      "xchgl \\reg, %ebx\n\t"
00127      ".endif\n\t"
00128      ".endif\n\t"
00129      ".endm\n\t"
00130      ".macro bpopl name reg\n\t"
00131      ".if 1 - \\name\n\t"
00132      ".if 2 - \\name\n\t"
00133      "popl %ebx\n\t"
00134      ".else\n\t"
00135      "xchgl \\reg, %ebx\n\t"
00136      ".endif\n\t"
00137      ".endif\n\t"
00138      ".endm\n\t"
00139      ".macro bmovl name reg\n\t"
00140      ".if 1 - \\name\n\t"
00141      ".if 2 - \\name\n\t"
00142      "movl \\reg, %ebx\n\t"
00143      ".endif\n\t"
00144      ".endif\n\t"
00145      ".endm\n\t");
00146 
00147 #define XENOMAI_SYS_MUX(nr, op, args...) \
00148   ({                                                                  \
00149     unsigned resultvar;                                               \
00150     asm volatile (                                                    \
00151     LOADARGS_##nr                                                     \
00152     "movl %1, %%eax\n\t"                                              \
00153     "int $0x80\n\t"                                                   \
00154     RESTOREARGS_##nr                                                  \
00155     : "=a" (resultvar)                                                \
00156     : "i" (__xn_mux_code(0,op)) ASMFMT_##nr(args) : "memory", "cc");  \
00157     (int) resultvar; })
00158 
00159 #define XENOMAI_SKIN_MUX(nr, id, op, args...) \
00160   ({                                                                  \
00161     int muxcode = __xn_mux_code(id,op);                               \
00162     unsigned resultvar;                                               \
00163     asm volatile (                                                    \
00164     LOADARGS_##nr                                                     \
00165     "movl %1, %%eax\n\t"                                              \
00166     "int $0x80\n\t"                                                   \
00167     RESTOREARGS_##nr                                                  \
00168     : "=a" (resultvar)                                                \
00169     : "m" (muxcode) ASMFMT_##nr(args) : "memory", "cc");              \
00170     (int) resultvar; })
00171 
00172 #define LOADARGS_0
00173 #define LOADARGS_1 \
00174     "bpushl .L__X'%k2, %k2\n\t" \
00175     "bmovl .L__X'%k2, %k2\n\t"
00176 #define LOADARGS_2      LOADARGS_1
00177 #define LOADARGS_3      LOADARGS_1
00178 #define LOADARGS_4      LOADARGS_1
00179 #define LOADARGS_5      LOADARGS_1
00180 
00181 #define RESTOREARGS_0
00182 #define RESTOREARGS_1 \
00183     "bpopl .L__X'%k2, %k2\n\t"
00184 #define RESTOREARGS_2   RESTOREARGS_1
00185 #define RESTOREARGS_3   RESTOREARGS_1
00186 #define RESTOREARGS_4   RESTOREARGS_1
00187 #define RESTOREARGS_5   RESTOREARGS_1
00188 
00189 #define ASMFMT_0()
00190 #define ASMFMT_1(arg1) \
00191         , "acdSD" (arg1)
00192 #define ASMFMT_2(arg1, arg2) \
00193         , "adSD" (arg1), "c" (arg2)
00194 #define ASMFMT_3(arg1, arg2, arg3) \
00195         , "aSD" (arg1), "c" (arg2), "d" (arg3)
00196 #define ASMFMT_4(arg1, arg2, arg3, arg4) \
00197         , "aD" (arg1), "c" (arg2), "d" (arg3), "S" (arg4)
00198 #define ASMFMT_5(arg1, arg2, arg3, arg4, arg5) \
00199         , "a" (arg1), "c" (arg2), "d" (arg3), "S" (arg4), "D" (arg5)
00200 
00201 /* Register mapping for accessing syscall args. */
00202 
00203 #define __xn_reg_mux(regs)    ((regs)->orig_eax)
00204 #define __xn_reg_rval(regs)   ((regs)->eax)
00205 #define __xn_reg_arg1(regs)   ((regs)->ebx)
00206 #define __xn_reg_arg2(regs)   ((regs)->ecx)
00207 #define __xn_reg_arg3(regs)   ((regs)->edx)
00208 #define __xn_reg_arg4(regs)   ((regs)->esi)
00209 #define __xn_reg_arg5(regs)   ((regs)->edi)
00210 
00211 #define __xn_reg_mux_p(regs)        ((__xn_reg_mux(regs) & 0xffff) == __xn_sys_mux)
00212 #define __xn_mux_id(regs)           ((__xn_reg_mux(regs) >> 16) & 0xff)
00213 #define __xn_mux_op(regs)           ((__xn_reg_mux(regs) >> 24) & 0xff)
00214 #define __xn_mux_code(id,op)        ((op << 24)|((id << 16) & 0xff0000)|(__xn_sys_mux & 0xffff))
00215 
00216 #define XENOMAI_SYSCALL0(op)                XENOMAI_SYS_MUX(0,op)
00217 #define XENOMAI_SYSCALL1(op,a1)             XENOMAI_SYS_MUX(1,op,a1)
00218 #define XENOMAI_SYSCALL2(op,a1,a2)          XENOMAI_SYS_MUX(2,op,a1,a2)
00219 #define XENOMAI_SYSCALL3(op,a1,a2,a3)       XENOMAI_SYS_MUX(3,op,a1,a2,a3)
00220 #define XENOMAI_SYSCALL4(op,a1,a2,a3,a4)    XENOMAI_SYS_MUX(4,op,a1,a2,a3,a4)
00221 #define XENOMAI_SYSCALL5(op,a1,a2,a3,a4,a5) XENOMAI_SYS_MUX(5,op,a1,a2,a3,a4,a5)
00222 
00223 #define XENOMAI_SKINCALL0(id,op)                XENOMAI_SKIN_MUX(0,id,op)
00224 #define XENOMAI_SKINCALL1(id,op,a1)             XENOMAI_SKIN_MUX(1,id,op,a1)
00225 #define XENOMAI_SKINCALL2(id,op,a1,a2)          XENOMAI_SKIN_MUX(2,id,op,a1,a2)
00226 #define XENOMAI_SKINCALL3(id,op,a1,a2,a3)       XENOMAI_SKIN_MUX(3,id,op,a1,a2,a3)
00227 #define XENOMAI_SKINCALL4(id,op,a1,a2,a3,a4)    XENOMAI_SKIN_MUX(4,id,op,a1,a2,a3,a4)
00228 #define XENOMAI_SKINCALL5(id,op,a1,a2,a3,a4,a5) XENOMAI_SKIN_MUX(5,id,op,a1,a2,a3,a4,a5)
00229 
00230 typedef struct xnsysinfo {
00231 
00232     unsigned long long cpufreq; /* CPU frequency */
00233     unsigned long tickval;      /* Tick duration (ns) */
00234 
00235 } xnsysinfo_t;
00236 
00237 typedef struct xninquiry {
00238 
00239     char name[32];
00240     int prio;
00241     unsigned long status;
00242     void *khandle;
00243     void *uhandle;
00244 
00245 } xninquiry_t;
00246 
00247 struct task_struct;
00248 
00249 #endif /* !_RTAI_ASM_I386_XNCALL_H */

Generated on Sat Jul 24 19:36:02 2004 for RTAI API by doxygen 1.3.4