1 
2 /*--------------------------------------------------------------------*/
3 /*--- mips/Linux-specific kernel interface.     vki-mips64-linux.h ---*/
4 /*--------------------------------------------------------------------*/
5 
6 /*
7    This file is part of Valgrind, a dynamic binary instrumentation
8    framework.
9 
10    Copyright (C) 2010-2015 RT-RK
11       mips-valgrind@rt-rk.com
12 
13    This program is free software; you can redistribute it and/or
14    modify it under the terms of the GNU General Public License as
15    published by the Free Software Foundation; either version 2 of the
16    License, or (at your option) any later version.
17 
18    This program is distributed in the hope that it will be useful, but
19    WITHOUT ANY WARRANTY; without even the implied warranty of
20    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
21    General Public License for more details.
22 
23    You should have received a copy of the GNU General Public License
24    along with this program; if not, write to the Free Software
25    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
26    02111-1307, USA.
27 */
28 
29 #ifndef __VKI_MIPS64_LINUX_H
30 #define __VKI_MIPS64_LINUX_H
31 
32 #include <config.h>
33 
34 // mips endian
35 #if defined (_MIPSEL)
36 #define VKI_LITTLE_ENDIAN  1
37 #elif defined (_MIPSEB)
38 #define VKI_BIG_ENDIAN  1
39 #endif
40 
41 //----------------------------------------------------------------------
42 // From linux-2.6.35.9/include/asm-mips/cachectl.h
43 //----------------------------------------------------------------------
44 
45 #define VKI_ICACHE  (1<<0)          /* flush instruction cache        */
46 #define VKI_DCACHE  (1<<1)          /* writeback and flush data cache */
47 #define VKI_BCACHE  (VKI_ICACHE | VKI_DCACHE) /* flush both caches    */
48 
49 //----------------------------------------------------------------------
50 // From linux-2.6.35.9/include/mips-mips/types.h
51 //----------------------------------------------------------------------
52 
53 typedef __signed__ char __vki_s8;
54 typedef unsigned   char __vki_u8;
55 
56 typedef __signed__ short __vki_s16;
57 typedef unsigned   short __vki_u16;
58 
59 typedef __signed__ int __vki_s32;
60 typedef unsigned   int __vki_u32;
61 
62 typedef __signed char vki_s8;
63 typedef unsigned char vki_u8;
64 
65 typedef __signed short vki_s16;
66 typedef unsigned short vki_u16;
67 
68 typedef __signed int vki_s32;
69 typedef unsigned int vki_u32;
70 
71 #if (_MIPS_SZLONG == 64)
72 typedef __signed__ long __vki_s64;
73 typedef unsigned   long __vki_u64;
74 #else
75 typedef __signed__ long long __vki_s64;
76 typedef unsigned   long long __vki_u64;
77 #endif
78 
79 //----------------------------------------------------------------------
80 // From linux-2.6.35.9/include/asm-mips/page.h
81 //----------------------------------------------------------------------
82 
83 /* PAGE_SHIFT determines the page size */
84 #define VKI_PAGE_SHIFT  MIPS_PAGE_SHIFT
85 #define VKI_PAGE_SIZE   (1UL << VKI_PAGE_SHIFT)
86 #define VKI_PAGE_MASK   (~(VKI_PAGE_SIZE-1))
87 #define VKI_MAX_PAGE_SHIFT      VKI_PAGE_SHIFT
88 #define VKI_MAX_PAGE_SIZE       VKI_PAGE_SIZE
89 
90 //----------------------------------------------------------------------
91 // From linux-2.6.35.9/arch/mips/include/bits/shm.h
92 //----------------------------------------------------------------------
93 
94 #define VKI_SHMLBA  0x40000
95 
96 //----------------------------------------------------------------------
97 // From linux-2.6.35.9/include/asm-mips/signal.h
98 //----------------------------------------------------------------------
99 
100 #define VKI_MINSIGSTKSZ 2048
101 
102 #define VKI_SIG_BLOCK   1  /* for blocking signals */
103 #define VKI_SIG_UNBLOCK 2  /* for unblocking signals */
104 #define VKI_SIG_SETMASK 3  /* for setting the signal mask */
105 
106 /* Type of a signal handler.  */
107 typedef void __vki_signalfn_t(int);
108 typedef __vki_signalfn_t __user *__vki_sighandler_t;
109 
110 typedef void __vki_restorefn_t(void);
111 typedef __vki_restorefn_t __user *__vki_sigrestore_t;
112 
113 #define VKI_SIG_DFL     ((__vki_sighandler_t)0)   /* default signal handling */
114 #define VKI_SIG_IGN     ((__vki_sighandler_t)1)   /* ignore signal */
115 #define VKI_SIG_ERR     ((__vki_sighandler_t)-1)  /* error return from signal */
116 
117 #define _VKI_NSIG       128
118 #define _VKI_NSIG_BPW   64
119 #define _VKI_NSIG_WORDS (_VKI_NSIG / _VKI_NSIG_BPW)
120 
121 typedef unsigned long vki_old_sigset_t;  /* at least 32 bits */
122 
123 typedef struct {
124         unsigned long sig[_VKI_NSIG_WORDS];
125 } vki_sigset_t;
126 
127 #define VKI_SIGHUP           1          /* Hangup (POSIX).                    */
128 #define VKI_SIGINT           2          /* Interrupt (ANSI).                  */
129 #define VKI_SIGQUIT          3          /* Quit (POSIX).                      */
130 #define VKI_SIGILL           4          /* Illegal instruction (ANSI).        */
131 #define VKI_SIGTRAP          5          /* Trace trap (POSIX).                */
132 #define VKI_SIGIOT           6          /* IOT trap (4.2 BSD).                */
133 #define VKI_SIGABRT          VKI_SIGIOT /* Abort (ANSI).                      */
134 #define VKI_SIGEMT           7
135 #define VKI_SIGFPE           8          /* Floating-point exception (ANSI).   */
136 #define VKI_SIGKILL          9          /* Kill, unblockable (POSIX).         */
137 #define VKI_SIGBUS          10          /* BUS error (4.2 BSD).               */
138 #define VKI_SIGSEGV         11          /* Segmentation violation (ANSI).     */
139 #define VKI_SIGSYS          12
140 #define VKI_SIGPIPE         13          /* Broken pipe (POSIX).               */
141 #define VKI_SIGALRM         14          /* Alarm clock (POSIX).               */
142 #define VKI_SIGTERM         15          /* Termination (ANSI).                */
143 #define VKI_SIGUSR1         16          /* User-defined signal 1 (POSIX).     */
144 #define VKI_SIGUSR2         17          /* User-defined signal 2 (POSIX).     */
145 #define VKI_SIGCHLD         18          /* Child status has changed (POSIX).  */
146 #define VKI_SIGCLD          VKI_SIGCHLD /* Same as SIGCHLD (System V).        */
147 #define VKI_SIGPWR          19          /* Power failure restart (System V).  */
148 #define VKI_SIGWINCH        20          /* Window size change (4.3 BSD, Sun). */
149 #define VKI_SIGURG          21          /* Urgent condition on socket.        */
150 #define VKI_SIGIO           22          /* I/O now possible (4.2 BSD).        */
151 #define VKI_SIGPOLL         VKI_SIGIO   /* Pollable event occurred (System V).*/
152 #define VKI_SIGSTOP         23          /* Stop, unblockable (POSIX).         */
153 #define VKI_SIGTSTP         24          /* Keyboard stop (POSIX).             */
154 #define VKI_SIGCONT         25          /* Continue (POSIX).                  */
155 #define VKI_SIGTTIN         26          /* Background read from tty (POSIX).  */
156 #define VKI_SIGTTOU         27          /* Background write to tty (POSIX).   */
157 #define VKI_SIGVTALRM       28          /* Virtual alarm clock (4.2 BSD).     */
158 #define VKI_SIGPROF         29          /* Profiling alarm clock (4.2 BSD).   */
159 #define VKI_SIGXCPU         30          /* CPU limit exceeded (4.2 BSD).      */
160 #define VKI_SIGXFSZ         31          /* File size limit exceeded (4.2 BSD).*/
161 
162 /* These should not be considered constants from userland.  */
163 #define VKI_SIGRTMIN    32
164 // [[This was (_NSIG-1) in 2.4.X... not sure if it matters.]]
165 #define VKI_SIGRTMAX    (_VKI_NSIG - 1)
166 
167 #define VKI_SA_ONSTACK      0x08000000u
168 #define VKI_SA_RESETHAND    0x80000000u
169 #define VKI_SA_RESTART      0x10000000u
170 #define VKI_SA_SIGINFO      0x00000008u
171 #define VKI_SA_NODEFER      0x40000000u
172 #define VKI_SA_NOCLDWAIT    0x00010000u
173 #define VKI_SA_NOCLDSTOP    0x00000001u
174 
175 #define VKI_SA_NOMASK           VKI_SA_NODEFER
176 #define VKI_SA_ONESHOT          VKI_SA_RESETHAND
177 //#define VKI_SA_INTERRUPT      0x20000000  /* dummy -- ignored */
178 
179 #define VKI_SA_RESTORER         0x04000000
180 
181 #define VKI_SS_ONSTACK          1
182 #define VKI_SS_DISABLE          2
183 
184 struct vki_old_sigaction {
185        // [[Nb: a 'k' prefix is added to "sa_handler" because
186        // bits/sigaction.h (which gets dragged in somehow via signal.h)
187        // #defines it as something else.  Since that is done for glibc's
188        // purposes, which we don't care about here, we use our own name.]]
189        unsigned long sa_flags;
190        __vki_sighandler_t ksa_handler;
191        vki_old_sigset_t sa_mask;
192        __vki_sigrestore_t sa_restorer;
193 };
194 
195 struct vki_sigaction {
196        unsigned int    sa_flags;
197        __vki_sighandler_t  sa_handler;
198        vki_sigset_t        sa_mask;
199 };
200 
201 
202 struct vki_sigaction_base {
203        // [[See comment about extra 'k' above]]
204        unsigned int sa_flags;
205        __vki_sighandler_t ksa_handler;
206        vki_sigset_t sa_mask;           // mask last for extensibility
207        __vki_sigrestore_t sa_restorer;
208 };
209 
210 /* On Linux we use the same type for passing sigactions to
211    and from the kernel.  Hence: */
212 typedef  struct vki_sigaction_base  vki_sigaction_toK_t;
213 typedef  struct vki_sigaction_base  vki_sigaction_fromK_t;
214 
215 typedef struct vki_sigaltstack {
216         void __user *ss_sp;
217         vki_size_t ss_size;
218         int ss_flags;
219 } vki_stack_t;
220 
221 //----------------------------------------------------------------------
222 // From linux-2.6.35.9/include/asm-mips/sigcontext.h
223 //----------------------------------------------------------------------
224 
225 struct _vki_fpreg {
226        unsigned short significand[4];
227        unsigned short exponent;
228 };
229 
230 struct _vki_fpxreg {
231        unsigned short significand[4];
232        unsigned short exponent;
233        unsigned short padding[3];
234 };
235 
236 struct _vki_xmmreg {
237        unsigned long element[4];
238 };
239 
240 struct _vki_fpstate {
241        /* Regular FPU environment */
242        unsigned long    cw;
243        unsigned long    sw;
244        unsigned long    tag;
245        unsigned long    ipoff;
246        unsigned long    cssel;
247        unsigned long    dataoff;
248        unsigned long    datasel;
249        struct _vki_fpreg    _st[8];
250        unsigned short   status;
251        unsigned short   magic;           /* 0xffff = regular FPU data only */
252 
253        /* FXSR FPU environment */
254        unsigned long    _fxsr_env[6];    /* FXSR FPU env is ignored */
255        unsigned long    mxcsr;
256        unsigned long    reserved;
257        struct _vki_fpxreg   _fxsr_st[8]; /* FXSR FPU reg data is ignored */
258        struct _vki_xmmreg   _xmm[8];
259        unsigned long    padding[56];
260 };
261 
262 //----------------------------------------------------------------------
263 // From linux-2.6.35.9/include/asm-mips/sigcontext.h
264 //----------------------------------------------------------------------
265 struct vki_sigcontext {
266        __vki_u64   sc_regs[32];
267        __vki_u64   sc_fpregs[32];
268        __vki_u64   sc_mdhi;
269        __vki_u64   sc_hi1;
270        __vki_u64   sc_hi2;
271        __vki_u64   sc_hi3;
272        __vki_u64   sc_mdlo;
273        __vki_u64   sc_lo1;
274        __vki_u64   sc_lo2;
275        __vki_u64   sc_lo3;
276        __vki_u64   sc_pc;
277        __vki_u64   sc_fpc_csr;
278        __vki_u64   sc_used_math;
279        __vki_u64   sc_dsp;
280        __vki_u64   sc_reserved;
281 };
282 
283 //----------------------------------------------------------------------
284 // From linux-2.6.35.9/include/asm-mips/mman.h
285 //----------------------------------------------------------------------
286 
287 #define VKI_PROT_NONE       0x0      /* No page permissions */
288 #define VKI_PROT_READ       0x1      /* page can be read */
289 #define VKI_PROT_WRITE      0x2      /* page can be written */
290 #define VKI_PROT_EXEC       0x4      /* page can be executed */
291 #define VKI_PROT_GROWSDOWN  0x01000000  /* mprotect flag: extend change to start
292                                            of growsdown vma */
293 #define VKI_PROT_GROWSUP    0x02000000  /* mprotect flag: extend change to end
294                                            of growsup vma */
295 
296 #define VKI_MAP_SHARED      0x001     /* Share changes */
297 #define VKI_MAP_PRIVATE     0x002     /* Changes are private */
298 //#define VKI_MAP_TYPE      0x0f        /* Mask for type of mapping */
299 #define VKI_MAP_FIXED       0x010     /* Interpret addr exactly */
300 
301 #define VKI_MAP_NORESERVE   0x0400   /* don't reserve swap pages */
302 
303 /* These are linux-specific */
304 #define VKI_MAP_NORESERVE   0x0400          /* don't check for reservations */
305 #define VKI_MAP_ANONYMOUS   0x0800          /* don't use a file */
306 #define VKI_MAP_GROWSDOWN   0x1000          /* stack-like segment */
307 #define VKI_MAP_DENYWRITE   0x2000          /* ETXTBSY */
308 #define VKI_MAP_EXECUTABLE  0x4000          /* mark it as an executable */
309 #define VKI_MAP_LOCKED      0x8000          /* pages are locked */
310 #define VKI_MAP_POPULATE    0x10000         /* populate (prefault) pagetables */
311 #define VKI_MAP_NONBLOCK    0x20000         /* do not block on IO */
312 
313 //----------------------------------------------------------------------
314 // From linux-2.6.35.9/include/asm-mips/fcntl.h
315 //----------------------------------------------------------------------
316 
317 #define VKI_O_RDONLY        00
318 #define VKI_O_WRONLY        01
319 #define VKI_O_RDWR          02
320 #define VKI_O_ACCMODE       03
321 
322 #define VKI_O_CREAT         0x0100      /* not fcntl */
323 #define VKI_O_EXCL          0x0400      /* not fcntl */
324 
325 #define VKI_O_TRUNC         0x0200      /* not fcntl */
326 
327 #define VKI_O_APPEND        0x0008
328 #define VKI_O_NONBLOCK      0x0080
329 #define VKI_O_LARGEFILE     0x2000
330 
331 #define VKI_AT_FDCWD        -100
332 
333 #define VKI_F_DUPFD         0           /* dup */
334 #define VKI_F_GETFD         1           /* get close_on_exec */
335 #define VKI_F_SETFD         2           /* set/clear close_on_exec */
336 #define VKI_F_GETFL         3           /* get file->f_flags */
337 #define VKI_F_SETFL         4           /* set file->f_flags */
338 
339 #define VKI_F_GETLK         14
340 #define VKI_F_SETLK         6
341 #define VKI_F_SETLKW        7
342 
343 #define VKI_F_SETOWN        24          /*  for sockets. */
344 #define VKI_F_GETOWN        23          /*  for sockets. */
345 #define VKI_F_SETSIG        10          /*  for sockets. */
346 #define VKI_F_GETSIG        11          /*  for sockets. */
347 
348 #define VKI_F_SETOWN_EX     15
349 #define VKI_F_GETOWN_EX     16
350 
351 #define VKI_F_OFD_GETLK     36
352 #define VKI_F_OFD_SETLK     37
353 #define VKI_F_OFD_SETLKW    38
354 
355 #define VKI_F_GETLK64       33          /*  using 'struct flock64' */
356 #define VKI_F_SETLK64       34
357 #define VKI_F_SETLKW64      35
358 
359 /* for F_[GET|SET]FL */
360 #define VKI_FD_CLOEXEC      1      /* actually anything with low bit set goes */
361 
362 #define VKI_F_LINUX_SPECIFIC_BASE 1024
363 
364 struct vki_f_owner_ex {
365        int type;
366        __vki_kernel_pid_t pid;
367 };
368 
369 //----------------------------------------------------------------------
370 // From linux-2.6.35.9/include/asm-mips/resource.h
371 //----------------------------------------------------------------------
372 
373 #define VKI_RLIMIT_DATA     2   /* max data size */
374 #define VKI_RLIMIT_STACK    3   /* max stack size */
375 #define VKI_RLIMIT_CORE     4   /* max core file size */
376 #define VKI_RLIMIT_NOFILE   5   /* max number of open files */
377 
378 //----------------------------------------------------------------------
379 // From linux-2.6.35.9/include/asm-mips/socket.h
380 //----------------------------------------------------------------------
381 
382 #define VKI_SOL_SOCKET   0xffff
383 
384 #define VKI_SO_TYPE      0x1008
385 
386 #define VKI_SO_ATTACH_FILTER	26
387 
388 //----------------------------------------------------------------------
389 // From linux-2.6.35.9/include/asm-i386/sockios.h
390 //----------------------------------------------------------------------
391 
392 #define VKI_SIOCSPGRP           0x8902
393 #define VKI_SIOCGPGRP           0x8904
394 #define VKI_SIOCATMARK          0x8905
395 #define VKI_SIOCGSTAMP          0x8906      /* Get stamp (timeval) */
396 #define VKI_SIOCGSTAMPNS        0x8907      /* Get stamp (timespec) */
397 
398 //----------------------------------------------------------------------
399 // From linux-2.6.35.9/include/asm-mips/stat.h
400 //----------------------------------------------------------------------
401 
402 struct vki_stat {
403         unsigned int    st_dev;
404         unsigned int    st_pad0[3];     /* Reserved for st_dev expansion  */
405 
406         unsigned long   st_ino;
407 
408         int             st_mode;
409         unsigned int    st_nlink;
410 
411         unsigned int    st_uid;
412         unsigned int    st_gid;
413 
414         unsigned int    st_rdev;
415         unsigned int    st_pad1[3];     /* Reserved for st_rdev expansion  */
416 
417         long            st_size;
418 
419         /*
420          * Actually this should be timestruc_t st_atime, st_mtime and st_ctime
421          * but we don't have it under Linux.
422          */
423         unsigned int    st_atime;
424         unsigned int    st_atime_nsec;  /* Reserved for st_atime expansion  */
425 
426         unsigned int    st_mtime;
427         unsigned int    st_mtime_nsec;  /* Reserved for st_mtime expansion  */
428 
429         unsigned int    st_ctime;
430         unsigned int    st_ctime_nsec;  /* Reserved for st_ctime expansion  */
431 
432         unsigned int    st_blksize;
433         unsigned int    st_pad2;
434 
435         long long       st_blocks;
436 };
437 
438 struct vki_stat64 {
439         unsigned long   st_dev;
440         unsigned long   st_pad0[3];     /* Reserved for st_dev expansion  */
441 
442         unsigned long long      st_ino;
443 
444         int             st_mode;
445         unsigned int    st_nlink;
446 
447         unsigned int    st_uid;
448         unsigned int    st_gid;
449 
450         unsigned long   st_rdev;
451         unsigned long   st_pad1[3];     /* Reserved for st_rdev expansion  */
452 
453         long long       st_size;
454 
455         /*
456          * Actually this should be timestruc_t st_atime, st_mtime and st_ctime
457          * but we don't have it under Linux.
458          */
459         unsigned long   st_atime;
460         unsigned long   st_atime_nsec;  /* Reserved for st_atime expansion  */
461 
462         unsigned long   st_mtime;
463         unsigned long   st_mtime_nsec;  /* Reserved for st_mtime expansion  */
464 
465         unsigned long   st_ctime;
466         unsigned long   st_ctime_nsec;  /* Reserved for st_ctime expansion  */
467 
468         unsigned long   st_blksize;
469         unsigned long   st_pad2;
470 
471         long long       st_blocks;
472 };
473 
474 //----------------------------------------------------------------------
475 // From linux-2.6.35.9/include/asm-mips/statfs.h
476 //----------------------------------------------------------------------
477 
478 struct vki_statfs {
479        __vki_u32 f_type;
480 #define f_fstyp f_type
481        __vki_u32 f_bsize;
482        __vki_u32 f_frsize;
483        __vki_u32 f_blocks;
484        __vki_u32 f_bfree;
485        __vki_u32 f_files;
486        __vki_u32 f_ffree;
487        __vki_u32 f_bavail;
488        __vki_kernel_fsid_t f_fsid;
489        __vki_u32 f_namelen;
490        __vki_u32 f_spare[6];
491 };
492 
493 //----------------------------------------------------------------------
494 // From linux-2.6.35.9/include/asm-mips/termios.h
495 //----------------------------------------------------------------------
496 
497 struct vki_winsize {
498        unsigned short ws_row;
499        unsigned short ws_col;
500        unsigned short ws_xpixel;
501        unsigned short ws_ypixel;
502 };
503 
504 #define NCC     8
505 #define NCCS    23
506 struct vki_termio {
507        unsigned short c_iflag;      /* input mode flags */
508        unsigned short c_oflag;      /* output mode flags */
509        unsigned short c_cflag;      /* control mode flags */
510        unsigned short c_lflag;      /* local mode flags */
511        char           c_line;       /* line discipline */
512        unsigned char  c_cc[NCCS];   /* control characters */
513 };
514 
515 //----------------------------------------------------------------------
516 // From linux-2.6.35.9/include/asm-mips/termbits.h
517 //----------------------------------------------------------------------
518 
519 typedef unsigned char   vki_cc_t;
520 typedef unsigned long   vki_speed_t;
521 typedef unsigned long   vki_tcflag_t;
522 
523 struct vki_termios {
524        vki_tcflag_t c_iflag;        /* input mode flags */
525        vki_tcflag_t c_oflag;        /* output mode flags */
526        vki_tcflag_t c_cflag;        /* control mode flags */
527        vki_tcflag_t c_lflag;        /* local mode flags */
528        vki_cc_t c_line;             /* line discipline */
529        vki_cc_t c_cc[NCCS];         /* control characters */
530 };
531 
532 //----------------------------------------------------------------------
533 // From linux-2.6.35.9/include/asm-mips/ioctl.h
534 //----------------------------------------------------------------------
535 
536 #define _VKI_IOC_NRBITS     8
537 #define _VKI_IOC_TYPEBITS   8
538 #define _VKI_IOC_SIZEBITS   13
539 #define _VKI_IOC_DIRBITS    3
540 
541 #define _VKI_IOC_NRMASK     ((1 << _VKI_IOC_NRBITS)-1)
542 #define _VKI_IOC_TYPEMASK   ((1 << _VKI_IOC_TYPEBITS)-1)
543 #define _VKI_IOC_SIZEMASK   ((1 << _VKI_IOC_SIZEBITS)-1)
544 #define _VKI_IOC_DIRMASK    ((1 << _VKI_IOC_DIRBITS)-1)
545 
546 #define _VKI_IOC_NRSHIFT    0
547 #define _VKI_IOC_TYPESHIFT  (_VKI_IOC_NRSHIFT+_VKI_IOC_NRBITS)
548 #define _VKI_IOC_SIZESHIFT  (_VKI_IOC_TYPESHIFT+_VKI_IOC_TYPEBITS)
549 #define _VKI_IOC_DIRSHIFT   (_VKI_IOC_SIZESHIFT+_VKI_IOC_SIZEBITS)
550 
551 #define _VKI_IOC_NONE   1U
552 #define _VKI_IOC_READ   2U
553 #define _VKI_IOC_WRITE  4U
554 
555 #define _VKI_IOC(dir,type,nr,size) \
556                 (((dir)  << _VKI_IOC_DIRSHIFT) | \
557                 ((type) << _VKI_IOC_TYPESHIFT) | \
558                 ((nr)   << _VKI_IOC_NRSHIFT) | \
559                 ((size) << _VKI_IOC_SIZESHIFT))
560 
561 /* provoke compile error for invalid uses of size argument */
562 extern unsigned int __VKI_invalid_size_argument_for_IOC;
563 /* used to create numbers */
564 #define _VKI_IO(type,nr)        _VKI_IOC(_VKI_IOC_NONE,(type),(nr),0)
565 #define _VKI_IOR(type,nr,size)  _VKI_IOC(_VKI_IOC_READ,(type),(nr), \
566                                 (_VKI_IOC_TYPECHECK(size)))
567 #define _VKI_IOW(type,nr,size)  _VKI_IOC(_VKI_IOC_WRITE,(type),(nr), \
568                                 (_VKI_IOC_TYPECHECK(size)))
569 #define _VKI_IOWR(type,nr,size) _VKI_IOC(_VKI_IOC_READ|_VKI_IOC_WRITE,(type), \
570                                 (nr),(_VKI_IOC_TYPECHECK(size)))
571 
572 /* used to decode ioctl numbers.. */
573 #define _VKI_IOC_DIR(nr)    (((nr) >> _VKI_IOC_DIRSHIFT) & _VKI_IOC_DIRMASK)
574 #define _VKI_IOC_TYPE(nr)   (((nr) >> _VKI_IOC_TYPESHIFT) & _VKI_IOC_TYPEMASK)
575 #define _VKI_IOC_NR(nr)     (((nr) >> _VKI_IOC_NRSHIFT) & _VKI_IOC_NRMASK)
576 #define _VKI_IOC_SIZE(nr)   (((nr) >> _VKI_IOC_SIZESHIFT) & _VKI_IOC_SIZEMASK)
577 
578 //----------------------------------------------------------------------
579 // From linux-2.6.35.9/include/asm-mips/ioctls.h
580 //----------------------------------------------------------------------
581 
582 #define VKI_TCGETA              0x5401
583 #define VKI_TCSETA              0x5402 /* Clashes with SNDCTL_TMR_START
584                                           sound ioctl */
585 #define VKI_TCSETAW             0x5403
586 #define VKI_TCSETAF             0x5404
587 
588 #define VKI_TCSBRK              0x5405
589 #define VKI_TCXONC              0x5406
590 #define VKI_TCFLSH              0x5407
591 
592 #define VKI_TCGETS              0x540d
593 #define VKI_TCSETS              0x540e
594 #define VKI_TCSETSW             0x540f
595 #define VKI_TCSETSF             0x5410
596 
597 #define VKI_TIOCEXCL            0x740d  /* set exclusive use of tty */
598 #define VKI_TIOCNXCL            0x740e  /* reset exclusive use of tty */
599 #define VKI_TIOCOUTQ            0x7472  /* output queue size */
600 #define VKI_TIOCSTI             0x5472  /* simulate terminal input */
601 #define VKI_TIOCMGET            0x741d  /* get all modem bits */
602 #define VKI_TIOCMBIS            0x741b  /* bis modem bits */
603 #define VKI_TIOCMBIC            0x741c  /* bic modem bits */
604 #define VKI_TIOCMSET            0x741a  /* set all modem bits */
605 #define VKI_TIOCPKT             0x5470  /* pty: set/clear packet mode */
606 #define VKI_TIOCPKT_DATA        0x00    /* data packet */
607 #define VKI_TIOCPKT_FLUSHREAD   0x01    /* flush packet */
608 #define VKI_TIOCPKT_FLUSHWRITE  0x02    /* flush packet */
609 #define VKI_TIOCPKT_STOP        0x04    /* stop output */
610 #define VKI_TIOCPKT_START       0x08    /* start output */
611 #define VKI_TIOCPKT_NOSTOP      0x10    /* no more ^S, ^Q */
612 #define VKI_TIOCPKT_DOSTOP      0x20    /* now do ^S ^Q */
613 
614 /* set window size */
615 #define VKI_TIOCSWINSZ          _VKI_IOW('t', 103, struct vki_winsize)
616 /* get window size */
617 #define VKI_TIOCGWINSZ          _VKI_IOR('t', 104, struct vki_winsize)
618 #define VKI_TIOCNOTTY           0x5471 /* void tty association */
619 #define VKI_TIOCSETD            0x7401
620 #define VKI_TIOCGETD            0x7400
621 
622 #define VKI_FIOCLEX             0x6601
623 #define VKI_FIONCLEX            0x6602
624 #define VKI_FIOASYNC            0x667d
625 #define VKI_FIONBIO             0x667e
626 #define VKI_FIOQSIZE            0x667f
627 
628 #define VKI_TIOCGLTC            0x7474 /* get special local chars */
629 #define VKI_TIOCSLTC            0x7475 /* set special local chars */
630 #define VKI_TIOCSPGRP           _VKI_IOW('t', 118, int) /* set pgrp of tty */
631 #define VKI_TIOCGPGRP           _VKI_IOR('t', 119, int) /* get pgrp of tty */
632 #define VKI_TIOCCONS            _VKI_IOW('t', 120, int) /* become virtual
633                                                            console */
634 
635 #define VKI_FIONREAD            0x467f
636 #define VKI_TIOCINQ             FIONREAD
637 
638 #define VKI_TIOCGETP            0x7408
639 #define VKI_TIOCSETP            0x7409
640 #define VKI_TIOCSETN            0x740a /* TIOCSETP wo flush */
641 
642 #define VKI_TIOCSBRK            0x5427 /* BSD compatibility */
643 #define VKI_TIOCCBRK            0x5428 /* BSD compatibility */
644 #define VKI_TIOCGSID            0x7416 /* Return the session ID of FD */
645 #define VKI_TIOCGPTN            _VKI_IOR('T',0x30, unsigned int) /* Get Pty
646                                                    Number (of pty-mux device) */
647 #define VKI_TIOCSPTLCK          _VKI_IOW('T',0x31, int) /* Lock/unlock Pty */
648 
649 /* I hope the range from 0x5480 on is free ... */
650 #define VKI_TIOCSCTTY           0x5480 /* become controlling tty */
651 #define VKI_TIOCGSOFTCAR        0x5481
652 #define VKI_TIOCSSOFTCAR        0x5482
653 #define VKI_TIOCLINUX           0x5483
654 #define VKI_TIOCGSERIAL         0x5484
655 #define VKI_TIOCSSERIAL         0x5485
656 #define VKI_TCSBRKP             0x5486 /* Needed for POSIX tcsendbreak() */
657 #define VKI_TIOCSERCONFIG       0x5488
658 #define VKI_TIOCSERGWILD        0x5489
659 #define VKI_TIOCSERSWILD        0x548a
660 #define VKI_TIOCGLCKTRMIOS      0x548b
661 #define VKI_TIOCSLCKTRMIOS      0x548c
662 #define VKI_TIOCSERGSTRUCT      0x548d /* For debugging only */
663 #define VKI_TIOCSERGETLSR       0x548e /* Get line status register */
664 #define VKI_TIOCSERGETMULTI     0x548f /* Get multiport config  */
665 #define VKI_TIOCSERSETMULTI     0x5490 /* Set multiport config */
666 #define VKI_TIOCMIWAIT          0x5491 /* wait for a change on serial input
667                                           line(s) */
668 #define VKI_TIOCGICOUNT         0x5492 /* read serial port inline interrupt
669                                           counts */
670 #define VKI_TIOCGHAYESESP       0x5493 /* Get Hayes ESP configuration */
671 #define VKI_TIOCSHAYESESP       0x5494 /* Set Hayes ESP configuration */
672 
673 //----------------------------------------------------------------------
674 // From asm-generic/poll.h
675 //----------------------------------------------------------------------
676 
677 /* These are specified by iBCS2 */
678 #define VKI_POLLIN              0x0001
679 
680 struct vki_pollfd {
681        int fd;
682        short events;
683        short revents;
684 };
685 //----------------------------------------------------------------------
686 // From linux-2.6.35.9/include/asm-mips/elf.h
687 //----------------------------------------------------------------------
688 
689 #define VKI_ELF_NGREG           45  /* includes nip, msr, lr, etc. */
690 #define VKI_ELF_NFPREG          33  /* includes fpscr */
691 
692 typedef unsigned long vki_elf_greg_t;
693 typedef vki_elf_greg_t vki_elf_gregset_t[VKI_ELF_NGREG];
694 
695 typedef double vki_elf_fpreg_t;
696 typedef vki_elf_fpreg_t vki_elf_fpregset_t[VKI_ELF_NFPREG];
697 
698 typedef struct vki_user_fxsr_struct vki_elf_fpxregset_t;
699 
700 #define VKI_AT_SYSINFO          32
701 //----------------------------------------------------------------------
702 // From linux-2.6.35.9/include/asm-mips/ucontext.h
703 //----------------------------------------------------------------------
704 
705 struct vki_ucontext {
706        unsigned long          uc_flags;
707        struct vki_ucontext    *uc_link;
708        vki_stack_t            uc_stack;
709        struct vki_sigcontext  uc_mcontext;
710        vki_sigset_t           uc_sigmask;  /* mask last for extensibility */
711 };
712 
713 //----------------------------------------------------------------------
714 // From linux-2.6.35.9/include/asm-mips/ipcbuf.h
715 //----------------------------------------------------------------------
716 
717 struct vki_ipc64_perm {
718        __vki_kernel_key_t  key;
719        __vki_kernel_uid_t  uid;
720        __vki_kernel_gid_t  gid;
721        __vki_kernel_uid_t  cuid;
722        __vki_kernel_gid_t  cgid;
723        __vki_kernel_mode_t mode;
724        unsigned short  seq;
725        unsigned short  __pad1;
726        unsigned long   __unused1;
727        unsigned long   __unused2;
728 };
729 
730 //----------------------------------------------------------------------
731 // From linux-2.6.35.9/include/asm-mips/sembuf.h
732 //----------------------------------------------------------------------
733 
734 struct vki_semid64_ds {
735        struct vki_ipc64_perm sem_perm;         /* permissions .. see ipc.h */
736        __vki_kernel_time_t sem_otime;          /* last semop time */
737        __vki_kernel_time_t sem_ctime;          /* last change time */
738        unsigned long   sem_nsems;              /* no. of semaphores in array */
739        unsigned long   __unused1;
740        unsigned long   __unused2;
741 };
742 
743 //----------------------------------------------------------------------
744 // From linux-2.6.35.9/include/asm-mips/msgbuf.h
745 //----------------------------------------------------------------------
746 
747 struct vki_msqid64_ds {
748        struct vki_ipc64_perm msg_perm;
749        __vki_kernel_time_t msg_stime;     /* last msgsnd time */
750        __vki_kernel_time_t msg_rtime;     /* last msgrcv time */
751        __vki_kernel_time_t msg_ctime;     /* last change time */
752        unsigned long  msg_cbytes;         /* current number of bytes on queue */
753        unsigned long  msg_qnum;           /* number of messages in queue */
754        unsigned long  msg_qbytes;         /* max number of bytes on queue */
755        __vki_kernel_pid_t msg_lspid;      /* pid of last msgsnd */
756        __vki_kernel_pid_t msg_lrpid;      /* last receive pid */
757        unsigned long  __unused4;
758        unsigned long  __unused5;
759 };
760 
761 //----------------------------------------------------------------------
762 // From linux-2.6.35.9/include/asm-mips/ipc.h
763 //----------------------------------------------------------------------
764 
765 struct vki_ipc_kludge {
766        struct vki_msgbuf __user *msgp;
767        long msgtyp;
768 };
769 
770 #define VKI_SEMOP            1
771 #define VKI_SEMGET           2
772 #define VKI_SEMCTL           3
773 #define VKI_SEMTIMEDOP       4
774 #define VKI_MSGSND          11
775 #define VKI_MSGRCV          12
776 #define VKI_MSGGET          13
777 #define VKI_MSGCTL          14
778 #define VKI_SHMAT           21
779 #define VKI_SHMDT           22
780 #define VKI_SHMGET          23
781 #define VKI_SHMCTL          24
782 
783 //----------------------------------------------------------------------
784 // From linux-2.6.35.9/include/asm-mips/shmbuf.h
785 //----------------------------------------------------------------------
786 
787 struct vki_shmid64_ds {
788        struct vki_ipc64_perm       shm_perm;       /* operation perms */
789        vki_size_t                  shm_segsz;      /* size of segment (bytes) */
790        __vki_kernel_time_t         shm_atime;      /* last attach time */
791        __vki_kernel_time_t         shm_dtime;      /* last detach time */
792        __vki_kernel_time_t         shm_ctime;      /* last change time */
793        __vki_kernel_pid_t          shm_cpid;       /* pid of creator */
794        __vki_kernel_pid_t          shm_lpid;       /* pid of last operator */
795        unsigned long               shm_nattch;     /* no. of current attaches */
796        unsigned long               __unused1;
797        unsigned long               __unused2;
798 };
799 
800 struct vki_shminfo64 {
801        unsigned long   shmmax;
802        unsigned long   shmmin;
803        unsigned long   shmmni;
804        unsigned long   shmseg;
805        unsigned long   shmall;
806        unsigned long   __unused1;
807        unsigned long   __unused2;
808        unsigned long   __unused3;
809        unsigned long   __unused4;
810 };
811 
812 //----------------------------------------------------------------------
813 // From linux-2.6.35.9/include/asm-mips/ptrace.h
814 //----------------------------------------------------------------------
815 
816 struct vki_pt_regs {
817 #ifdef CONFIG_32BIT
818         /* Pad bytes for argument save space on the stack. */
819        unsigned long pad0[6];
820 #endif
821 
822        /* Saved main processor registers. */
823        unsigned long regs[32];
824 
825        /* Saved special registers. */
826        unsigned long cp0_status;
827        unsigned long hi;
828        unsigned long lo;
829 #ifdef CONFIG_CPU_HAS_SMARTMIPS
830        unsigned long acx;
831 #endif
832        unsigned long cp0_badvaddr;
833        unsigned long cp0_cause;
834        unsigned long cp0_epc;
835 #ifdef CONFIG_MIPS_MT_SMTC
836        unsigned long cp0_tcstatus;
837 #endif /* CONFIG_MIPS_MT_SMTC */
838 #ifdef CONFIG_CPU_CAVIUM_OCTEON
839        unsigned long long mpl[3];        /* MTM{0,1,2} */
840        unsigned long long mtp[3];        /* MTP{0,1,2} */
841 #endif
842 } __attribute__ ((aligned (8)));
843 
844 
845 #define vki_user_regs_struct vki_pt_regs
846 
847 #define MIPS_lo     lo
848 #define MIPS_hi     hi
849 #define MIPS_r31    regs[31]
850 #define MIPS_r30    regs[30]
851 #define MIPS_r29    regs[29]
852 #define MIPS_r28    regs[28]
853 #define MIPS_r27    regs[27]
854 #define MIPS_r26    regs[26]
855 #define MIPS_r25    regs[25]
856 #define MIPS_r24    regs[24]
857 #define MIPS_r23    regs[23]
858 #define MIPS_r22    regs[22]
859 #define MIPS_r21    regs[21]
860 #define MIPS_r20    regs[20]
861 #define MIPS_r19    regs[19]
862 #define MIPS_r18    regs[18]
863 #define MIPS_r17    regs[17]
864 #define MIPS_r16    regs[16]
865 #define MIPS_r15    regs[15]
866 #define MIPS_r14    regs[14]
867 #define MIPS_r13    regs[13]
868 #define MIPS_r12    regs[12]
869 #define MIPS_r11    regs[11]
870 #define MIPS_r10    regs[10]
871 #define MIPS_r9     regs[9]
872 #define MIPS_r8     regs[8]
873 #define MIPS_r7     regs[7]
874 #define MIPS_r6     regs[6]
875 #define MIPS_r5     regs[5]
876 #define MIPS_r4     regs[4]
877 #define MIPS_r3     regs[3]
878 #define MIPS_r2     regs[2]
879 #define MIPS_r1     regs[1]
880 #define MIPS_r0     regs[0]
881 
882 //----------------------------------------------------------------------
883 // From linux-2.6.35.9/include/asm-i386/ptrace.h
884 //----------------------------------------------------------------------
885 
886 #define VKI_PTRACE_GETREGS            12
887 #define VKI_PTRACE_SETREGS            13
888 #define VKI_PTRACE_GETFPREGS          14
889 #define VKI_PTRACE_SETFPREGS          15
890 #define VKI_PTRACE_GETFPXREGS         18
891 #define VKI_PTRACE_SETFPXREGS         19
892 
893 /* Calls to trace a 64bit program from a 32bit program.  */
894 #define VKI_PTRACE_PEEKTEXT_3264    0xc0
895 #define VKI_PTRACE_PEEKDATA_3264    0xc1
896 #define VKI_PTRACE_POKETEXT_3264    0xc2
897 #define VKI_PTRACE_POKEDATA_3264    0xc3
898 #define VKI_PTRACE_GET_THREAD_AREA_3264     0xc4s
899 
900 //----------------------------------------------------------------------
901 // From linux-2.6.35.9/include/asm-generic/siginfo.h
902 //----------------------------------------------------------------------
903 
904 #define HAVE_ARCH_SIGINFO_T
905 typedef union vki_sigval {
906         int sival_int;
907         void __user *sival_ptr;
908 } vki_sigval_t;
909 
910 #ifndef __VKI_ARCH_SI_PREAMBLE_SIZE
911 #define __VKI_ARCH_SI_PREAMBLE_SIZE (4 * sizeof(int))
912 #endif
913 
914 #define VKI_SI_MAX_SIZE 128
915 
916 #ifndef VKI_SI_PAD_SIZE
917 #define VKI_SI_PAD_SIZE ((VKI_SI_MAX_SIZE - __VKI_ARCH_SI_PREAMBLE_SIZE) / sizeof(int))
918 #endif
919 
920 #ifndef __VKI_ARCH_SI_UID_T
921 #define __VKI_ARCH_SI_UID_T vki_uid_t
922 #endif
923 
924 #ifndef __VKI_ARCH_SI_BAND_T
925 #define __VKI_ARCH_SI_BAND_T long
926 #endif
927 
928 typedef struct vki_siginfo {
929         int si_signo;
930         int si_code;
931         int si_errno;
932         int __pad0[VKI_SI_MAX_SIZE / sizeof(int) - VKI_SI_PAD_SIZE - 3];
933 
934         union {
935                 int _pad[VKI_SI_PAD_SIZE];
936 
937                 /* kill() */
938                 struct {
939                         vki_pid_t _pid;             /* sender's pid */
940                         __VKI_ARCH_SI_UID_T _uid;   /* sender's uid */
941                 } _kill;
942 
943                 /* POSIX.1b timers */
944                 struct {
945                         vki_timer_t _tid;           /* timer id */
946                         int _overrun;           /* overrun count */
947                         char _pad[sizeof( __VKI_ARCH_SI_UID_T) - sizeof(int)];
948                         vki_sigval_t _sigval;       /* same as below */
949                         int _sys_private;       /* not to be passed to user */
950                 } _timer;
951 
952                 /* POSIX.1b signals */
953                 struct {
954                         vki_pid_t _pid;             /* sender's pid */
955                         __VKI_ARCH_SI_UID_T _uid;   /* sender's uid */
956                         vki_sigval_t _sigval;
957                 } _rt;
958 
959                 /* SIGCHLD */
960                 struct {
961                         vki_pid_t _pid;             /* which child */
962                         __VKI_ARCH_SI_UID_T _uid;   /* sender's uid */
963                         int _status;            /* exit code */
964                         vki_clock_t _utime;
965                         vki_clock_t _stime;
966                 } _sigchld;
967 
968                 /* IRIX SIGCHLD */
969                 struct {
970                         vki_pid_t _pid;             /* which child */
971                         vki_clock_t _utime;
972                         int _status;            /* exit code */
973                         vki_clock_t _stime;
974                 } _irix_sigchld;
975 
976                 /* SIGILL, SIGFPE, SIGSEGV, SIGBUS */
977                 struct {
978                         void __user *_addr; /* faulting insn/memory ref. */
979 #ifdef __ARCH_SI_TRAPNO
980                         int _trapno;    /* TRAP # which caused the signal */
981 #endif
982                 } _sigfault;
983 
984                 /* SIGPOLL, SIGXFSZ (To do ...)  */
985                 struct {
986                         __VKI_ARCH_SI_BAND_T _band; /* POLL_IN, POLL_OUT, POLL_MSG */
987                         int _fd;
988                 } _sigpoll;
989         } _sifields;
990 } vki_siginfo_t;
991 
992 //----------------------------------------------------------------------
993 // From linux-2.6.35.5/include/asm/break.h
994 //----------------------------------------------------------------------
995 #define VKI_BRK_OVERFLOW 6  /* Overflow check */
996 #define VKI_BRK_DIVZERO  7  /* Divide by zero check */
997 
998 //----------------------------------------------------------------------
999 // From linux-3.6.35.5/arch/mips/include/socket.h
1000 //----------------------------------------------------------------------
1001 enum vki_sock_type {
1002         VKI_SOCK_STREAM = 2,
1003         // [[others omitted]]
1004 };
1005 #define ARCH_HAS_SOCKET_TYPES 1
1006 
1007 //----------------------------------------------------------------------
1008 // From linux-3.13.0/include/asm/errno.h
1009 //----------------------------------------------------------------------
1010 
1011 #define	VKI_ENOSYS       89  /* Function not implemented */
1012 #define	VKI_EOVERFLOW    79  /* Value too large for defined data type */
1013 
1014 #endif // __VKI_MIPS64_LINUX_H
1015 
1016 /*--------------------------------------------------------------------*/
1017 /*--- end                                       vki-mips64-linux.h ---*/
1018 /*--------------------------------------------------------------------*/
1019