mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 09:02:43 +00:00 
			
		
		
		
	Kernel: Detect and display CPUID hypervisor signature
This commit is contained in:
		
							parent
							
								
									4cc346fb19
								
							
						
					
					
						commit
						b22357b17b
					
				
					 2 changed files with 20 additions and 0 deletions
				
			
		|  | @ -173,6 +173,8 @@ public: | ||||||
|     void early_initialize(u32 cpu); |     void early_initialize(u32 cpu); | ||||||
|     void initialize(u32 cpu); |     void initialize(u32 cpu); | ||||||
| 
 | 
 | ||||||
|  |     void detect_hypervisor(); | ||||||
|  | 
 | ||||||
|     void idle_begin() |     void idle_begin() | ||||||
|     { |     { | ||||||
|         s_idle_cpu_mask.fetch_or(1u << m_cpu, AK::MemoryOrder::memory_order_relaxed); |         s_idle_cpu_mask.fetch_or(1u << m_cpu, AK::MemoryOrder::memory_order_relaxed); | ||||||
|  |  | ||||||
|  | @ -349,6 +349,9 @@ UNMAP_AFTER_INIT void Processor::initialize(u32 cpu) | ||||||
|         else |         else | ||||||
|             asm volatile("fnsave %0" |             asm volatile("fnsave %0" | ||||||
|                          : "=m"(s_clean_fpu_state)); |                          : "=m"(s_clean_fpu_state)); | ||||||
|  | 
 | ||||||
|  |         if (has_feature(CPUFeature::HYPERVISOR)) | ||||||
|  |             detect_hypervisor(); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     m_info = new ProcessorInfo(*this); |     m_info = new ProcessorInfo(*this); | ||||||
|  | @ -360,6 +363,21 @@ UNMAP_AFTER_INIT void Processor::initialize(u32 cpu) | ||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | UNMAP_AFTER_INIT void Processor::detect_hypervisor() | ||||||
|  | { | ||||||
|  |     CPUID hypervisor_leaf_range(0x40000000); | ||||||
|  | 
 | ||||||
|  |     // Get signature of hypervisor.
 | ||||||
|  |     alignas(sizeof(u32)) char hypervisor_signature_buffer[13]; | ||||||
|  |     *reinterpret_cast<u32*>(hypervisor_signature_buffer) = hypervisor_leaf_range.ebx(); | ||||||
|  |     *reinterpret_cast<u32*>(hypervisor_signature_buffer + 4) = hypervisor_leaf_range.ecx(); | ||||||
|  |     *reinterpret_cast<u32*>(hypervisor_signature_buffer + 8) = hypervisor_leaf_range.edx(); | ||||||
|  |     hypervisor_signature_buffer[12] = '\0'; | ||||||
|  |     StringView hypervisor_signature(hypervisor_signature_buffer); | ||||||
|  | 
 | ||||||
|  |     dmesgln("CPU[{}]: CPUID hypervisor signature '{}' ({:#x} {:#x} {:#x}), max leaf {:#x}", id(), hypervisor_signature, hypervisor_leaf_range.ebx(), hypervisor_leaf_range.ecx(), hypervisor_leaf_range.edx(), hypervisor_leaf_range.eax()); | ||||||
|  | } | ||||||
|  | 
 | ||||||
| void Processor::write_raw_gdt_entry(u16 selector, u32 low, u32 high) | void Processor::write_raw_gdt_entry(u16 selector, u32 low, u32 high) | ||||||
| { | { | ||||||
|     u16 i = (selector & 0xfffc) >> 3; |     u16 i = (selector & 0xfffc) >> 3; | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Jean-Baptiste Boric
						Jean-Baptiste Boric