Skip to contentSkip to conversation

Add risu_ppc.c file

PATCH In review G 3 2 participants 4 messages Apr 25, 2017

lore
Share & tools
lore

G 3

author
#0 lore raw

PATCH 2/9 Add risu_ppc.c file

Add the risu_ppc.c file. It defines several functions used by risu.

---
 risu_ppc.c | 41 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)
 create mode 100644 risu_ppc.c
risu_ppc.c new file +41 -0
new file mode 100644
index 0000000..70a1cf7
@@ -0,0 +1,41 @@
+/*****************************************************************
+ * File: risu_ppc.c
+ * Date: 3-27-2017
+ * Description: Implement advance_pc(), set_ucontext_paramreg(),
+ *              get_reginfo_paramreg(), get_risuop()
+ *****************************************************************/
+
+#include "risu.h"
+
+/* Advances the program counter register to the next instruction */
+void advance_pc(void *vuc)
+{
+    ucontext_t *uc = (ucontext_t*)vuc;
+    uc->uc_mcontext->ss.srr0 += 4;
+}
+
+/* Sets register r0 to the address of a memory block. */
+void set_ucontext_paramreg(void *vuc, uint64_t value)
+{
+    ucontext_t *uc = vuc;
+    uc->uc_mcontext->ss.r0 = value;
+}
+
+/*
+ * Returns the register that keeps track of a memory block address.
+ * Used for the load and store to memory instructions like LFD.
+ * Returns general purpose register r0.
+ */
+uint64_t get_reginfo_paramreg(struct reginfo *ri)
+{
+    return ri->gpr[0];
+}
+
+int get_risuop(struct reginfo *ri)
+{
+    uint32_t insn = ri->faulting_insn;
+    uint32_t op = insn & 0xf;
+    uint32_t key = insn & ~0xf;
+    uint32_t risukey = 0x00005af0;
+    return (key != risukey) ? -1 : op;
+}
Signature · 1 line
2.10.2
#1 lore raw
Quoted 14 lines · On 25 April 2017 at 04:18, G 3 <[email protected]> wrote:

Add the risu_ppc.c file. It defines several functions used by risu.

---
 risu_ppc.c | 41 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)
 create mode 100644 risu_ppc.c
risu_ppc.c new file +0 -0
new file mode 100644
index 0000000..70a1cf7

risu_ppc.c line 6

Quoted 6 lines
risu_ppc.c new file +6 -0
@@ -0,0 +1,41 @@
+/*****************************************************************
+ * File: risu_ppc.c
+ * Date: 3-27-2017
+ * Description: Implement advance_pc(), set_ucontext_paramreg(),
+ *              get_reginfo_paramreg(), get_risuop()
+ *****************************************************************/

All new files should have a brief copyright and license statement in their header comment.

thanks
-- PMM

#2 lore raw
In reply to G 3
Quoted 26 lines · On 25 April 2017 at 04:18, G 3 <[email protected]> wrote:

Add the risu_ppc.c file. It defines several functions used by risu.

---
 risu_ppc.c | 41 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)
 create mode 100644 risu_ppc.c
risu_ppc.c new file +12 -0
new file mode 100644
index 0000000..70a1cf7
@@ -0,0 +1,41 @@
+/*****************************************************************
+ * File: risu_ppc.c
+ * Date: 3-27-2017
+ * Description: Implement advance_pc(), set_ucontext_paramreg(),
+ *              get_reginfo_paramreg(), get_risuop()
+ *****************************************************************/
+
+#include "risu.h"
+
+/* Advances the program counter register to the next instruction */
+void advance_pc(void *vuc)
+{

risu_ppc.c line 22

Quoted 10 lines
risu_ppc.c new file +10 -0
+    ucontext_t *uc = (ucontext_t*)vuc;
+    uc->uc_mcontext->ss.srr0 += 4;
+}
+
+/* Sets register r0 to the address of a memory block. */
+void set_ucontext_paramreg(void *vuc, uint64_t value)
+{
+    ucontext_t *uc = vuc;
+    uc->uc_mcontext->ss.r0 = value;
+}

This doesn't look like it matches the Linux PPC uc_mcontext struct, which (like the ppc64 one) has a uc_mcontext.regs field, not uc_mcontext->ss.

Risu is a Linux program, so all CPU backends must build on Linux. It could perhaps be ported to other host OSes, but we'd need to put in more infrastructure for dealing with host OS differences, not just have "PPC works only on OSX and the others work only on Linux".

thanks
-- PMM

author
#3 lore raw
Quoted 42 lines · Peter Maydell
Quoted 26 lines · On 25 April 2017 at 04:18, G 3 <[email protected]> wrote:

Add the risu_ppc.c file. It defines several functions used by risu.

---
 risu_ppc.c | 41 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)
 create mode 100644 risu_ppc.c
risu_ppc.c new file +12 -0
new file mode 100644
index 0000000..70a1cf7
@@ -0,0 +1,41 @@
+/*****************************************************************
+ * File: risu_ppc.c
+ * Date: 3-27-2017
+ * Description: Implement advance_pc(), set_ucontext_paramreg(),
+ *              get_reginfo_paramreg(), get_risuop()
+ *****************************************************************/
+
+#include "risu.h"
+
+/* Advances the program counter register to the next instruction */
+void advance_pc(void *vuc)
+{

risu_ppc.c line 22

Quoted 10 lines
risu_ppc.c new file +10 -0
+    ucontext_t *uc = (ucontext_t*)vuc;
+    uc->uc_mcontext->ss.srr0 += 4;
+}
+
+/* Sets register r0 to the address of a memory block. */
+void set_ucontext_paramreg(void *vuc, uint64_t value)
+{
+    ucontext_t *uc = vuc;
+    uc->uc_mcontext->ss.r0 = value;
+}

This doesn't look like it matches the Linux PPC uc_mcontext struct, which (like the ppc64 one) has a uc_mcontext.regs field, not uc_mcontext->ss.

Quoted 8 lines

Risu is a Linux program, so all CPU backends must build on Linux. It could perhaps be ported to other host OSes, but we'd need to put in more infrastructure for dealing with host OS differences, not just have "PPC works only on OSX and the others work only on Linux".

thanks
-- PMM

What about having it work on both Mac OS X and Linux? A few #ifdef's should work.