https://git.reactos.org/?p=reactos.git;a=commitdiff;h=b1fca7ea557f079c3c674…
commit b1fca7ea557f079c3c674f7d6eb5217b1c559d08
Author: Justin Miller <justinmiller100(a)gmail.com>
AuthorDate: Thu Dec 9 06:54:16 2021 -0800
Commit: GitHub <noreply(a)github.com>
CommitDate: Thu Dec 9 17:54:16 2021 +0300
[SDK][XDK] Add more definitions for ARM64 and start fixing PE binaries (#4142)
- Add context structure and definitions, NEON128 structure,
runtime function entry, dispatcher context, scope table
All definitions are based on the latest SDK for arm64.
[SDK] Use _TARGET_PE64 in the pefixup
[GENINC] Add AA64 identifier for ARM64 PE binaries
CORE-17518
---
sdk/include/xdk/winnt_old.h | 145 ++++++++++++++++++++++++++++++++++++++++++++
sdk/tools/CMakeLists.txt | 2 +-
sdk/tools/geninc/geninc.c | 4 +-
3 files changed, 149 insertions(+), 2 deletions(-)
diff --git a/sdk/include/xdk/winnt_old.h b/sdk/include/xdk/winnt_old.h
index 9eaef1dcf10..c554bafa12e 100644
--- a/sdk/include/xdk/winnt_old.h
+++ b/sdk/include/xdk/winnt_old.h
@@ -2149,6 +2149,151 @@ typedef struct _DISPATCHER_CONTEXT
DWORD Reserved;
} DISPATCHER_CONTEXT, *PDISPATCHER_CONTEXT;
+#elif defined(_ARM64_)
+
+#define CONTEXT_ARM64 0x00400000L
+#define CONTEXT_CONTROL (CONTEXT_ARM64 | 0x1L)
+#define CONTEXT_INTEGER (CONTEXT_ARM64 | 0x2L)
+#define CONTEXT_FLOATING_POINT (CONTEXT_ARM64 | 0x4L)
+#define CONTEXT_DEBUG_REGISTERS (CONTEXT_ARM64 | 0x8L)
+#define CONTEXT_X18 (CONTEXT_ARM64 | 0x10L)
+#define CONTEXT_FULL (CONTEXT_CONTROL | CONTEXT_INTEGER | CONTEXT_FLOATING_POINT)
+
+
+#define EXCEPTION_READ_FAULT 0
+#define EXCEPTION_WRITE_FAULT 1
+#define EXCEPTION_EXECUTE_FAULT 8
+
+typedef union NEON128 {
+ struct {
+ ULONGLONG Low;
+ LONGLONG High;
+ } DUMMYSTRUCTNAME;
+ double D[2];
+ float S[4];
+ WORD H[8];
+ BYTE B[16];
+} NEON128, *PNEON128;
+
+#define ARM64_MAX_BREAKPOINTS 8
+#define ARM64_MAX_WATCHPOINTS 2
+
+typedef struct _CONTEXT {
+
+ //
+ // Control flags.
+ //
+
+ DWORD ContextFlags;
+
+ //
+ // Integer registers
+ //
+
+ DWORD Cpsr;
+ union {
+ struct {
+ DWORD64 X0;
+ DWORD64 X1;
+ DWORD64 X2;
+ DWORD64 X3;
+ DWORD64 X4;
+ DWORD64 X5;
+ DWORD64 X6;
+ DWORD64 X7;
+ DWORD64 X8;
+ DWORD64 X9;
+ DWORD64 X10;
+ DWORD64 X11;
+ DWORD64 X12;
+ DWORD64 X13;
+ DWORD64 X14;
+ DWORD64 X15;
+ DWORD64 X16;
+ DWORD64 X17;
+ DWORD64 X18;
+ DWORD64 X19;
+ DWORD64 X20;
+ DWORD64 X21;
+ DWORD64 X22;
+ DWORD64 X23;
+ DWORD64 X24;
+ DWORD64 X25;
+ DWORD64 X26;
+ DWORD64 X27;
+ DWORD64 X28;
+ DWORD64 Fp;
+ DWORD64 Lr;
+ } DUMMYSTRUCTNAME;
+ DWORD64 X[31];
+ } DUMMYUNIONNAME;
+
+ DWORD64 Sp;
+ DWORD64 Pc;
+
+ //
+ // Floating Point/NEON Registers
+ //
+
+ NEON128 V[32];
+ DWORD Fpcr;
+ DWORD Fpsr;
+
+ //
+ // Debug registers
+ //
+
+ DWORD Bcr[ARM64_MAX_BREAKPOINTS];
+ DWORD64 Bvr[ARM64_MAX_BREAKPOINTS];
+ DWORD Wcr[ARM64_MAX_WATCHPOINTS];
+ DWORD64 Wvr[ARM64_MAX_WATCHPOINTS];
+
+} _CONTEXT, *P_CONTEXT;
+typedef _CONTEXT CONTEXT, *PCONTEXT;
+
+typedef struct _IMAGE_ARM64_RUNTIME_FUNCTION_ENTRY {
+ DWORD BeginAddress;
+ union {
+ DWORD UnwindData;
+ struct {
+ DWORD Flag : 2;
+ DWORD FunctionLength : 11;
+ DWORD RegF : 3;
+ DWORD RegI : 4;
+ DWORD H : 1;
+ DWORD CR : 2;
+ DWORD FrameSize : 9;
+ } DUMMYSTRUCTNAME;
+ } DUMMYUNIONNAME;
+} IMAGE_ARM64_RUNTIME_FUNCTION_ENTRY, * PIMAGE_ARM64_RUNTIME_FUNCTION_ENTRY;
+typedef struct _IMAGE_ARM64_RUNTIME_FUNCTION_ENTRY RUNTIME_FUNCTION, *PRUNTIME_FUNCTION;
+
+typedef struct _SCOPE_TABLE_ARM64 {
+ DWORD Count;
+ struct
+ {
+ DWORD BeginAddress;
+ DWORD EndAddress;
+ DWORD HandlerAddress;
+ DWORD JumpTarget;
+ } ScopeRecord[1];
+} SCOPE_TABLE_ARM64, *PSCOPE_TABLE_ARM64;
+typedef SCOPE_TABLE_ARM64 SCOPE_TABLE, *PSCOPE_TABLE;
+
+typedef struct _DISPATCHER_CONTEXT {
+ ULONG_PTR ControlPc;
+ ULONG_PTR ImageBase;
+ PRUNTIME_FUNCTION FunctionEntry;
+ ULONG_PTR EstablisherFrame;
+ ULONG_PTR TargetPc;
+ PCONTEXT ContextRecord;
+ PEXCEPTION_ROUTINE LanguageHandler;
+ PVOID HandlerData;
+ struct _UNWIND_HISTORY_TABLE *HistoryTable;
+ DWORD ScopeIndex;
+ BOOLEAN ControlPcIsUnwound;
+ PBYTE NonVolatileRegisters;
+} DISPATCHER_CONTEXT, *PDISPATCHER_CONTEXT;
#else
#error "undefined processor type"
#endif
diff --git a/sdk/tools/CMakeLists.txt b/sdk/tools/CMakeLists.txt
index 374ccd2f10a..535712d171d 100644
--- a/sdk/tools/CMakeLists.txt
+++ b/sdk/tools/CMakeLists.txt
@@ -50,7 +50,7 @@ if(NOT MSVC)
add_subdirectory(rsym)
add_host_tool(pefixup pefixup.c)
-if (ARCH STREQUAL "amd64")
+if (ARCH STREQUAL "amd64" OR ARCH STREQUAL "arm64")
target_compile_definitions(pefixup PRIVATE _TARGET_PE64)
endif()
target_link_libraries(pefixup PRIVATE host_includes)
diff --git a/sdk/tools/geninc/geninc.c b/sdk/tools/geninc/geninc.c
index 295f2cfe8b8..b1e501f8b4d 100644
--- a/sdk/tools/geninc/geninc.c
+++ b/sdk/tools/geninc/geninc.c
@@ -10,6 +10,7 @@
#define IMAGE_FILE_MACHINE_I386 0x014c
#define IMAGE_FILE_MACHINE_AMD64 0x8664
#define IMAGE_FILE_MACHINE_ARMNT 0x01c4
+#define IMAGE_FILE_MACHINE_ARM64 0xaa64
#ifdef _MSC_VER
#define PRIx64 "I64x"
@@ -117,7 +118,8 @@ int main(int argc, char* argv[])
if ((Machine != IMAGE_FILE_MACHINE_I386) &&
(Machine != IMAGE_FILE_MACHINE_AMD64) &&
- (Machine != IMAGE_FILE_MACHINE_ARMNT))
+ (Machine != IMAGE_FILE_MACHINE_ARMNT) &&
+ (Machine != IMAGE_FILE_MACHINE_ARM64))
{
fprintf(stderr, "Invalid Machine: 0x%x.\n", Machine);
goto quit;