Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
Suyu
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
many-archive
Suyu
Commits
3873b36d
There was an error fetching the commit references. Please try again later.
Commit
3873b36d
authored
8 years ago
by
MerryMage
Committed by
Subv
8 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Memory: ReadBlock/WriteBlock
parent
c084fc82
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/core/memory.cpp
+74
-3
74 additions, 3 deletions
src/core/memory.cpp
src/core/memory.h
+3
-1
3 additions, 1 deletion
src/core/memory.h
src/core/mmio.h
+4
-0
4 additions, 0 deletions
src/core/mmio.h
with
81 additions
and
4 deletions
src/core/memory.cpp
+
74
−
3
View file @
3873b36d
...
...
@@ -364,6 +364,45 @@ u64 Read64(const VAddr addr) {
return
Read
<
u64_le
>
(
addr
);
}
void
ReadBlock
(
const
VAddr
src_addr
,
u8
*
dest_buffer
,
const
size_t
size
)
{
size_t
remaining_size
=
size
;
size_t
page_index
=
src_addr
>>
PAGE_BITS
;
size_t
page_offset
=
src_addr
&
PAGE_MASK
;
while
(
remaining_size
>
0
)
{
const
size_t
copy_amount
=
std
::
min
(
PAGE_SIZE
-
page_offset
,
remaining_size
);
const
VAddr
current_vaddr
=
(
page_index
<<
PAGE_BITS
)
+
page_offset
;
switch
(
current_page_table
->
attributes
[
page_index
])
{
case
PageType
::
Unmapped
:
{
LOG_ERROR
(
HW_Memory
,
"unmapped ReadBlock @ 0x%08X (start address = 0x%08X, size = %zu)"
,
current_vaddr
,
src_addr
,
size
);
std
::
memset
(
dest_buffer
,
0
,
copy_amount
);
break
;
}
case
PageType
::
Memory
:
{
DEBUG_ASSERT
(
current_page_table
->
pointers
[
page_index
]);
const
u8
*
src_ptr
=
current_page_table
->
pointers
[
page_index
]
+
page_offset
;
std
::
memcpy
(
dest_buffer
,
src_ptr
,
copy_amount
);
break
;
}
case
PageType
::
Special
:
{
DEBUG_ASSERT
(
GetMMIOHandler
(
current_vaddr
));
GetMMIOHandler
(
current_vaddr
)
->
ReadBlock
(
current_vaddr
,
dest_buffer
,
copy_amount
);
break
;
}
default
:
UNREACHABLE
();
}
page_index
++
;
page_offset
=
0
;
dest_buffer
+=
copy_amount
;
remaining_size
-=
copy_amount
;
}
}
void
Write8
(
const
VAddr
addr
,
const
u8
data
)
{
Write
<
u8
>
(
addr
,
data
);
}
...
...
@@ -380,9 +419,41 @@ void Write64(const VAddr addr, const u64 data) {
Write
<
u64_le
>
(
addr
,
data
);
}
void
WriteBlock
(
const
VAddr
addr
,
const
u8
*
data
,
const
size_t
size
)
{
for
(
u32
offset
=
0
;
offset
<
size
;
offset
++
)
{
Write8
(
addr
+
offset
,
data
[
offset
]);
void
WriteBlock
(
const
VAddr
dest_addr
,
const
u8
*
src_buffer
,
const
size_t
size
)
{
size_t
remaining_size
=
size
;
size_t
page_index
=
dest_addr
>>
PAGE_BITS
;
size_t
page_offset
=
dest_addr
&
PAGE_MASK
;
while
(
remaining_size
>
0
)
{
const
size_t
copy_amount
=
std
::
min
(
PAGE_SIZE
-
page_offset
,
remaining_size
);
const
VAddr
current_vaddr
=
(
page_index
<<
PAGE_BITS
)
+
page_offset
;
switch
(
current_page_table
->
attributes
[
page_index
])
{
case
PageType
::
Unmapped
:
{
LOG_ERROR
(
HW_Memory
,
"unmapped WriteBlock @ 0x%08X (start address = 0x%08X, size = %zu)"
,
current_vaddr
,
dest_addr
,
size
);
break
;
}
case
PageType
::
Memory
:
{
DEBUG_ASSERT
(
current_page_table
->
pointers
[
page_index
]);
u8
*
dest_ptr
=
current_page_table
->
pointers
[
page_index
]
+
page_offset
;
std
::
memcpy
(
dest_ptr
,
src_buffer
,
copy_amount
);
break
;
}
case
PageType
::
Special
:
{
DEBUG_ASSERT
(
GetMMIOHandler
(
current_vaddr
));
GetMMIOHandler
(
current_vaddr
)
->
WriteBlock
(
current_vaddr
,
src_buffer
,
copy_amount
);
break
;
}
default
:
UNREACHABLE
();
}
page_index
++
;
page_offset
=
0
;
src_buffer
+=
copy_amount
;
remaining_size
-=
copy_amount
;
}
}
...
...
This diff is collapsed.
Click to expand it.
src/core/memory.h
+
3
−
1
View file @
3873b36d
...
...
@@ -118,12 +118,14 @@ u16 Read16(VAddr addr);
u32
Read32
(
VAddr
addr
);
u64
Read64
(
VAddr
addr
);
void
ReadBlock
(
const
VAddr
src_addr
,
u8
*
dest_buffer
,
size_t
size
);
void
Write8
(
VAddr
addr
,
u8
data
);
void
Write16
(
VAddr
addr
,
u16
data
);
void
Write32
(
VAddr
addr
,
u32
data
);
void
Write64
(
VAddr
addr
,
u64
data
);
void
WriteBlock
(
VAddr
addr
,
const
u8
*
data
,
size_t
size
);
void
WriteBlock
(
const
VAddr
dest_
addr
,
const
u8
*
src_buffer
,
size_t
size
);
u8
*
GetPointer
(
VAddr
virtual_address
);
...
...
This diff is collapsed.
Click to expand it.
src/core/mmio.h
+
4
−
0
View file @
3873b36d
...
...
@@ -25,10 +25,14 @@ public:
virtual
u32
Read32
(
VAddr
addr
)
=
0
;
virtual
u64
Read64
(
VAddr
addr
)
=
0
;
virtual
bool
ReadBlock
(
VAddr
src_addr
,
u8
*
dest_buffer
,
size_t
size
)
=
0
;
virtual
void
Write8
(
VAddr
addr
,
u8
data
)
=
0
;
virtual
void
Write16
(
VAddr
addr
,
u16
data
)
=
0
;
virtual
void
Write32
(
VAddr
addr
,
u32
data
)
=
0
;
virtual
void
Write64
(
VAddr
addr
,
u64
data
)
=
0
;
virtual
bool
WriteBlock
(
VAddr
dest_addr
,
const
u8
*
src_buffer
,
size_t
size
)
=
0
;
};
using
MMIORegionPointer
=
std
::
shared_ptr
<
MMIORegion
>
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment