]>
Commit | Line | Data |
---|---|---|
25402f5d HL |
1 | /** @file\r |
2 | Specific relocation fixups for ARM architecture.\r | |
3 | \r | |
4 | Copyright (c) 2006 - 2009, Intel Corporation. All rights reserved.<BR>\r | |
5 | Portions copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>\r | |
6 | Portions copyright (c) 2011 - 2013, ARM Ltd. All rights reserved.<BR>\r | |
7 | \r | |
8 | This program and the accompanying materials\r | |
9 | are licensed and made available under the terms and conditions of the BSD License\r | |
10 | which accompanies this distribution. The full text of the license may be found at\r | |
11 | http://opensource.org/licenses/bsd-license.php.\r | |
12 | \r | |
13 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
14 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
15 | \r | |
16 | **/\r | |
17 | \r | |
18 | #include "BasePeCoffLibInternals.h"\r | |
19 | #include <Library/BaseLib.h>\r | |
20 | \r | |
21 | //\r | |
22 | // Note: Currently only large memory model is supported by UEFI relocation code.\r | |
23 | //\r | |
24 | \r | |
25 | /**\r | |
26 | Performs an AARCH64-based specific relocation fixup and is a no-op on other\r | |
27 | instruction sets.\r | |
28 | \r | |
29 | @param Reloc The pointer to the relocation record.\r | |
30 | @param Fixup The pointer to the address to fix up.\r | |
31 | @param FixupData The pointer to a buffer to log the fixups.\r | |
32 | @param Adjust The offset to adjust the fixup.\r | |
33 | \r | |
34 | @return Status code.\r | |
35 | \r | |
36 | **/\r | |
37 | RETURN_STATUS\r | |
38 | PeCoffLoaderRelocateImageEx (\r | |
39 | IN UINT16 **Reloc,\r | |
40 | IN OUT CHAR8 *Fixup,\r | |
41 | IN OUT CHAR8 **FixupData,\r | |
42 | IN UINT64 Adjust\r | |
43 | )\r | |
44 | {\r | |
45 | UINT64 *F64;\r | |
46 | \r | |
47 | switch ((**Reloc) >> 12) {\r | |
48 | \r | |
49 | case EFI_IMAGE_REL_BASED_DIR64:\r | |
50 | F64 = (UINT64 *) Fixup;\r | |
51 | *F64 = *F64 + (UINT64) Adjust;\r | |
52 | if (*FixupData != NULL) {\r | |
53 | *FixupData = ALIGN_POINTER(*FixupData, sizeof(UINT64));\r | |
54 | *(UINT64 *)(*FixupData) = *F64;\r | |
55 | *FixupData = *FixupData + sizeof(UINT64);\r | |
56 | }\r | |
57 | break;\r | |
58 | \r | |
59 | default:\r | |
60 | return RETURN_UNSUPPORTED;\r | |
61 | }\r | |
62 | \r | |
63 | return RETURN_SUCCESS;\r | |
64 | }\r | |
65 | \r | |
66 | /**\r | |
67 | Returns TRUE if the machine type of PE/COFF image is supported. Supported\r | |
68 | does not mean the image can be executed it means the PE/COFF loader supports\r | |
69 | loading and relocating of the image type. It's up to the caller to support\r | |
70 | the entry point.\r | |
71 | \r | |
72 | @param Machine Machine type from the PE Header.\r | |
73 | \r | |
74 | @return TRUE if this PE/COFF loader can load the image\r | |
75 | \r | |
76 | **/\r | |
77 | BOOLEAN\r | |
78 | PeCoffLoaderImageFormatSupported (\r | |
79 | IN UINT16 Machine\r | |
80 | )\r | |
81 | {\r | |
ff351683 | 82 | if ((Machine == IMAGE_FILE_MACHINE_ARM64) || (Machine == IMAGE_FILE_MACHINE_EBC)) {\r |
25402f5d HL |
83 | return TRUE;\r |
84 | }\r | |
85 | \r | |
86 | return FALSE;\r | |
87 | }\r | |
88 | \r | |
89 | /**\r | |
90 | Performs an ARM-based specific re-relocation fixup and is a no-op on other\r | |
91 | instruction sets. This is used to re-relocated the image into the EFI virtual\r | |
92 | space for runtime calls.\r | |
93 | \r | |
94 | @param Reloc The pointer to the relocation record.\r | |
95 | @param Fixup The pointer to the address to fix up.\r | |
96 | @param FixupData The pointer to a buffer to log the fixups.\r | |
97 | @param Adjust The offset to adjust the fixup.\r | |
98 | \r | |
99 | @return Status code.\r | |
100 | \r | |
101 | **/\r | |
102 | RETURN_STATUS\r | |
103 | PeHotRelocateImageEx (\r | |
104 | IN UINT16 **Reloc,\r | |
105 | IN OUT CHAR8 *Fixup,\r | |
106 | IN OUT CHAR8 **FixupData,\r | |
107 | IN UINT64 Adjust\r | |
108 | )\r | |
109 | {\r | |
110 | UINT64 *Fixup64;\r | |
111 | \r | |
112 | switch ((**Reloc) >> 12) {\r | |
113 | case EFI_IMAGE_REL_BASED_DIR64:\r | |
114 | Fixup64 = (UINT64 *) Fixup;\r | |
115 | *FixupData = ALIGN_POINTER (*FixupData, sizeof (UINT64));\r | |
116 | if (*(UINT64 *) (*FixupData) == *Fixup64) {\r | |
117 | *Fixup64 = *Fixup64 + (UINT64) Adjust;\r | |
118 | }\r | |
119 | \r | |
120 | *FixupData = *FixupData + sizeof (UINT64);\r | |
121 | break;\r | |
122 | \r | |
123 | default:\r | |
124 | DEBUG ((EFI_D_ERROR, "PeHotRelocateEx:unknown fixed type\n"));\r | |
125 | return RETURN_UNSUPPORTED;\r | |
126 | }\r | |
127 | \r | |
128 | return RETURN_SUCCESS;\r | |
129 | }\r |