summaryrefslogtreecommitdiff
path: root/nios2.c
blob: 87eb3f3c0065938977667fa205e5dcb66b949df3 (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
/*
 * 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 <stdio.h>
#include <string.h>

#include "nios2sim-ng.h"
#include "nios2.h"

void nios2_cpu_reset(struct nios2 *cpu)
{
	memset(cpu, 0x00, sizeof(struct nios2));
	cpu->mode = NIOS2_SUPERVISOR_MODE;
}

bool nios2_in_user_mode(struct nios2 *cpu)
{
	if (!cpu->has_mmu)
		return false;
	else if (cpu->mode != NIOS2_USER_MODE)
		return false;
	else
		return true;
}

bool nios2_in_supervisor_mode(struct nios2 *cpu)
{
	return !nios2_in_user_mode(cpu);
}

uint32_t nios2_cpu_fetch_instr(struct nios2 *cpu, uint32_t *mem_base)
{
	uint32_t instr = 0;

	return instr;
}

int nios2_cpu_execute_instr(struct nios2 *cpu, uint32_t instr)
{
	instruction_handler handle_instr = instruction_get_handler(instr);

	if (unlikely(handle_instr == NULL)) {
		err("Invalid instruction %08x\n", instr);
		return -1;
	}

	return handle_instr(cpu, instr);
}