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