summaryrefslogtreecommitdiffstats
path: root/src/emu/mem.c
blob: cdbf2ae980e7fe4e1ab06d62cc36bc50f0de1ef0 (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
#include <stdint.h>
#include <sys/types.h>
#include <string.h>

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

uint8_t *MEM;

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

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

void push(uint32_t value)
{
	GPR[SP] -= 4;
	store(GPR[SP], value);
}

uint32_t pop(void)
{
	uint32_t tmp32 = load(GPR[SP]);
	GPR[SP] += 4;
	return tmp32;
}