Rust로 스스로 만든 OS 6일
6318 단어 rust
https://os.phil-opp.com/ja/minimal-rust-kernel/#kaneruwoshi-xing-suru
bootloader crate말하는 것 があるらしいけど, まずは自作を試みる.
でも参考にはする.
私達のカーネルをELFファイルにコンパイルする。
依存であるbootloaderをスタンドアロンの実行ファイルとしてコンパイルする。
カーネルのELFファイルのバイト列をブートローダーにリンクする。
たぶんリンクはlld、それ以外はcargo(rustc)で進める.
まずはELF形式のカーネルをビルドする.
빌드 한정을
target.json
として作成する.{
"llvm-target": "x86_64-unknown-none",
"data-layout": "e-m:e-i64:64-f80:128-n8:16:32:64-S128",
"arch": "x86_64",
"target-endian": "little",
"target-pointer-width": "64",
"target-c-int-width": "32",
"os": "none",
"executables": true,
"linker-flavor": "ld.lld",
"linker": "rust-lld",
"panic-strategy": "abort",
"disable-redzone": true,
"features": "-mmx,-sse,+soft-float",
"exe-suffix": ".elf"
}
코만드
build --target target.json --package kernel --bin kernel
でビルドできる.macOS의 결합, binutils의
greadelf
でバイナリを確認できる.$ brew install binutils
$ /usr/local/Cellar/binutils/2.36.1/bin/greadelf -h ../target/target/debug/kernel.elf
ELF Header:
Magic: 7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00
Class: ELF64
Data: 2's complement, little endian
Version: 1 (current)
OS/ABI: UNIX - System V
ABI Version: 0
Type: EXEC (Executable file)
Machine: Advanced Micro Devices X86-64
Version: 0x1
Entry point address: 0x201120
Start of program headers: 64 (bytes into file)
Start of section headers: 4472 (bytes into file)
Flags: 0x0
Size of this header: 64 (bytes)
Size of program headers: 56 (bytes)
Number of program headers: 4
Size of section headers: 64 (bytes)
Number of section headers: 15
Section header string table index: 13
엔트리 포인트 주소가 자체 제작 OS본적이지 않고, 다시 부트 로더에 카네르를 참조할 수 있습니다.
調べてたら先駆者を見つけた.
https://natsutan.hatenablog.com/entry/2021/04/14/190451
この人はCのUEFIAprikaらRustのカーネルを読んでいるだけど、自分は全部Rustでやってみたい.
上記브로그の参考브로그は全部Rustでやってた.
https://www.akiradeveloper.com/post/mikanos-rust/
このカーネルファイルは、0x100000に配置されるようにビルドされているため、 UEFIによってアドレス指定方式でページをアロケートして、そこに書きます。
これが全てっぽい.
自作OS本과 https://github.com/akiradeveloper/MikanOS.rs/blob/master/boot/src/main.rsを見ながら進める.
一通り書いた時点で起動してみると、QEMU가패닉시타.

ディレクトリ構成を修正すると、panicせず起動できたようだ.


今日の進捗 -> https://github.com/ytannai/kabos/tree/8e5091cbb471ca660dab44091051d79d692692c2
Reference
이 문제에 관하여(Rust로 스스로 만든 OS 6일), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://dev.to/ytannai/rust-os-6-l40텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)