Skip to content
This repository was archived by the owner on Jan 14, 2026. It is now read-only.

Commit 63e6c43

Browse files
committed
format
1 parent dab6d3f commit 63e6c43

9 files changed

Lines changed: 64 additions & 56 deletions

File tree

src/include/task/multi_task.h

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
* @brief タスク状態
99
*/
1010
typedef enum {
11-
TASK_STATE_READY = 0, // 実行可能
11+
TASK_STATE_READY = 0, // 実行可能
1212
TASK_STATE_RUNNING = 1, // 実行中
1313
TASK_STATE_BLOCKED = 2, // ブロック中
14-
TASK_STATE_DEAD = 3 // 終了済み
14+
TASK_STATE_DEAD = 3 // 終了済み
1515
} task_state_t;
1616

1717
/**
@@ -22,26 +22,26 @@ typedef struct {
2222
uint64_t rax, rbx, rcx, rdx;
2323
uint64_t rsi, rdi, rbp, rsp;
2424
uint64_t r8, r9, r10, r11, r12, r13, r14, r15;
25-
uint64_t rip; // 命令ポインタ
25+
uint64_t rip; // 命令ポインタ
2626
uint64_t rflags; // フラグレジスタ
27-
uint64_t cr3; // ページディレクトリベースレジスタ
27+
uint64_t cr3; // ページディレクトリベースレジスタ
2828
} registers_t;
2929

3030
/**
3131
* @brief タスク制御ブロック(TCB)
3232
*/
3333
typedef struct task {
34-
uint32_t tid; // タスクID
35-
char name[32]; // タスク名(デバッグ用)
36-
task_state_t state; // タスク状態
37-
int kernel_mode; // カーネルモードフラグ(1=カーネル、0=ユーザー)
38-
registers_t regs; // レジスタコンテキスト
39-
uint64_t kernel_stack; // カーネルスタックポインタ
40-
uint64_t user_stack; // ユーザースタックポインタ
34+
uint32_t tid; // タスクID
35+
char name[32]; // タスク名(デバッグ用)
36+
task_state_t state; // タスク状態
37+
int kernel_mode; // カーネルモードフラグ(1=カーネル、0=ユーザー)
38+
registers_t regs; // レジスタコンテキスト
39+
uint64_t kernel_stack; // カーネルスタックポインタ
40+
uint64_t user_stack; // ユーザースタックポインタ
4141
uint64_t page_directory; // ページディレクトリの物理アドレス
42-
uint64_t time_slice; // タイムスライス(ticks)
43-
uint64_t total_time; // 累計実行時間(ticks)
44-
struct task *next; // 次のタスク(リンクリスト)
42+
uint64_t time_slice; // タイムスライス(ticks)
43+
uint64_t total_time; // 累計実行時間(ticks)
44+
struct task *next; // 次のタスク(リンクリスト)
4545
} task_t;
4646

4747
/**

src/kernel/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ void kmain(BOOT_INFO *boot_info) {
3939

4040
console_init();
4141
console_set_framebuffer(boot_info);
42-
set_log_level(ALL);
42+
set_log_level(ALL);
4343

4444
gdt_build();
4545
gdt_install_lgdt();

src/kernel/mem/paging.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ void *alloc_page_table(void) {
3131
(unsigned)phys);
3232
return NULL;
3333
}
34-
printk("alloc_page_table: clearing table at virt=0x%x (phys=0x%x)\n", (unsigned)virt, (unsigned)phys);
34+
printk("alloc_page_table: clearing table at virt=0x%x (phys=0x%x)\n",
35+
(unsigned)virt, (unsigned)phys);
3536
// ページングが有効化されていない場合、virtはphysと同じ(アイデンティティ)
3637
// しかし、physが1MBを超える場合、アクセスできない可能性がある
3738
// 安全のため、物理アドレスで直接アクセス
@@ -63,7 +64,8 @@ int map_page(uint32_t phys, uint32_t virt, uint32_t flags) {
6364
(unsigned)pd_idx);
6465
return -1;
6566
}
66-
printk("map_page: new_pt_virt=0x%x, converting to phys\n", (unsigned)(uintptr_t)new_pt_virt);
67+
printk("map_page: new_pt_virt=0x%x, converting to phys\n",
68+
(unsigned)(uintptr_t)new_pt_virt);
6769
uint32_t new_pt_phys =
6870
vmem_virt_to_phys((uint32_t)(uintptr_t)new_pt_virt);
6971
printk("map_page: new_pt_phys=0x%x\n", (unsigned)new_pt_phys);
@@ -209,9 +211,9 @@ void paging_enable(void) {
209211
asm volatile("mov %%cr4, %0" : "=r"(cr4));
210212
printk("paging_enable: Current CR0=0x%lx CR3=0x%lx CR4=0x%lx\n",
211213
(unsigned long)cr0, (unsigned long)cr3, (unsigned long)cr4);
212-
printk("paging_enable: PG bit=%d, PAE bit=%d\n",
213-
(int)((cr0 >> 31) & 1), (int)((cr4 >> 5) & 1));
214-
214+
printk("paging_enable: PG bit=%d, PAE bit=%d\n", (int)((cr0 >> 31) & 1),
215+
(int)((cr4 >> 5) & 1));
216+
215217
// 注意: x86-64ロングモードでは、UEFIがすでに64ビットページングを設定しています。
216218
// 現在の32ビットページング構造(2レベル: PD→PT)は互換性がありません。
217219
// 64ビットモードでは4レベル(PML4→PDPT→PD→PT)構造が必要です。

src/kernel/mem/vmem.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ uint32_t vmem_virt_to_phys(uint32_t virt) {
3838
uint64_t cr3;
3939
asm volatile("mov %%cr3, %0" : "=r"(cr3));
4040
uint32_t pd_phys = cr3 & 0xFFFFF000;
41-
uint32_t pd_virt = (phys2virt ? phys2virt(pd_phys) : default_phys2virt(pd_phys));
41+
uint32_t pd_virt =
42+
(phys2virt ? phys2virt(pd_phys) : default_phys2virt(pd_phys));
4243
if (pd_virt == 0) {
4344
printk("vmem_virt_to_phys: phys2virt returned 0 for pd_phys=0x%x\n",
4445
(unsigned)pd_phys);
@@ -68,7 +69,8 @@ uint32_t vmem_virt_to_phys(uint32_t virt) {
6869
}
6970

7071
uint32_t pt_phys = pde & 0xFFFFF000;
71-
uint32_t pt_virt = (phys2virt ? phys2virt(pt_phys) : default_phys2virt(pt_phys));
72+
uint32_t pt_virt =
73+
(phys2virt ? phys2virt(pt_phys) : default_phys2virt(pt_phys));
7274
if (pt_virt == 0) {
7375
printk("vmem_virt_to_phys: phys2virt returned 0 for pt_phys=0x%x\n",
7476
(unsigned)pt_phys);

src/kernel/task/multi_task.c

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010

1111
#define MAX_TASKS 64
1212
#define KERNEL_STACK_SIZE 0x4000 // 16KB
13-
#define USER_STACK_SIZE 0x4000 // 16KB
14-
#define TIME_SLICE_DEFAULT 10 // 10 ticks
13+
#define USER_STACK_SIZE 0x4000 // 16KB
14+
#define TIME_SLICE_DEFAULT 10 // 10 ticks
1515

1616
static task_t *tasks[MAX_TASKS];
1717
static task_t *current_task = NULL;
@@ -71,7 +71,6 @@ static uint64_t create_task_page_directory(void) {
7171
pd[i] = current_pd[i];
7272
}
7373

74-
7574
// 物理アドレスを返す
7675
uint32_t pd_phys = vmem_virt_to_phys((uint32_t)(uintptr_t)pd_virt);
7776
return pd_phys;
@@ -95,8 +94,8 @@ void task_init(void) {
9594
// idle タスクは現在実行中のコンテキスト(kmain)として初期化
9695
idle_task.tid = 0;
9796
str_copy(idle_task.name, "idle", sizeof(idle_task.name));
98-
idle_task.state = TASK_STATE_RUNNING; // 既に実行中
99-
idle_task.kernel_mode = 1; // カーネルモード
97+
idle_task.state = TASK_STATE_RUNNING; // 既に実行中
98+
idle_task.kernel_mode = 1; // カーネルモード
10099
idle_task.time_slice = TIME_SLICE_DEFAULT;
101100
idle_task.total_time = 0;
102101
idle_task.next = NULL;
@@ -113,14 +112,17 @@ void task_init(void) {
113112
uint64_t current_rsp;
114113
asm volatile("mov %%rsp, %0" : "=r"(current_rsp));
115114
idle_task.regs.rsp = current_rsp;
116-
idle_task.regs.rip = 0; // task_switch から戻る時に設定される
115+
idle_task.regs.rip = 0; // task_switch から戻る時に設定される
117116
idle_task.regs.rflags = 0x202; // IF=1 (割り込み有効)
118-
117+
119118
// 他のレジスタをゼロ初期化
120-
idle_task.regs.rax = idle_task.regs.rbx = idle_task.regs.rcx = idle_task.regs.rdx = 0;
119+
idle_task.regs.rax = idle_task.regs.rbx = idle_task.regs.rcx =
120+
idle_task.regs.rdx = 0;
121121
idle_task.regs.rsi = idle_task.regs.rdi = idle_task.regs.rbp = 0;
122-
idle_task.regs.r8 = idle_task.regs.r9 = idle_task.regs.r10 = idle_task.regs.r11 = 0;
123-
idle_task.regs.r12 = idle_task.regs.r13 = idle_task.regs.r14 = idle_task.regs.r15 = 0;
122+
idle_task.regs.r8 = idle_task.regs.r9 = idle_task.regs.r10 =
123+
idle_task.regs.r11 = 0;
124+
idle_task.regs.r12 = idle_task.regs.r13 = idle_task.regs.r14 =
125+
idle_task.regs.r15 = 0;
124126

125127
// カーネルスタックは現在のスタックをそのまま使用
126128
idle_task.kernel_stack = current_rsp;
@@ -167,15 +169,14 @@ task_t *task_create(void (*entry)(void), const char *name, int kernel_mode) {
167169
}
168170

169171
// タスク構造体を仮想アドレスに変換
170-
uint32_t task_virt =
171-
vmem_phys_to_virt((uint32_t)(uintptr_t)task);
172+
uint32_t task_virt = vmem_phys_to_virt((uint32_t)(uintptr_t)task);
172173
task = (task_t *)(uintptr_t)task_virt;
173174

174175
// タスク構造体を初期化
175176
task->tid = next_tid++;
176177
str_copy(task->name, name, sizeof(task->name));
177178
task->state = TASK_STATE_READY;
178-
task->kernel_mode = kernel_mode; // カーネルモードフラグを設定
179+
task->kernel_mode = kernel_mode; // カーネルモードフラグを設定
179180
task->time_slice = TIME_SLICE_DEFAULT;
180181
task->total_time = 0;
181182
task->next = NULL;
@@ -200,13 +201,15 @@ task_t *task_create(void (*entry)(void), const char *name, int kernel_mode) {
200201
// スタックの初期化:entry関数が戻る先としてtask_exitをpush
201202
// task_switch は ret 命令で task->regs.rip にジャンプする
202203
// entry 関数が ret で戻る時、スタックの task_exit にジャンプする
203-
uint64_t *stack_ptr = (uint64_t *)kstack_virt; // スタック最上位から開始
204-
stack_ptr--; // 8バイト下げる
205-
*stack_ptr = (uint64_t)task_exit; // entry から戻る先
204+
uint64_t *stack_ptr =
205+
(uint64_t *)kstack_virt; // スタック最上位から開始
206+
stack_ptr--; // 8バイト下げる
207+
*stack_ptr = (uint64_t)task_exit; // entry から戻る先
206208

207209
// レジスタを初期化
208210
task->regs.rsp = (uint64_t)stack_ptr;
209-
task->regs.rip = (uint64_t)entry; // task_switch が ret でここにジャンプ
211+
task->regs.rip =
212+
(uint64_t)entry; // task_switch が ret でここにジャンプ
210213
task->regs.rflags = 0x202; // IF=1
211214
task->regs.cr3 = current_cr3_val;
212215
} else {
@@ -225,8 +228,7 @@ task_t *task_create(void (*entry)(void), const char *name, int kernel_mode) {
225228
return NULL;
226229
}
227230
uint32_t ustack_virt =
228-
vmem_phys_to_virt((uint32_t)(uintptr_t)ustack) +
229-
0x1000;
231+
vmem_phys_to_virt((uint32_t)(uintptr_t)ustack) + 0x1000;
230232
task->user_stack = ustack_virt;
231233

232234
// レジスタを初期化
@@ -245,8 +247,8 @@ task_t *task_create(void (*entry)(void), const char *name, int kernel_mode) {
245247
tasks[slot] = task;
246248

247249
#ifdef INIT_MSG
248-
printk("task_create: Created task '%s' (TID=%u)\n",
249-
name, (unsigned)task->tid);
250+
printk("task_create: Created task '%s' (TID=%u)\n", name,
251+
(unsigned)task->tid);
250252
#endif
251253

252254
return task;
@@ -304,7 +306,8 @@ void task_schedule(void) {
304306

305307
// 次のタスクがなければidleタスクに戻る(現在のタスクがDEADまたはidleでない場合)
306308
if (!next_task) {
307-
if (current_task->state == TASK_STATE_DEAD || current_task != &idle_task) {
309+
if (current_task->state == TASK_STATE_DEAD ||
310+
current_task != &idle_task) {
308311
next_task = &idle_task;
309312
} else {
310313
// 現在のタスクがidleで、他に実行可能なタスクがない場合は継続

src/kernel/tests/multi_task_test.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ void multi_task_test(void) {
5050

5151
printk("Tasks created. Manually yielding to trigger first switch...\n");
5252
new_line();
53-
53+
5454
// 最初のタスクスイッチを手動でトリガー
5555
task_yield();
56-
56+
5757
printk("\n[MAIN] Back to main after tasks completed\n");
5858
printk("====== TEST COMPLETE ======\n");
5959
new_line();

src/kernel/tests/run.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ void run_test() {
7676
#endif
7777

7878
#ifdef MULTI_TASK_TEST
79-
printk("> MULTI TASK TEST\n");
80-
multi_task_test();
81-
new_line();
79+
printk("> MULTI TASK TEST\n");
80+
multi_task_test();
81+
new_line();
8282
#endif
8383
}

src/kernel/util/bdf.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ static int parse_bdf(const char *data, size_t size) {
107107
int in_bitmap = 0;
108108

109109
while (p < end && *p) {
110-
111110
// フォント情報のパース
112111
if (starts_with(p, "FONTBOUNDINGBOX")) {
113112
p += 15; // "FONTBOUNDINGBOX"の長さ
@@ -183,7 +182,8 @@ static int parse_bdf(const char *data, size_t size) {
183182
} else if (in_bitmap && current_glyph) {
184183
// ビットマップデータを読み込む
185184
p = skip_spaces(p);
186-
if ((*p >= '0' && *p <= '9') || (*p >= 'A' && *p <= 'F') ||
185+
if ((*p >= '0' && *p <= '9') ||
186+
(*p >= 'A' && *p <= 'F') ||
187187
(*p >= 'a' && *p <= 'f')) {
188188
if (bitmap_line < MAX_GLYPH_HEIGHT) {
189189
char hex_str[3] = { 0 };
@@ -236,7 +236,8 @@ int bdf_init(const char *path) {
236236

237237
// ファイルサイズを取得
238238
size_t file_size = inode.i_size;
239-
if (file_size == 0 || file_size > 1024 * 1024) { // 1MBを超える場合はエラー
239+
if (file_size == 0 ||
240+
file_size > 1024 * 1024) { // 1MBを超える場合はエラー
240241
printk("BDF: Invalid file size: %u\n", (uint32_t)file_size);
241242
return 0;
242243
}

src/kernel/util/init_msg.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,12 @@ void kernel_init() {
127127
#endif
128128

129129
#ifdef INIT_MSG
130-
new_line();
131-
printk("> MULTI TASK INIT\n");
130+
new_line();
131+
printk("> MULTI TASK INIT\n");
132132
#endif
133-
task_init();
133+
task_init();
134134
#ifdef INIT_MSG
135-
printk("ok\n");
135+
printk("ok\n");
136136
#endif
137137
}
138138

0 commit comments

Comments
 (0)