processor.h
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:13k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

  1. /*
  2.  * include/asm-i386/processor.h
  3.  *
  4.  * Copyright (C) 1994 Linus Torvalds
  5.  */
  6. #ifndef __ASM_I386_PROCESSOR_H
  7. #define __ASM_I386_PROCESSOR_H
  8. #include <asm/vm86.h>
  9. #include <asm/math_emu.h>
  10. #include <asm/segment.h>
  11. #include <asm/page.h>
  12. #include <asm/types.h>
  13. #include <asm/sigcontext.h>
  14. #include <asm/cpufeature.h>
  15. #include <linux/cache.h>
  16. #include <linux/config.h>
  17. #include <linux/threads.h>
  18. /*
  19.  * Default implementation of macro that returns current
  20.  * instruction pointer ("program counter").
  21.  */
  22. #define current_text_addr() ({ void *pc; __asm__("movl $1f,%0n1:":"=g" (pc)); pc; })
  23. /*
  24.  *  CPU type and hardware bug flags. Kept separately for each CPU.
  25.  *  Members of this structure are referenced in head.S, so think twice
  26.  *  before touching them. [mj]
  27.  */
  28. struct cpuinfo_x86 {
  29. __u8 x86; /* CPU family */
  30. __u8 x86_vendor; /* CPU vendor */
  31. __u8 x86_model;
  32. __u8 x86_mask;
  33. char wp_works_ok; /* It doesn't on 386's */
  34. char hlt_works_ok; /* Problems on some 486Dx4's and old 386's */
  35. char hard_math;
  36. char rfu;
  37.         int cpuid_level; /* Maximum supported CPUID level, -1=no CPUID */
  38. __u32 x86_capability[NCAPINTS];
  39. char x86_vendor_id[16];
  40. char x86_model_id[64];
  41. int  x86_cache_size;  /* in KB - valid for CPUS which support this
  42.     call  */
  43. int fdiv_bug;
  44. int f00f_bug;
  45. int coma_bug;
  46. unsigned long loops_per_jiffy;
  47. unsigned long *pgd_quick;
  48. unsigned long *pmd_quick;
  49. unsigned long *pte_quick;
  50. unsigned long pgtable_cache_sz;
  51. } __attribute__((__aligned__(SMP_CACHE_BYTES)));
  52. #define X86_VENDOR_INTEL 0
  53. #define X86_VENDOR_CYRIX 1
  54. #define X86_VENDOR_AMD 2
  55. #define X86_VENDOR_UMC 3
  56. #define X86_VENDOR_NEXGEN 4
  57. #define X86_VENDOR_CENTAUR 5
  58. #define X86_VENDOR_RISE 6
  59. #define X86_VENDOR_TRANSMETA 7
  60. #define X86_VENDOR_NSC 8
  61. #define X86_VENDOR_UNKNOWN 0xff
  62. /*
  63.  * capabilities of CPUs
  64.  */
  65. extern struct cpuinfo_x86 boot_cpu_data;
  66. extern struct tss_struct init_tss[NR_CPUS];
  67. #ifdef CONFIG_SMP
  68. extern struct cpuinfo_x86 cpu_data[];
  69. #define current_cpu_data cpu_data[smp_processor_id()]
  70. #else
  71. #define cpu_data (&boot_cpu_data)
  72. #define current_cpu_data boot_cpu_data
  73. #endif
  74. #define cpu_has_pge (test_bit(X86_FEATURE_PGE,  boot_cpu_data.x86_capability))
  75. #define cpu_has_pse (test_bit(X86_FEATURE_PSE,  boot_cpu_data.x86_capability))
  76. #define cpu_has_pae (test_bit(X86_FEATURE_PAE,  boot_cpu_data.x86_capability))
  77. #define cpu_has_tsc (test_bit(X86_FEATURE_TSC,  boot_cpu_data.x86_capability))
  78. #define cpu_has_de (test_bit(X86_FEATURE_DE,   boot_cpu_data.x86_capability))
  79. #define cpu_has_vme (test_bit(X86_FEATURE_VME,  boot_cpu_data.x86_capability))
  80. #define cpu_has_fxsr (test_bit(X86_FEATURE_FXSR, boot_cpu_data.x86_capability))
  81. #define cpu_has_xmm (test_bit(X86_FEATURE_XMM,  boot_cpu_data.x86_capability))
  82. #define cpu_has_fpu (test_bit(X86_FEATURE_FPU,  boot_cpu_data.x86_capability))
  83. #define cpu_has_apic (test_bit(X86_FEATURE_APIC, boot_cpu_data.x86_capability))
  84. extern char ignore_irq13;
  85. extern void identify_cpu(struct cpuinfo_x86 *);
  86. extern void print_cpu_info(struct cpuinfo_x86 *);
  87. extern void dodgy_tsc(void);
  88. /*
  89.  * EFLAGS bits
  90.  */
  91. #define X86_EFLAGS_CF 0x00000001 /* Carry Flag */
  92. #define X86_EFLAGS_PF 0x00000004 /* Parity Flag */
  93. #define X86_EFLAGS_AF 0x00000010 /* Auxillary carry Flag */
  94. #define X86_EFLAGS_ZF 0x00000040 /* Zero Flag */
  95. #define X86_EFLAGS_SF 0x00000080 /* Sign Flag */
  96. #define X86_EFLAGS_TF 0x00000100 /* Trap Flag */
  97. #define X86_EFLAGS_IF 0x00000200 /* Interrupt Flag */
  98. #define X86_EFLAGS_DF 0x00000400 /* Direction Flag */
  99. #define X86_EFLAGS_OF 0x00000800 /* Overflow Flag */
  100. #define X86_EFLAGS_IOPL 0x00003000 /* IOPL mask */
  101. #define X86_EFLAGS_NT 0x00004000 /* Nested Task */
  102. #define X86_EFLAGS_RF 0x00010000 /* Resume Flag */
  103. #define X86_EFLAGS_VM 0x00020000 /* Virtual Mode */
  104. #define X86_EFLAGS_AC 0x00040000 /* Alignment Check */
  105. #define X86_EFLAGS_VIF 0x00080000 /* Virtual Interrupt Flag */
  106. #define X86_EFLAGS_VIP 0x00100000 /* Virtual Interrupt Pending */
  107. #define X86_EFLAGS_ID 0x00200000 /* CPUID detection flag */
  108. /*
  109.  * Generic CPUID function
  110.  */
  111. static inline void cpuid(int op, int *eax, int *ebx, int *ecx, int *edx)
  112. {
  113. __asm__("cpuid"
  114. : "=a" (*eax),
  115.   "=b" (*ebx),
  116.   "=c" (*ecx),
  117.   "=d" (*edx)
  118. : "0" (op));
  119. }
  120. /*
  121.  * CPUID functions returning a single datum
  122.  */
  123. static inline unsigned int cpuid_eax(unsigned int op)
  124. {
  125. unsigned int eax;
  126. __asm__("cpuid"
  127. : "=a" (eax)
  128. : "0" (op)
  129. : "bx", "cx", "dx");
  130. return eax;
  131. }
  132. static inline unsigned int cpuid_ebx(unsigned int op)
  133. {
  134. unsigned int eax, ebx;
  135. __asm__("cpuid"
  136. : "=a" (eax), "=b" (ebx)
  137. : "0" (op)
  138. : "cx", "dx" );
  139. return ebx;
  140. }
  141. static inline unsigned int cpuid_ecx(unsigned int op)
  142. {
  143. unsigned int eax, ecx;
  144. __asm__("cpuid"
  145. : "=a" (eax), "=c" (ecx)
  146. : "0" (op)
  147. : "bx", "dx" );
  148. return ecx;
  149. }
  150. static inline unsigned int cpuid_edx(unsigned int op)
  151. {
  152. unsigned int eax, edx;
  153. __asm__("cpuid"
  154. : "=a" (eax), "=d" (edx)
  155. : "0" (op)
  156. : "bx", "cx");
  157. return edx;
  158. }
  159. /*
  160.  * Intel CPU features in CR4
  161.  */
  162. #define X86_CR4_VME 0x0001 /* enable vm86 extensions */
  163. #define X86_CR4_PVI 0x0002 /* virtual interrupts flag enable */
  164. #define X86_CR4_TSD 0x0004 /* disable time stamp at ipl 3 */
  165. #define X86_CR4_DE 0x0008 /* enable debugging extensions */
  166. #define X86_CR4_PSE 0x0010 /* enable page size extensions */
  167. #define X86_CR4_PAE 0x0020 /* enable physical address extensions */
  168. #define X86_CR4_MCE 0x0040 /* Machine check enable */
  169. #define X86_CR4_PGE 0x0080 /* enable global pages */
  170. #define X86_CR4_PCE 0x0100 /* enable performance counters at ipl 3 */
  171. #define X86_CR4_OSFXSR 0x0200 /* enable fast FPU save and restore */
  172. #define X86_CR4_OSXMMEXCPT 0x0400 /* enable unmasked SSE exceptions */
  173. #define load_cr3(pgdir) 
  174. asm volatile("movl %0,%%cr3": :"r" (__pa(pgdir)));
  175. /*
  176.  * Save the cr4 feature set we're using (ie
  177.  * Pentium 4MB enable and PPro Global page
  178.  * enable), so that any CPU's that boot up
  179.  * after us can get the correct flags.
  180.  */
  181. extern unsigned long mmu_cr4_features;
  182. static inline void set_in_cr4 (unsigned long mask)
  183. {
  184. mmu_cr4_features |= mask;
  185. __asm__("movl %%cr4,%%eaxnt"
  186. "orl %0,%%eaxnt"
  187. "movl %%eax,%%cr4n"
  188. : : "irg" (mask)
  189. :"ax");
  190. }
  191. static inline void clear_in_cr4 (unsigned long mask)
  192. {
  193. mmu_cr4_features &= ~mask;
  194. __asm__("movl %%cr4,%%eaxnt"
  195. "andl %0,%%eaxnt"
  196. "movl %%eax,%%cr4n"
  197. : : "irg" (~mask)
  198. :"ax");
  199. }
  200. /*
  201.  *      Cyrix CPU configuration register indexes
  202.  */
  203. #define CX86_CCR0 0xc0
  204. #define CX86_CCR1 0xc1
  205. #define CX86_CCR2 0xc2
  206. #define CX86_CCR3 0xc3
  207. #define CX86_CCR4 0xe8
  208. #define CX86_CCR5 0xe9
  209. #define CX86_CCR6 0xea
  210. #define CX86_CCR7 0xeb
  211. #define CX86_DIR0 0xfe
  212. #define CX86_DIR1 0xff
  213. #define CX86_ARR_BASE 0xc4
  214. #define CX86_RCR_BASE 0xdc
  215. /*
  216.  *      Cyrix CPU indexed register access macros
  217.  */
  218. #define getCx86(reg) ({ outb((reg), 0x22); inb(0x23); })
  219. #define setCx86(reg, data) do { 
  220. outb((reg), 0x22); 
  221. outb((data), 0x23); 
  222. } while (0)
  223. /*
  224.  * Bus types (default is ISA, but people can check others with these..)
  225.  */
  226. #ifdef CONFIG_EISA
  227. extern int EISA_bus;
  228. #else
  229. #define EISA_bus (0)
  230. #endif
  231. extern int MCA_bus;
  232. /* from system description table in BIOS.  Mostly for MCA use, but
  233. others may find it useful. */
  234. extern unsigned int machine_id;
  235. extern unsigned int machine_submodel_id;
  236. extern unsigned int BIOS_revision;
  237. extern unsigned int mca_pentium_flag;
  238. /*
  239.  * User space process size: 3GB (default).
  240.  */
  241. #define TASK_SIZE (PAGE_OFFSET)
  242. /* This decides where the kernel will search for a free chunk of vm
  243.  * space during mmap's.
  244.  */
  245. #define TASK_UNMAPPED_BASE (TASK_SIZE / 3)
  246. /*
  247.  * Size of io_bitmap in longwords: 32 is ports 0-0x3ff.
  248.  */
  249. #define IO_BITMAP_SIZE 32
  250. #define IO_BITMAP_OFFSET offsetof(struct tss_struct,io_bitmap)
  251. #define INVALID_IO_BITMAP_OFFSET 0x8000
  252. struct i387_fsave_struct {
  253. long cwd;
  254. long swd;
  255. long twd;
  256. long fip;
  257. long fcs;
  258. long foo;
  259. long fos;
  260. long st_space[20]; /* 8*10 bytes for each FP-reg = 80 bytes */
  261. long status; /* software status information */
  262. };
  263. struct i387_fxsave_struct {
  264. unsigned short cwd;
  265. unsigned short swd;
  266. unsigned short twd;
  267. unsigned short fop;
  268. long fip;
  269. long fcs;
  270. long foo;
  271. long fos;
  272. long mxcsr;
  273. long reserved;
  274. long st_space[32]; /* 8*16 bytes for each FP-reg = 128 bytes */
  275. long xmm_space[32]; /* 8*16 bytes for each XMM-reg = 128 bytes */
  276. long padding[56];
  277. } __attribute__ ((aligned (16)));
  278. struct i387_soft_struct {
  279. long cwd;
  280. long swd;
  281. long twd;
  282. long fip;
  283. long fcs;
  284. long foo;
  285. long fos;
  286. long st_space[20]; /* 8*10 bytes for each FP-reg = 80 bytes */
  287. unsigned char ftop, changed, lookahead, no_update, rm, alimit;
  288. struct info *info;
  289. unsigned long entry_eip;
  290. };
  291. union i387_union {
  292. struct i387_fsave_struct fsave;
  293. struct i387_fxsave_struct fxsave;
  294. struct i387_soft_struct soft;
  295. };
  296. typedef struct {
  297. unsigned long seg;
  298. } mm_segment_t;
  299. struct tss_struct {
  300. unsigned short back_link,__blh;
  301. unsigned long esp0;
  302. unsigned short ss0,__ss0h;
  303. unsigned long esp1;
  304. unsigned short ss1,__ss1h;
  305. unsigned long esp2;
  306. unsigned short ss2,__ss2h;
  307. unsigned long __cr3;
  308. unsigned long eip;
  309. unsigned long eflags;
  310. unsigned long eax,ecx,edx,ebx;
  311. unsigned long esp;
  312. unsigned long ebp;
  313. unsigned long esi;
  314. unsigned long edi;
  315. unsigned short es, __esh;
  316. unsigned short cs, __csh;
  317. unsigned short ss, __ssh;
  318. unsigned short ds, __dsh;
  319. unsigned short fs, __fsh;
  320. unsigned short gs, __gsh;
  321. unsigned short ldt, __ldth;
  322. unsigned short trace, bitmap;
  323. unsigned long io_bitmap[IO_BITMAP_SIZE+1];
  324. /*
  325.  * pads the TSS to be cacheline-aligned (size is 0x100)
  326.  */
  327. unsigned long __cacheline_filler[5];
  328. };
  329. struct thread_struct {
  330. unsigned long esp0;
  331. unsigned long eip;
  332. unsigned long esp;
  333. unsigned long fs;
  334. unsigned long gs;
  335. /* Hardware debugging registers */
  336. unsigned long debugreg[8];  /* %%db0-7 debug registers */
  337. /* fault info */
  338. unsigned long cr2, trap_no, error_code;
  339. /* floating point info */
  340. union i387_union i387;
  341. /* virtual 86 mode info */
  342. struct vm86_struct * vm86_info;
  343. unsigned long screen_bitmap;
  344. unsigned long v86flags, v86mask, saved_esp0;
  345. /* IO permissions */
  346. int ioperm;
  347. unsigned long io_bitmap[IO_BITMAP_SIZE+1];
  348. };
  349. #define INIT_THREAD  {
  350. 0,
  351. 0, 0, 0, 0, 
  352. { [0 ... 7] = 0 }, /* debugging registers */
  353. 0, 0, 0,
  354. { { 0, }, }, /* 387 state */
  355. 0,0,0,0,0,
  356. 0,{~0,} /* io permissions */
  357. }
  358. #define INIT_TSS  {
  359. 0,0, /* back_link, __blh */
  360. sizeof(init_stack) + (long) &init_stack, /* esp0 */
  361. __KERNEL_DS, 0, /* ss0 */
  362. 0,0,0,0,0,0, /* stack1, stack2 */
  363. 0, /* cr3 */
  364. 0,0, /* eip,eflags */
  365. 0,0,0,0, /* eax,ecx,edx,ebx */
  366. 0,0,0,0, /* esp,ebp,esi,edi */
  367. 0,0,0,0,0,0, /* es,cs,ss */
  368. 0,0,0,0,0,0, /* ds,fs,gs */
  369. __LDT(0),0, /* ldt */
  370. 0, INVALID_IO_BITMAP_OFFSET, /* tace, bitmap */
  371. {~0, } /* ioperm */
  372. }
  373. #define start_thread(regs, new_eip, new_esp) do {
  374. __asm__("movl %0,%%fs ; movl %0,%%gs": :"r" (0));
  375. set_fs(USER_DS);
  376. regs->xds = __USER_DS;
  377. regs->xes = __USER_DS;
  378. regs->xss = __USER_DS;
  379. regs->xcs = __USER_CS;
  380. regs->eip = new_eip;
  381. regs->esp = new_esp;
  382. } while (0)
  383. /* Forward declaration, a strange C thing */
  384. struct task_struct;
  385. struct mm_struct;
  386. /* Free all resources held by a thread. */
  387. extern void release_thread(struct task_struct *);
  388. /*
  389.  * create a kernel thread without removing it from tasklists
  390.  */
  391. extern int kernel_thread(int (*fn)(void *), void * arg, unsigned long flags);
  392. /* Copy and release all segment info associated with a VM */
  393. extern void copy_segments(struct task_struct *p, struct mm_struct * mm);
  394. extern void release_segments(struct mm_struct * mm);
  395. /*
  396.  * Return saved PC of a blocked thread.
  397.  */
  398. static inline unsigned long thread_saved_pc(struct thread_struct *t)
  399. {
  400. return ((unsigned long *)t->esp)[3];
  401. }
  402. unsigned long get_wchan(struct task_struct *p);
  403. #define KSTK_EIP(tsk) (((unsigned long *)(4096+(unsigned long)(tsk)))[1019])
  404. #define KSTK_ESP(tsk) (((unsigned long *)(4096+(unsigned long)(tsk)))[1022])
  405. #define THREAD_SIZE (2*PAGE_SIZE)
  406. #define alloc_task_struct() ((struct task_struct *) __get_free_pages(GFP_KERNEL,1))
  407. #define free_task_struct(p) free_pages((unsigned long) (p), 1)
  408. #define get_task_struct(tsk)      atomic_inc(&virt_to_page(tsk)->count)
  409. #define init_task (init_task_union.task)
  410. #define init_stack (init_task_union.stack)
  411. struct microcode {
  412. unsigned int hdrver;
  413. unsigned int rev;
  414. unsigned int date;
  415. unsigned int sig;
  416. unsigned int cksum;
  417. unsigned int ldrver;
  418. unsigned int pf;
  419. unsigned int reserved[5];
  420. unsigned int bits[500];
  421. };
  422. /* '6' because it used to be for P6 only (but now covers Pentium 4 as well) */
  423. #define MICROCODE_IOCFREE _IO('6',0)
  424. /* REP NOP (PAUSE) is a good thing to insert into busy-wait loops. */
  425. static inline void rep_nop(void)
  426. {
  427. __asm__ __volatile__("rep;nop");
  428. }
  429. #define cpu_relax() rep_nop()
  430. /* Prefetch instructions for Pentium III and AMD Athlon */
  431. #ifdef  CONFIG_MPENTIUMIII
  432. #define ARCH_HAS_PREFETCH
  433. extern inline void prefetch(const void *x)
  434. {
  435. __asm__ __volatile__ ("prefetchnta (%0)" : : "r"(x));
  436. }
  437. #elif CONFIG_X86_USE_3DNOW
  438. #define ARCH_HAS_PREFETCH
  439. #define ARCH_HAS_PREFETCHW
  440. #define ARCH_HAS_SPINLOCK_PREFETCH
  441. extern inline void prefetch(const void *x)
  442. {
  443.  __asm__ __volatile__ ("prefetch (%0)" : : "r"(x));
  444. }
  445. extern inline void prefetchw(const void *x)
  446. {
  447.  __asm__ __volatile__ ("prefetchw (%0)" : : "r"(x));
  448. }
  449. #define spin_lock_prefetch(x) prefetchw(x)
  450. #endif
  451. #endif /* __ASM_I386_PROCESSOR_H */