Chapter 1
Execution Environment
The execution environment is defined by the Target Triplet, which specifies the platform, CPU architecture, and library required for the build. For example: x86_64-unknown-linux-gnu
.
Components of the Target Triplet:
- Platform: The specific operating system or runtime environment.
- CPU Architecture: The underlying hardware architecture (e.g., x86_64, ARM).
- Library: The standard library or runtime support required.
If the target platform contains no std
or any support syscall, such platform called bare-metal, Rust
contains a core
lib independent of any platform support.
If we change .cargo/config
s.t.:
1 | # os/.cargo/config |
it called cross compile because the running platform is different form execution platform.
No Std and No Main
The basic functionality provided by std
and start
semantic is panic_handler
and main
entry.
To toggle it off with:
1 |
RISCV
As for riscv, thing will be tough in here, we need to complete our own entry point, exit, and basic functionality like print/println
.
First, we need to define linker
and entry
for stack allocation.
Linker:
1 | # os/src/linker.ld |
Stack Space:
1 | # os/src/entry.asm |
For riscv, we need to call RustSBI
(a underlying specification for rust in riscv).
After implement sbi_call
, we could construct put_char
:
1 | const SBI_CONSOLE_PUTCHAR: usize = 1; |
With a formal interface for write
:
1 | struct Stdout; |
Now we construct basic functionality in println
, you could also handle panic_handler
and others…