summaryrefslogtreecommitdiff
path: root/emux64/src/cpu/cpu_cycle.c
diff options
context:
space:
mode:
authorIan Moffett <ian@osmora.org>2025-10-13 01:47:03 -0400
committerIan Moffett <ian@osmora.org>2025-10-13 01:47:03 -0400
commit27e11e67eb7ba5e6d7645081e881f01792db431b (patch)
tree67d47cd51d1a6de35b601992df348c7bcb67c665 /emux64/src/cpu/cpu_cycle.c
parentfb72582468d8efede977793ad8e6a858a81a0e44 (diff)
emux64: cpu: Seperate arithop core from add logic
Signed-off-by: Ian Moffett <ian@osmora.org>
Diffstat (limited to 'emux64/src/cpu/cpu_cycle.c')
-rw-r--r--emux64/src/cpu/cpu_cycle.c48
1 files changed, 44 insertions, 4 deletions
diff --git a/emux64/src/cpu/cpu_cycle.c b/emux64/src/cpu/cpu_cycle.c
index cdbf87f..b3a8987 100644
--- a/emux64/src/cpu/cpu_cycle.c
+++ b/emux64/src/cpu/cpu_cycle.c
@@ -34,6 +34,19 @@
#include "cpu/cpu.h"
/*
+ * Represents arithmetic arguments
+ *
+ * @dest_reg: Destination register [R]
+ * @op1: Operand 1 [IMM]
+ * op2: Operand 2 [IMM]
+ */
+struct arithop {
+ uint8_t dest_reg;
+ uint64_t op1;
+ uint64_t op2;
+};
+
+/*
* Returns true if the register is an
* X<n> type register
*
@@ -112,16 +125,27 @@ cpu_fetch32(struct osmx_core *core, uint64_t *res)
return 0;
}
+/*
+ * Get arithmetic parameters
+ *
+ * @core: Core that is executing
+ * @res: Result written here
+ *
+ * Returns zero on success
+ */
static int
-cpu_do_add(struct osmx_core *core)
+cpu_arithop(struct osmx_core *core, struct arithop *res)
{
uint8_t dest, op1, op2;
- uint64_t op1_val;
uint64_t op2_val;
bool op2_is_imm;
bool op2_is_big;
int error = 0;
+ if (core == NULL || res == NULL) {
+ return -EINVAL;
+ }
+
/* Grab the dest register */
error = cpu_fetch(core, &dest);
if (error < 0) {
@@ -161,8 +185,24 @@ cpu_do_add(struct osmx_core *core)
return error;
}
- op1_val = core->xn[op1];
- core->xn[dest] = op1_val + op2_val;
+ res->dest_reg = dest;
+ res->op1 = core->xn[op1];
+ res->op2 = op2_val;
+ return 0;
+}
+
+static int
+cpu_do_add(struct osmx_core *core)
+{
+ struct arithop ops;
+ int error;
+
+ error = cpu_arithop(core, &ops);
+ if (error < 0) {
+ return error;
+ }
+
+ core->xn[ops.dest_reg] = ops.op1 + ops.op2;
return 0;
}