Skip to content

Commit 624eb1c

Browse files
shankerwangmiaochenx97
authored andcommitted
loongarch64: able to start on legacy firmware
On legacy firmware, the DMW is already enabled by the firmware, and the addresses in all the pointers and the PC register are virtual addresses. GRUB, however, is location independent, so will not be affected. The only problem happens at the GRUB_EFI_MAX_USABLE_ADDRESS, which should be dynamically decided by detecting if DMW is enabled.
1 parent 2f40e35 commit 624eb1c

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

include/grub/loongarch64/efi/memory.h

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,25 @@
1919
#ifndef GRUB_MEMORY_CPU_HEADER
2020
#include <grub/efi/memory.h>
2121

22-
#define GRUB_EFI_MAX_USABLE_ADDRESS 0xfffffffffffULL
22+
static inline grub_uint64_t
23+
grub_efi_max_usable_address(void)
24+
{
25+
static grub_uint64_t addr;
26+
static int addr_valid = 0;
27+
28+
if (!addr_valid)
29+
{
30+
asm volatile ("csrrd %0, 0x181" : "=r" (addr));
31+
if (addr & 0x1)
32+
addr |= 0xfffffffffffUL;
33+
else
34+
addr = 0xfffffffffffUL;
35+
addr_valid = 1;
36+
}
37+
38+
return addr;
39+
}
40+
41+
#define GRUB_EFI_MAX_USABLE_ADDRESS (grub_efi_max_usable_address())
2342

2443
#endif /* ! GRUB_MEMORY_CPU_HEADER */

0 commit comments

Comments
 (0)