ia32priv.h 15 KB

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