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