From 759de1ccd2c9913ccdda1988f4d4ca59b974b329 Mon Sep 17 00:00:00 2001
From: Iain Sandoe <iain@sandoe.co.uk>
Date: Mon, 25 Mar 2019 00:09:30 +0000
Subject: [PATCH] [llvm] Add ppc64 thread state.

---
 llvm/include/llvm/BinaryFormat/MachO.h | 115 +++++++++++++++++++++++++
 1 file changed, 115 insertions(+)

diff --git a/llvm/include/llvm/BinaryFormat/MachO.h b/llvm/include/llvm/BinaryFormat/MachO.h
index c5294c76ebf..488a4744c9b 100644
--- a/llvm/include/llvm/BinaryFormat/MachO.h
+++ b/llvm/include/llvm/BinaryFormat/MachO.h
@@ -1951,6 +1951,112 @@ inline void swapStruct(ppc_state_hdr_t &x) {
   sys::swapByteOrder(x.count);
 }
 
+struct ppc_thread_state64_t {
+  uint64_t srr0;
+  uint64_t srr1;
+  uint64_t r0;
+  uint64_t r1;
+  uint64_t r2;
+  uint64_t r3;
+  uint64_t r4;
+  uint64_t r5;
+  uint64_t r6;
+  uint64_t r7;
+  uint64_t r8;
+  uint64_t r9;
+  uint64_t r10;
+  uint64_t r11;
+  uint64_t r12;
+  uint64_t r13;
+  uint64_t r14;
+  uint64_t r15;
+  uint64_t r16;
+  uint64_t r17;
+  uint64_t r18;
+  uint64_t r19;
+  uint64_t r20;
+  uint64_t r21;
+  uint64_t r22;
+  uint64_t r23;
+  uint64_t r24;
+  uint64_t r25;
+  uint64_t r26;
+  uint64_t r27;
+  uint64_t r28;
+  uint64_t r29;
+  uint64_t r30;
+  uint64_t r31;
+  uint32_t ct;
+  /* Slightly awkward, we have to emulate the 4byte align of uint64 when
+     not the first entry in a struct.  */
+  uint32_t xer[2]; /* uint64_t xer; */
+  uint32_t lr[2];  /* uint64_t lr; */
+  uint32_t ctr[2]; /* uint64_t ctr; */
+  uint32_t vrsave;
+};
+
+inline void swapStruct(ppc_thread_state64_t &x) {
+  sys::swapByteOrder(x.srr0);
+  sys::swapByteOrder(x.srr1);
+  sys::swapByteOrder(x.r0);
+  sys::swapByteOrder(x.r1);
+  sys::swapByteOrder(x.r2);
+  sys::swapByteOrder(x.r3);
+  sys::swapByteOrder(x.r4);
+  sys::swapByteOrder(x.r5);
+  sys::swapByteOrder(x.r6);
+  sys::swapByteOrder(x.r7);
+  sys::swapByteOrder(x.r8);
+  sys::swapByteOrder(x.r9);
+  sys::swapByteOrder(x.r10);
+  sys::swapByteOrder(x.r11);
+  sys::swapByteOrder(x.r12);
+  sys::swapByteOrder(x.r13);
+  sys::swapByteOrder(x.r14);
+  sys::swapByteOrder(x.r15);
+  sys::swapByteOrder(x.r16);
+  sys::swapByteOrder(x.r17);
+  sys::swapByteOrder(x.r18);
+  sys::swapByteOrder(x.r19);
+  sys::swapByteOrder(x.r20);
+  sys::swapByteOrder(x.r21);
+  sys::swapByteOrder(x.r22);
+  sys::swapByteOrder(x.r23);
+  sys::swapByteOrder(x.r24);
+  sys::swapByteOrder(x.r25);
+  sys::swapByteOrder(x.r26);
+  sys::swapByteOrder(x.r27);
+  sys::swapByteOrder(x.r28);
+  sys::swapByteOrder(x.r29);
+  sys::swapByteOrder(x.r30);
+  sys::swapByteOrder(x.r31);
+  sys::swapByteOrder(x.ct);
+  union { uint64_t ll; uint32_t l[2]; } sw;
+  sw.l[0] = x.xer[0];
+  sw.l[1] = x.xer[1];
+  sys::swapByteOrder(sw.ll);
+  x.xer[0] = sw.l[0];
+  x.xer[1] = sw.l[1];
+  sw.l[0] = x.lr[0];
+  sw.l[1] = x.lr[1];
+  sys::swapByteOrder(sw.ll);
+  x.lr[0] = sw.l[0];
+  x.lr[1] = sw.l[1];
+  sw.l[0] = x.ctr[0];
+  sw.l[1] = x.ctr[1];
+  sys::swapByteOrder(sw.ll);
+  x.ctr[0] = sw.l[0];
+  x.ctr[1] = sw.l[1];
+  sys::swapByteOrder(x.vrsave);
+}
+
+struct ppc64_thread_state_t {
+  ppc_state_hdr_t tsh;
+  union {
+    ppc_thread_state64_t ts64;
+  } uts;
+};
+
 enum PPCThreadFlavors {
   PPC_THREAD_STATE = 1,
   PPC_FLOAT_STATE = 2,
@@ -1970,6 +2076,15 @@ inline void swapStruct(ppc_thread_state_t &x) {
 const uint32_t PPC_THREAD_STATE_COUNT =
     sizeof(ppc_thread_state32_t) / sizeof(uint32_t);
 
+inline void swapStruct(ppc64_thread_state_t &x) {
+  swapStruct(x.tsh);
+  if (x.tsh.flavor == PPC_THREAD_STATE64)
+    swapStruct(x.uts.ts64);
+}
+
+const uint32_t PPC_THREAD_STATE64_COUNT =
+    sizeof(ppc_thread_state64_t) / sizeof(uint32_t);
+
 // Define a union of all load command structs
 #define LOAD_COMMAND_STRUCT(LCStruct) LCStruct LCStruct##_data;
 
