-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmemory.hpp
91 lines (73 loc) · 2.19 KB
/
memory.hpp
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/*
* ARM9 emulator - Memory subsystem
*
* Copyright (C) 2011 - Miguel Boton (Waninkoko)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __MEMORY_HPP__
#define __MEMORY_HPP__
#include <vector>
#include "types.h"
using namespace std;
/* Virtual space class */
class VSpace {
/* Buffer */
u8 *buffer;
public:
/* Parameters */
u32 vaddr;
u32 size;
public:
VSpace(u32 vaddr, u32 size);
~VSpace(void);
/* Read functions */
u8 Read8 (u32 address);
u16 Read16(u32 address);
u32 Read32(u32 address);
/* Write functions */
void Write8 (u32 address, u8 value);
void Write16(u32 address, u16 value);
void Write32(u32 address, u32 value);
/* Copy functions */
void Memcpy(u32 dst, void *src, u32 size);
void Memcpy(void *dst, u32 src, u32 size);
};
/* Memory class */
class Memory {
/* Virtual spaces */
static vector<VSpace *> Spaces;
private:
static VSpace * Find(u32 address);
public:
/* Create/Destroy spaces */
static bool Create (u32 vaddr, u32 size);
static void Destroy(void);
static void Destroy(u32 vaddr);
/* Load functions */
static bool LoadBinary(const char *filename, u32 &entry);
static bool LoadELF (const char *filename, u32 &entry);
/* Read functions */
static u8 Read8 (u32 address);
static u16 Read16(u32 address);
static u32 Read32(u32 address);
/* Write functions */
static void Write8 (u32 address, u8 value);
static void Write16(u32 address, u16 value);
static void Write32(u32 address, u32 value);
/* Copy functions */
static void Memcpy(u32 dst, void *src, u32 size);
static void Memcpy(void *dst, u32 src, u32 size);
};
#endif /* __MEMORY_HPP__ */