summaryrefslogtreecommitdiff
path: root/instruction.c
diff options
context:
space:
mode:
Diffstat (limited to 'instruction.c')
-rw-r--r--instruction.c59
1 files changed, 59 insertions, 0 deletions
diff --git a/instruction.c b/instruction.c
new file mode 100644
index 0000000..ef7e9f9
--- /dev/null
+++ b/instruction.c
@@ -0,0 +1,59 @@
+/*
+ * Copyright (C) 2010 Tobias Klauser <tklauser@distanz.ch>
+ *
+ * This file is part of nios2sim-ng.
+ *
+ * This file is subject to the terms and conditions of the GNU General Public
+ * License. See the file "COPYING" in the main directory of this archive
+ * for more details.
+ */
+
+#include "nios2sim-ng.h"
+#include "instruction.h"
+#include "nios2.h"
+
+/*
+ * J-Type instructions
+ */
+
+uint32_t call(struct nios2 *cpu, uint32_t opcode)
+{
+ J_TYPE(instr, opcode);
+
+ return PC_INC_BY_INSTR;
+}
+
+uint32_t jmpi(struct nios2 *cpu, uint32_t opcode)
+{
+ J_TYPE(instr, opcode);
+
+ return PC_INC_BY_INSTR;
+}
+
+/*
+ * I-Type instructions
+ */
+
+uint32_t ldbu(struct nios2 *cpu, uint32_t opcode)
+{
+ I_TYPE(instr, opcode);
+
+ return PC_INC_NORMAL;
+}
+
+uint32_t addi(struct nios2 *cpu, uint32_t opcode)
+{
+ I_TYPE(instr, opcode);
+
+ /* rB <- rA + IMM16 */
+ cpu->gp_regs[instr->b] = cpu->gp_regs[instr->a] + (int16_t) (instr->imm16);
+
+ return PC_INC_NORMAL;
+}
+
+instruction_handler i_type_inst_handlers[I_TYPE_COUNT] = {
+ [CALL] = call,
+ [JMPI] = jmpi,
+ [LDBU] = ldbu,
+ [ADDI] = addi,
+};