Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
bootloader
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
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
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
redox-os
bootloader
Commits
c0a96aa7
Verified
Commit
c0a96aa7
authored
3 years ago
by
Jeremy Soller
Browse files
Options
Downloads
Patches
Plain Diff
Reduce memory used by x86_64 page tables
parent
0874fabe
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/arch/x86_64/paging.rs
+22
-23
22 additions, 23 deletions
src/arch/x86_64/paging.rs
src/main.rs
+1
-1
1 addition, 1 deletion
src/main.rs
with
23 additions
and
24 deletions
src/arch/x86_64/paging.rs
+
22
−
23
View file @
c0a96aa7
...
@@ -23,13 +23,10 @@ pub unsafe fn paging_create<
...
@@ -23,13 +23,10 @@ pub unsafe fn paging_create<
D
:
Disk
,
D
:
Disk
,
M
:
Iterator
<
Item
=
OsMemoryEntry
>
,
M
:
Iterator
<
Item
=
OsMemoryEntry
>
,
V
:
Iterator
<
Item
=
OsVideoMode
>
V
:
Iterator
<
Item
=
OsVideoMode
>
>
(
os
:
&
mut
dyn
Os
<
D
,
M
,
V
>
,
kernel_phys
:
usize
)
->
Option
<
usize
>
{
>
(
os
:
&
mut
dyn
Os
<
D
,
M
,
V
>
,
kernel_phys
:
usize
,
kernel_size
:
usize
)
->
Option
<
usize
>
{
// Create PML4
// Create PML4
let
pml4
=
paging_allocate
(
os
)
?
;
let
pml4
=
paging_allocate
(
os
)
?
;
// Recursive mapping for compatibility
pml4
[
511
]
=
pml4
.as_ptr
()
as
u64
|
1
<<
1
|
1
;
{
{
// Create PDP for identity mapping
// Create PDP for identity mapping
let
pdp
=
paging_allocate
(
os
)
?
;
let
pdp
=
paging_allocate
(
os
)
?
;
...
@@ -38,20 +35,15 @@ pub unsafe fn paging_create<
...
@@ -38,20 +35,15 @@ pub unsafe fn paging_create<
pml4
[
0
]
=
pdp
.as_ptr
()
as
u64
|
1
<<
1
|
1
;
pml4
[
0
]
=
pdp
.as_ptr
()
as
u64
|
1
<<
1
|
1
;
pml4
[
256
]
=
pdp
.as_ptr
()
as
u64
|
1
<<
1
|
1
;
pml4
[
256
]
=
pdp
.as_ptr
()
as
u64
|
1
<<
1
|
1
;
// Identity map 8 GiB pages
// Identity map 8 GiB
using 2 MiB
pages
for
pdp_i
in
0
..
8
{
for
pdp_i
in
0
..
8
{
let
pd
=
paging_allocate
(
os
)
?
;
let
pd
=
paging_allocate
(
os
)
?
;
pdp
[
pdp_i
]
=
pd
.as_ptr
()
as
u64
|
1
<<
1
|
1
;
pdp
[
pdp_i
]
=
pd
.as_ptr
()
as
u64
|
1
<<
1
|
1
;
for
pd_i
in
0
..
pd
.len
()
{
for
pd_i
in
0
..
pd
.len
()
{
let
pt
=
paging_allocate
(
os
)
?
;
let
addr
=
pd
[
pd_i
]
=
pt
.as_ptr
()
as
u64
|
1
<<
1
|
1
;
pdp_i
as
u64
*
0x4000_0000
+
for
pt_i
in
0
..
pt
.len
()
{
pd_i
as
u64
*
0x20_0000
;
let
addr
=
pd
[
pd_i
]
=
addr
|
1
<<
7
|
1
<<
1
|
1
;
pdp_i
as
u64
*
0x4000_0000
+
pd_i
as
u64
*
0x20_0000
+
pt_i
as
u64
*
0x1000
;
pt
[
pt_i
]
=
addr
|
1
<<
1
|
1
;
}
}
}
}
}
}
}
...
@@ -63,23 +55,30 @@ pub unsafe fn paging_create<
...
@@ -63,23 +55,30 @@ pub unsafe fn paging_create<
// Link second to last PML4 entry to PDP
// Link second to last PML4 entry to PDP
pml4
[
510
]
=
pdp
.as_ptr
()
as
u64
|
1
<<
1
|
1
;
pml4
[
510
]
=
pdp
.as_ptr
()
as
u64
|
1
<<
1
|
1
;
// Map 1 GiB at kernel offset
// Map kernel_size at kernel offset
for
pdp_i
in
0
..
1
{
let
mut
kernel_mapped
=
0
;
let
mut
pdp_i
=
0
;
while
kernel_mapped
<
kernel_size
&&
pdp_i
<
pdp
.len
()
{
let
pd
=
paging_allocate
(
os
)
?
;
let
pd
=
paging_allocate
(
os
)
?
;
pdp
[
pdp_i
]
=
pd
.as_ptr
()
as
u64
|
1
<<
1
|
1
;
pdp
[
pdp_i
]
=
pd
.as_ptr
()
as
u64
|
1
<<
1
|
1
;
for
pd_i
in
0
..
pd
.len
()
{
pdp_i
+=
1
;
let
mut
pd_i
=
0
;
while
kernel_mapped
<
kernel_size
&&
pd_i
<
pd
.len
(){
let
pt
=
paging_allocate
(
os
)
?
;
let
pt
=
paging_allocate
(
os
)
?
;
pd
[
pd_i
]
=
pt
.as_ptr
()
as
u64
|
1
<<
1
|
1
;
pd
[
pd_i
]
=
pt
.as_ptr
()
as
u64
|
1
<<
1
|
1
;
for
pt_i
in
0
..
pt
.len
()
{
pd_i
+=
1
;
let
addr
=
pdp_i
as
u64
*
0x4000_0000
+
let
mut
pt_i
=
0
;
pd_i
as
u64
*
0x20_0000
+
while
kernel_mapped
<
kernel_size
&&
pt_i
<
pt
.len
()
{
pt_i
as
u64
*
0x1000
+
let
addr
=
(
kernel_phys
+
kernel_mapped
)
as
u64
;
kernel_phys
as
u64
;
pt
[
pt_i
]
=
addr
|
1
<<
1
|
1
;
pt
[
pt_i
]
=
addr
|
1
<<
1
|
1
;
pt_i
+=
1
;
kernel_mapped
+=
4096
;
}
}
}
}
}
}
assert!
(
kernel_mapped
>=
kernel_size
);
}
}
Some
(
pml4
.as_ptr
()
as
usize
)
Some
(
pml4
.as_ptr
()
as
usize
)
...
...
This diff is collapsed.
Click to expand it.
src/main.rs
+
1
−
1
View file @
c0a96aa7
...
@@ -291,7 +291,7 @@ fn main<
...
@@ -291,7 +291,7 @@ fn main<
kernel
kernel
};
};
let
page_phys
=
unsafe
{
paging_create
(
os
,
kernel
.as_ptr
()
as
usize
)
}
let
page_phys
=
unsafe
{
paging_create
(
os
,
kernel
.as_ptr
()
as
usize
,
kernel
.len
()
)
}
.expect
(
"Failed to set up paging"
);
.expect
(
"Failed to set up paging"
);
//TODO: properly reserve page table allocations so kernel does not re-use them
//TODO: properly reserve page table allocations so kernel does not re-use them
...
...
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