From e1051b8c95059c28d8215b84dcbe4f41b326cb56 Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Thu, 11 Nov 2010 09:27:41 +0100 Subject: Baisc instruction handling --- instruction.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 instruction.c (limited to 'instruction.c') 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 + * + * 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, +}; -- cgit v1.2.3-54-g00ecf