Skip to content

Rustで作った簡易OSです。画面出力できます。

Notifications You must be signed in to change notification settings

Aventern/Anchovy-OS

Repository files navigation

Rust OS - x86_64 Bare Metal Kernel

Rustで作成した学習目的のx86_64 bare metalカーネルです。

VGA画面出力、割り込みハンドリング、PS/2キーボード入力、シェルコマンドに対応しています。

デモ

Welcome to Rust OS!
===================
Kernel initialization complete!

> help
=== Available Commands ===
help         - Show this help
echo <text>  - Print text
clear        - Clear screen
exit         - Shutdown kernel

> echo Hello World
Hello World

> exit
Goodbye!

クイックスタート

必要な環境

項目 要件
OS macOS または Linux (Ubuntu 20.04+)
Rust nightly toolchain
QEMU qemu-system-x86_64
RAM 4GB以上推奨

セットアップ

# 1. リポジトリをクローン
git clone https://github.com/Aventern/rust-os.git
cd rust-os

# 2. セットアップスクリプトを実行(依存関係を自動インストール)
./setup.sh

# 3. 実行
./run_os.sh

手動セットアップ

セットアップスクリプトを使わない場合:

# Rust nightly をインストール
rustup toolchain install nightly
rustup default nightly

# 必要なコンポーネントをインストール
rustup component add rust-src
rustup component add llvm-tools-preview

# bootimage ツールをインストール
cargo install bootimage

# QEMU をインストール
# macOS:
brew install qemu
# Ubuntu:
sudo apt install qemu-system-x86

ビルドと実行

# ビルド(bootimageを作成)
cargo bootimage

# QEMU で実行
./run_os.sh

# または直接実行
qemu-system-x86_64 \
  -drive format=raw,file=target/x86_64-unknown-none/debug/bootimage-rust_os.bin \
  -m 256M \
  -nographic \
  -serial stdio

ブラウザでVNC表示(リモート環境向け)

# websockify をインストール
pip3 install websockify

# noVNC をクローン
git clone --depth 1 https://github.com/novnc/noVNC.git novnc

# QEMU を VNC モードで起動
qemu-system-x86_64 \
  -drive format=raw,file=target/x86_64-unknown-none/debug/bootimage-rust_os.bin \
  -m 256M \
  -vnc :0 \
  -serial file:serial.log &

# websockify を起動
websockify --web=novnc 6080 localhost:5900 &

# ブラウザで開く
# http://localhost:6080/vnc.html?host=localhost&port=6080

シリアルログ出力

カーネルの起動ログはシリアルポートに出力されます:

=== Rust OS Boot ===
[OK] VGA initialized
[..] Initializing IDT...
[OK] IDT initialized
[..] Initializing PIC...
[OK] PIC initialized
[..] Enabling interrupts...
[OK] Interrupts enabled
[OK] Kernel ready
[..] Entering main loop

プロジェクト構造

rust-os/
├── src/
│   ├── main.rs              # カーネルエントリーポイント (_start)
│   ├── lib.rs               # ライブラリ + println!/serial_println! マクロ
│   ├── vga_buffer.rs        # VGA テキストモード出力 (80x25)
│   ├── serial.rs            # シリアルポート出力 (COM1, 0x3f8)
│   ├── interrupts.rs        # IDT設定、割り込みハンドラー
│   ├── keyboard.rs          # PS/2 キーボードドライバー
│   └── keyboard_input.rs    # シェルコマンド処理
├── .cargo/
│   └── config.toml          # ビルド設定(ターゲット、rustflags)
├── Cargo.toml               # 依存関係
├── setup.sh                 # 自動セットアップ(OS自動判定)
├── setup_macos.sh           # macOS用セットアップ
├── setup_linux.sh           # Linux用セットアップ
└── run_os.sh                # QEMU実行スクリプト

実装済み機能

  • x86_64 bare metal ターゲット
  • bootloader 0.9 統合
  • VGA テキストバッファ出力
  • シリアルポート出力(デバッグログ)
  • println! / serial_println! マクロ
  • パニックハンドラー
  • 割り込みハンドリング(IDT, PIC)
  • PS/2 キーボードドライバー
  • シェルコマンド(help, echo, clear, exit)

トラブルシューティング

ビルドエラー: can't find crate for core

rustup component add rust-src --toolchain nightly

ビルドエラー: PIE関連 / bootloaderがパニック

.cargo/config.toml に以下が設定されていることを確認:

[target.x86_64-unknown-none]
rustflags = ["-C", "relocation-model=static", "-C", "link-arg=-no-pie"]

これがないと、カーネルがPIE(Position Independent Executable)としてコンパイルされ、 bootloader 0.9 がメモリマッピングに失敗してパニックします。

QEMU が起動しない

# bootimage が作成されているか確認
ls -la target/x86_64-unknown-none/debug/bootimage-rust_os.bin

# なければ再ビルド
cargo clean
cargo bootimage

シリアル出力が見えない

-nographic -serial stdio オプションを使用するか、-serial file:serial.log でファイルに出力:

qemu-system-x86_64 \
  -drive format=raw,file=target/x86_64-unknown-none/debug/bootimage-rust_os.bin \
  -m 256M \
  -serial file:serial.log &

cat serial.log

参考リソース

ライセンス

MIT License

About

Rustで作った簡易OSです。画面出力できます。

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors