Skip to content

Commit e379504

Browse files
committed
Add documentation in README
1 parent 3115471 commit e379504

File tree

2 files changed

+37
-5
lines changed

2 files changed

+37
-5
lines changed

README.md

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,43 @@ Written for the [second edition](https://github.com/phil-opp/blog_os/issues/360)
1010

1111
TODO
1212

13+
## Configuration
14+
15+
The bootloader exposes a few variables which can be configured through the `Cargo.toml` of your kernel:
16+
17+
```toml
18+
[package.metadata.bootloader]
19+
# The address at which the kernel stack is placed. If not provided, the bootloader
20+
# dynamically searches for a location.
21+
kernel-stack-address = "0xFFFFFF8000000000"
22+
23+
# The size of the kernel stack, given in number of 4KiB pages. Defaults to 512.
24+
kernel-stack-size = 128
25+
26+
# The virtual address offset from which physical memory is mapped, as described in
27+
# https://os.phil-opp.com/paging-implementation/#map-the-complete-physical-memory
28+
# Only applies if the `map_physical_memory` feature of the crate is enabled.
29+
# If not provided, the bootloader dynamically searches for a location.
30+
physical-memory-offset = "0xFFFF800000000000"
31+
```
32+
33+
Note that the addresses **must** be given as strings (in either hex or decimal format), as [TOML](https://github.com/toml-lang/toml) does not support unsigned 64-bit integers.
34+
1335
## Requirements
1436

1537
You need a nightly [Rust](https://www.rust-lang.org) compiler and [cargo xbuild](https://github.com/rust-osdev/cargo-xbuild). You also need the `llvm-tools-preview` component, which can be installed through `rustup component add llvm-tools-preview`.
1638

1739
## Build
1840

19-
The simplest way to use the bootloader is in combination with the [bootimage](https://github.com/rust-osdev/bootimage) tool. This crate **requires at least bootimage 0.7.6**. With the tool installed, you can add a normal cargo dependency on the `bootloader` crate to your kernel and then run `bootimage build` to create a bootable disk image. You can also execute `bootimage run` to run your kernel in [QEMU](https://www.qemu.org/) (needs to be installed).
41+
The simplest way to use the bootloader is in combination with the [bootimage](https://github.com/rust-osdev/bootimage) tool. This crate **requires at least bootimage PLACEHOLDER**. With the tool installed, you can add a normal cargo dependency on the `bootloader` crate to your kernel and then run `bootimage build` to create a bootable disk image. You can also execute `bootimage run` to run your kernel in [QEMU](https://www.qemu.org/) (needs to be installed).
2042

21-
To compile the bootloader manually, you need to invoke `cargo xbuild` with a `KERNEL` environment variable that points to your kernel executable (in the ELF format):
43+
To compile the bootloader manually, you need to invoke `cargo xbuild` with two environment variables:
44+
* `KERNEL`: points to your kernel executable (in the ELF format)
45+
* `KERNEL_MANIFEST`: points to the `Cargo.toml` describing your kernel
2246

47+
For example:
2348
```
24-
KERNEL=/path/to/your/kernel/target/debug/your_kernel cargo xbuild
49+
KERNEL=/path/to/your/kernel/target/debug/your_kernel KERNEL_MANIFEST=/path/to/your/kernel/Cargo.toml cargo xbuild
2550
```
2651

2752
As an example, you can build the bootloader with example kernel from the `example-kernel` directory with the following commands:
@@ -30,7 +55,7 @@ As an example, you can build the bootloader with example kernel from the `exampl
3055
cd example-kernel
3156
cargo xbuild
3257
cd ..
33-
KERNEL=example-kernel/target/x86_64-example-kernel/debug/example-kernel cargo xbuild --release --features binary
58+
KERNEL=example-kernel/target/x86_64-example-kernel/debug/example-kernel KERNEL_MANIFEST=example-kernel/Cargo.toml cargo xbuild --release --features binary
3459
```
3560

3661
The `binary` feature is required to enable the dependencies required for compiling the bootloader executable. The command results in a bootloader executable at `target/x86_64-bootloader.json/release/bootloader`. This executable is still an ELF file, which can't be run directly.
@@ -64,7 +89,7 @@ The bootloader crate can be configured through some cargo features:
6489
- `vga_320x200`: This feature switches the VGA hardware to mode 0x13, a graphics mode with resolution 320x200 and 256 colors per pixel. The framebuffer is linear and lives at address `0xa0000`.
6590
- `recursive_page_table`: Maps the level 4 page table recursively and adds the [`recursive_page_table_address`](https://docs.rs/bootloader/0.4.0/bootloader/bootinfo/struct.BootInfo.html#structfield.recursive_page_table_addr) field to the passed `BootInfo`.
6691
- `map_physical_memory`: Maps the complete physical memory in the virtual address space and passes a [`physical_memory_offset`](https://docs.rs/bootloader/0.4.0/bootloader/bootinfo/struct.BootInfo.html#structfield.physical_memory_offset) field in the `BootInfo`.
67-
- The virtual address where the physical memory should be mapped is configurable by setting the `BOOTLOADER_PHYSICAL_MEMORY_OFFSET` environment variable (supports decimal and hex numbers (prefixed with `0x`)).
92+
- The virtual address where the physical memory should be mapped is configurable by setting the `physical-memory-offset` field in the kernel's `Cargo.toml`, as explained in [Configuration](#Configuration).
6893

6994
## Advanced Documentation
7095
See these guides for advanced usage of this crate:

build.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,14 @@ fn parse_to_config(cfg: &mut BootloaderConfig, table: &toml::value::Table) {
5959
cfg.kernel_stack_address = Some(parse_aligned_addr(key.as_str(), &s));
6060
}
6161
("physical-memory-offset", Value::String(s)) => {
62+
#[cfg(feature = "map_physical_memory")]
6263
cfg.physical_memory_offset = Some(parse_aligned_addr(key.as_str(), &s));
64+
65+
#[cfg(not(feature = "map_physical_memory"))]
66+
panic!(
67+
"`physical-memory-offset` is only supported when the `map_physical_memory` \
68+
feature of the crate is enabled"
69+
);
6370
}
6471
("kernel-stack-size", Value::Integer(i)) => {
6572
if i <= 0 {

0 commit comments

Comments
 (0)