summaryrefslogtreecommitdiffstats
path: root/src/emu/mem.c
blob: 5ab8389fcb95af6da31e33ce8682eb62fc641978 (plain) (blame)
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
#include <stdint.h>
#include <sys/types.h>
#include <string.h>
#include <inttypes.h>

#include "cpu.h"
#include "mem.h"
#include "log.h"

uint8_t *MEM;
uint64_t mem_size = 64 * 1024 * 1024;

void store(size_t addr, uint32_t value)
{
	if (addr & 0x2)
		trap(TRP_UNALIGNED);
	if (addr >= mem_size)
		trap(TRP_SEGV);
	memcpy(&MEM[addr], &value, 4);
}

uint32_t load(size_t addr)
{
	uint32_t tmp32;
	if (addr & 0x2)
		trap(TRP_UNALIGNED);
	if (addr >= mem_size)
		trap(TRP_SEGV);
	memcpy(&tmp32, &MEM[addr], 4);
	return tmp32;
}

void push(uint32_t value)
{
	//debug("push(%"PRIu32")", value);
	GPR[StP] -= 4;
	store(GPR[StP], value);
}

uint32_t pop(void)
{
	uint32_t tmp32 = load(GPR[StP]);
	//debug("pop(%"PRIu32")", tmp32);
	GPR[StP] += 4;
	return tmp32;
}