processor_64.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. /*
  2. * Copyright (C) 1994 Linus Torvalds
  3. */
  4. #ifndef __ASM_X86_64_PROCESSOR_H
  5. #define __ASM_X86_64_PROCESSOR_H
  6. #include <asm/segment.h>
  7. #include <asm/page.h>
  8. #include <asm/types.h>
  9. #include <asm/sigcontext.h>
  10. #include <asm/cpufeature.h>
  11. #include <linux/threads.h>
  12. #include <asm/msr.h>
  13. #include <asm/current.h>
  14. #include <asm/system.h>
  15. #include <asm/mmsegment.h>
  16. #include <asm/percpu.h>
  17. #include <linux/personality.h>
  18. #include <linux/cpumask.h>
  19. #include <asm/desc_defs.h>
  20. /*
  21. * CPU type and hardware bug flags. Kept separately for each CPU.
  22. */
  23. struct cpuinfo_x86 {
  24. __u8 x86; /* CPU family */
  25. __u8 x86_vendor; /* CPU vendor */
  26. __u8 x86_model;
  27. __u8 x86_mask;
  28. int cpuid_level; /* Maximum supported CPUID level, -1=no CPUID */
  29. __u32 x86_capability[NCAPINTS];
  30. char x86_vendor_id[16];
  31. char x86_model_id[64];
  32. int x86_cache_size; /* in KB */
  33. int x86_clflush_size;
  34. int x86_cache_alignment;
  35. int x86_tlbsize; /* number of 4K pages in DTLB/ITLB combined(in pages)*/
  36. __u8 x86_virt_bits, x86_phys_bits;
  37. __u8 x86_max_cores; /* cpuid returned max cores value */
  38. __u8 x86_coreid_bits; /* cpuid returned core id bits */
  39. __u32 x86_power;
  40. __u32 extended_cpuid_level; /* Max extended CPUID function supported */
  41. unsigned long loops_per_jiffy;
  42. #ifdef CONFIG_SMP
  43. cpumask_t llc_shared_map; /* cpus sharing the last level cache */
  44. #endif
  45. __u8 apicid;
  46. #ifdef CONFIG_SMP
  47. __u8 booted_cores; /* number of cores as seen by OS */
  48. __u8 phys_proc_id; /* Physical Processor id. */
  49. __u8 cpu_core_id; /* Core id. */
  50. __u8 cpu_index; /* index into per_cpu list */
  51. #endif
  52. } ____cacheline_aligned;
  53. #define X86_VENDOR_INTEL 0
  54. #define X86_VENDOR_CYRIX 1
  55. #define X86_VENDOR_AMD 2
  56. #define X86_VENDOR_UMC 3
  57. #define X86_VENDOR_NEXGEN 4
  58. #define X86_VENDOR_CENTAUR 5
  59. #define X86_VENDOR_TRANSMETA 7
  60. #define X86_VENDOR_NUM 8
  61. #define X86_VENDOR_UNKNOWN 0xff
  62. #ifdef CONFIG_SMP
  63. DECLARE_PER_CPU(struct cpuinfo_x86, cpu_info);
  64. #define cpu_data(cpu) per_cpu(cpu_info, cpu)
  65. #define current_cpu_data cpu_data(smp_processor_id())
  66. #else
  67. #define cpu_data(cpu) boot_cpu_data
  68. #define current_cpu_data boot_cpu_data
  69. #endif
  70. extern char ignore_irq13;
  71. extern void identify_cpu(struct cpuinfo_x86 *);
  72. /*
  73. * User space process size. 47bits minus one guard page.
  74. */
  75. #define TASK_SIZE64 (0x800000000000UL - 4096)
  76. /* This decides where the kernel will search for a free chunk of vm
  77. * space during mmap's.
  78. */
  79. #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? 0xc0000000 : 0xFFFFe000)
  80. #define TASK_SIZE (test_thread_flag(TIF_IA32) ? IA32_PAGE_OFFSET : TASK_SIZE64)
  81. #define TASK_SIZE_OF(child) ((test_tsk_thread_flag(child, TIF_IA32)) ? IA32_PAGE_OFFSET : TASK_SIZE64)
  82. struct i387_fxsave_struct {
  83. u16 cwd;
  84. u16 swd;
  85. u16 twd;
  86. u16 fop;
  87. u64 rip;
  88. u64 rdp;
  89. u32 mxcsr;
  90. u32 mxcsr_mask;
  91. u32 st_space[32]; /* 8*16 bytes for each FP-reg = 128 bytes */
  92. u32 xmm_space[64]; /* 16*16 bytes for each XMM-reg = 256 bytes */
  93. u32 padding[24];
  94. } __attribute__ ((aligned (16)));
  95. union i387_union {
  96. struct i387_fxsave_struct fxsave;
  97. };
  98. extern struct cpuinfo_x86 boot_cpu_data;
  99. /* Save the original ist values for checking stack pointers during debugging */
  100. struct orig_ist {
  101. unsigned long ist[7];
  102. };
  103. DECLARE_PER_CPU(struct orig_ist, orig_ist);
  104. #define INIT_THREAD { \
  105. .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
  106. }
  107. #define INIT_TSS { \
  108. .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
  109. }
  110. #define INIT_MMAP \
  111. { &init_mm, 0, 0, NULL, PAGE_SHARED, VM_READ | VM_WRITE | VM_EXEC, 1, NULL, NULL }
  112. #define start_thread(regs,new_rip,new_rsp) do { \
  113. asm volatile("movl %0,%%fs; movl %0,%%es; movl %0,%%ds": :"r" (0)); \
  114. load_gs_index(0); \
  115. (regs)->ip = (new_rip); \
  116. (regs)->sp = (new_rsp); \
  117. write_pda(oldrsp, (new_rsp)); \
  118. (regs)->cs = __USER_CS; \
  119. (regs)->ss = __USER_DS; \
  120. (regs)->flags = 0x200; \
  121. set_fs(USER_DS); \
  122. } while(0)
  123. /*
  124. * Return saved PC of a blocked thread.
  125. * What is this good for? it will be always the scheduler or ret_from_fork.
  126. */
  127. #define thread_saved_pc(t) (*(unsigned long *)((t)->thread.sp - 8))
  128. #define task_pt_regs(tsk) ((struct pt_regs *)(tsk)->thread.sp0 - 1)
  129. #define KSTK_ESP(tsk) -1 /* sorry. doesn't work for syscall. */
  130. #if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2)
  131. #define ASM_NOP1 P6_NOP1
  132. #define ASM_NOP2 P6_NOP2
  133. #define ASM_NOP3 P6_NOP3
  134. #define ASM_NOP4 P6_NOP4
  135. #define ASM_NOP5 P6_NOP5
  136. #define ASM_NOP6 P6_NOP6
  137. #define ASM_NOP7 P6_NOP7
  138. #define ASM_NOP8 P6_NOP8
  139. #else
  140. #define ASM_NOP1 K8_NOP1
  141. #define ASM_NOP2 K8_NOP2
  142. #define ASM_NOP3 K8_NOP3
  143. #define ASM_NOP4 K8_NOP4
  144. #define ASM_NOP5 K8_NOP5
  145. #define ASM_NOP6 K8_NOP6
  146. #define ASM_NOP7 K8_NOP7
  147. #define ASM_NOP8 K8_NOP8
  148. #endif
  149. /* Opteron nops */
  150. #define K8_NOP1 ".byte 0x90\n"
  151. #define K8_NOP2 ".byte 0x66,0x90\n"
  152. #define K8_NOP3 ".byte 0x66,0x66,0x90\n"
  153. #define K8_NOP4 ".byte 0x66,0x66,0x66,0x90\n"
  154. #define K8_NOP5 K8_NOP3 K8_NOP2
  155. #define K8_NOP6 K8_NOP3 K8_NOP3
  156. #define K8_NOP7 K8_NOP4 K8_NOP3
  157. #define K8_NOP8 K8_NOP4 K8_NOP4
  158. /* P6 nops */
  159. /* uses eax dependencies (Intel-recommended choice) */
  160. #define P6_NOP1 ".byte 0x90\n"
  161. #define P6_NOP2 ".byte 0x66,0x90\n"
  162. #define P6_NOP3 ".byte 0x0f,0x1f,0x00\n"
  163. #define P6_NOP4 ".byte 0x0f,0x1f,0x40,0\n"
  164. #define P6_NOP5 ".byte 0x0f,0x1f,0x44,0x00,0\n"
  165. #define P6_NOP6 ".byte 0x66,0x0f,0x1f,0x44,0x00,0\n"
  166. #define P6_NOP7 ".byte 0x0f,0x1f,0x80,0,0,0,0\n"
  167. #define P6_NOP8 ".byte 0x0f,0x1f,0x84,0x00,0,0,0,0\n"
  168. #define ASM_NOP_MAX 8
  169. static inline void prefetchw(void *x)
  170. {
  171. alternative_input("prefetcht0 (%1)",
  172. "prefetchw (%1)",
  173. X86_FEATURE_3DNOW,
  174. "r" (x));
  175. }
  176. #define stack_current() \
  177. ({ \
  178. struct thread_info *ti; \
  179. asm("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
  180. ti->task; \
  181. })
  182. #endif /* __ASM_X86_64_PROCESSOR_H */