]> git.proxmox.com Git - mirror_edk2.git/blame - ArmVirtPkg/Library/ArmXenRelocatablePlatformLib/AARCH64/RelocatableVirtHelper.S
ArmVirtPkg/RelocatableVirtHelper: use correct FindMemNode argument order
[mirror_edk2.git] / ArmVirtPkg / Library / ArmXenRelocatablePlatformLib / AARCH64 / RelocatableVirtHelper.S
CommitLineData
f9849036
AB
1#\r
2# Copyright (c) 2011-2013, ARM Limited. All rights reserved.\r
3#\r
4# This program and the accompanying materials\r
5# are licensed and made available under the terms and conditions of the BSD License\r
6# which accompanies this distribution. The full text of the license may be found at\r
7# http://opensource.org/licenses/bsd-license.php\r
8#\r
9# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
10# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
11#\r
12#\r
13\r
14#include <AsmMacroIoLibV8.h>\r
15#include <Base.h>\r
16#include <Library/ArmLib.h>\r
17#include <Library/PcdLib.h>\r
18#include <AutoGen.h>\r
19\r
20.text\r
21.align 2\r
22\r
23GCC_ASM_EXPORT(ArmPlatformPeiBootAction)\r
24GCC_ASM_EXPORT(ArmPlatformIsPrimaryCore)\r
25GCC_ASM_EXPORT(ArmPlatformGetPrimaryCoreMpId)\r
26GCC_ASM_EXPORT(ArmPlatformGetCorePosition)\r
27GCC_ASM_EXPORT(ArmGetPhysAddrTop)\r
28\r
29GCC_ASM_IMPORT(_gPcd_FixedAtBuild_PcdArmPrimaryCore)\r
30GCC_ASM_IMPORT(_gPcd_FixedAtBuild_PcdArmPrimaryCoreMask)\r
31GCC_ASM_IMPORT(_gPcd_FixedAtBuild_PcdCoreCount)\r
32\r
f9849036
AB
33.LArm64LinuxMagic:\r
34 .byte 0x41, 0x52, 0x4d, 0x64\r
35\r
36// VOID\r
37// ArmPlatformPeiBootAction (\r
38// VOID *DeviceTreeBaseAddress, // passed by loader in x0\r
39// VOID *ImageBase // passed by FDF trampoline in x1\r
40// );\r
41ASM_PFX(ArmPlatformPeiBootAction):\r
42 mov x29, x30 // preserve LR\r
03b6bed1
AB
43 mov x28, x0 // preserve DTB pointer\r
44 mov x27, x1 // preserve base of image pointer\r
f9849036
AB
45\r
46 //\r
47 // If we are booting from RAM using the Linux kernel boot protocol, x0 will\r
48 // point to the DTB image in memory. Otherwise, we are just coming out of\r
03b6bed1 49 // reset, and x0 will be 0.\r
f9849036
AB
50 //\r
51 cbz x0, .Lout\r
f9849036
AB
52\r
53 //\r
54 // The base of the runtime image has been preserved in x1. Check whether\r
55 // the expected magic number can be found in the header.\r
56 //\r
57 ldr w8, .LArm64LinuxMagic\r
58 ldr w9, [x1, #0x38]\r
59 cmp w8, w9\r
60 bne .Lout\r
61\r
62 //\r
63 //\r
64 // OK, so far so good. We have confirmed that we likely have a DTB and are\r
65 // booting via the arm64 Linux boot protocol. Update the base-of-image PCD\r
66 // to the actual relocated value, and add the shift of PcdFdBaseAddress to\r
67 // PcdFvBaseAddress as well\r
68 //\r
69 adr x8, PcdGet64 (PcdFdBaseAddress)\r
70 adr x9, PcdGet64 (PcdFvBaseAddress)\r
71 ldr x6, [x8]\r
72 ldr x7, [x9]\r
73 sub x7, x7, x6\r
74 add x7, x7, x1\r
75 str x1, [x8]\r
76 str x7, [x9]\r
77\r
03b6bed1
AB
78 //\r
79 // Discover the memory size and offset from the DTB, and record in the\r
80 // respective PCDs. This will also return false if a corrupt DTB is\r
81 // encountered. Since we are calling a C function, use the window at the\r
82 // beginning of the FD image as a temp stack.\r
83 //\r
8457f5e4
AB
84 adr x1, PcdGet64 (PcdSystemMemoryBase)\r
85 adr x2, PcdGet64 (PcdSystemMemorySize)\r
03b6bed1
AB
86 mov sp, x7\r
87 bl FindMemnode\r
88 cbz x0, .Lout\r
89\r
f9849036
AB
90 //\r
91 // Copy the DTB to the slack space right after the 64 byte arm64/Linux style\r
92 // image header at the base of this image (defined in the FDF), and record the\r
93 // pointer in PcdDeviceTreeInitialBaseAddress.\r
94 //\r
95 adr x8, PcdGet64 (PcdDeviceTreeInitialBaseAddress)\r
03b6bed1
AB
96 add x27, x27, #0x40\r
97 str x27, [x8]\r
f9849036 98\r
03b6bed1
AB
99 mov x0, x27\r
100 mov x1, x28\r
101 bl CopyFdt\r
f9849036
AB
102\r
103.Lout:\r
104 ret x29\r
105\r
106//UINTN\r
107//ArmPlatformGetPrimaryCoreMpId (\r
108// VOID\r
109// );\r
110ASM_PFX(ArmPlatformGetPrimaryCoreMpId):\r
111 LoadConstantToReg (_gPcd_FixedAtBuild_PcdArmPrimaryCore, x0)\r
112 ldrh w0, [x0]\r
113 ret\r
114\r
115//UINTN\r
116//ArmPlatformIsPrimaryCore (\r
117// IN UINTN MpId\r
118// );\r
119ASM_PFX(ArmPlatformIsPrimaryCore):\r
120 mov x0, #1\r
121 ret\r
122\r
123//UINTN\r
124//ArmPlatformGetCorePosition (\r
125// IN UINTN MpId\r
126// );\r
127// With this function: CorePos = (ClusterId * 4) + CoreId\r
128ASM_PFX(ArmPlatformGetCorePosition):\r
129 and x1, x0, #ARM_CORE_MASK\r
130 and x0, x0, #ARM_CLUSTER_MASK\r
131 add x0, x1, x0, LSR #6\r
132 ret\r
133\r
134//EFI_PHYSICAL_ADDRESS\r
135//GetPhysAddrTop (\r
136// VOID\r
137// );\r
138ASM_PFX(ArmGetPhysAddrTop):\r
139 mrs x0, id_aa64mmfr0_el1\r
140 adr x1, .LPARanges\r
141 and x0, x0, #7\r
142 ldrb w1, [x1, x0]\r
143 mov x0, #1\r
144 lsl x0, x0, x1\r
145 ret\r
146\r
147//\r
148// Bits 0..2 of the AA64MFR0_EL1 system register encode the size of the\r
149// physical address space support on this CPU:\r
150// 0 == 32 bits, 1 == 36 bits, etc etc\r
151// 6 and 7 are reserved\r
152//\r
153.LPARanges:\r
154 .byte 32, 36, 40, 42, 44, 48, -1, -1\r
155\r
156ASM_FUNCTION_REMOVE_IF_UNREFERENCED\r