Mercurial > repos > blastem
view mem.c @ 735:539d12fa6a4d
Add a define in both the source and Makefile for enabling logging of z80 instruction address/cycle counts. Fix Z80 in/out instructions to eliminate assumptions about which registers are stored in native regs. Fix read_16 to not corrupt the low byte when the read has to call into a C function.
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Mon, 25 May 2015 18:56:22 -0700 |
parents | 140af5509ce7 |
children | b52cd6854c28 |
line wrap: on
line source
/* Copyright 2013 Michael Pavone This file is part of BlastEm. BlastEm is free software distributed under the terms of the GNU General Public License version 3 or greater. See COPYING for full license text. */ #include <sys/mman.h> #include <stddef.h> #include <stdint.h> #include <stdlib.h> #include <unistd.h> #include "mem.h" /* void * alloc_code(size_t *size) { *size += PAGE_SIZE - (*size & (PAGE_SIZE - 1)); return mmap(NULL, *size, PROT_EXEC | PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); } */ /* void * alloc_code(size_t *size) { char * ret = malloc(*size); char * base = (char *)(((intptr_t)ret) & (~(PAGE_SIZE-1))); mprotect(base, (ret + *size) - base, PROT_EXEC | PROT_READ | PROT_WRITE); return ret; } */ void * alloc_code(size_t *size) { *size += PAGE_SIZE - (*size & (PAGE_SIZE - 1)); void * ret = sbrk(*size); if (ret == ((void *)-1)) { return NULL; } mprotect(ret, *size, PROT_EXEC | PROT_READ | PROT_WRITE); return ret; }