Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
BasedOnStyle: LLVM
160 changes: 160 additions & 0 deletions PROGRESS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
# WebVM 開発進捗

## 現在の進捗状況

### 完了した機能

#### 1. カーネル基盤
- [x] WebAssemblyカーネルの基本構造
- [x] WASI システムコールの実装
- [x] `fd_write` (stdout/stderr)
- [x] `fd_read` (stdin)
- [x] `proc_exit`
- [x] `clock_time_get`
- [x] Linux風のディレクトリ構造
- `/kernel/init/` - 初期化
- `/kernel/mm/` - メモリ管理
- `/kernel/fs/` - ファイルシステム
- `/kernel/drivers/` - デバイスドライバ
- `/kernel/shell/` - シェル
- `/kernel/lib/` - ライブラリ関数

#### 2. メモリ管理
- [x] 基本的なメモリアロケータ (`kmalloc`/`kfree`)
- [x] 32MBの静的メモリプール
- [x] SharedArrayBuffer対応 (128MB)

#### 3. ファイルシステム
- [x] VFS (Virtual File System) の基本実装
- [x] マウントポイント管理
- [x] 疑似ファイルシステム (スタブ)
- `/proc/version`
- `/etc/passwd`

#### 4. デバイスドライバ
- [x] コンソールドライバ
- [x] ドライバ登録システム
- [x] ANSI エスケープシーケンス対応

#### 5. シェル
- [x] 基本的なコマンドラインインターフェース
- [x] ビルトインコマンド
- `help` - ヘルプ表示
- `clear` - 画面クリア
- `echo` - テキスト出力
- `ps` - プロセス一覧 (スタブ)
- `ls` - ファイル一覧 (スタブ)
- `cat` - ファイル表示 (スタブ)
- `about` - システム情報
- `exit` - 終了

#### 6. GUI/ブラウザ統合
- [x] ターミナルウィンドウ UI
- [x] ウィンドウマネージャー (ドラッグ、最大化)
- [x] stdin/stdout のブラウザ統合
- [x] コマンドハンドラー経由の入力処理

#### 7. ビルドシステム
- [x] Ninja ビルドシステム
- [x] TypeScript/JavaScript モジュール構造
- [x] CSS分離

## 🚧 やること

### 高優先度

#### 1. プロセス管理
- [ ] プロセステーブルの実装
- [ ] `fork()` の代替実装 (`posix_spawn`)
- [ ] プロセススケジューラー
- [ ] プロセス間通信 (IPC)

#### 2. ファイルシステム
- [ ] 実際のファイルシステム実装
- [ ] IndexedDB バックエンド
- [ ] ディレクトリ操作 (mkdir, rmdir)
- [ ] ファイル操作 (open, read, write, close)
- [ ] パーミッション管理

#### 3. ネットワーク
- [ ] ソケット API の実装
- [ ] WebSocket ベースのネットワーク層
- [ ] 基本的なネットワークコマンド (ping, wget 相当)

### 中優先度

#### 4. シェル拡張
- [ ] パイプ機能
- [ ] リダイレクト
- [ ] 環境変数
- [ ] ジョブコントロール
- [ ] コマンド履歴
- [ ] タブ補完

#### 5. デバイスドライバ
- [ ] キーボードドライバ (詳細な入力処理)
- [ ] マウスドライバ
- [ ] フレームバッファドライバ (グラフィックス)

#### 6. 標準ユーティリティ
- [ ] 基本的なUNIXコマンド群
- [ ] `cp`, `mv`, `rm`
- [ ] `grep`, `sed`, `awk`
- [ ] `vi` または `nano` エディタ

### 低優先度

#### 7. 高度な機能
- [ ] マルチスレッド (pthread)
- [ ] 共有ライブラリ
- [ ] デバッガー
- [ ] パッケージマネージャー

#### 8. パフォーマンス最適化
- [ ] メモリ管理の最適化
- [ ] ファイルシステムキャッシュ
- [ ] コンパイラ最適化

## 既知の問題

1. **メモリ管理**
- `mm_stats` 構造体が未定義 (`kernel/mm/memory.c:134`)
- `kmalloc` 実装が不完全 (`kernel/lib/string.c:79`)

2. **ファイルシステム**
- ディレクトリ作成が未実装 (`kernel/fs/vfs.c:94, 125`)
- procfs の完全な実装が必要 (`kernel/fs/vfs.c:183`)

3. **標準ライブラリ**
- 可変引数の処理が未実装 (`kernel/lib/stdio.c:95-96, 103-104`)
- 数値変換が未実装 (`kernel/drivers/console.c:111`)

4. **ドライバ**
- 追加ドライバが必要 (`kernel/drivers/drivers.c:69-72`)

## 技術的な詳細

### メモリレイアウト
- カーネル最大メモリ: 128MB (134217728 bytes)
- メモリプール: 32MB
- スタックサイズ: 1MB
- WebAssembly ページ: 2048 (64KB/ページ)

### ビルド要件
- clang (wasm32 ターゲット)
- wasm-ld
- ninja
- pnpm
- TypeScript

### アーキテクチャ
1. **カーネル層** (C/WebAssembly)
2. **システムライブラリ層** (TypeScript)
3. **GUI層** (HTML/CSS/JavaScript)

## 次のステップ

1. プロセス管理の基本実装を開始
2. 実際のファイルシステムの実装
3. より多くのシェルコマンドの追加
4. テストスイートの作成
27 changes: 22 additions & 5 deletions build.ninja
Original file line number Diff line number Diff line change
@@ -1,15 +1,32 @@
rule CC
command = clang -O2 -nostdlib -target wasm32-unknown-unknown -fno-builtin -matomics -mbulk-memory -c $in -o $out
rule LD
command = wasm-ld -z stack-size=1048576 --export=_start --allow-undefined --import-memory --shared-memory --max-memory=67108864 $in -o $out
command = wasm-ld -z stack-size=1048576 --export=_start --export=handle_command --allow-undefined --import-memory --shared-memory --max-memory=134217728 $in -o $out
rule COPY
command = cp $in $out
rule TSC
command = npx tsc --outDir build

build build/kernel/hello.o: CC kernel/hello.c
build build/kernel.wasm: LD build/kernel/hello.o
build build/gui/index.html: COPY gui/index.html
# カーネルオブジェクトファイル
build build/kernel/init/main.o: CC kernel/init/main.c
build build/kernel/mm/memory.o: CC kernel/mm/memory.c
build build/kernel/fs/vfs.o: CC kernel/fs/vfs.c
build build/kernel/drivers/console.o: CC kernel/drivers/console.c
build build/kernel/drivers/drivers.o: CC kernel/drivers/drivers.c
build build/kernel/lib/string.o: CC kernel/lib/string.c
build build/kernel/lib/stdio.o: CC kernel/lib/stdio.c
build build/kernel/lib/wasi_wrapper.o: CC kernel/lib/wasi_wrapper.c
build build/kernel/shell/shell.o: CC kernel/shell/shell.c
build build/kernel/shell/shell_api.o: CC kernel/shell/shell_api.c

# カーネルリンク
build build/kernel.wasm: LD build/kernel/init/main.o build/kernel/mm/memory.o build/kernel/fs/vfs.o build/kernel/drivers/console.o build/kernel/drivers/drivers.o build/kernel/lib/string.o build/kernel/lib/stdio.o build/kernel/lib/wasi_wrapper.o build/kernel/shell/shell.o build/kernel/shell/shell_api.o

# GUI とシステムライブラリ
build build/index.html: COPY gui/index.html
build build/gui/styles.css: COPY gui/styles.css
build build/gui/terminal.js: COPY gui/terminal.js
build build/gui/window-manager.js: COPY gui/window-manager.js
build build/syslib/index.js: TSC syslib/index.ts

default build/kernel.wasm build/gui/index.html build/syslib/index.js
default build/kernel.wasm build/index.html build/gui/styles.css build/gui/terminal.js build/gui/window-manager.js build/syslib/index.js
45 changes: 40 additions & 5 deletions gui/index.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,46 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>WebVM - POSIX-compatible WebAssembly OS</title>
<link rel="stylesheet" href="gui/styles.css">
</head>
<body>
<div id="desktop">
<!-- ターミナルウィンドウ -->
<div class="window" id="terminal-window" style="top: 50px; left: 50px; width: 800px; height: 600px;">
<div class="window-header">
<div class="window-title">Terminal - WebVM</div>
<div class="window-controls">
<div class="window-control minimize"></div>
<div class="window-control maximize"></div>
<div class="window-control close"></div>
</div>
</div>
<div class="window-content">
<div class="terminal" id="terminal">
<div id="terminal-output" class="terminal-output"></div>
<div class="terminal-input-line">
<span class="terminal-prompt">$ </span>
<input type="text" id="terminal-input" class="terminal-input" autofocus />
<span class="terminal-cursor"></span>
</div>
</div>
</div>
</div>
</div>

<script type="module">
import { boot } from "../syslib/index.js";
import { boot } from "./syslib/index.js";
import { initializeTerminal } from "./gui/terminal.js";
import { initializeWindowManager } from "./gui/window-manager.js";

// 初期化
initializeTerminal();
initializeWindowManager();

// カーネルを起動
boot();
</script>
<body>
<h1>Hello WebVM</h1>
</body>
</html>
</body>
</html>
140 changes: 140 additions & 0 deletions gui/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
/**
* WebVM GUI スタイルシート
*/

/* ベーススタイル */
body {
margin: 0;
padding: 0;
background-color: #1e1e1e;
font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
color: #d4d4d4;
overflow: hidden;
}

/* デスクトップ */
#desktop {
width: 100vw;
height: 100vh;
position: relative;
}

/* ウィンドウシステム */
.window {
position: absolute;
background-color: #2d2d30;
border: 1px solid #464647;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.5);
display: flex;
flex-direction: column;
}

.window-header {
background-color: #3c3c3c;
padding: 8px;
cursor: move;
display: flex;
justify-content: space-between;
align-items: center;
user-select: none;
}

.window-title {
color: #cccccc;
font-size: 14px;
}

.window-controls {
display: flex;
gap: 8px;
}

.window-control {
width: 12px;
height: 12px;
border-radius: 50%;
cursor: pointer;
transition: opacity 0.2s;
}

.window-control:hover {
opacity: 0.8;
}

.close {
background-color: #f44336;
}

.minimize {
background-color: #ffeb3b;
}

.maximize {
background-color: #4caf50;
}

.window-content {
flex: 1;
overflow: auto;
padding: 0;
}

/* ターミナルスタイル */
.terminal {
background-color: #1e1e1e;
color: #d4d4d4;
padding: 10px;
font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
font-size: 14px;
line-height: 1.4;
height: 100%;
box-sizing: border-box;
overflow-y: auto;
}

.terminal-output {
white-space: pre-wrap;
word-wrap: break-word;
}

.terminal-input-line {
display: flex;
align-items: center;
}

.terminal-prompt {
color: #4ec9b0;
margin-right: 5px;
}

.terminal-input {
background: transparent;
border: none;
color: #d4d4d4;
font-family: inherit;
font-size: inherit;
outline: none;
flex: 1;
}

.terminal-cursor {
display: inline-block;
width: 8px;
height: 16px;
background-color: #d4d4d4;
animation: blink 1s infinite;
}

@keyframes blink {
0%, 50% { opacity: 1; }
51%, 100% { opacity: 0; }
}

/* レスポンシブ対応 */
@media (max-width: 768px) {
.window {
width: calc(100vw - 20px) !important;
left: 10px !important;
right: 10px !important;
}
}
Loading