make oldconfig will rebuild these...
[linux-2.4.21-pre4.git] / include / asm-ia64 / ia32.h
1 #ifndef _ASM_IA64_IA32_H
2 #define _ASM_IA64_IA32_H
3
4 #include <linux/config.h>
5
6 #ifdef CONFIG_IA32_SUPPORT
7
8 #include <linux/param.h>
9
10 /*
11  * 32 bit structures for IA32 support.
12  */
13
14 /* 32bit compatibility types */
15 typedef unsigned int    __kernel_size_t32;
16 typedef int             __kernel_ssize_t32;
17 typedef int             __kernel_ptrdiff_t32;
18 typedef int             __kernel_time_t32;
19 typedef int             __kernel_clock_t32;
20 typedef int             __kernel_pid_t32;
21 typedef unsigned short  __kernel_ipc_pid_t32;
22 typedef unsigned short  __kernel_uid_t32;
23 typedef unsigned int    __kernel_uid32_t32;
24 typedef unsigned short  __kernel_gid_t32;
25 typedef unsigned int    __kernel_gid32_t32;
26 typedef unsigned short  __kernel_dev_t32;
27 typedef unsigned int    __kernel_ino_t32;
28 typedef unsigned short  __kernel_mode_t32;
29 typedef unsigned short  __kernel_umode_t32;
30 typedef short           __kernel_nlink_t32;
31 typedef int             __kernel_daddr_t32;
32 typedef int             __kernel_off_t32;
33 typedef unsigned int    __kernel_caddr_t32;
34 typedef long            __kernel_loff_t32;
35 typedef __kernel_fsid_t __kernel_fsid_t32;
36
37 #define IA32_PAGE_SHIFT         12      /* 4KB pages */
38 #define IA32_PAGE_SIZE          (1UL << IA32_PAGE_SHIFT)
39 #define IA32_PAGE_MASK          (~(IA32_PAGE_SIZE - 1))
40 #define IA32_PAGE_ALIGN(addr)   (((addr) + IA32_PAGE_SIZE - 1) & IA32_PAGE_MASK)
41 #define IA32_CLOCKS_PER_SEC     100     /* Cast in stone for IA32 Linux */
42 #define IA32_TICK(tick)         ((unsigned long long)(tick) * IA32_CLOCKS_PER_SEC / CLOCKS_PER_SEC)
43
44 struct timespec32 {
45         int     tv_sec;
46         int     tv_nsec;
47 };
48
49 /* fcntl.h */
50 struct flock32 {
51        short l_type;
52        short l_whence;
53        __kernel_off_t32 l_start;
54        __kernel_off_t32 l_len;
55        __kernel_pid_t32 l_pid;
56 };
57
58 #define F_GETLK64       12
59 #define F_SETLK64       13
60 #define F_SETLKW64      14
61
62 /* sigcontext.h */
63 /*
64  * As documented in the iBCS2 standard..
65  *
66  * The first part of "struct _fpstate" is just the
67  * normal i387 hardware setup, the extra "status"
68  * word is used to save the coprocessor status word
69  * before entering the handler.
70  */
71 struct _fpreg_ia32 {
72        unsigned short significand[4];
73        unsigned short exponent;
74 };
75
76 struct _fpxreg_ia32 {
77         unsigned short significand[4];
78         unsigned short exponent;
79         unsigned short padding[3];
80 };
81
82 struct _xmmreg_ia32 {
83         unsigned int element[4];
84 };
85
86
87 struct _fpstate_ia32 {
88        unsigned int    cw,
89                        sw,
90                        tag,
91                        ipoff,
92                        cssel,
93                        dataoff,
94                        datasel;
95        struct _fpreg_ia32      _st[8];
96        unsigned short  status;
97        unsigned short  magic;          /* 0xffff = regular FPU data only */
98
99        /* FXSR FPU environment */
100        unsigned int         _fxsr_env[6];   /* FXSR FPU env is ignored */
101        unsigned int         mxcsr;
102        unsigned int         reserved;
103        struct _fpxreg_ia32  _fxsr_st[8];    /* FXSR FPU reg data is ignored */
104        struct _xmmreg_ia32  _xmm[8];
105        unsigned int         padding[56];
106 };
107
108 struct sigcontext_ia32 {
109        unsigned short gs, __gsh;
110        unsigned short fs, __fsh;
111        unsigned short es, __esh;
112        unsigned short ds, __dsh;
113        unsigned int edi;
114        unsigned int esi;
115        unsigned int ebp;
116        unsigned int esp;
117        unsigned int ebx;
118        unsigned int edx;
119        unsigned int ecx;
120        unsigned int eax;
121        unsigned int trapno;
122        unsigned int err;
123        unsigned int eip;
124        unsigned short cs, __csh;
125        unsigned int eflags;
126        unsigned int esp_at_signal;
127        unsigned short ss, __ssh;
128        unsigned int fpstate;            /* really (struct _fpstate_ia32 *) */
129        unsigned int oldmask;
130        unsigned int cr2;
131 };
132
133 /* user.h */
134 /*
135  * IA32 (Pentium III/4) FXSR, SSE support
136  *
137  * Provide support for the GDB 5.0+ PTRACE_{GET|SET}FPXREGS requests for
138  * interacting with the FXSR-format floating point environment.  Floating
139  * point data can be accessed in the regular format in the usual manner,
140  * and both the standard and SIMD floating point data can be accessed via
141  * the new ptrace requests.  In either case, changes to the FPU environment
142  * will be reflected in the task's state as expected.
143  */
144 struct ia32_user_i387_struct {
145         int     cwd;
146         int     swd;
147         int     twd;
148         int     fip;
149         int     fcs;
150         int     foo;
151         int     fos;
152         int     st_space[20];   /* 8*10 bytes for each FP-reg = 80 bytes */
153 };
154
155 struct ia32_user_fxsr_struct {
156         unsigned short  cwd;
157         unsigned short  swd;
158         unsigned short  twd;
159         unsigned short  fop;
160         int     fip;
161         int     fcs;
162         int     foo;
163         int     fos;
164         int     mxcsr;
165         int     reserved;
166         int     st_space[32];   /* 8*16 bytes for each FP-reg = 128 bytes */
167         int     xmm_space[32];  /* 8*16 bytes for each XMM-reg = 128 bytes */
168         int     padding[56];
169 };
170
171 /* signal.h */
172 #define _IA32_NSIG             64
173 #define _IA32_NSIG_BPW         32
174 #define _IA32_NSIG_WORDS               (_IA32_NSIG / _IA32_NSIG_BPW)
175
176 #define IA32_SET_SA_HANDLER(ka,handler,restorer)                                \
177                                 ((ka)->sa.sa_handler = (__sighandler_t)         \
178                                         (((unsigned long)(restorer) << 32)      \
179                                          | ((handler) & 0xffffffff)))
180 #define IA32_SA_HANDLER(ka)     ((unsigned long) (ka)->sa.sa_handler & 0xffffffff)
181 #define IA32_SA_RESTORER(ka)    ((unsigned long) (ka)->sa.sa_handler >> 32)
182
183 typedef struct {
184        unsigned int sig[_IA32_NSIG_WORDS];
185 } sigset32_t;
186
187 struct sigaction32 {
188        unsigned int sa_handler;         /* Really a pointer, but need to deal with 32 bits */
189        unsigned int sa_flags;
190        unsigned int sa_restorer;        /* Another 32 bit pointer */
191        sigset32_t sa_mask;              /* A 32 bit mask */
192 };
193
194 typedef unsigned int old_sigset32_t;    /* at least 32 bits */
195
196 struct old_sigaction32 {
197        unsigned int  sa_handler;        /* Really a pointer, but need to deal
198                                              with 32 bits */
199        old_sigset32_t sa_mask;          /* A 32 bit mask */
200        unsigned int sa_flags;
201        unsigned int sa_restorer;        /* Another 32 bit pointer */
202 };
203
204 typedef struct sigaltstack_ia32 {
205         unsigned int    ss_sp;
206         int             ss_flags;
207         unsigned int    ss_size;
208 } stack_ia32_t;
209
210 struct ucontext_ia32 {
211         unsigned int      uc_flags;
212         unsigned int      uc_link;
213         stack_ia32_t      uc_stack;
214         struct sigcontext_ia32 uc_mcontext;
215         sigset_t          uc_sigmask;   /* mask last for extensibility */
216 };
217
218 struct stat32 {
219        unsigned short st_dev;
220        unsigned short __pad1;
221        unsigned int st_ino;
222        unsigned short st_mode;
223        unsigned short st_nlink;
224        unsigned short st_uid;
225        unsigned short st_gid;
226        unsigned short st_rdev;
227        unsigned short __pad2;
228        unsigned int  st_size;
229        unsigned int  st_blksize;
230        unsigned int  st_blocks;
231        unsigned int  st_atime;
232        unsigned int  __unused1;
233        unsigned int  st_mtime;
234        unsigned int  __unused2;
235        unsigned int  st_ctime;
236        unsigned int  __unused3;
237        unsigned int  __unused4;
238        unsigned int  __unused5;
239 };
240
241 struct stat64 {
242         unsigned short  st_dev;
243         unsigned char   __pad0[10];
244         unsigned int    __st_ino;
245         unsigned int    st_mode;
246         unsigned int    st_nlink;
247         unsigned int    st_uid;
248         unsigned int    st_gid;
249         unsigned short  st_rdev;
250         unsigned char   __pad3[10];
251         unsigned int    st_size_lo;
252         unsigned int    st_size_hi;
253         unsigned int    st_blksize;
254         unsigned int    st_blocks;      /* Number 512-byte blocks allocated. */
255         unsigned int    __pad4;         /* future possible st_blocks high bits */
256         unsigned int    st_atime;
257         unsigned int    __pad5;
258         unsigned int    st_mtime;
259         unsigned int    __pad6;
260         unsigned int    st_ctime;
261         unsigned int    __pad7;         /* will be high 32 bits of ctime someday */
262         unsigned int    st_ino_lo;
263         unsigned int    st_ino_hi;
264 };
265
266 struct statfs32 {
267        int f_type;
268        int f_bsize;
269        int f_blocks;
270        int f_bfree;
271        int f_bavail;
272        int f_files;
273        int f_ffree;
274        __kernel_fsid_t32 f_fsid;
275        int f_namelen;  /* SunOS ignores this field. */
276        int f_spare[6];
277 };
278
279 typedef union sigval32 {
280         int sival_int;
281         unsigned int sival_ptr;
282 } sigval_t32;
283
284 typedef struct siginfo32 {
285         int si_signo;
286         int si_errno;
287         int si_code;
288
289         union {
290                 int _pad[((128/sizeof(int)) - 3)];
291
292                 /* kill() */
293                 struct {
294                         unsigned int _pid;      /* sender's pid */
295                         unsigned int _uid;      /* sender's uid */
296                 } _kill;
297
298                 /* POSIX.1b timers */
299                 struct {
300                         unsigned int _timer1;
301                         unsigned int _timer2;
302                 } _timer;
303
304                 /* POSIX.1b signals */
305                 struct {
306                         unsigned int _pid;      /* sender's pid */
307                         unsigned int _uid;      /* sender's uid */
308                         sigval_t32 _sigval;
309                 } _rt;
310
311                 /* SIGCHLD */
312                 struct {
313                         unsigned int _pid;      /* which child */
314                         unsigned int _uid;      /* sender's uid */
315                         int _status;            /* exit code */
316                         __kernel_clock_t32 _utime;
317                         __kernel_clock_t32 _stime;
318                 } _sigchld;
319
320                 /* SIGILL, SIGFPE, SIGSEGV, SIGBUS */
321                 struct {
322                         unsigned int _addr;     /* faulting insn/memory ref. */
323                 } _sigfault;
324
325                 /* SIGPOLL */
326                 struct {
327                         int _band;      /* POLL_IN, POLL_OUT, POLL_MSG */
328                         int _fd;
329                 } _sigpoll;
330         } _sifields;
331 } siginfo_t32;
332
333 struct linux32_dirent {
334         u32     d_ino;
335         u32     d_off;
336         u16     d_reclen;
337         char    d_name[256];
338 };
339
340 struct old_linux32_dirent {
341         u32     d_ino;
342         u32     d_offset;
343         u16     d_namlen;
344         char    d_name[1];
345 };
346
347 /*
348  * IA-32 ELF specific definitions for IA-64.
349  */
350
351 #define _ASM_IA64_ELF_H         /* Don't include elf.h */
352
353 #include <linux/sched.h>
354 #include <asm/processor.h>
355
356 /*
357  * This is used to ensure we don't load something for the wrong architecture.
358  */
359 #define elf_check_arch(x) ((x)->e_machine == EM_386)
360
361 /*
362  * These are used to set parameters in the core dumps.
363  */
364 #define ELF_CLASS       ELFCLASS32
365 #define ELF_DATA        ELFDATA2LSB
366 #define ELF_ARCH        EM_386
367
368 #define IA32_PAGE_OFFSET        0xc0000000
369 #define IA32_STACK_TOP          IA32_PAGE_OFFSET
370
371 /*
372  * The system segments (GDT, TSS, LDT) have to be mapped below 4GB so the IA-32 engine can
373  * access them.
374  */
375 #define IA32_GDT_OFFSET         (IA32_PAGE_OFFSET)
376 #define IA32_TSS_OFFSET         (IA32_PAGE_OFFSET + PAGE_SIZE)
377 #define IA32_LDT_OFFSET         (IA32_PAGE_OFFSET + 2*PAGE_SIZE)
378
379 #define USE_ELF_CORE_DUMP
380 #define ELF_EXEC_PAGESIZE       IA32_PAGE_SIZE
381
382 /*
383  * This is the location that an ET_DYN program is loaded if exec'ed.
384  * Typical use of this is to invoke "./ld.so someprog" to test out a
385  * new version of the loader.  We need to make sure that it is out of
386  * the way of the program that it will "exec", and that there is
387  * sufficient room for the brk.
388  */
389 #define ELF_ET_DYN_BASE         (IA32_PAGE_OFFSET/3 + 0x1000000)
390
391 void ia64_elf32_init(struct pt_regs *regs);
392 #define ELF_PLAT_INIT(_r)       ia64_elf32_init(_r)
393
394 #define elf_addr_t      u32
395 #define elf_caddr_t     u32
396
397 /* ELF register definitions.  This is needed for core dump support.  */
398
399 #define ELF_NGREG       128                     /* XXX fix me */
400 #define ELF_NFPREG      128                     /* XXX fix me */
401
402 typedef unsigned long elf_greg_t;
403 typedef elf_greg_t elf_gregset_t[ELF_NGREG];
404
405 typedef struct {
406         unsigned long w0;
407         unsigned long w1;
408 } elf_fpreg_t;
409 typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
410
411 /* This macro yields a bitmask that programs can use to figure out
412    what instruction set this CPU supports.  */
413 #define ELF_HWCAP       0
414
415 /* This macro yields a string that ld.so will use to load
416    implementation specific libraries for optimization.  Not terribly
417    relevant until we have real hardware to play with... */
418 #define ELF_PLATFORM    0
419
420 #ifdef __KERNEL__
421 # define SET_PERSONALITY(EX,IBCS2)                              \
422         (current->personality = (IBCS2) ? PER_SVR4 : PER_LINUX)
423 #endif
424
425 #define IA32_EFLAG      0x200
426
427 /*
428  * IA-32 ELF specific definitions for IA-64.
429  */
430
431 #define __USER_CS      0x23
432 #define __USER_DS      0x2B
433
434 #define FIRST_TSS_ENTRY 6
435 #define FIRST_LDT_ENTRY (FIRST_TSS_ENTRY+1)
436 #define _TSS(n) ((((unsigned long) n)<<4)+(FIRST_TSS_ENTRY<<3))
437 #define _LDT(n) ((((unsigned long) n)<<4)+(FIRST_LDT_ENTRY<<3))
438
439 #define IA32_SEGSEL_RPL         (0x3 << 0)
440 #define IA32_SEGSEL_TI          (0x1 << 2)
441 #define IA32_SEGSEL_INDEX_SHIFT 3
442
443 #define IA32_SEG_BASE           16
444 #define IA32_SEG_TYPE           40
445 #define IA32_SEG_SYS            44
446 #define IA32_SEG_DPL            45
447 #define IA32_SEG_P              47
448 #define IA32_SEG_HIGH_LIMIT     48
449 #define IA32_SEG_AVL            52
450 #define IA32_SEG_DB             54
451 #define IA32_SEG_G              55
452 #define IA32_SEG_HIGH_BASE      56
453
454 #define IA32_SEG_DESCRIPTOR(base, limit, segtype, nonsysseg, dpl, segpresent, avl, segdb, gran) \
455                (((limit) & 0xffff)                                                              \
456                 | (((unsigned long) (base) & 0xffffff) << IA32_SEG_BASE)                        \
457                 | ((unsigned long) (segtype) << IA32_SEG_TYPE)                                  \
458                 | ((unsigned long) (nonsysseg) << IA32_SEG_SYS)                                 \
459                 | ((unsigned long) (dpl) << IA32_SEG_DPL)                                       \
460                 | ((unsigned long) (segpresent) << IA32_SEG_P)                                  \
461                 | ((((unsigned long) (limit) >> 16) & 0xf) << IA32_SEG_HIGH_LIMIT)              \
462                 | ((unsigned long) (avl) << IA32_SEG_AVL)                                       \
463                 | ((unsigned long) (segdb) << IA32_SEG_DB)                                      \
464                 | ((unsigned long) (gran) << IA32_SEG_G)                                        \
465                 | ((((unsigned long) (base) >> 24) & 0xff) << IA32_SEG_HIGH_BASE))
466
467 #define SEG_LIM         32
468 #define SEG_TYPE        52
469 #define SEG_SYS         56
470 #define SEG_DPL         57
471 #define SEG_P           59
472 #define SEG_AVL         60
473 #define SEG_DB          62
474 #define SEG_G           63
475
476 /* Unscramble an IA-32 segment descriptor into the IA-64 format.  */
477 #define IA32_SEG_UNSCRAMBLE(sd)                                                                  \
478         (   (((sd) >> IA32_SEG_BASE) & 0xffffff) | ((((sd) >> IA32_SEG_HIGH_BASE) & 0xff) << 24) \
479          | ((((sd) & 0xffff) | ((((sd) >> IA32_SEG_HIGH_LIMIT) & 0xf) << 16)) << SEG_LIM)        \
480          | ((((sd) >> IA32_SEG_TYPE) & 0xf) << SEG_TYPE)                                         \
481          | ((((sd) >> IA32_SEG_SYS) & 0x1) << SEG_SYS)                                           \
482          | ((((sd) >> IA32_SEG_DPL) & 0x3) << SEG_DPL)                                           \
483          | ((((sd) >> IA32_SEG_P) & 0x1) << SEG_P)                                               \
484          | ((((sd) >> IA32_SEG_AVL) & 0x1) << SEG_AVL)                                           \
485          | ((((sd) >> IA32_SEG_DB) & 0x1) << SEG_DB)                                             \
486          | ((((sd) >> IA32_SEG_G) & 0x1) << SEG_G))
487
488 #define IA32_IOBASE     0x2000000000000000 /* Virtual address for I/O space */
489
490 #define IA32_CR0        0x80000001      /* Enable PG and PE bits */
491 #define IA32_CR4        0x600           /* MMXEX and FXSR on */
492
493 /*
494  *  IA32 floating point control registers starting values
495  */
496
497 #define IA32_FSR_DEFAULT        0x55550000              /* set all tag bits */
498 #define IA32_FCR_DEFAULT        0x17800000037fUL        /* extended precision, all masks */
499
500 #define IA32_PTRACE_GETREGS     12
501 #define IA32_PTRACE_SETREGS     13
502 #define IA32_PTRACE_GETFPREGS   14
503 #define IA32_PTRACE_SETFPREGS   15
504 #define IA32_PTRACE_GETFPXREGS  18
505 #define IA32_PTRACE_SETFPXREGS  19
506
507 #define ia32_start_thread(regs,new_ip,new_sp) do {                              \
508         set_fs(USER_DS);                                                        \
509         ia64_psr(regs)->cpl = 3;        /* set user mode */                     \
510         ia64_psr(regs)->ri = 0;         /* clear return slot number */          \
511         ia64_psr(regs)->is = 1;         /* IA-32 instruction set */             \
512         regs->cr_iip = new_ip;                                                  \
513         regs->ar_rsc = 0xc;             /* enforced lazy mode, priv. level 3 */ \
514         regs->ar_rnat = 0;                                                      \
515         regs->loadrs = 0;                                                       \
516         regs->r12 = new_sp;                                                     \
517 } while (0)
518
519 /*
520  * Local Descriptor Table (LDT) related declarations.
521  */
522
523 #define IA32_LDT_ENTRIES        8192            /* Maximum number of LDT entries supported. */
524 #define IA32_LDT_ENTRY_SIZE     8               /* The size of each LDT entry. */
525
526 struct ia32_modify_ldt_ldt_s {
527         unsigned int entry_number;
528         unsigned int base_addr;
529         unsigned int limit;
530         unsigned int seg_32bit:1;
531         unsigned int contents:2;
532         unsigned int read_exec_only:1;
533         unsigned int limit_in_pages:1;
534         unsigned int seg_not_present:1;
535         unsigned int useable:1;
536 };
537
538 extern void ia32_gdt_init (void);
539 extern int ia32_setup_frame1 (int sig, struct k_sigaction *ka, siginfo_t *info,
540                                sigset_t *set, struct pt_regs *regs);
541 extern void ia32_init_addr_space (struct pt_regs *regs);
542 extern int ia32_setup_arg_pages (struct linux_binprm *bprm);
543 extern int ia32_exception (struct pt_regs *regs, unsigned long isr);
544 extern int ia32_intercept (struct pt_regs *regs, unsigned long isr);
545 extern unsigned long ia32_do_mmap (struct file *, unsigned long, unsigned long, int, int, loff_t);
546 extern void ia32_load_segment_descriptors (struct task_struct *task);
547
548 #define ia32f2ia64f(dst,src) \
549         do { \
550         register double f6 asm ("f6"); \
551         asm volatile ("ldfe f6=[%2];; stf.spill [%1]=f6" : "=f"(f6): "r"(dst), "r"(src) : "memory"); \
552         } while(0)
553
554 #define ia64f2ia32f(dst,src) \
555         do { \
556         register double f6 asm ("f6"); \
557         asm volatile ("ldf.fill f6=[%2];; stfe [%1]=f6" : "=f"(f6): "r"(dst),  "r"(src) : "memory"); \
558         } while(0)
559
560 #endif /* !CONFIG_IA32_SUPPORT */
561
562 #endif /* _ASM_IA64_IA32_H */