From 27e54fb59e46cc309e9bdbd0697cafb11938c23c Mon Sep 17 00:00:00 2001
From: Ruslan Bukin
Date: Wed, 1 Jul 2015 13:59:26 +0000
Subject: [PATCH] Make libproc compilable on AArch64.
---
lib/libproc/proc_bkpt.c | 22 ++++++++++++++--------
lib/libproc/proc_regs.c | 16 ++++++++++++----
2 files changed, 26 insertions(+), 12 deletions(-)
diff --git a/lib/libproc/proc_bkpt.c b/lib/libproc/proc_bkpt.c
index 1e4a6cc92835..50d8a9d67908 100644
--- a/lib/libproc/proc_bkpt.c
+++ b/lib/libproc/proc_bkpt.c
@@ -42,18 +42,24 @@ __FBSDID("$FreeBSD$");
#include
#include "_libproc.h"
-#if defined(__i386__) || defined(__amd64__)
-#define BREAKPOINT_INSTR 0xcc /* int 0x3 */
+#if defined(__aarch64__)
+#define AARCH64_BRK 0xd4200000
+#define AARCH64_BRK_IMM16_SHIFT 5
+#define AARCH64_BRK_IMM16_VAL (0xd << AARCH64_BRK_IMM16_SHIFT)
+#define BREAKPOINT_INSTR (AARCH64_BRK | AARCH64_BRK_IMM16_VAL)
+#define BREAKPOINT_INSTR_SZ 4
+#elif defined(__amd64__) || defined(__i386__)
+#define BREAKPOINT_INSTR 0xcc /* int 0x3 */
#define BREAKPOINT_INSTR_SZ 1
+#elif defined(__arm__)
+#define BREAKPOINT_INSTR 0xe7ffffff /* bkpt */
+#define BREAKPOINT_INSTR_SZ 4
#elif defined(__mips__)
-#define BREAKPOINT_INSTR 0xd /* break */
+#define BREAKPOINT_INSTR 0xd /* break */
#define BREAKPOINT_INSTR_SZ 4
#elif defined(__powerpc__)
-#define BREAKPOINT_INSTR 0x7fe00008 /* trap */
-#define BREAKPOINT_INSTR_SZ 4
-#elif defined(__arm__)
-#define BREAKPOINT_INSTR 0xe7ffffff /* bkpt */
-#define BREAKPOINT_INSTR_SZ 4
+#define BREAKPOINT_INSTR 0x7fe00008 /* trap */
+#define BREAKPOINT_INSTR_SZ 4
#else
#error "Add support for your architecture"
#endif
diff --git a/lib/libproc/proc_regs.c b/lib/libproc/proc_regs.c
index 35d8d386731e..aae43ba17105 100644
--- a/lib/libproc/proc_regs.c
+++ b/lib/libproc/proc_regs.c
@@ -54,7 +54,9 @@ proc_regget(struct proc_handle *phdl, proc_reg_t reg, unsigned long *regvalue)
return (-1);
switch (reg) {
case REG_PC:
-#if defined(__amd64__)
+#if defined(__aarch64__)
+ *regvalue = regs.elr;
+#elif defined(__amd64__)
*regvalue = regs.r_rip;
#elif defined(__arm__)
*regvalue = regs.r_pc;
@@ -67,7 +69,9 @@ proc_regget(struct proc_handle *phdl, proc_reg_t reg, unsigned long *regvalue)
#endif
break;
case REG_SP:
-#if defined(__amd64__)
+#if defined(__aarch64__)
+ *regvalue = regs.sp;
+#elif defined(__amd64__)
*regvalue = regs.r_rsp;
#elif defined(__arm__)
*regvalue = regs.r_sp;
@@ -101,7 +105,9 @@ proc_regset(struct proc_handle *phdl, proc_reg_t reg, unsigned long regvalue)
return (-1);
switch (reg) {
case REG_PC:
-#if defined(__amd64__)
+#if defined(__aarch64__)
+ regs.elr = regvalue;
+#elif defined(__amd64__)
regs.r_rip = regvalue;
#elif defined(__arm__)
regs.r_pc = regvalue;
@@ -114,7 +120,9 @@ proc_regset(struct proc_handle *phdl, proc_reg_t reg, unsigned long regvalue)
#endif
break;
case REG_SP:
-#if defined(__amd64__)
+#if defined(__aarch64__)
+ regs.sp = regvalue;
+#elif defined(__amd64__)
regs.r_rsp = regvalue;
#elif defined(__arm__)
regs.r_sp = regvalue;