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