ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.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 #define SIGEV_PAD_SIZE32 ((SIGEV_MAX_SIZE/sizeof(int)) - 3)
203
204 typedef struct siginfo32 {
205         int si_signo;
206         int si_errno;
207         int si_code;
208
209         union {
210                 int _pad[((128/sizeof(int)) - 3)];
211
212                 /* kill() */
213                 struct {
214                         unsigned int _pid;      /* sender's pid */
215                         unsigned int _uid;      /* sender's uid */
216                 } _kill;
217
218                 /* POSIX.1b timers */
219                 struct {
220                         timer_t _tid;           /* timer id */
221                         int _overrun;           /* overrun count */
222                         char _pad[sizeof(unsigned int) - sizeof(int)];
223                         sigval_t32 _sigval;     /* same as below */
224                         int _sys_private;       /* not to be passed to user */
225                 } _timer;
226
227                 /* POSIX.1b signals */
228                 struct {
229                         unsigned int _pid;      /* sender's pid */
230                         unsigned int _uid;      /* sender's uid */
231                         sigval_t32 _sigval;
232                 } _rt;
233
234                 /* SIGCHLD */
235                 struct {
236                         unsigned int _pid;      /* which child */
237                         unsigned int _uid;      /* sender's uid */
238                         int _status;            /* exit code */
239                         compat_clock_t _utime;
240                         compat_clock_t _stime;
241                 } _sigchld;
242
243                 /* SIGILL, SIGFPE, SIGSEGV, SIGBUS */
244                 struct {
245                         unsigned int _addr;     /* faulting insn/memory ref. */
246                 } _sigfault;
247
248                 /* SIGPOLL */
249                 struct {
250                         int _band;      /* POLL_IN, POLL_OUT, POLL_MSG */
251                         int _fd;
252                 } _sigpoll;
253         } _sifields;
254 } siginfo_t32;
255
256 typedef struct sigevent32 {
257         sigval_t32 sigev_value;
258         int sigev_signo;
259         int sigev_notify;
260         union {
261                 int _pad[SIGEV_PAD_SIZE32];
262                 struct {
263                         u32 _function;
264                         u32 _attribute; /* really pthread_attr_t */
265                 } _sigev_thread;
266         } _sigev_un;
267 } sigevent_t32;
268
269 struct old_linux32_dirent {
270         u32     d_ino;
271         u32     d_offset;
272         u16     d_namlen;
273         char    d_name[1];
274 };
275
276 /*
277  * IA-32 ELF specific definitions for IA-64.
278  */
279
280 #define _ASM_IA64_ELF_H         /* Don't include elf.h */
281
282 #include <linux/sched.h>
283 #include <asm/processor.h>
284
285 /*
286  * This is used to ensure we don't load something for the wrong architecture.
287  */
288 #define elf_check_arch(x) ((x)->e_machine == EM_386)
289
290 /*
291  * These are used to set parameters in the core dumps.
292  */
293 #define ELF_CLASS       ELFCLASS32
294 #define ELF_DATA        ELFDATA2LSB
295 #define ELF_ARCH        EM_386
296
297 #define IA32_PAGE_OFFSET        0xc0000000
298 #define IA32_STACK_TOP          IA32_PAGE_OFFSET
299
300 /*
301  * The system segments (GDT, TSS, LDT) have to be mapped below 4GB so the IA-32 engine can
302  * access them.
303  */
304 #define IA32_GDT_OFFSET         (IA32_PAGE_OFFSET)
305 #define IA32_TSS_OFFSET         (IA32_PAGE_OFFSET + PAGE_SIZE)
306 #define IA32_LDT_OFFSET         (IA32_PAGE_OFFSET + 2*PAGE_SIZE)
307
308 #define ELF_EXEC_PAGESIZE       IA32_PAGE_SIZE
309
310 /*
311  * This is the location that an ET_DYN program is loaded if exec'ed.
312  * Typical use of this is to invoke "./ld.so someprog" to test out a
313  * new version of the loader.  We need to make sure that it is out of
314  * the way of the program that it will "exec", and that there is
315  * sufficient room for the brk.
316  */
317 #define ELF_ET_DYN_BASE         (IA32_PAGE_OFFSET/3 + 0x1000000)
318
319 void ia64_elf32_init(struct pt_regs *regs);
320 #define ELF_PLAT_INIT(_r, load_addr)    ia64_elf32_init(_r)
321
322 #define elf_addr_t      u32
323
324 /* This macro yields a bitmask that programs can use to figure out
325    what instruction set this CPU supports.  */
326 #define ELF_HWCAP       0
327
328 /* This macro yields a string that ld.so will use to load
329    implementation specific libraries for optimization.  Not terribly
330    relevant until we have real hardware to play with... */
331 #define ELF_PLATFORM    0
332
333 #ifdef __KERNEL__
334 # define SET_PERSONALITY(EX,IBCS2)                              \
335         (current->personality = (IBCS2) ? PER_SVR4 : PER_LINUX)
336 #endif
337
338 #define IA32_EFLAG      0x200
339
340 /*
341  * IA-32 ELF specific definitions for IA-64.
342  */
343
344 #define __USER_CS      0x23
345 #define __USER_DS      0x2B
346
347 /*
348  * The per-cpu GDT has 32 entries: see <asm-i386/segment.h>
349  */
350 #define GDT_ENTRIES 32
351
352 #define GDT_SIZE        (GDT_ENTRIES * 8)
353
354 #define TSS_ENTRY 14
355 #define LDT_ENTRY       (TSS_ENTRY + 1)
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 _TSS                    ((unsigned long) TSS_ENTRY << IA32_SEGSEL_INDEX_SHIFT)
362 #define _LDT                    ((unsigned long) LDT_ENTRY << IA32_SEGSEL_INDEX_SHIFT)
363
364 #define IA32_SEG_BASE           16
365 #define IA32_SEG_TYPE           40
366 #define IA32_SEG_SYS            44
367 #define IA32_SEG_DPL            45
368 #define IA32_SEG_P              47
369 #define IA32_SEG_HIGH_LIMIT     48
370 #define IA32_SEG_AVL            52
371 #define IA32_SEG_DB             54
372 #define IA32_SEG_G              55
373 #define IA32_SEG_HIGH_BASE      56
374
375 #define IA32_SEG_DESCRIPTOR(base, limit, segtype, nonsysseg, dpl, segpresent, avl, segdb, gran) \
376                (((limit) & 0xffff)                                                              \
377                 | (((unsigned long) (base) & 0xffffff) << IA32_SEG_BASE)                        \
378                 | ((unsigned long) (segtype) << IA32_SEG_TYPE)                                  \
379                 | ((unsigned long) (nonsysseg) << IA32_SEG_SYS)                                 \
380                 | ((unsigned long) (dpl) << IA32_SEG_DPL)                                       \
381                 | ((unsigned long) (segpresent) << IA32_SEG_P)                                  \
382                 | ((((unsigned long) (limit) >> 16) & 0xf) << IA32_SEG_HIGH_LIMIT)              \
383                 | ((unsigned long) (avl) << IA32_SEG_AVL)                                       \
384                 | ((unsigned long) (segdb) << IA32_SEG_DB)                                      \
385                 | ((unsigned long) (gran) << IA32_SEG_G)                                        \
386                 | ((((unsigned long) (base) >> 24) & 0xff) << IA32_SEG_HIGH_BASE))
387
388 #define SEG_LIM         32
389 #define SEG_TYPE        52
390 #define SEG_SYS         56
391 #define SEG_DPL         57
392 #define SEG_P           59
393 #define SEG_AVL         60
394 #define SEG_DB          62
395 #define SEG_G           63
396
397 /* Unscramble an IA-32 segment descriptor into the IA-64 format.  */
398 #define IA32_SEG_UNSCRAMBLE(sd)                                                                  \
399         (   (((sd) >> IA32_SEG_BASE) & 0xffffff) | ((((sd) >> IA32_SEG_HIGH_BASE) & 0xff) << 24) \
400          | ((((sd) & 0xffff) | ((((sd) >> IA32_SEG_HIGH_LIMIT) & 0xf) << 16)) << SEG_LIM)        \
401          | ((((sd) >> IA32_SEG_TYPE) & 0xf) << SEG_TYPE)                                         \
402          | ((((sd) >> IA32_SEG_SYS) & 0x1) << SEG_SYS)                                           \
403          | ((((sd) >> IA32_SEG_DPL) & 0x3) << SEG_DPL)                                           \
404          | ((((sd) >> IA32_SEG_P) & 0x1) << SEG_P)                                               \
405          | ((((sd) >> IA32_SEG_AVL) & 0x1) << SEG_AVL)                                           \
406          | ((((sd) >> IA32_SEG_DB) & 0x1) << SEG_DB)                                             \
407          | ((((sd) >> IA32_SEG_G) & 0x1) << SEG_G))
408
409 #define IA32_IOBASE     0x2000000000000000 /* Virtual address for I/O space */
410
411 #define IA32_CR0        0x80000001      /* Enable PG and PE bits */
412 #define IA32_CR4        0x600           /* MMXEX and FXSR on */
413
414 /*
415  *  IA32 floating point control registers starting values
416  */
417
418 #define IA32_FSR_DEFAULT        0x55550000              /* set all tag bits */
419 #define IA32_FCR_DEFAULT        0x17800000037fUL        /* extended precision, all masks */
420
421 #define IA32_PTRACE_GETREGS     12
422 #define IA32_PTRACE_SETREGS     13
423 #define IA32_PTRACE_GETFPREGS   14
424 #define IA32_PTRACE_SETFPREGS   15
425 #define IA32_PTRACE_GETFPXREGS  18
426 #define IA32_PTRACE_SETFPXREGS  19
427
428 #define ia32_start_thread(regs,new_ip,new_sp) do {                              \
429         set_fs(USER_DS);                                                        \
430         ia64_psr(regs)->cpl = 3;        /* set user mode */                     \
431         ia64_psr(regs)->ri = 0;         /* clear return slot number */          \
432         ia64_psr(regs)->is = 1;         /* IA-32 instruction set */             \
433         regs->cr_iip = new_ip;                                                  \
434         regs->ar_rsc = 0xc;             /* enforced lazy mode, priv. level 3 */ \
435         regs->ar_rnat = 0;                                                      \
436         regs->loadrs = 0;                                                       \
437         regs->r12 = new_sp;                                                     \
438 } while (0)
439
440 /*
441  * Local Descriptor Table (LDT) related declarations.
442  */
443
444 #define IA32_LDT_ENTRIES        8192            /* Maximum number of LDT entries supported. */
445 #define IA32_LDT_ENTRY_SIZE     8               /* The size of each LDT entry. */
446
447 #define LDT_entry_a(info) \
448         ((((info)->base_addr & 0x0000ffff) << 16) | ((info)->limit & 0x0ffff))
449
450 #define LDT_entry_b(info)                               \
451         (((info)->base_addr & 0xff000000) |             \
452         (((info)->base_addr & 0x00ff0000) >> 16) |      \
453         ((info)->limit & 0xf0000) |                     \
454         (((info)->read_exec_only ^ 1) << 9) |           \
455         ((info)->contents << 10) |                      \
456         (((info)->seg_not_present ^ 1) << 15) |         \
457         ((info)->seg_32bit << 22) |                     \
458         ((info)->limit_in_pages << 23) |                \
459         ((info)->useable << 20) |                       \
460         0x7100)
461
462 #define LDT_empty(info) (                       \
463         (info)->base_addr       == 0    &&      \
464         (info)->limit           == 0    &&      \
465         (info)->contents        == 0    &&      \
466         (info)->read_exec_only  == 1    &&      \
467         (info)->seg_32bit       == 0    &&      \
468         (info)->limit_in_pages  == 0    &&      \
469         (info)->seg_not_present == 1    &&      \
470         (info)->useable         == 0    )
471
472 static inline void
473 load_TLS (struct thread_struct *t, unsigned int cpu)
474 {
475         extern unsigned long *cpu_gdt_table[NR_CPUS];
476
477         memcpy(cpu_gdt_table[cpu] + GDT_ENTRY_TLS_MIN + 0, &t->tls_array[0], sizeof(long));
478         memcpy(cpu_gdt_table[cpu] + GDT_ENTRY_TLS_MIN + 1, &t->tls_array[1], sizeof(long));
479         memcpy(cpu_gdt_table[cpu] + GDT_ENTRY_TLS_MIN + 2, &t->tls_array[2], sizeof(long));
480 }
481
482 struct ia32_user_desc {
483         unsigned int entry_number;
484         unsigned int base_addr;
485         unsigned int limit;
486         unsigned int seg_32bit:1;
487         unsigned int contents:2;
488         unsigned int read_exec_only:1;
489         unsigned int limit_in_pages:1;
490         unsigned int seg_not_present:1;
491         unsigned int useable:1;
492 };
493
494 struct linux_binprm;
495
496 extern void ia32_init_addr_space (struct pt_regs *regs);
497 extern int ia32_setup_arg_pages (struct linux_binprm *bprm, int exec_stack);
498 extern unsigned long ia32_do_mmap (struct file *, unsigned long, unsigned long, int, int, loff_t);
499 extern void ia32_load_segment_descriptors (struct task_struct *task);
500
501 #define ia32f2ia64f(dst,src)                    \
502 do {                                            \
503         ia64_ldfe(6,src);                       \
504         ia64_stop();                            \
505         ia64_stf_spill(dst, 6);                 \
506 } while(0)
507
508 #define ia64f2ia32f(dst,src)                    \
509 do {                                            \
510         ia64_ldf_fill(6, src);                  \
511         ia64_stop();                            \
512         ia64_stfe(dst, 6);                      \
513 } while(0)
514
515 struct user_regs_struct32 {
516         __u32 ebx, ecx, edx, esi, edi, ebp, eax;
517         unsigned short ds, __ds, es, __es;
518         unsigned short fs, __fs, gs, __gs;
519         __u32 orig_eax, eip;
520         unsigned short cs, __cs;
521         __u32 eflags, esp;
522         unsigned short ss, __ss;
523 };
524
525 /* Prototypes for use in elfcore32.h */
526 extern int save_ia32_fpstate (struct task_struct *tsk, struct ia32_user_i387_struct *save);
527 extern int save_ia32_fpxstate (struct task_struct *tsk, struct ia32_user_fxsr_struct *save);
528
529 #endif /* !CONFIG_IA32_SUPPORT */
530
531 #endif /* _ASM_IA64_IA32_H */