summaryrefslogtreecommitdiff
path: root/instruction.c
blob: ef7e9f95950f1c64c7ac4cc4694a091ce1366c24 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
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,
};