summaryrefslogblamecommitdiffstats
path: root/src/emu/mem.c
blob: 21caafda429de2a90dd1278942fe5749c2eb589d (plain) (tree)
1
2
3
4
5
6
7
8
9


                      
                     

                
                
                
 
             
                                     




                                       

                               







                                      

                               





                                      
                                          






                                       
                                         


                     
#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[SP] -= 4;
	store(GPR[SP], value);
}

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