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