mirror of
				https://gitlab.com/qemu-project/edk2.git
				synced 2025-10-30 07:56:39 +08:00 
			
		
		
		
	UefiCpuPkg: RiscV64: initialize FPU
The OpenSSL library uses floating point registers. The is no guarantee that a prior firmware stage has enabled the FPU. Provide a library BaseRiscVFpuLib to * Enable the FPU and set it to state 'dirty'. * Clear the fcsr CSR. Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
This commit is contained in:
		 Heinrich Schuchardt
					Heinrich Schuchardt
				
			
				
					committed by
					
						![mergify[bot]](/assets/img/avatar_default.png) mergify[bot]
						mergify[bot]
					
				
			
			
				
	
			
			
			![mergify[bot]](/assets/img/avatar_default.png) mergify[bot]
						mergify[bot]
					
				
			
						parent
						
							28dd588ca8
						
					
				
				
					commit
					f8c738577f
				
			| @ -359,6 +359,12 @@ InitializeCpu ( | ||||
|   Status = RiscVConfigureMmu (); | ||||
|   ASSERT_EFI_ERROR (Status); | ||||
|  | ||||
|   // | ||||
|   // Initialize FPU | ||||
|   // | ||||
|   Status = RiscVInitializeFpu (); | ||||
|   ASSERT_EFI_ERROR (Status); | ||||
|  | ||||
|   // | ||||
|   // Install Boot protocol | ||||
|   // | ||||
|  | ||||
| @ -14,6 +14,7 @@ | ||||
|  | ||||
| #include <Protocol/Cpu.h> | ||||
| #include <Protocol/RiscVBootProtocol.h> | ||||
| #include <Library/BaseRiscVFpuLib.h> | ||||
| #include <Library/BaseRiscVSbiLib.h> | ||||
| #include <Library/BaseRiscVMmuLib.h> | ||||
| #include <Library/BaseLib.h> | ||||
|  | ||||
| @ -38,6 +38,7 @@ | ||||
|   PeCoffGetEntryPointLib | ||||
|   RiscVSbiLib | ||||
|   RiscVMmuLib | ||||
|   RiscVFpuLib | ||||
|   CacheMaintenanceLib | ||||
|  | ||||
| [Sources] | ||||
|  | ||||
							
								
								
									
										21
									
								
								UefiCpuPkg/Include/Library/BaseRiscVFpuLib.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								UefiCpuPkg/Include/Library/BaseRiscVFpuLib.h
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,21 @@ | ||||
| /** @file | ||||
|  | ||||
|   Copyright (c) 2024, Canonical Services Ltd<BR> | ||||
|   SPDX-License-Identifier: BSD-2-Clause-Patent | ||||
|  | ||||
| **/ | ||||
|  | ||||
| #ifndef BASE_RISCV_FPU_LIB_H_ | ||||
| #define BASE_RISCV_FPU_LIB_H_ | ||||
|  | ||||
| /** | ||||
|   Initialize floating point unit | ||||
|  | ||||
| **/ | ||||
| EFI_STATUS | ||||
| EFIAPI | ||||
| RiscVInitializeFpu ( | ||||
|   VOID | ||||
|   ); | ||||
|  | ||||
| #endif /* BASE_RISCV_FPU_LIB_H_ */ | ||||
							
								
								
									
										26
									
								
								UefiCpuPkg/Library/BaseRiscVFpuLib/BaseRiscVFpuLib.inf
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								UefiCpuPkg/Library/BaseRiscVFpuLib/BaseRiscVFpuLib.inf
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,26 @@ | ||||
| ## @file | ||||
| #  RISC-V FPU library. | ||||
| # | ||||
| #  Copyright (c) 2024, Canonical Services Ltd | ||||
| # | ||||
| #  SPDX-License-Identifier: BSD-2-Clause-Patent | ||||
| # | ||||
| ## | ||||
|  | ||||
| [Defines] | ||||
|   INF_VERSION         = 0x0001001b | ||||
|   BASE_NAME           = BaseRiscVFpuLib | ||||
|   FILE_GUID           = e600fe4d-8595-40f3-90a0-5f043ce155c2 | ||||
|   MODULE_TYPE         = BASE | ||||
|   VERSION_STRING      = 1.0 | ||||
|   LIBRARY_CLASS       = RiscVFpuLib | ||||
|  | ||||
| [Sources] | ||||
|   RiscVFpuCore.S | ||||
|  | ||||
| [Packages] | ||||
|   MdePkg/MdePkg.dec | ||||
|   UefiCpuPkg/UefiCpuPkg.dec | ||||
|  | ||||
| [LibraryClasses] | ||||
|   BaseLib | ||||
							
								
								
									
										22
									
								
								UefiCpuPkg/Library/BaseRiscVFpuLib/RiscVFpuCore.S
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								UefiCpuPkg/Library/BaseRiscVFpuLib/RiscVFpuCore.S
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,22 @@ | ||||
| /** @file | ||||
| * | ||||
| *  Copyright (c) 2024, Canonical Services Ltd | ||||
| * | ||||
| *  SPDX-License-Identifier: BSD-2-Clause-Patent | ||||
| * | ||||
| **/ | ||||
|  | ||||
| #include <Library/BaseRiscVFpuLib.h> | ||||
| #include <Register/RiscV64/RiscVImpl.h> | ||||
|  | ||||
| // | ||||
| // Initialize floating point unit | ||||
| // | ||||
| ASM_FUNC (RiscVInitializeFpu) | ||||
|   csrr  a0, CSR_SSTATUS | ||||
|   li    a1, MSTATUS_FS | ||||
|   or    a0, a0, a1 | ||||
|   csrw  CSR_SSTATUS, a0 | ||||
|   csrw  CSR_FCSR, x0 | ||||
|   li    a0, 0 | ||||
|   ret | ||||
| @ -75,6 +75,8 @@ | ||||
|   SmmRelocationLib|Include/Library/SmmRelocationLib.h | ||||
|  | ||||
| [LibraryClasses.RISCV64] | ||||
|   ##  @libraryclass  Provides function to initialize the FPU. | ||||
|   RiscVFpuLib|Include/Library/BaseRiscVFpuLib.h | ||||
|   ##  @libraryclass  Provides functions to manage MMU features on RISCV64 CPUs. | ||||
|   ## | ||||
|   RiscVMmuLib|Include/Library/BaseRiscVMmuLib.h | ||||
|  | ||||
| @ -224,6 +224,7 @@ | ||||
| [Components.RISCV64] | ||||
|   UefiCpuPkg/Library/BaseRiscV64CpuExceptionHandlerLib/BaseRiscV64CpuExceptionHandlerLib.inf | ||||
|   UefiCpuPkg/Library/BaseRiscV64CpuTimerLib/BaseRiscV64CpuTimerLib.inf | ||||
|   UefiCpuPkg/Library/BaseRiscVFpuLib/BaseRiscVFpuLib.inf | ||||
|   UefiCpuPkg/Library/BaseRiscVMmuLib/BaseRiscVMmuLib.inf | ||||
|   UefiCpuPkg/CpuTimerDxeRiscV64/CpuTimerDxeRiscV64.inf | ||||
|   UefiCpuPkg/CpuDxeRiscV64/CpuDxeRiscV64.inf | ||||
|  | ||||
		Reference in New Issue
	
	Block a user