1 #ifndef _ASM_IA64_IA32_H
2 #define _ASM_IA64_IA32_H
4 #include <linux/config.h>
8 #ifdef CONFIG_IA32_SUPPORT
10 #include <linux/binfmts.h>
11 #include <linux/compat.h>
13 #include <asm/processor.h>
16 * 32 bit structures for IA32 support.
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 */
27 * As documented in the iBCS2 standard..
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.
35 unsigned short significand[4];
36 unsigned short exponent;
40 unsigned short significand[4];
41 unsigned short exponent;
42 unsigned short padding[3];
46 unsigned int element[4];
50 struct _fpstate_ia32 {
58 struct _fpreg_ia32 _st[8];
59 unsigned short status;
60 unsigned short magic; /* 0xffff = regular FPU data only */
62 /* FXSR FPU environment */
63 unsigned int _fxsr_env[6]; /* FXSR FPU env is ignored */
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];
71 struct sigcontext_ia32 {
72 unsigned short gs, __gsh;
73 unsigned short fs, __fsh;
74 unsigned short es, __esh;
75 unsigned short ds, __dsh;
87 unsigned short cs, __csh;
89 unsigned int esp_at_signal;
90 unsigned short ss, __ssh;
91 unsigned int fpstate; /* really (struct _fpstate_ia32 *) */
98 * IA32 (Pentium III/4) FXSR, SSE support
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.
107 struct ia32_user_i387_struct {
115 /* 8*10 bytes for each FP-reg = 80 bytes */
116 struct _fpreg_ia32 st_space[8];
119 struct ia32_user_fxsr_struct {
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 */
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)
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 */
150 struct old_sigaction32 {
151 unsigned int sa_handler; /* Really a pointer, but need to deal
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 */
158 typedef struct sigaltstack_ia32 {
161 unsigned int ss_size;
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 */
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;
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;
197 typedef union sigval32 {
199 unsigned int sival_ptr;
202 #define SIGEV_PAD_SIZE32 ((SIGEV_MAX_SIZE/sizeof(int)) - 3)
204 typedef struct siginfo32 {
210 int _pad[((128/sizeof(int)) - 3)];
214 unsigned int _pid; /* sender's pid */
215 unsigned int _uid; /* sender's uid */
218 /* POSIX.1b timers */
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 */
227 /* POSIX.1b signals */
229 unsigned int _pid; /* sender's pid */
230 unsigned int _uid; /* sender's uid */
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;
243 /* SIGILL, SIGFPE, SIGSEGV, SIGBUS */
245 unsigned int _addr; /* faulting insn/memory ref. */
250 int _band; /* POLL_IN, POLL_OUT, POLL_MSG */
256 typedef struct sigevent32 {
257 sigval_t32 sigev_value;
261 int _pad[SIGEV_PAD_SIZE32];
264 u32 _attribute; /* really pthread_attr_t */
269 struct old_linux32_dirent {
277 * IA-32 ELF specific definitions for IA-64.
280 #define _ASM_IA64_ELF_H /* Don't include elf.h */
282 #include <linux/sched.h>
283 #include <asm/processor.h>
286 * This is used to ensure we don't load something for the wrong architecture.
288 #define elf_check_arch(x) ((x)->e_machine == EM_386)
291 * These are used to set parameters in the core dumps.
293 #define ELF_CLASS ELFCLASS32
294 #define ELF_DATA ELFDATA2LSB
295 #define ELF_ARCH EM_386
297 #define IA32_PAGE_OFFSET 0xc0000000
298 #define IA32_STACK_TOP IA32_PAGE_OFFSET
301 * The system segments (GDT, TSS, LDT) have to be mapped below 4GB so the IA-32 engine can
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)
308 #define ELF_EXEC_PAGESIZE IA32_PAGE_SIZE
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.
317 #define ELF_ET_DYN_BASE (IA32_PAGE_OFFSET/3 + 0x1000000)
319 void ia64_elf32_init(struct pt_regs *regs);
320 #define ELF_PLAT_INIT(_r, load_addr) ia64_elf32_init(_r)
322 #define elf_addr_t u32
324 /* This macro yields a bitmask that programs can use to figure out
325 what instruction set this CPU supports. */
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
334 # define SET_PERSONALITY(EX,IBCS2) \
335 (current->personality = (IBCS2) ? PER_SVR4 : PER_LINUX)
338 #define IA32_EFLAG 0x200
341 * IA-32 ELF specific definitions for IA-64.
344 #define __USER_CS 0x23
345 #define __USER_DS 0x2B
348 * The per-cpu GDT has 32 entries: see <asm-i386/segment.h>
350 #define GDT_ENTRIES 32
352 #define GDT_SIZE (GDT_ENTRIES * 8)
355 #define LDT_ENTRY (TSS_ENTRY + 1)
357 #define IA32_SEGSEL_RPL (0x3 << 0)
358 #define IA32_SEGSEL_TI (0x1 << 2)
359 #define IA32_SEGSEL_INDEX_SHIFT 3
361 #define _TSS ((unsigned long) TSS_ENTRY << IA32_SEGSEL_INDEX_SHIFT)
362 #define _LDT ((unsigned long) LDT_ENTRY << IA32_SEGSEL_INDEX_SHIFT)
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
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))
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))
409 #define IA32_IOBASE 0x2000000000000000 /* Virtual address for I/O space */
411 #define IA32_CR0 0x80000001 /* Enable PG and PE bits */
412 #define IA32_CR4 0x600 /* MMXEX and FXSR on */
415 * IA32 floating point control registers starting values
418 #define IA32_FSR_DEFAULT 0x55550000 /* set all tag bits */
419 #define IA32_FCR_DEFAULT 0x17800000037fUL /* extended precision, all masks */
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
428 #define ia32_start_thread(regs,new_ip,new_sp) do { \
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 */ \
437 regs->r12 = new_sp; \
441 * Local Descriptor Table (LDT) related declarations.
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. */
447 #define LDT_entry_a(info) \
448 ((((info)->base_addr & 0x0000ffff) << 16) | ((info)->limit & 0x0ffff))
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) | \
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 )
473 load_TLS (struct thread_struct *t, unsigned int cpu)
475 extern unsigned long *cpu_gdt_table[NR_CPUS];
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));
482 struct ia32_user_desc {
483 unsigned int entry_number;
484 unsigned int base_addr;
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;
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);
501 #define ia32f2ia64f(dst,src) \
505 ia64_stf_spill(dst, 6); \
508 #define ia64f2ia32f(dst,src) \
510 ia64_ldf_fill(6, src); \
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;
520 unsigned short cs, __cs;
522 unsigned short ss, __ss;
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);
529 #endif /* !CONFIG_IA32_SUPPORT */
531 #endif /* _ASM_IA64_IA32_H */