ia32priv.h 15 KB

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