CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
hrydgard

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: hrydgard/ppsspp
Path: blob/master/Core/MemMapHelpers.h
Views: 1401
1
// Copyright (C) 2003 Dolphin Project / 2012 PPSSPP Project.
2
3
// This program is free software: you can redistribute it and/or modify
4
// it under the terms of the GNU General Public License as published by
5
// the Free Software Foundation, version 2.0 or later versions.
6
7
// This program is distributed in the hope that it will be useful,
8
// but WITHOUT ANY WARRANTY; without even the implied warranty of
9
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
// GNU General Public License 2.0 for more details.
11
12
// A copy of the GPL 2.0 should have been included with the program.
13
// If not, see http://www.gnu.org/licenses/
14
15
// Official SVN repository and contact information can be found at
16
// http://code.google.com/p/dolphin-emu/
17
18
#pragma once
19
20
#include <cstring>
21
22
#include "Common/CommonTypes.h"
23
#include "Common/StringUtils.h"
24
#include "Core/Debugger/MemBlockInfo.h"
25
#include "Core/MemMap.h"
26
#include "Core/MIPS/MIPS.h"
27
28
// To avoid pulling in the entire HLE.h.
29
extern MIPSState *currentMIPS;
30
31
namespace Memory
32
{
33
34
inline void Memcpy(const u32 to_address, const void *from_data, const u32 len, const char *tag, size_t tagLen) {
35
u8 *to = GetPointerWriteRange(to_address, len);
36
if (to) {
37
memcpy(to, from_data, len);
38
if (!tag) {
39
tag = "Memcpy";
40
tagLen = sizeof("Memcpy") - 1;
41
}
42
NotifyMemInfo(MemBlockFlags::WRITE, to_address, len, tag, tagLen);
43
}
44
// if not, GetPointer will log.
45
}
46
47
inline void Memcpy(void *to_data, const u32 from_address, const u32 len, const char *tag, size_t tagLen) {
48
const u8 *from = GetPointerRange(from_address, len);
49
if (from) {
50
memcpy(to_data, from, len);
51
if (!tag) {
52
tag = "Memcpy";
53
tagLen = sizeof("Memcpy") - 1;
54
}
55
NotifyMemInfo(MemBlockFlags::READ, from_address, len, tag, tagLen);
56
}
57
// if not, GetPointer will log.
58
}
59
60
inline void Memcpy(const u32 to_address, const u32 from_address, const u32 len, const char *tag, size_t tagLen) {
61
u8 *to = GetPointerWriteRange(to_address, len);
62
// If not, GetPointer will log.
63
if (!to)
64
return;
65
const u8 *from = GetPointerRange(from_address, len);
66
if (!from)
67
return;
68
69
memcpy(to, from, len);
70
71
if (MemBlockInfoDetailed(len)) {
72
if (!tag) {
73
NotifyMemInfoCopy(to_address, from_address, len, "Memcpy/");
74
} else {
75
NotifyMemInfo(MemBlockFlags::READ, from_address, len, tag, tagLen);
76
NotifyMemInfo(MemBlockFlags::WRITE, to_address, len, tag, tagLen);
77
}
78
}
79
}
80
81
template<size_t tagLen>
82
inline void Memcpy(const u32 to_address, const void *from_data, const u32 len, const char(&tag)[tagLen]) {
83
Memcpy(to_address, from_data, len, tag, tagLen);
84
}
85
86
template<size_t tagLen>
87
inline void Memcpy(void *to_data, const u32 from_address, const u32 len, const char(&tag)[tagLen]) {
88
Memcpy(to_data, from_address, len, tag, tagLen);
89
}
90
91
template<size_t tagLen>
92
inline void Memcpy(const u32 to_address, const u32 from_address, const u32 len, const char(&tag)[tagLen]) {
93
Memcpy(to_address, from_address, len, tag, tagLen);
94
}
95
96
inline void Memcpy(const u32 to_address, const void *from_data, const u32 len) {
97
Memcpy(to_address, from_data, len, nullptr, 0);
98
}
99
100
inline void Memcpy(void *to_data, const u32 from_address, const u32 len) {
101
Memcpy(to_data, from_address, len, nullptr, 0);
102
}
103
104
inline void Memcpy(const u32 to_address, const u32 from_address, const u32 len) {
105
Memcpy(to_address, from_address, len, nullptr, 0);
106
}
107
108
void Memset(const u32 _Address, const u8 _Data, const u32 _iLength, const char *tag = "Memset");
109
110
}
111
112