Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
redox-os
bootloader
Commits
2100b117
Verified
Commit
2100b117
authored
Feb 10, 2022
by
Jeremy Soller
Browse files
Add support for live disk
parent
b53bcfd7
Changes
5
Hide whitespace changes
Inline
Side-by-side
Cargo.toml
View file @
2100b117
...
...
@@ -27,3 +27,7 @@ redox_uefi_std = "0.1.5"
[target."x86_64-unknown-uefi".dependencies]
x86
=
"0.43.0"
[features]
default
=
[]
live
=
[]
mk/aarch64-unknown-uefi.mk
View file @
2100b117
...
...
@@ -15,6 +15,19 @@ $(BUILD)/bootloader.efi: Cargo.lock Cargo.toml $(shell find src -type f)
-C
soft-float
\
--emit
link
=
$@
$(BUILD)/bootloader-live.efi
:
Cargo.lock Cargo.toml $(shell find src -type f)
mkdir
-p
$(BUILD)
cargo rustc
\
-Z
build-std
=
core,alloc
\
-Z
build-std-features
=
compiler-builtins-mem
\
--target
$(TARGET)
\
--bin
bootloader
\
--release
\
--features
live
\
--
\
-C
soft-float
\
--emit
link
=
$@
$(BUILD)/esp.bin
:
$(BUILD)/bootloader.efi
mkdir
-p
$(BUILD)
rm
-f
$@
.partial
...
...
mk/x86-unknown-none.mk
View file @
2100b117
...
...
@@ -19,6 +19,20 @@ $(BUILD)/bootloader.bin: $(BUILD)/bootloader.elf $(shell find asm/$(TARGET) -typ
mkdir
-p
$(BUILD)
nasm
-f
bin
-o
$@
-l
$@
.lst
-D
STAGE3
=
$<
-iasm
/
$(TARGET)
asm/
$(TARGET)
/bootloader.asm
$(BUILD)/libbootloader-live.a
:
Cargo.lock Cargo.toml $(shell find src -type f)
mkdir
-p
$(BUILD)
cargo rustc
--lib
--target
$(TARGET)
--release
--features
live
--
-C
soft-float
-C
debuginfo
=
2
--emit
link
=
$@
$(BUILD)/bootloader-live.elf
:
linkers/$(TARGET).ld $(BUILD)/libbootloader-live.a
mkdir
-p
$(BUILD)
$(LD)
-m
elf_i386
--gc-sections
-z
max-page-size
=
0x1000
-T
$<
-o
$@
$(BUILD)
/libbootloader-live.a
&&
\
$(OBJCOPY)
--only-keep-debug
$@
$@
.sym
&&
\
$(OBJCOPY)
--strip-debug
$@
$(BUILD)/bootloader-live.bin
:
$(BUILD)/bootloader-live.elf $(shell find asm/$(TARGET) -type f)
mkdir
-p
$(BUILD)
nasm
-f
bin
-o
$@
-l
$@
.lst
-D
STAGE3
=
$<
-iasm
/
$(TARGET)
asm/
$(TARGET)
/bootloader.asm
$(BUILD)/harddrive.bin
:
$(BUILD)/bootloader.bin $(BUILD)/filesystem.bin
mkdir
-p
$(BUILD)
rm
-f
$@
.partial
...
...
mk/x86_64-unknown-uefi.mk
View file @
2100b117
...
...
@@ -15,6 +15,19 @@ $(BUILD)/bootloader.efi: Cargo.lock Cargo.toml $(shell find src -type f)
-C
soft-float
\
--emit
link
=
$@
$(BUILD)/bootloader-live.efi
:
Cargo.lock Cargo.toml $(shell find src -type f)
mkdir
-p
$(BUILD)
cargo rustc
\
-Z
build-std
=
core,alloc
\
-Z
build-std-features
=
compiler-builtins-mem
\
--target
$(TARGET)
\
--bin
bootloader
\
--release
\
--features
live
\
--
\
-C
soft-float
\
--emit
link
=
$@
$(BUILD)/esp.bin
:
$(BUILD)/bootloader.efi
mkdir
-p
$(BUILD)
rm
-f
$@
.partial
...
...
src/main.rs
View file @
2100b117
...
...
@@ -215,6 +215,12 @@ fn main<
os
.set_text_highlight
(
false
);
println!
();
let
stack_size
=
128
*
KIBI
;
let
stack_base
=
os
.alloc_zeroed_page_aligned
(
stack_size
);
if
stack_base
.is_null
()
{
panic!
(
"Failed to allocate memory for stack"
);
}
let
kernel
=
{
let
node
=
fs
.find_node
(
"kernel"
,
fs
.header
.1
.root
)
.expect
(
"Failed to find kernel file"
);
...
...
@@ -251,14 +257,35 @@ fn main<
let
page_phys
=
unsafe
{
paging_create
(
os
,
kernel
.as_ptr
()
as
usize
)
}
.expect
(
"Failed to set up paging"
);
//TODO: properly reserve page table allocations so kernel does not re-use them
let
stack_size
=
128
*
KIBI
;
let
stack_base
=
os
.alloc_zeroed_page_aligned
(
stack_size
);
if
stack_base
.is_null
()
{
panic!
(
"Failed to allocate memory for stack"
);
}
let
live_opt
=
if
cfg!
(
feature
=
"live"
)
{
let
size
=
fs
.header
.1
.size
;
print!
(
"Live: 0/{} MiB"
,
size
/
MIBI
as
u64
);
let
ptr
=
os
.alloc_zeroed_page_aligned
(
size
as
usize
);
if
ptr
.is_null
()
{
panic!
(
"Failed to allocate memory for live"
);
}
let
live
=
unsafe
{
slice
::
from_raw_parts_mut
(
ptr
,
size
as
usize
)
};
let
mut
i
=
0
;
for
chunk
in
live
.chunks_mut
(
MIBI
)
{
print!
(
"
\r
Live: {}/{} MiB"
,
i
/
MIBI
as
u64
,
size
/
MIBI
as
u64
);
i
+=
fs
.disk
.read_at
(
fs
.block
+
i
/
redoxfs
::
BLOCK_SIZE
,
chunk
)
.expect
(
"Failed to read live disk"
)
as
u64
;
}
println!
(
"
\r
Live: {}/{} MiB"
,
i
/
MIBI
as
u64
,
size
/
MIBI
as
u64
);
Some
(
live
)
}
else
{
None
};
//TODO: properly reserve live disk so kernel does not re-use it
let
mut
env_size
=
4
*
KIBI
;
let
env_base
=
os
.alloc_zeroed_page_aligned
(
env_size
);
...
...
@@ -274,7 +301,13 @@ fn main<
i
:
0
,
};
writeln!
(
w
,
"REDOXFS_BLOCK={:016x}"
,
fs
.block
)
.unwrap
();
if
let
Some
(
live
)
=
live_opt
{
writeln!
(
w
,
"DISK_LIVE_ADDR={:016x}"
,
live
.as_ptr
()
as
usize
)
.unwrap
();
writeln!
(
w
,
"DISK_LIVE_SIZE={:016x}"
,
live
.len
())
.unwrap
();
writeln!
(
w
,
"REDOXFS_BLOCK={:016x}"
,
0
)
.unwrap
();
}
else
{
writeln!
(
w
,
"REDOXFS_BLOCK={:016x}"
,
fs
.block
)
.unwrap
();
}
write!
(
w
,
"REDOXFS_UUID="
)
.unwrap
();
for
i
in
0
..
fs
.header
.1
.uuid
.len
()
{
if
i
==
4
||
i
==
6
||
i
==
8
||
i
==
10
{
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment