forked from PlaneteCasio/Casio_asm
62 lines
1.5 KiB
C
62 lines
1.5 KiB
C
#ifndef MMU_H
|
|
#define MMU_H
|
|
|
|
#include "../common/types.h"
|
|
|
|
typedef void(*mmu_getter_t)(int, char*, void*);
|
|
typedef void(*mmu_setter_t)(int, char, void*);
|
|
|
|
typedef struct memory_map_t {
|
|
int pos;
|
|
int len;
|
|
union {
|
|
char* pointer;
|
|
void* opaque;
|
|
};
|
|
mmu_getter_t getter;
|
|
mmu_setter_t setter;
|
|
char access;
|
|
char info;
|
|
} memory_map_t;
|
|
|
|
typedef struct mmu_t {
|
|
memory_map_t segments[32];
|
|
char onError;
|
|
char length;
|
|
} mmu_t;
|
|
|
|
#define MMU_ACCESS_absent 8
|
|
#define MMU_ACCESS_r 4
|
|
#define MMU_ACCESS_w 2
|
|
#define MMU_ACCESS_x 1
|
|
|
|
#define MMU_ONERROR_ZERO 1
|
|
#define MMU_ONERROR_NONE 0
|
|
|
|
//byte by byte access
|
|
void Mmu_readByte(mmu_t *mmu, char *byte, int offset);
|
|
void Mmu_writeByte(mmu_t *mmu, char byte, int offset);
|
|
|
|
//half word access
|
|
void Mmu_readHalfWord(mmu_t *mmu, half_word_t *half, int offset);
|
|
void Mmu_writeHalfWord(mmu_t *mmu, half_word_t half, int offset);
|
|
|
|
//full word access
|
|
void Mmu_readWord(mmu_t *mmu, word_t *word, int offset);
|
|
void Mmu_writeWord(mmu_t *mmu, word_t word, int offset);
|
|
|
|
//block access
|
|
void Mmu_readBlock(mmu_t *mmu, void* data, int offset, int length);
|
|
void Mmu_writeBlock(mmu_t *mmu, void* data, int offset, int length);
|
|
|
|
//access check
|
|
int Mmu_checkAccess(mmu_t *mmu, int offset);
|
|
|
|
//configuration
|
|
int Mmu_addSegment(mmu_t *mmu, int pos, int len, char* pointer, char access, char info);
|
|
int Mmu_addAbsentSegment(mmu_t *mmu, int pos, int len, mmu_getter_t getter, mmu_setter_t setter, void* opaque, char access, char info);
|
|
int Mmu_removeSegment(mmu_t *mmu, int pos);
|
|
void initMMU(mmu_t *mmu);
|
|
|
|
#endif
|