1 
2 /*--------------------------------------------------------------------*/
3 /*--- PPC32/Linux-specific kernel interface.     vki-ppc32-linux.h ---*/
4 /*--------------------------------------------------------------------*/
5 
6 /*
7    This file is part of Valgrind, a dynamic binary instrumentation
8    framework.
9 
10    Copyright (C) 2005-2015 Julian Seward
11       jseward@acm.org
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    The GNU General Public License is contained in the file COPYING.
29 */
30 
31 #ifndef __VKI_PPC32_LINUX_H
32 #define __VKI_PPC32_LINUX_H
33 
34 // ppc32 is big-endian.
35 #define VKI_BIG_ENDIAN  1
36 
37 //----------------------------------------------------------------------
38 // From linux-2.6.9/include/asm-ppc/types.h
39 //----------------------------------------------------------------------
40 
41 typedef unsigned char __vki_u8;
42 
43 typedef __signed__ short __vki_s16;
44 typedef unsigned short __vki_u16;
45 
46 typedef __signed__ int __vki_s32;
47 typedef unsigned int __vki_u32;
48 
49 typedef __signed__ long long __vki_s64;
50 typedef unsigned long long __vki_u64;
51 
52 typedef unsigned short vki_u16;
53 
54 typedef unsigned int vki_u32;
55 
56 typedef struct {
57         __vki_u32 u[4];
58 } __vki_vector128;
59 
60 //----------------------------------------------------------------------
61 // From linux-2.6.9/include/asm-ppc/page.h
62 //----------------------------------------------------------------------
63 
64 /* PAGE_SHIFT determines the page size, unfortunately
65    page size might vary between 32-bit and 64-bit ppc kernels */
66 extern UWord VKI_PAGE_SHIFT;
67 extern UWord VKI_PAGE_SIZE;
68 #define VKI_MAX_PAGE_SHIFT	16
69 #define VKI_MAX_PAGE_SIZE	(1UL << VKI_MAX_PAGE_SHIFT)
70 
71 //----------------------------------------------------------------------
72 // From linux-2.6.35.4/arch/powerpc/include/asm/shmparam.h
73 //----------------------------------------------------------------------
74 
75 #define VKI_SHMLBA  VKI_PAGE_SIZE
76 
77 //----------------------------------------------------------------------
78 // From linux-2.6.9/include/asm-ppc/signal.h
79 //----------------------------------------------------------------------
80 
81 #define VKI_MINSIGSTKSZ	2048
82 
83 #define VKI_SIG_BLOCK         0    /* for blocking signals */
84 #define VKI_SIG_UNBLOCK       1    /* for unblocking signals */
85 #define VKI_SIG_SETMASK       2    /* for setting the signal mask */
86 
87 /* Type of a signal handler.  */
88 typedef void __vki_signalfn_t(int);
89 typedef __vki_signalfn_t __user *__vki_sighandler_t;
90 
91 typedef void __vki_restorefn_t(void);
92 typedef __vki_restorefn_t __user *__vki_sigrestore_t;
93 
94 #define VKI_SIG_DFL     ((__vki_sighandler_t)0)     /* default signal handling */
95 #define VKI_SIG_IGN     ((__vki_sighandler_t)1)     /* ignore signal */
96 
97 #define _VKI_NSIG       64
98 #define _VKI_NSIG_BPW	32
99 #define _VKI_NSIG_WORDS	(_VKI_NSIG / _VKI_NSIG_BPW)
100 
101 typedef unsigned long vki_old_sigset_t;		/* at least 32 bits */
102 
103 typedef struct {
104         unsigned long sig[_VKI_NSIG_WORDS];
105 } vki_sigset_t;
106 
107 #define VKI_SIGHUP		 1
108 #define VKI_SIGINT		 2
109 #define VKI_SIGQUIT		 3
110 #define VKI_SIGILL		 4
111 #define VKI_SIGTRAP		 5
112 #define VKI_SIGABRT		 6
113 //#define VKI_SIGIOT		 6
114 #define VKI_SIGBUS		 7
115 #define VKI_SIGFPE		 8
116 #define VKI_SIGKILL		 9
117 #define VKI_SIGUSR1		10
118 #define VKI_SIGSEGV		11
119 #define VKI_SIGUSR2		12
120 #define VKI_SIGPIPE		13
121 #define VKI_SIGALRM		14
122 #define VKI_SIGTERM		15
123 #define VKI_SIGSTKFLT		16
124 #define VKI_SIGCHLD		17
125 #define VKI_SIGCONT		18
126 #define VKI_SIGSTOP		19
127 #define VKI_SIGTSTP		20
128 #define VKI_SIGTTIN		21
129 #define VKI_SIGTTOU		22
130 #define VKI_SIGURG		23
131 #define VKI_SIGXCPU		24
132 #define VKI_SIGXFSZ		25
133 #define VKI_SIGVTALRM		26
134 #define VKI_SIGPROF		27
135 #define VKI_SIGWINCH		28
136 #define VKI_SIGIO		29
137 #define VKI_SIGPWR		30
138 #define VKI_SIGSYS		31
139 #define VKI_SIGUNUSED		31
140 
141 /* These should not be considered constants from userland.  */
142 #define VKI_SIGRTMIN    32
143 // [[This was (_NSIG-1) in 2.4.X... not sure if it matters.]]
144 #define VKI_SIGRTMAX    _VKI_NSIG
145 
146 #define VKI_SA_NOCLDSTOP	0x00000001
147 #define VKI_SA_NOCLDWAIT	0x00000002
148 #define VKI_SA_SIGINFO		0x00000004
149 #define VKI_SA_ONSTACK		0x08000000
150 #define VKI_SA_RESTART		0x10000000
151 #define VKI_SA_NODEFER		0x40000000
152 #define VKI_SA_RESETHAND	0x80000000
153 
154 #define VKI_SA_NOMASK		VKI_SA_NODEFER
155 #define VKI_SA_ONESHOT		VKI_SA_RESETHAND
156 //#define VKI_SA_INTERRUPT	0x20000000 /* dummy -- ignored */
157 
158 #define VKI_SA_RESTORER		0x04000000
159 
160 #define VKI_SS_ONSTACK		1
161 #define VKI_SS_DISABLE		2
162 
163 /* These are 'legacy' sigactions in which the size of sa_mask is fixed
164    (cannot be expanded at any future point) because it is sandwiched
165    between two other fields.
166    (there is identical kludgery in vki-x86-linux.h) */
167 struct vki_old_sigaction {
168         // [[Nb: a 'k' prefix is added to "sa_handler" because
169         // bits/sigaction.h (which gets dragged in somehow via signal.h)
170         // #defines it as something else.  Since that is done for glibc's
171         // purposes, which we don't care about here, we use our own name.]]
172         __vki_sighandler_t ksa_handler;
173         vki_old_sigset_t sa_mask;
174         unsigned long sa_flags;
175         __vki_sigrestore_t sa_restorer;
176 };
177 
178 struct vki_sigaction_base {
179         // [[See comment about extra 'k' above]]
180 	__vki_sighandler_t ksa_handler;
181 	unsigned long sa_flags;
182 	__vki_sigrestore_t sa_restorer;
183 	vki_sigset_t sa_mask;		/* mask last for extensibility */
184 };
185 
186 /* On Linux we use the same type for passing sigactions to
187    and from the kernel.  Hence: */
188 typedef  struct vki_sigaction_base  vki_sigaction_toK_t;
189 typedef  struct vki_sigaction_base  vki_sigaction_fromK_t;
190 
191 
192 typedef struct vki_sigaltstack {
193 	void __user *ss_sp;
194 	int ss_flags;
195 	vki_size_t ss_size;
196 } vki_stack_t;
197 
198 
199 //----------------------------------------------------------------------
200 // From linux-2.6.9/include/asm-ppc/ptrace.h
201 //----------------------------------------------------------------------
202 
203 struct vki_pt_regs {
204         unsigned long gpr[32];
205         unsigned long nip;
206         unsigned long msr;
207         unsigned long orig_gpr3;        /* Used for restarting system calls */
208         unsigned long ctr;
209         unsigned long link;
210         unsigned long xer;
211         unsigned long ccr;
212         unsigned long mq;               /* 601 only (not used at present) */
213                                         /* Used on APUS to hold IPL value. */
214         unsigned long trap;             /* Reason for being here */
215         /* N.B. for critical exceptions on 4xx, the dar and dsisr
216            fields are overloaded to hold srr0 and srr1. */
217         unsigned long dar;              /* Fault registers */
218         unsigned long dsisr;            /* on 4xx/Book-E used for ESR */
219         unsigned long result;           /* Result of a system call */
220 
221         /* Not in kernel's definition, but apparently needed to stop
222            assertion at coredump-elf.c:267 firing.  These padding
223            words make the struct have the same size as a
224            'vki_elf_greg_t'.  See message from Ghassan Hammouri on
225            valgrind-developers on 6 April 06. */
226         unsigned long pad[4];
227 };
228 
229 #define vki_user_regs_struct vki_pt_regs
230 
231 #define VKI_PT_R0		0
232 #define VKI_PT_R1		1
233 #define VKI_PT_R2		2
234 #define VKI_PT_R3		3
235 #define VKI_PT_R4		4
236 #define VKI_PT_R5		5
237 #define VKI_PT_R6		6
238 #define VKI_PT_R7		7
239 #define VKI_PT_R8		8
240 #define VKI_PT_R9		9
241 #define VKI_PT_R10		10
242 #define VKI_PT_R11		11
243 #define VKI_PT_R12		12
244 #define VKI_PT_R13		13
245 #define VKI_PT_R14		14
246 #define VKI_PT_R15		15
247 #define VKI_PT_R16		16
248 #define VKI_PT_R17		17
249 #define VKI_PT_R18		18
250 #define VKI_PT_R19		19
251 #define VKI_PT_R20		20
252 #define VKI_PT_R21		21
253 #define VKI_PT_R22		22
254 #define VKI_PT_R23		23
255 #define VKI_PT_R24		24
256 #define VKI_PT_R25		25
257 #define VKI_PT_R26		26
258 #define VKI_PT_R27		27
259 #define VKI_PT_R28		28
260 #define VKI_PT_R29		29
261 #define VKI_PT_R30		30
262 #define VKI_PT_R31		31
263 #define VKI_PT_NIP		32
264 #define VKI_PT_MSR		33
265 #define VKI_PT_ORIG_R3		34
266 #define VKI_PT_CTR		35
267 #define VKI_PT_LNK		36
268 #define VKI_PT_XER		37
269 #define VKI_PT_CCR		38
270 #define VKI_PT_MQ		39
271 #define VKI_PT_TRAP		40
272 #define VKI_PT_DAR		41
273 #define VKI_PT_DSISR		42
274 #define VKI_PT_RESULT		43
275 
276 //----------------------------------------------------------------------
277 // From linux-2.6.9/include/asm-ppc/sigcontext.h
278 //----------------------------------------------------------------------
279 
280 struct vki_sigcontext {
281         unsigned long      _unused[4];
282         int                signal;
283         unsigned long      handler;
284         unsigned long      oldmask;
285         struct vki_pt_regs *regs;
286 };
287 
288 //----------------------------------------------------------------------
289 // From linux-2.6.9/include/asm-ppc/mman.h
290 //----------------------------------------------------------------------
291 
292 #define VKI_PROT_NONE		0x0      /* No page permissions */
293 #define VKI_PROT_READ		0x1      /* page can be read */
294 #define VKI_PROT_WRITE		0x2      /* page can be written */
295 #define VKI_PROT_EXEC		0x4      /* page can be executed */
296 #define VKI_PROT_GROWSDOWN	0x01000000	/* mprotect flag: extend change to start of growsdown vma */
297 #define VKI_PROT_GROWSUP	0x02000000	/* mprotect flag: extend change to end of growsup vma */
298 
299 #define VKI_MAP_SHARED		0x01     /* Share changes */
300 #define VKI_MAP_PRIVATE		0x02     /* Changes are private */
301 //#define VKI_MAP_TYPE		0x0f     /* Mask for type of mapping */
302 #define VKI_MAP_FIXED		0x10     /* Interpret addr exactly */
303 #define VKI_MAP_ANONYMOUS	0x20     /* don't use a file */
304 #define VKI_MAP_NORESERVE	0x40     /* don't reserve swap pages */
305 
306 //----------------------------------------------------------------------
307 // From linux-2.6.9/include/asm-ppc/fcntl.h
308 //----------------------------------------------------------------------
309 
310 #define VKI_O_ACCMODE		   03
311 #define VKI_O_RDONLY		   00
312 #define VKI_O_WRONLY		   01
313 #define VKI_O_RDWR		   02
314 #define VKI_O_CREAT		 0100		/* not fcntl */
315 #define VKI_O_EXCL		 0200		/* not fcntl */
316 #define VKI_O_TRUNC		01000		/* not fcntl */
317 #define VKI_O_APPEND		02000
318 #define VKI_O_NONBLOCK		04000
319 #define VKI_O_LARGEFILE     0200000
320 
321 #define VKI_AT_FDCWD            -100
322 
323 #define VKI_F_DUPFD		 0			/* dup */
324 #define VKI_F_GETFD		 1			/* get close_on_exec */
325 #define VKI_F_SETFD		 2			/* set/clear close_on_exec */
326 #define VKI_F_GETFL		 3			/* get file->f_flags */
327 #define VKI_F_SETFL		 4			/* set file->f_flags */
328 #define VKI_F_GETLK		 5
329 #define VKI_F_SETLK		 6
330 #define VKI_F_SETLKW		 7
331 
332 #define VKI_F_SETOWN		 8			/*  for sockets. */
333 #define VKI_F_GETOWN		 9			/*  for sockets. */
334 #define VKI_F_SETSIG		10			/*  for sockets. */
335 #define VKI_F_GETSIG		11			/*  for sockets. */
336 
337 #define VKI_F_GETLK64		12			/*  using 'struct flock64' */
338 #define VKI_F_SETLK64		13
339 #define VKI_F_SETLKW64		14
340 
341 #define VKI_F_SETOWN_EX		15
342 #define VKI_F_GETOWN_EX		16
343 
344 #define VKI_F_OFD_GETLK		36
345 #define VKI_F_OFD_SETLK		37
346 #define VKI_F_OFD_SETLKW	38
347 
348 #define VKI_F_OWNER_TID		0
349 #define VKI_F_OWNER_PID		1
350 #define VKI_F_OWNER_PGRP	2
351 
352 struct vki_f_owner_ex {
353 	int	type;
354 	__vki_kernel_pid_t	pid;
355 };
356 
357 /* for F_[GET|SET]FL */
358 #define VKI_FD_CLOEXEC	 1		/* actually anything with low bit set goes */
359 
360 #define VKI_F_LINUX_SPECIFIC_BASE	1024
361 
362 //----------------------------------------------------------------------
363 // From linux-2.6.9/include/asm-ppc/resource.h
364 //----------------------------------------------------------------------
365 
366 #define VKI_RLIMIT_DATA		2   /* max data size */
367 #define VKI_RLIMIT_STACK	3   /* max stack size */
368 #define VKI_RLIMIT_CORE		4   /* max core file size */
369 #define VKI_RLIMIT_NOFILE	7   /* max number of open files */
370 
371 //----------------------------------------------------------------------
372 // From linux-2.6.9/include/asm-ppc/socket.h
373 //----------------------------------------------------------------------
374 
375 #define VKI_SOL_SOCKET	1
376 
377 #define VKI_SO_TYPE	3
378 
379 #define VKI_SO_ATTACH_FILTER	26
380 
381 //----------------------------------------------------------------------
382 // From linux-2.6.8.1/include/asm-ppc/sockios.h
383 //----------------------------------------------------------------------
384 
385 #define VKI_SIOCSPGRP		0x8902
386 #define VKI_SIOCGPGRP		0x8904
387 #define VKI_SIOCATMARK		0x8905
388 #define VKI_SIOCGSTAMP		0x8906          /* Get stamp (timeval) */
389 #define VKI_SIOCGSTAMPNS	0x8907          /* Get stamp (timespec) */
390 
391 //----------------------------------------------------------------------
392 // From linux-2.6.10/include/asm-ppc/stat.h
393 //----------------------------------------------------------------------
394 
395 //.. #define VKI_S_IFMT		00170000
396 //.. #define VKI_S_IFSOCK	 0140000
397 //.. #define VKI_S_IFLNK	 0120000
398 //.. #define VKI_S_IFREG	 0100000
399 //.. #define VKI_S_IFBLK	 0060000
400 //.. #define VKI_S_IFDIR	 0040000
401 //.. #define VKI_S_IFCHR	 0020000
402 //.. #define VKI_S_IFIFO	 0010000
403 //.. #define VKI_S_ISUID	 0004000
404 //.. #define VKI_S_ISGID	 0002000
405 //.. #define VKI_S_ISVTX	 0001000
406 //..
407 //.. #define VKI_S_ISLNK(m)	(((m) & VKI_S_IFMT) == VKI_S_IFLNK)
408 //.. #define VKI_S_ISREG(m)	(((m) & VKI_S_IFMT) == VKI_S_IFREG)
409 //.. #define VKI_S_ISDIR(m)	(((m) & VKI_S_IFMT) == VKI_S_IFDIR)
410 //.. #define VKI_S_ISCHR(m)	(((m) & VKI_S_IFMT) == VKI_S_IFCHR)
411 //.. #define VKI_S_ISBLK(m)	(((m) & VKI_S_IFMT) == VKI_S_IFBLK)
412 //.. #define VKI_S_ISFIFO(m)	(((m) & VKI_S_IFMT) == VKI_S_IFIFO)
413 //.. #define VKI_S_ISSOCK(m)	(((m) & VKI_S_IFMT) == VKI_S_IFSOCK)
414 
415 struct vki_stat {
416    unsigned		st_dev;
417    unsigned long	st_ino;
418    unsigned int		st_mode;
419    unsigned short	st_nlink;
420    unsigned int		st_uid;
421    unsigned int		st_gid;
422    unsigned		st_rdev;
423    long			st_size;
424    unsigned long	st_blksize;
425    unsigned long	st_blocks;
426    unsigned long	st_atime;
427    unsigned long	st_atime_nsec;
428    unsigned long	st_mtime;
429    unsigned long	st_mtime_nsec;
430    unsigned long	st_ctime;
431    unsigned long	st_ctime_nsec;
432    unsigned long	__unused4;
433    unsigned long	__unused5;
434 };
435 
436 struct vki_stat64 {
437    unsigned long long   st_dev;
438    unsigned long long   st_ino;
439    unsigned int         st_mode;
440    unsigned int         st_nlink;
441    unsigned int         st_uid;
442    unsigned int         st_gid;
443    unsigned long long   st_rdev;
444    unsigned short int   __pad2;
445    long long            st_size;
446    long                 st_blksize;
447 
448    long long            st_blocks;
449    long                 st_atime;
450    unsigned long        st_atime_nsec;
451    long                 st_mtime;
452    unsigned long int    st_mtime_nsec;
453    long                 st_ctime;
454    unsigned long int    st_ctime_nsec;
455    unsigned long int    __unused4;
456    unsigned long int    __unused5;
457 };
458 
459 
460 //----------------------------------------------------------------------
461 // From linux-2.6.9/include/asm-ppc/statfs.h
462 //----------------------------------------------------------------------
463 
464 // [[Nb: asm-ppc/statfs.h just #include asm-generic/statfs.h directly]]
465 struct vki_statfs {
466    __vki_u32 f_type;
467    __vki_u32 f_bsize;
468    __vki_u32 f_blocks;
469    __vki_u32 f_bfree;
470    __vki_u32 f_bavail;
471    __vki_u32 f_files;
472    __vki_u32 f_ffree;
473    __vki_kernel_fsid_t f_fsid;
474    __vki_u32 f_namelen;
475    __vki_u32 f_frsize;
476    __vki_u32 f_spare[5];
477 };
478 
479 //----------------------------------------------------------------------
480 // From linux-2.6.9/include/asm-ppc/termios.h
481 //----------------------------------------------------------------------
482 
483 struct vki_winsize {
484    unsigned short ws_row;
485    unsigned short ws_col;
486    unsigned short ws_xpixel;
487    unsigned short ws_ypixel;
488 };
489 
490 #define NCC 10
491 struct vki_termio {
492    unsigned short	c_iflag;		/* input mode flags */
493    unsigned short	c_oflag;		/* output mode flags */
494    unsigned short	c_cflag;		/* control mode flags */
495    unsigned short	c_lflag;		/* local mode flags */
496    unsigned char	c_line;			/* line discipline */
497    unsigned char	c_cc[NCC];		/* control characters */
498 };
499 
500 //----------------------------------------------------------------------
501 // From linux-2.6.9/include/asm-ppc/termbits.h
502 //----------------------------------------------------------------------
503 
504 typedef unsigned char   vki_cc_t;
505 typedef unsigned int    vki_speed_t;
506 typedef unsigned int    vki_tcflag_t;
507 
508 #define NCCS 19
509 struct vki_termios {
510         vki_tcflag_t	c_iflag;		/* input mode flags */
511         vki_tcflag_t	c_oflag;		/* output mode flags */
512         vki_tcflag_t	c_cflag;		/* control mode flags */
513         vki_tcflag_t	c_lflag;		/* local mode flags */
514         vki_cc_t	c_cc[NCCS];		/* control characters */
515         vki_cc_t	c_line;			/* line discipline (== c_cc[19]) */
516         vki_speed_t	c_ispeed;		/* input speed */
517         vki_speed_t	c_ospeed;		/* output speed */
518 };
519 
520 //----------------------------------------------------------------------
521 // From linux-2.6.9/include/asm-ppc/ioctl.h
522 //----------------------------------------------------------------------
523 
524 #define _VKI_IOC_NRBITS		 8
525 #define _VKI_IOC_TYPEBITS	 8
526 #define _VKI_IOC_SIZEBITS	13
527 #define _VKI_IOC_DIRBITS	 3
528 
529 #define _VKI_IOC_NRMASK		((1 << _VKI_IOC_NRBITS)-1)
530 #define _VKI_IOC_TYPEMASK	((1 << _VKI_IOC_TYPEBITS)-1)
531 #define _VKI_IOC_SIZEMASK	((1 << _VKI_IOC_SIZEBITS)-1)
532 #define _VKI_IOC_DIRMASK	((1 << _VKI_IOC_DIRBITS)-1)
533 
534 #define _VKI_IOC_NRSHIFT	0
535 #define _VKI_IOC_TYPESHIFT	(_VKI_IOC_NRSHIFT+_VKI_IOC_NRBITS)
536 #define _VKI_IOC_SIZESHIFT	(_VKI_IOC_TYPESHIFT+_VKI_IOC_TYPEBITS)
537 #define _VKI_IOC_DIRSHIFT	(_VKI_IOC_SIZESHIFT+_VKI_IOC_SIZEBITS)
538 
539 #define _VKI_IOC_NONE	1U
540 #define _VKI_IOC_READ	2U
541 #define _VKI_IOC_WRITE	4U
542 
543 #define _VKI_IOC(dir,type,nr,size) \
544         (((dir)  << _VKI_IOC_DIRSHIFT) | \
545          ((type) << _VKI_IOC_TYPESHIFT) | \
546          ((nr)   << _VKI_IOC_NRSHIFT) | \
547          ((size) << _VKI_IOC_SIZESHIFT))
548 
549 /* used to create numbers */
550 #define _VKI_IO(type,nr)			_VKI_IOC(_VKI_IOC_NONE,(type),(nr),0)
551 #define _VKI_IOR(type,nr,size)	_VKI_IOC(_VKI_IOC_READ,(type),(nr),(_VKI_IOC_TYPECHECK(size)))
552 #define _VKI_IOW(type,nr,size)	_VKI_IOC(_VKI_IOC_WRITE,(type),(nr),(_VKI_IOC_TYPECHECK(size)))
553 #define _VKI_IOWR(type,nr,size)	_VKI_IOC(_VKI_IOC_READ|_VKI_IOC_WRITE,(type),(nr),(_VKI_IOC_TYPECHECK(size)))
554 
555 /* used to decode them.. */
556 #define _VKI_IOC_DIR(nr)		(((nr) >> _VKI_IOC_DIRSHIFT)  & _VKI_IOC_DIRMASK)
557 //.. #define _VKI_IOC_TYPE(nr)		(((nr) >> _VKI_IOC_TYPESHIFT) & _VKI_IOC_TYPEMASK)
558 //.. #define _VKI_IOC_NR(nr)		(((nr) >> _VKI_IOC_NRSHIFT)   & _VKI_IOC_NRMASK)
559 #define _VKI_IOC_SIZE(nr)		(((nr) >> _VKI_IOC_SIZESHIFT) & _VKI_IOC_SIZEMASK)
560 
561 //----------------------------------------------------------------------
562 // From linux-2.6.9/include/asm-ppc/ioctls.h
563 //----------------------------------------------------------------------
564 
565 #define VKI_FIOCLEX		_VKI_IO('f', 1)
566 #define VKI_FIONCLEX		_VKI_IO('f', 2)
567 #define VKI_FIOASYNC		_VKI_IOW('f', 125, int)
568 #define VKI_FIONBIO		_VKI_IOW('f', 126, int)
569 #define VKI_FIONREAD		_VKI_IOR('f', 127, int)
570 //#define VKI_TIOCINQ		VKI_FIONREAD
571 #define VKI_FIOQSIZE		_VKI_IOR('f', 128, vki_loff_t)
572 
573 //#define VKI_TIOCGETP		_VKI_IOR('t', 8, struct vki_sgttyb)
574 //#define VKI_TIOCSETP		_VKI_IOW('t', 9, struct vki_sgttyb)
575 //#define VKI_TIOCSETN		_VKI_IOW('t', 10, struct vki_sgttyb)    /* TIOCSETP wo flush */
576 
577 //#define VKI_TIOCSETC		_VKI_IOW('t', 17, struct vki_tchars)
578 //#define VKI_TIOCGETC		_VKI_IOR('t', 18, struct vki_tchars)
579 #define VKI_TCGETS		_VKI_IOR('t', 19, struct vki_termios)
580 #define VKI_TCSETS		_VKI_IOW('t', 20, struct vki_termios)
581 #define VKI_TCSETSW		_VKI_IOW('t', 21, struct vki_termios)
582 #define VKI_TCSETSF		_VKI_IOW('t', 22, struct vki_termios)
583 
584 #define VKI_TCGETA		_VKI_IOR('t', 23, struct vki_termio)
585 #define VKI_TCSETA		_VKI_IOW('t', 24, struct vki_termio)
586 #define VKI_TCSETAW		_VKI_IOW('t', 25, struct vki_termio)
587 #define VKI_TCSETAF		_VKI_IOW('t', 28, struct vki_termio)
588 
589 #define VKI_TCSBRK		_VKI_IO('t', 29)
590 #define VKI_TCXONC		_VKI_IO('t', 30)
591 #define VKI_TCFLSH		_VKI_IO('t', 31)
592 
593 #define VKI_TIOCSWINSZ		_VKI_IOW('t', 103, struct vki_winsize)
594 #define VKI_TIOCGWINSZ		_VKI_IOR('t', 104, struct vki_winsize)
595 //#define VKI_TIOCSTART		_VKI_IO('t', 110)	   /* start output, like ^Q */
596 //#define VKI_TIOCSTOP		_VKI_IO('t', 111)	   /* stop output, like ^S */
597 #define VKI_TIOCOUTQ		_VKI_IOR('t', 115, int)	   /* output queue size */
598 
599 //#define VKI_TIOCGLTC		_VKI_IOR('t', 116, struct vki_ltchars)
600 //#define VKI_TIOCSLTC		_VKI_IOW('t', 117, struct vki_ltchars)
601 #define VKI_TIOCSPGRP		_VKI_IOW('t', 118, int)
602 #define VKI_TIOCGPGRP		_VKI_IOR('t', 119, int)
603 
604 //#define VKI_TIOCEXCL		0x540C
605 //#define VKI_TIOCNXCL		0x540D
606 #define VKI_TIOCSCTTY		0x540E
607 
608 //#define VKI_TIOCSTI		0x5412
609 #define VKI_TIOCMGET		0x5415
610 #define VKI_TIOCMBIS		0x5416
611 #define VKI_TIOCMBIC		0x5417
612 #define VKI_TIOCMSET		0x5418
613 //# define VKI_TIOCM_LE		0x001
614 //# define VKI_TIOCM_DTR	0x002
615 //# define VKI_TIOCM_RTS	0x004
616 //# define VKI_TIOCM_ST		0x008
617 //# define VKI_TIOCM_SR		0x010
618 //# define VKI_TIOCM_CTS	0x020
619 //# define VKI_TIOCM_CAR	0x040
620 //# define VKI_TIOCM_RNG	0x080
621 //# define VKI_TIOCM_DSR	0x100
622 //# define VKI_TIOCM_CD		VKI_TIOCM_CAR
623 //# define VKI_TIOCM_RI		VKI_TIOCM_RNG
624 
625 //#define VKI_TIOCGSOFTCAR	0x5419
626 //#define VKI_TIOCSSOFTCAR	0x541A
627 #define VKI_TIOCLINUX		0x541C
628 //#define VKI_TIOCCONS		0x541D
629 #define VKI_TIOCGSERIAL	0x541E
630 #define VKI_TIOCSSERIAL	0x541F
631 //#define VKI_TIOCPKT		0x5420
632 //# define VKI_TIOCPKT_DATA		 0
633 //# define VKI_TIOCPKT_FLUSHREAD	 1
634 //# define VKI_TIOCPKT_FLUSHWRITE	 2
635 //# define VKI_TIOCPKT_STOP		 4
636 //# define VKI_TIOCPKT_START		 8
637 //# define VKI_TIOCPKT_NOSTOP		16
638 //# define VKI_TIOCPKT_DOSTOP		32
639 
640 #define VKI_TIOCNOTTY		0x5422
641 //#define VKI_TIOCSETD		0x5423
642 //#define VKI_TIOCGETD		0x5424
643 #define VKI_TCSBRKP		0x5425  /* Needed for POSIX tcsendbreak() */
644 //#define VKI_TIOCSBRK		0x5427  /* BSD compatibility */
645 //#define VKI_TIOCCBRK		0x5428  /* BSD compatibility */
646 //#define VKI_TIOCGSID		0x5429  /* Return the session ID of FD */
647 #define VKI_TIOCGPTN		_VKI_IOR('T',0x30, unsigned int) /* Get Pty Number (of pty-mux device) */
648 #define VKI_TIOCSPTLCK		_VKI_IOW('T',0x31, int)  /* Lock/unlock Pty */
649 
650 //#define VKI_TIOCSERCONFIG	0x5453
651 //#define VKI_TIOCSERGWILD	0x5454
652 //#define VKI_TIOCSERSWILD  	0x5455
653 //#define VKI_TIOCGLCKTRMIOS	0x5456
654 //#define VKI_TIOCSLCKTRMIOS	0x5457
655 //#define VKI_TIOCSERGSTRUCT	0x5458 /* For debugging only */
656 #define VKI_TIOCSERGETLSR	0x5459 /* Get line status register */
657   /* ioctl (fd, VKI_TIOCSERGETLSR, &result) where result may be as below */
658 //# define VKI_TIOCSER_TEMT	0x01   /* Transmitter physically empty */
659 //#define VKI_TIOCSERGETMULTI	0x545A /* Get multiport config  */
660 //#define VKI_TIOCSERSETMULTI	0x545B /* Set multiport config */
661 
662 //#define VKI_TIOCMIWAIT	0x545C  /* wait for a change on serial input line(s) */
663 #define VKI_TIOCGICOUNT		0x545D  /* read serial port inline interrupt counts */
664 
665 //----------------------------------------------------------------------
666 // From linux-2.6.9/include/asm-ppc/poll.h
667 //----------------------------------------------------------------------
668 
669 //.. /* These are specified by iBCS2 */
670 //.. #define VKI_POLLIN		0x0001
671 
672 struct vki_pollfd {
673 	int fd;
674 	short events;
675 	short revents;
676 };
677 
678 //.. //----------------------------------------------------------------------
679 //.. // From linux-2.6.8.1/include/asm-i386/user.h
680 //.. //----------------------------------------------------------------------
681 //..
682 //.. struct vki_user_i387_struct {
683 //.. 	long	cwd;
684 //.. 	long	swd;
685 //.. 	long	twd;
686 //.. 	long	fip;
687 //.. 	long	fcs;
688 //.. 	long	foo;
689 //.. 	long	fos;
690 //.. 	long	st_space[20];	/* 8*10 bytes for each FP-reg = 80 bytes */
691 //.. };
692 //..
693 //.. struct vki_user_fxsr_struct {
694 //.. 	unsigned short	cwd;
695 //.. 	unsigned short	swd;
696 //.. 	unsigned short	twd;
697 //.. 	unsigned short	fop;
698 //.. 	long	fip;
699 //.. 	long	fcs;
700 //.. 	long	foo;
701 //.. 	long	fos;
702 //.. 	long	mxcsr;
703 //.. 	long	reserved;
704 //.. 	long	st_space[32];	/* 8*16 bytes for each FP-reg = 128 bytes */
705 //.. 	long	xmm_space[32];	/* 8*16 bytes for each XMM-reg = 128 bytes */
706 //.. 	long	padding[56];
707 //.. };
708 //..
709 //.. /*
710 //..  * This is the old layout of "struct pt_regs", and
711 //..  * is still the layout used by user mode (the new
712 //..  * pt_regs doesn't have all registers as the kernel
713 //..  * doesn't use the extra segment registers)
714 //..  */
715 //.. struct vki_user_regs_struct {
716 //.. 	long ebx, ecx, edx, esi, edi, ebp, eax;
717 //.. 	unsigned short ds, __ds, es, __es;
718 //.. 	unsigned short fs, __fs, gs, __gs;
719 //.. 	long orig_eax, eip;
720 //.. 	unsigned short cs, __cs;
721 //.. 	long eflags, esp;
722 //.. 	unsigned short ss, __ss;
723 //.. };
724 
725 //----------------------------------------------------------------------
726 // From linux-2.6.9/include/asm-ppc/elf.h
727 //----------------------------------------------------------------------
728 
729 #define VKI_ELF_NGREG			48	/* includes nip, msr, lr, etc. */
730 #define VKI_ELF_NFPREG			33	/* includes fpscr */
731 #define VKI_ELF_NVRREG			33	/* includes vscr */
732 
733 /* General registers */
734 typedef unsigned long vki_elf_greg_t;
735 typedef vki_elf_greg_t vki_elf_gregset_t[VKI_ELF_NGREG];
736 
737 /* Floating point registers */
738 typedef double vki_elf_fpreg_t;
739 typedef vki_elf_fpreg_t vki_elf_fpregset_t[VKI_ELF_NFPREG];
740 
741 /* Altivec registers */
742 typedef __vki_vector128 vki_elf_vrreg_t;
743 typedef vki_elf_vrreg_t vki_elf_vrregset_t[VKI_ELF_NVRREG];
744 
745 #define VKI_AT_DCACHEBSIZE		19
746 #define VKI_AT_ICACHEBSIZE		20
747 #define VKI_AT_UCACHEBSIZE		21
748 /* A special ignored type value for PPC, for glibc compatibility.  */
749 #define VKI_AT_IGNOREPPC	  	22
750 
751 /* CAB: Do we want these? */
752 //#define VKI_AT_SYSINFO		32
753 //#define VKI_AT_SYSINFO_EHDR  		33
754 
755 //----------------------------------------------------------------------
756 // From linux-2.6.9/include/asm-ppc/ucontext.h
757 //----------------------------------------------------------------------
758 
759 struct vki_mcontext {
760         vki_elf_gregset_t	mc_gregs;
761         vki_elf_fpregset_t	mc_fregs;
762         unsigned long		mc_pad[2];
763         vki_elf_vrregset_t	mc_vregs __attribute__((__aligned__(16)));
764 };
765 
766 struct vki_ucontext {
767         unsigned long		uc_flags;
768         struct vki_ucontext	__user *uc_link;
769         vki_stack_t		uc_stack;
770         int			uc_pad[7];
771         struct vki_mcontext	__user *uc_regs;		/* points to uc_mcontext field */
772         vki_sigset_t		uc_sigmask;
773         /* glibc has 1024-bit signal masks, ours are 64-bit */
774         int			uc_maskext[30];
775         int			uc_pad2[3];
776         struct vki_mcontext	uc_mcontext;
777 };
778 
779 //.. //----------------------------------------------------------------------
780 //.. // From linux-2.6.8.1/include/asm-i386/segment.h
781 //.. //----------------------------------------------------------------------
782 //..
783 //.. #define VKI_GDT_ENTRY_TLS_ENTRIES	3
784 //.. #define VKI_GDT_ENTRY_TLS_MIN	6
785 //.. #define VKI_GDT_ENTRY_TLS_MAX 	(VKI_GDT_ENTRY_TLS_MIN + VKI_GDT_ENTRY_TLS_ENTRIES - 1)
786 
787 //----------------------------------------------------------------------
788 // From linux-2.6.9/include/asm-ppc/ldt.h
789 //----------------------------------------------------------------------
790 
791 //.. /* [[Nb: This is the structure passed to the modify_ldt syscall.  Just so as
792 //..    to confuse and annoy everyone, this is _not_ the same as an
793 //..    VgLdtEntry and has to be translated into such.  The logic for doing
794 //..    so, in vg_ldt.c, is copied from the kernel sources.]] */
795 //.. struct vki_user_desc {
796 //.. 	unsigned int	entry_number;
797 //.. 	unsigned long	base_addr;
798 //.. 	unsigned int	limit;
799 //.. 	unsigned int	seg_32bit:1;
800 //.. 	unsigned int	contents:2;
801 //.. 	unsigned int	read_exec_only:1;
802 //.. 	unsigned int	limit_in_pages:1;
803 //.. 	unsigned int	seg_not_present:1;
804 //.. 	unsigned int	useable:1;
805 //..         // [[Nb: this field is not in the kernel sources, but it has always
806 //..         // been in the Valgrind sources so I will keep it there in case it's
807 //..         // important... this is an x86-defined data structure so who
808 //..         // knows;  maybe it's important to set this field to zero at some
809 //..         // point.  --njn]]
810 //.. 	unsigned int	reserved:25;
811 //.. };
812 //..
813 //.. // [[Nb: for our convenience within Valgrind, use a more specific name]]
814 //.. typedef struct vki_user_desc vki_modify_ldt_t;
815 
816 // CAB: TODO
817 typedef void vki_modify_ldt_t;
818 
819 
820 //----------------------------------------------------------------------
821 // From linux-2.6.9/include/asm-ppc/ipcbuf.h
822 //----------------------------------------------------------------------
823 
824 struct vki_ipc64_perm
825 {
826    __vki_kernel_key_t	key;
827    __vki_kernel_uid_t	uid;
828    __vki_kernel_gid_t	gid;
829    __vki_kernel_uid_t	cuid;
830    __vki_kernel_gid_t	cgid;
831    __vki_kernel_mode_t	mode;
832    unsigned long	seq;
833    unsigned int		__pad2;
834    unsigned long long	__unused1;
835    unsigned long long	__unused2;
836 };
837 
838 //----------------------------------------------------------------------
839 // From linux-2.6.9/include/asm-ppc/sembuf.h
840 //----------------------------------------------------------------------
841 
842 struct vki_semid64_ds {
843    struct vki_ipc64_perm	sem_perm;		/* permissions .. see ipc.h */
844    unsigned int			__unused1;
845    __vki_kernel_time_t		sem_otime;		/* last semop time */
846    unsigned int			__unused2;
847    __vki_kernel_time_t		sem_ctime;		/* last change time */
848    unsigned long		sem_nsems;		/* no. of semaphores in array */
849    unsigned long		__unused3;
850    unsigned long		__unused4;
851 };
852 
853 //----------------------------------------------------------------------
854 // From linux-2.6.9/include/asm-ppc/msgbuf.h
855 //----------------------------------------------------------------------
856 
857 struct vki_msqid64_ds {
858    struct vki_ipc64_perm	msg_perm;
859    unsigned int			__unused1;
860    __vki_kernel_time_t		msg_stime;		/* last msgsnd time */
861    unsigned int			__unused2;
862    __vki_kernel_time_t		msg_rtime;		/* last msgrcv time */
863    unsigned int			__unused3;
864    __vki_kernel_time_t		msg_ctime;		/* last change time */
865    unsigned long		msg_cbytes;		/* current number of bytes on queue */
866    unsigned long		msg_qnum;		/* number of messages in queue */
867    unsigned long		msg_qbytes;		/* max number of bytes on queue */
868    __vki_kernel_pid_t		msg_lspid;		/* pid of last msgsnd */
869    __vki_kernel_pid_t		msg_lrpid;		/* last receive pid */
870    unsigned long		__unused4;
871    unsigned long		__unused5;
872 };
873 
874 //----------------------------------------------------------------------
875 // From linux-2.6.8.1/include/asm-ppc/ipc.h
876 //----------------------------------------------------------------------
877 
878 struct vki_ipc_kludge {
879         struct vki_msgbuf __user *msgp;
880         long msgtyp;
881 };
882 
883 #define VKI_SEMOP            1
884 #define VKI_SEMGET           2
885 #define VKI_SEMCTL           3
886 #define VKI_SEMTIMEDOP       4
887 #define VKI_MSGSND          11
888 #define VKI_MSGRCV          12
889 #define VKI_MSGGET          13
890 #define VKI_MSGCTL          14
891 #define VKI_SHMAT           21
892 #define VKI_SHMDT           22
893 #define VKI_SHMGET          23
894 #define VKI_SHMCTL          24
895 
896 //----------------------------------------------------------------------
897 // From linux-2.6.9/include/asm-ppc/shmbuf.h
898 //----------------------------------------------------------------------
899 
900 struct vki_shmid64_ds {
901    struct vki_ipc64_perm	shm_perm;		/* operation perms */
902    unsigned int			__unused1;
903    __vki_kernel_time_t		shm_atime;		/* last attach time */
904    unsigned int			__unused2;
905    __vki_kernel_time_t		shm_dtime;		/* last detach time */
906    unsigned int			__unused3;
907    __vki_kernel_time_t		shm_ctime;		/* last change time */
908    unsigned int			__unused4;
909    vki_size_t			shm_segsz;		/* size of segment (bytes) */
910    __vki_kernel_pid_t		shm_cpid;		/* pid of creator */
911    __vki_kernel_pid_t		shm_lpid;		/* pid of last operator */
912    unsigned long		shm_nattch;		/* no. of current attaches */
913    unsigned long		__unused5;
914    unsigned long		__unused6;
915 };
916 
917 struct vki_shminfo64 {
918    unsigned long	shmmax;
919    unsigned long	shmmin;
920    unsigned long	shmmni;
921    unsigned long	shmseg;
922    unsigned long	shmall;
923    unsigned long	__unused1;
924    unsigned long	__unused2;
925    unsigned long	__unused3;
926    unsigned long	__unused4;
927 };
928 
929 //----------------------------------------------------------------------
930 // From linux-2.6.8.1/include/asm-generic/errno.h
931 //----------------------------------------------------------------------
932 
933 #define	VKI_ENOSYS       38  /* Function not implemented */
934 #define	VKI_EOVERFLOW    75  /* Value too large for defined data type */
935 
936 //.. //----------------------------------------------------------------------
937 //.. // DRM ioctls
938 //.. //----------------------------------------------------------------------
939 //..
940 //.. // jrs 20050207: where did all this stuff come from?  Is it really
941 //.. // i386 specific, or should it go into the linux-generic category?
942 //.. //struct vki_drm_buf_pub {
943 //.. //	Int		  idx;	       /**< Index into the master buffer list */
944 //.. //	Int		  total;       /**< Buffer size */
945 //.. //	Int		  used;	       /**< Amount of buffer in use (for DMA) */
946 //.. //	void	  __user *address;     /**< Address of buffer */
947 //.. //};
948 //.. //
949 //.. //struct vki_drm_buf_map {
950 //.. //	Int	      count;		/**< Length of the buffer list */
951 //.. //	void	      __user *virtual;	/**< Mmap'd area in user-virtual */
952 //.. //	struct vki_drm_buf_pub __user *list;	/**< Buffer information */
953 //.. //};
954 //.. //
955 //.. ///* We need to pay attention to this, because it mmaps memory */
956 //.. //#define VKI_DRM_IOCTL_MAP_BUFS		_VKI_IOWR('d', 0x19, struct vki_drm_buf_map)
957 
958 //----------------------------------------------------------------------
959 // And that's it!
960 //----------------------------------------------------------------------
961 
962 #endif // __VKI_PPC32_LINUX_H
963 
964 /*--------------------------------------------------------------------*/
965 /*--- end                                                          ---*/
966 /*--------------------------------------------------------------------*/
967