ia32priv.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542
  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 partial_page {
  21. struct 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 partial_page_list {
  29. struct partial_page *pp_head; /* list head, points to the lowest
  30. * addressed partial page */
  31. struct rb_root ppl_rb;
  32. struct 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 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. struct old_linux32_dirent {
  245. u32 d_ino;
  246. u32 d_offset;
  247. u16 d_namlen;
  248. char d_name[1];
  249. };
  250. /*
  251. * IA-32 ELF specific definitions for IA-64.
  252. */
  253. #define _ASM_IA64_ELF_H /* Don't include elf.h */
  254. #include <linux/sched.h>
  255. #include <asm/processor.h>
  256. /*
  257. * This is used to ensure we don't load something for the wrong architecture.
  258. */
  259. #define elf_check_arch(x) ((x)->e_machine == EM_386)
  260. /*
  261. * These are used to set parameters in the core dumps.
  262. */
  263. #define ELF_CLASS ELFCLASS32
  264. #define ELF_DATA ELFDATA2LSB
  265. #define ELF_ARCH EM_386
  266. #define IA32_STACK_TOP IA32_PAGE_OFFSET
  267. #define IA32_GATE_OFFSET IA32_PAGE_OFFSET
  268. #define IA32_GATE_END IA32_PAGE_OFFSET + PAGE_SIZE
  269. /*
  270. * The system segments (GDT, TSS, LDT) have to be mapped below 4GB so the IA-32 engine can
  271. * access them.
  272. */
  273. #define IA32_GDT_OFFSET (IA32_PAGE_OFFSET + PAGE_SIZE)
  274. #define IA32_TSS_OFFSET (IA32_PAGE_OFFSET + 2*PAGE_SIZE)
  275. #define IA32_LDT_OFFSET (IA32_PAGE_OFFSET + 3*PAGE_SIZE)
  276. #define ELF_EXEC_PAGESIZE IA32_PAGE_SIZE
  277. /*
  278. * This is the location that an ET_DYN program is loaded if exec'ed.
  279. * Typical use of this is to invoke "./ld.so someprog" to test out a
  280. * new version of the loader. We need to make sure that it is out of
  281. * the way of the program that it will "exec", and that there is
  282. * sufficient room for the brk.
  283. */
  284. #define ELF_ET_DYN_BASE (IA32_PAGE_OFFSET/3 + 0x1000000)
  285. void ia64_elf32_init(struct pt_regs *regs);
  286. #define ELF_PLAT_INIT(_r, load_addr) ia64_elf32_init(_r)
  287. #define elf_addr_t u32
  288. /* This macro yields a bitmask that programs can use to figure out
  289. what instruction set this CPU supports. */
  290. #define ELF_HWCAP 0
  291. /* This macro yields a string that ld.so will use to load
  292. implementation specific libraries for optimization. Not terribly
  293. relevant until we have real hardware to play with... */
  294. #define ELF_PLATFORM NULL
  295. #ifdef __KERNEL__
  296. # define SET_PERSONALITY(EX,IBCS2) \
  297. (current->personality = (IBCS2) ? PER_SVR4 : PER_LINUX)
  298. #endif
  299. #define IA32_EFLAG 0x200
  300. /*
  301. * IA-32 ELF specific definitions for IA-64.
  302. */
  303. #define __USER_CS 0x23
  304. #define __USER_DS 0x2B
  305. /*
  306. * The per-cpu GDT has 32 entries: see <asm-i386/segment.h>
  307. */
  308. #define GDT_ENTRIES 32
  309. #define GDT_SIZE (GDT_ENTRIES * 8)
  310. #define TSS_ENTRY 14
  311. #define LDT_ENTRY (TSS_ENTRY + 1)
  312. #define IA32_SEGSEL_RPL (0x3 << 0)
  313. #define IA32_SEGSEL_TI (0x1 << 2)
  314. #define IA32_SEGSEL_INDEX_SHIFT 3
  315. #define _TSS ((unsigned long) TSS_ENTRY << IA32_SEGSEL_INDEX_SHIFT)
  316. #define _LDT ((unsigned long) LDT_ENTRY << IA32_SEGSEL_INDEX_SHIFT)
  317. #define IA32_SEG_BASE 16
  318. #define IA32_SEG_TYPE 40
  319. #define IA32_SEG_SYS 44
  320. #define IA32_SEG_DPL 45
  321. #define IA32_SEG_P 47
  322. #define IA32_SEG_HIGH_LIMIT 48
  323. #define IA32_SEG_AVL 52
  324. #define IA32_SEG_DB 54
  325. #define IA32_SEG_G 55
  326. #define IA32_SEG_HIGH_BASE 56
  327. #define IA32_SEG_DESCRIPTOR(base, limit, segtype, nonsysseg, dpl, segpresent, avl, segdb, gran) \
  328. (((limit) & 0xffff) \
  329. | (((unsigned long) (base) & 0xffffff) << IA32_SEG_BASE) \
  330. | ((unsigned long) (segtype) << IA32_SEG_TYPE) \
  331. | ((unsigned long) (nonsysseg) << IA32_SEG_SYS) \
  332. | ((unsigned long) (dpl) << IA32_SEG_DPL) \
  333. | ((unsigned long) (segpresent) << IA32_SEG_P) \
  334. | ((((unsigned long) (limit) >> 16) & 0xf) << IA32_SEG_HIGH_LIMIT) \
  335. | ((unsigned long) (avl) << IA32_SEG_AVL) \
  336. | ((unsigned long) (segdb) << IA32_SEG_DB) \
  337. | ((unsigned long) (gran) << IA32_SEG_G) \
  338. | ((((unsigned long) (base) >> 24) & 0xff) << IA32_SEG_HIGH_BASE))
  339. #define SEG_LIM 32
  340. #define SEG_TYPE 52
  341. #define SEG_SYS 56
  342. #define SEG_DPL 57
  343. #define SEG_P 59
  344. #define SEG_AVL 60
  345. #define SEG_DB 62
  346. #define SEG_G 63
  347. /* Unscramble an IA-32 segment descriptor into the IA-64 format. */
  348. #define IA32_SEG_UNSCRAMBLE(sd) \
  349. ( (((sd) >> IA32_SEG_BASE) & 0xffffff) | ((((sd) >> IA32_SEG_HIGH_BASE) & 0xff) << 24) \
  350. | ((((sd) & 0xffff) | ((((sd) >> IA32_SEG_HIGH_LIMIT) & 0xf) << 16)) << SEG_LIM) \
  351. | ((((sd) >> IA32_SEG_TYPE) & 0xf) << SEG_TYPE) \
  352. | ((((sd) >> IA32_SEG_SYS) & 0x1) << SEG_SYS) \
  353. | ((((sd) >> IA32_SEG_DPL) & 0x3) << SEG_DPL) \
  354. | ((((sd) >> IA32_SEG_P) & 0x1) << SEG_P) \
  355. | ((((sd) >> IA32_SEG_AVL) & 0x1) << SEG_AVL) \
  356. | ((((sd) >> IA32_SEG_DB) & 0x1) << SEG_DB) \
  357. | ((((sd) >> IA32_SEG_G) & 0x1) << SEG_G))
  358. #define IA32_IOBASE 0x2000000000000000UL /* Virtual address for I/O space */
  359. #define IA32_CR0 0x80000001 /* Enable PG and PE bits */
  360. #define IA32_CR4 0x600 /* MMXEX and FXSR on */
  361. /*
  362. * IA32 floating point control registers starting values
  363. */
  364. #define IA32_FSR_DEFAULT 0x55550000 /* set all tag bits */
  365. #define IA32_FCR_DEFAULT 0x17800000037fUL /* extended precision, all masks */
  366. #define IA32_PTRACE_GETREGS 12
  367. #define IA32_PTRACE_SETREGS 13
  368. #define IA32_PTRACE_GETFPREGS 14
  369. #define IA32_PTRACE_SETFPREGS 15
  370. #define IA32_PTRACE_GETFPXREGS 18
  371. #define IA32_PTRACE_SETFPXREGS 19
  372. #define ia32_start_thread(regs,new_ip,new_sp) do { \
  373. set_fs(USER_DS); \
  374. ia64_psr(regs)->cpl = 3; /* set user mode */ \
  375. ia64_psr(regs)->ri = 0; /* clear return slot number */ \
  376. ia64_psr(regs)->is = 1; /* IA-32 instruction set */ \
  377. regs->cr_iip = new_ip; \
  378. regs->ar_rsc = 0xc; /* enforced lazy mode, priv. level 3 */ \
  379. regs->ar_rnat = 0; \
  380. regs->loadrs = 0; \
  381. regs->r12 = new_sp; \
  382. } while (0)
  383. /*
  384. * Local Descriptor Table (LDT) related declarations.
  385. */
  386. #define IA32_LDT_ENTRIES 8192 /* Maximum number of LDT entries supported. */
  387. #define IA32_LDT_ENTRY_SIZE 8 /* The size of each LDT entry. */
  388. #define LDT_entry_a(info) \
  389. ((((info)->base_addr & 0x0000ffff) << 16) | ((info)->limit & 0x0ffff))
  390. #define LDT_entry_b(info) \
  391. (((info)->base_addr & 0xff000000) | \
  392. (((info)->base_addr & 0x00ff0000) >> 16) | \
  393. ((info)->limit & 0xf0000) | \
  394. (((info)->read_exec_only ^ 1) << 9) | \
  395. ((info)->contents << 10) | \
  396. (((info)->seg_not_present ^ 1) << 15) | \
  397. ((info)->seg_32bit << 22) | \
  398. ((info)->limit_in_pages << 23) | \
  399. ((info)->useable << 20) | \
  400. 0x7100)
  401. #define LDT_empty(info) ( \
  402. (info)->base_addr == 0 && \
  403. (info)->limit == 0 && \
  404. (info)->contents == 0 && \
  405. (info)->read_exec_only == 1 && \
  406. (info)->seg_32bit == 0 && \
  407. (info)->limit_in_pages == 0 && \
  408. (info)->seg_not_present == 1 && \
  409. (info)->useable == 0 )
  410. static inline void
  411. load_TLS (struct thread_struct *t, unsigned int cpu)
  412. {
  413. extern unsigned long *cpu_gdt_table[NR_CPUS];
  414. memcpy(cpu_gdt_table[cpu] + GDT_ENTRY_TLS_MIN + 0, &t->tls_array[0], sizeof(long));
  415. memcpy(cpu_gdt_table[cpu] + GDT_ENTRY_TLS_MIN + 1, &t->tls_array[1], sizeof(long));
  416. memcpy(cpu_gdt_table[cpu] + GDT_ENTRY_TLS_MIN + 2, &t->tls_array[2], sizeof(long));
  417. }
  418. struct ia32_user_desc {
  419. unsigned int entry_number;
  420. unsigned int base_addr;
  421. unsigned int limit;
  422. unsigned int seg_32bit:1;
  423. unsigned int contents:2;
  424. unsigned int read_exec_only:1;
  425. unsigned int limit_in_pages:1;
  426. unsigned int seg_not_present:1;
  427. unsigned int useable:1;
  428. };
  429. struct linux_binprm;
  430. extern void ia32_init_addr_space (struct pt_regs *regs);
  431. extern int ia32_setup_arg_pages (struct linux_binprm *bprm, int exec_stack);
  432. extern unsigned long ia32_do_mmap (struct file *, unsigned long, unsigned long, int, int, loff_t);
  433. extern void ia32_load_segment_descriptors (struct task_struct *task);
  434. #define ia32f2ia64f(dst,src) \
  435. do { \
  436. ia64_ldfe(6,src); \
  437. ia64_stop(); \
  438. ia64_stf_spill(dst, 6); \
  439. } while(0)
  440. #define ia64f2ia32f(dst,src) \
  441. do { \
  442. ia64_ldf_fill(6, src); \
  443. ia64_stop(); \
  444. ia64_stfe(dst, 6); \
  445. } while(0)
  446. struct user_regs_struct32 {
  447. __u32 ebx, ecx, edx, esi, edi, ebp, eax;
  448. unsigned short ds, __ds, es, __es;
  449. unsigned short fs, __fs, gs, __gs;
  450. __u32 orig_eax, eip;
  451. unsigned short cs, __cs;
  452. __u32 eflags, esp;
  453. unsigned short ss, __ss;
  454. };
  455. /* Prototypes for use in elfcore32.h */
  456. extern int save_ia32_fpstate (struct task_struct *, struct ia32_user_i387_struct __user *);
  457. extern int save_ia32_fpxstate (struct task_struct *, struct ia32_user_fxsr_struct __user *);
  458. #endif /* !CONFIG_IA32_SUPPORT */
  459. #endif /* _ASM_IA64_IA32_PRIV_H */