Move cpuid code to cpuid.h and TSC code to tsc.c.
This commit is contained in:
		
							parent
							
								
									f37bf9c778
								
							
						
					
					
						commit
						c1bee64676
					
				
					 7 changed files with 133 additions and 133 deletions
				
			
		|  | @ -29,11 +29,6 @@ | |||
| 
 | ||||
| GRUB_MOD_LICENSE ("GPLv3+"); | ||||
| 
 | ||||
| #define cpuid(num,a,b,c,d) \ | ||||
|   asm volatile ("xchgl %%ebx, %1; cpuid; xchgl %%ebx, %1" \ | ||||
| 		: "=a" (a), "=r" (b), "=c" (c), "=d" (d)  \ | ||||
| 		: "0" (num)) | ||||
| 
 | ||||
| static const struct grub_arg_option options[] = | ||||
|   { | ||||
|     /* TRANSLATORS: "(default)" at the end means that this option is used if
 | ||||
|  | @ -78,18 +73,18 @@ GRUB_MOD_INIT(cpuid) | |||
|     goto done; | ||||
| 
 | ||||
|   /* Check the highest input value for eax.  */ | ||||
|   cpuid (0, eax, ebx, ecx, edx); | ||||
|   grub_cpuid (0, eax, ebx, ecx, edx); | ||||
|   /* We only look at the first four characters.  */ | ||||
|   max_level = eax; | ||||
|   if (max_level == 0) | ||||
|     goto done; | ||||
| 
 | ||||
|   cpuid (0x80000000, eax, ebx, ecx, edx); | ||||
|   grub_cpuid (0x80000000, eax, ebx, ecx, edx); | ||||
|   ext_level = eax; | ||||
|   if (ext_level < 0x80000000) | ||||
|     goto done; | ||||
| 
 | ||||
|   cpuid (0x80000001, eax, ebx, ecx, edx); | ||||
|   grub_cpuid (0x80000001, eax, ebx, ecx, edx); | ||||
|   grub_cpuid_has_longmode = !!(edx & bit_LM); | ||||
| done: | ||||
| #endif | ||||
|  |  | |||
|  | @ -24,6 +24,7 @@ | |||
| #include <grub/time.h> | ||||
| #include <grub/misc.h> | ||||
| #include <grub/i386/tsc.h> | ||||
| #include <grub/i386/cpuid.h> | ||||
| #include <grub/i386/pit.h> | ||||
| #include <grub/cpu/io.h> | ||||
| 
 | ||||
|  | @ -35,6 +36,72 @@ static grub_uint64_t tsc_boot_time; | |||
|    in 32-bit.  */ | ||||
| grub_uint32_t grub_tsc_rate; | ||||
| 
 | ||||
| /* Read the TSC value, which increments with each CPU clock cycle. */ | ||||
| static __inline grub_uint64_t | ||||
| grub_get_tsc (void) | ||||
| { | ||||
|   grub_uint32_t lo, hi; | ||||
| 
 | ||||
|   /* The CPUID instruction is a 'serializing' instruction, and
 | ||||
|      avoids out-of-order execution of the RDTSC instruction. */ | ||||
| #ifdef __APPLE__ | ||||
|   __asm__ __volatile__ ("xorl %%eax, %%eax\n\t" | ||||
| #ifdef __x86_64__ | ||||
| 			"push %%rbx\n" | ||||
| #else | ||||
| 			"push %%ebx\n" | ||||
| #endif | ||||
| 			"cpuid\n" | ||||
| #ifdef __x86_64__ | ||||
| 			"pop %%rbx\n" | ||||
| #else | ||||
| 			"pop %%ebx\n" | ||||
| #endif | ||||
| 			:::"%rax", "%rcx", "%rdx"); | ||||
| #else | ||||
|   __asm__ __volatile__ ("xorl %%eax, %%eax\n\t" | ||||
| 			"cpuid":::"%rax", "%rbx", "%rcx", "%rdx"); | ||||
| #endif | ||||
|   /* Read TSC value.  We cannot use "=A", since this would use
 | ||||
|      %rax on x86_64. */ | ||||
|   __asm__ __volatile__ ("rdtsc":"=a" (lo), "=d" (hi)); | ||||
| 
 | ||||
|   return (((grub_uint64_t) hi) << 32) | lo; | ||||
| } | ||||
| 
 | ||||
| static __inline int | ||||
| grub_cpu_is_tsc_supported (void) | ||||
| { | ||||
|   if (! grub_cpu_is_cpuid_supported ()) | ||||
|     return 0; | ||||
| 
 | ||||
|   grub_uint32_t features; | ||||
| #ifdef __APPLE__ | ||||
|   __asm__ ("movl $1, %%eax\n\t" | ||||
| #ifdef __x86_64__ | ||||
| 	   "push %%rbx\n" | ||||
| #else | ||||
| 	   "push %%ebx\n" | ||||
| #endif | ||||
| 	   "cpuid\n" | ||||
| #ifdef __x86_64__ | ||||
| 	   "pop %%rbx\n" | ||||
| #else | ||||
| 	   "pop %%ebx\n" | ||||
| #endif | ||||
|            : "=d" (features) | ||||
|            : /* No inputs.  */ | ||||
| 	   : /* Clobbered:  */ "%rax", "%rcx"); | ||||
| #else | ||||
|   __asm__ ("movl $1, %%eax\n\t" | ||||
|            "cpuid\n" | ||||
|            : "=d" (features) | ||||
|            : /* No inputs.  */ | ||||
|            : /* Clobbered:  */ "%rax", "%rbx", "%rcx"); | ||||
| #endif | ||||
|   return (features & (1 << 4)) != 0; | ||||
| } | ||||
| 
 | ||||
| static void | ||||
| grub_pit_wait (grub_uint16_t tics) | ||||
| { | ||||
|  | @ -63,7 +130,7 @@ grub_pit_wait (grub_uint16_t tics) | |||
|              GRUB_PIT_SPEAKER_PORT); | ||||
| } | ||||
| 
 | ||||
| grub_uint64_t | ||||
| static grub_uint64_t | ||||
| grub_tsc_get_time_ms (void) | ||||
| { | ||||
|   grub_uint64_t a = grub_get_tsc () - tsc_boot_time; | ||||
|  |  | |||
|  | @ -25,6 +25,7 @@ | |||
| #include <grub/loader.h> | ||||
| #include <grub/autoefi.h> | ||||
| #include <grub/i386/tsc.h> | ||||
| #include <grub/i386/cpuid.h> | ||||
| #include <grub/efi/api.h> | ||||
| #include <grub/i386/pit.h> | ||||
| #include <grub/misc.h> | ||||
|  |  | |||
|  | @ -29,7 +29,7 @@ | |||
| #include <grub/video.h> | ||||
| #include <grub/i386/pc/int.h> | ||||
| #include <grub/i18n.h> | ||||
| #include <grub/cpu/tsc.h> | ||||
| #include <grub/cpu/cpuid.h> | ||||
| 
 | ||||
| GRUB_MOD_LICENSE ("GPLv3+"); | ||||
| 
 | ||||
|  | @ -58,11 +58,6 @@ real2pm (grub_vbe_farptr_t ptr) | |||
|                    + ((unsigned long) ptr & 0x0000FFFF)); | ||||
| } | ||||
| 
 | ||||
| #define cpuid(num,a,b,c,d) \ | ||||
|   asm volatile ("xchgl %%ebx, %1; cpuid; xchgl %%ebx, %1" \ | ||||
|                 : "=a" (a), "=r" (b), "=c" (c), "=d" (d)  \ | ||||
|                 : "0" (num)) | ||||
| 
 | ||||
| #define rdmsr(num,a,d) \ | ||||
|   asm volatile ("rdmsr" : "=a" (a), "=d" (d) : "c" (num)) | ||||
| 
 | ||||
|  | @ -136,7 +131,7 @@ grub_vbe_enable_mtrr (grub_uint8_t *base, grub_size_t size) | |||
|   if (! grub_cpu_is_cpuid_supported ()) | ||||
|     return; | ||||
| 
 | ||||
|   cpuid (1, eax, ebx, ecx, edx); | ||||
|   grub_cpuid (1, eax, ebx, ecx, edx); | ||||
|   features = edx; | ||||
|   if (! (features & 0x00001000)) /* MTRR */ | ||||
|     return; | ||||
|  | @ -147,11 +142,11 @@ grub_vbe_enable_mtrr (grub_uint8_t *base, grub_size_t size) | |||
|     return; | ||||
|   var_mtrrs = (mtrrcap & 0xFF); | ||||
| 
 | ||||
|   cpuid (0x80000000, eax, ebx, ecx, edx); | ||||
|   grub_cpuid (0x80000000, eax, ebx, ecx, edx); | ||||
|   max_extended_cpuid = eax; | ||||
|   if (max_extended_cpuid >= 0x80000008) | ||||
|     { | ||||
|       cpuid (0x80000008, eax, ebx, ecx, edx); | ||||
|       grub_cpuid (0x80000008, eax, ebx, ecx, edx); | ||||
|       maxphyaddr = (eax & 0xFF); | ||||
|     } | ||||
|   else | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue