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

Commit a5723fa

Browse files
committed
delete elf loader paging debug msg
1 parent cd3a935 commit a5723fa

10 files changed

Lines changed: 86 additions & 220 deletions

File tree

src/kernel/interrupt/idt.c

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ void irq_exception_ex(uint32_t vec, uint32_t error_code) {
154154
(unsigned long)stack_ptr[i]);
155155
}
156156

157-
uint64_t maybe_rip = 0, maybe_cs = 0, maybe_rsp = 0;
157+
uint64_t maybe_rip = 0, maybe_cs = 0;
158158
for (int idx = 17; idx <= 20; idx++) {
159159
uint64_t val = stack_ptr[idx];
160160
if (val != 0) {
@@ -212,14 +212,7 @@ void irq_exception_ex(uint32_t vec, uint32_t error_code) {
212212
printk(" CS: 0x%lx\n", saved_cs);
213213
printk(" RSP: 0x%lx\n", saved_rsp);
214214

215-
/* ELF 呼び出し直前のスナップショットが存在すれば表示する(デバッグ用) */
216-
printk("ELF: call-snapshot: func=0x%lx rdi=0x%lx rsi=0x%lx rdx=0x%lx rsp=0x%lx\n",
217-
(unsigned long)elf_call_snapshot_func_addr,
218-
(unsigned long)elf_call_snapshot_rdi,
219-
(unsigned long)elf_call_snapshot_rsi,
220-
(unsigned long)elf_call_snapshot_rdx,
221-
(unsigned long)elf_call_snapshot_rsp);
222-
215+
// Halt the system
223216
while (1) {
224217
asm volatile("hlt");
225218
}

src/kernel/mem/manager.c

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -162,10 +162,6 @@ static void *kmalloc_internal(uint32_t size, int retry_count) {
162162
void *user_ptr = (void *)((uintptr_t)cur +
163163
sizeof(block_header_t));
164164

165-
/* Calculate actual user bytes allocated (might be larger than wanted) */
166-
uint32_t actual_user_bytes =
167-
cur->size - sizeof(block_header_t);
168-
169165
uint32_t total_free = 0;
170166
uint32_t largest = 0;
171167
block_header_t *it = free_list;
@@ -190,12 +186,7 @@ static void *kmalloc_internal(uint32_t size, int retry_count) {
190186
wanted_with_canary -
191187
sizeof(uint32_t));
192188
*canary = KMALLOC_CANARY;
193-
if (size >= 256) {
194-
printk("mem: set canary at %p (user_ptr=%p wanted=%u wanted_with_canary=%u actual_allocated=%u) value=0x%08x\n",
195-
canary, user_ptr, wanted,
196-
wanted_with_canary, actual_user_bytes,
197-
*canary);
198-
}
189+
199190
spin_unlock_irqrestore(&heap_lock, flags);
200191
return user_ptr;
201192
}
@@ -536,11 +527,6 @@ void memory_init() {
536527
phys_end = (uint64_t)heap_end;
537528
printk("mem: WARNING memmap_reserve using virtual addresses as-phys start=0x%08x end=0x%08x\n",
538529
(unsigned)heap_start, (unsigned)heap_end);
539-
} else {
540-
printk("mem: reserving heap physical range phys_start=0x%08llx phys_end=0x%08llx (heap virt 0x%08x-0x%08x)\n",
541-
(unsigned long long)phys_start,
542-
(unsigned long long)phys_end, (unsigned)heap_start,
543-
(unsigned)heap_end);
544530
}
545531
memmap_reserve(phys_start, phys_end);
546532
}

src/kernel/mem/map.c

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,6 @@ void memmap_init(uint64_t start, uint64_t end) {
110110
memmap.max_frames = count; /* logical max */
111111
memmap.bitmap = NULL;
112112

113-
/* Diagnostic: print memmap summary so we can see physical ranges managed */
114-
printk("memmap: init start_addr=0x%08llx end_addr=0x%08llx start_frame=%llu frames=%llu\n",
115-
(unsigned long long)memmap.start_addr,
116-
(unsigned long long)memmap.end_addr,
117-
(unsigned long long)memmap.start_frame,
118-
(unsigned long long)memmap.frames);
119-
120113
/* clear any existing chunk list */
121114
{
122115
uint32_t flags = 0;
@@ -286,9 +279,6 @@ void memmap_reserve(uint64_t start, uint64_t end) {
286279
if (memmap.frames == 0)
287280
return;
288281

289-
printk("memmap_reserve: request start=0x%08llx end=0x%08llx\n",
290-
(unsigned long long)start, (unsigned long long)end);
291-
292282
uint64_t start_frame = start / FRAME_SIZE;
293283
uint64_t end_frame = (end + FRAME_SIZE - 1) / FRAME_SIZE;
294284

src/kernel/mem/paging.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,11 @@ 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",
35-
(unsigned)virt, (unsigned)phys);
36-
// ページングが有効化されていない場合、virtはphysと同じ(アイデンティティ)
37-
// しかし、physが1MBを超える場合、アクセスできない可能性がある
34+
3835
// 安全のため、物理アドレスで直接アクセス
3936
uint32_t *tbl_phys = (uint32_t *)(uintptr_t)phys;
4037
for (size_t i = 0; i < 1024; ++i)
4138
tbl_phys[i] = 0;
42-
printk("alloc_page_table: table cleared\n");
4339
// return the virtual pointer for convenience to callers
4440
return (void *)(uintptr_t)virt;
4541
}

src/kernel/mem/paging64.c

Lines changed: 13 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,6 @@ int map_page_64(uint64_t pml4_phys, uint64_t phys, uint64_t virt,
2727
if ((flags & PAGING_PRESENT) == 0)
2828
flags |= PAGING_PRESENT;
2929

30-
/* Debug: print incoming args to help diagnose caller/ABI issues */
31-
printk("map_page_64: enter pml4_phys=0x%016lx phys=0x%016lx virt=0x%016lx flags=0x%08x\n",
32-
(unsigned long)pml4_phys, (unsigned long)phys,
33-
(unsigned long)virt, (unsigned)flags);
34-
3530
// 64ビットページングのインデックス計算
3631
uint64_t pml4_idx = (virt >> 39) & 0x1FF; // bits 47-39
3732
uint64_t pdpt_idx = (virt >> 30) & 0x1FF; // bits 38-30
@@ -111,11 +106,6 @@ int map_page_64(uint64_t pml4_phys, uint64_t phys, uint64_t virt,
111106
PAGING_PRESENT | PAGING_RW | PAGING_USER;
112107
entry &= ~(1ULL << 63); // NXビットをクリア
113108
pdpt[pdpt_idx] = entry;
114-
/* Debug: print the PD we just created for this PDPT index */
115-
printk("map_page_64: created PD: pd_phys=0x%016lx pd_virt=0x%016lx pdpt_idx=%lu\n",
116-
(unsigned long)pd_phys,
117-
(unsigned long)(uintptr_t)pd_virt,
118-
(unsigned long)pdpt_idx);
119109
} else {
120110
// 既存のエントリ - NXビットをクリア
121111
pdpt[pdpt_idx] &= ~(1ULL << 63);
@@ -156,44 +146,43 @@ int map_page_64(uint64_t pml4_phys, uint64_t phys, uint64_t virt,
156146
entry &= ~(1ULL << 63); // NXビットをクリア
157147
pd[pd_idx] = entry;
158148
} else if (pd[pd_idx] & (1ULL << 7)) {
159-
// 既存エントリが2MBラージページ(PS bit=1)の場合:分割する
160-
printk("map_page_64: Breaking 2MB large page at PD[%lu] into 4KB pages\n",
161-
(unsigned long)pd_idx);
162-
163149
uint64_t large_page_base = pd[pd_idx] & 0xFFFFFFFFFFE00000ULL;
164150
uint64_t large_page_flags = pd[pd_idx] & 0xFFF;
165-
151+
166152
// 新しいPTを割り当て
167153
void *pt_virt = alloc_page_table();
168154
if (!pt_virt) {
169155
printk("map_page_64: Failed to allocate PT for page split\n");
170156
return -1;
171157
}
172158
uint64_t *pt_split = (uint64_t *)pt_virt;
173-
159+
174160
// 2MBラージページを512個の4KBページに分割
175161
for (int i = 0; i < 512; i++) {
176-
uint64_t page_phys = large_page_base + ((uint64_t)i * 0x1000);
162+
uint64_t page_phys =
163+
large_page_base + ((uint64_t)i * 0x1000);
177164
// PS bitを除去し、他のフラグは保持
178165
pt_split[i] = (page_phys & 0xFFFFFFFFFFFFF000ULL) |
179166
(large_page_flags & ~(1ULL << 7));
180167
}
181-
182-
uint64_t pt_phys = vmem_virt_to_phys64((uint64_t)(uintptr_t)pt_virt);
168+
169+
uint64_t pt_phys =
170+
vmem_virt_to_phys64((uint64_t)(uintptr_t)pt_virt);
183171
if (pt_phys == UINT64_MAX) {
184172
printk("map_page_64: vmem_virt_to_phys64 failed for pt_virt=0x%016lx\n",
185173
(unsigned long)(uintptr_t)pt_virt);
186174
return -1;
187175
}
188-
176+
189177
// PDエントリを新しいPTを指すように更新(PS bitをクリア)
190178
pd[pd_idx] = (pt_phys & 0xFFFFFFFFFFFFF000ULL) |
191179
PAGING_PRESENT | PAGING_RW | PAGING_USER;
192180
pd[pd_idx] &= ~(1ULL << 63); // NXビットをクリア
193-
181+
194182
// TLB を無効化(2MB分)
195183
for (uint64_t i = 0; i < 512; i++) {
196-
uint64_t flush_addr = (virt & 0xFFFFFFFFFFE00000ULL) + (i * 0x1000);
184+
uint64_t flush_addr =
185+
(virt & 0xFFFFFFFFFFE00000ULL) + (i * 0x1000);
197186
invlpg((void *)(uintptr_t)flush_addr);
198187
}
199188
} else {
@@ -216,12 +205,6 @@ int map_page_64(uint64_t pml4_phys, uint64_t phys, uint64_t virt,
216205
uint64_t entry = (phys & 0xFFFFFFFFFFFFF000ULL) | (flags & 0xFFF);
217206
entry &= ~(1ULL << 63); // NXビットをクリア(実行可能)
218207
pt[pt_idx] = entry;
219-
/* Debug: verify write */
220-
printk("map_page_64: set PTE: pml4_phys=0x%016lx pml4_idx=0x%03lx pdpt_idx=0x%03lx pd_idx=0x%03lx pt_idx=0x%03lx phys=0x%016lx entry=0x%016lx readback=0x%016lx\n",
221-
(unsigned long)pml4_phys, (unsigned long)pml4_idx,
222-
(unsigned long)pdpt_idx, (unsigned long)pd_idx,
223-
(unsigned long)pt_idx, (unsigned long)phys, (unsigned long)entry,
224-
(unsigned long)pt[pt_idx]);
225208

226209
// TLBを無効化
227210
invlpg((void *)(uintptr_t)virt);
@@ -336,14 +319,6 @@ void paging64_init_kernel_pml4(void) {
336319

337320
// カーネルPML4の物理アドレスを保存
338321
kernel_pml4_phys = new_pml4_phys;
339-
340-
printk("paging64_init_kernel_pml4: Switched from UEFI PML4 (0x%016lx) to kernel PML4 (0x%016lx)\n",
341-
uefi_cr3, new_pml4_phys);
342-
/* Debug: print the newly created PML4[0] so we can verify the low-4GB
343-
* identity mapping was installed correctly. */
344-
printk("paging64_init_kernel_pml4: new_pml4[0]=0x%016lx uefi_pml4[0]=0x%016lx\n",
345-
(unsigned long)new_pml4[0], (unsigned long)uefi_pml4[0]);
346-
printk("paging64_init_kernel_pml4: Added identity mapping for low 4GB (0x0-0xFFFFFFFF)\n");
347322
}
348323

349324
/**
@@ -402,7 +377,7 @@ uint64_t paging64_create_user_pml4(void) {
402377
new_pml4[i] = kernel_pml4[i];
403378
}
404379

405-
/*
380+
/*
406381
* IMPORTANT: Copy kernel_pml4[0] to enable access to kernel code/data
407382
* in low memory (identity-mapped region) even after CR3 switch.
408383
* Without this, iretq instruction itself (which is in kernel code at low
@@ -411,10 +386,7 @@ uint64_t paging64_create_user_pml4(void) {
411386
* User mappings at low addresses will still work because map_page_64
412387
* creates 4KB page tables which override the 2MB large pages from kernel.
413388
*/
414-
new_pml4[0] = kernel_pml4[0];
415-
printk("paging64_create_user_pml4: kernel_pml4_phys=0x%016lx kernel_pml4[0]=0x%016lx new_pml4[0]=0x%016lx\n",
416-
(unsigned long)kernel_pml4_phys, (unsigned long)kernel_pml4[0],
417-
(unsigned long)new_pml4[0]);
389+
new_pml4[0] = kernel_pml4[0];
418390

419391
return new_pml4_phys;
420392
}

src/kernel/mem/segment.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,20 @@ void gdt_build() {
2424
gdt_set_gate(0, 0, 0, 0, 0); /* NULL descriptor */
2525
gdt_set_gate(1, 0x0, 0xFFFFF, 0x9A,
2626
0xAF); /* 64-bit kernel code: 0xAF = Long mode */
27-
gdt_set_gate(2, 0x0, 0xFFFFF, 0x92, 0xCF); /* kernel data: 0xCF = 32-bit (L-bit must be 0 for data) */
27+
gdt_set_gate(
28+
2, 0x0, 0xFFFFF, 0x92,
29+
0xCF); /* kernel data: 0xCF = 32-bit (L-bit must be 0 for data) */
2830
gdt_set_gate(3, 0x0, 0xFFFFF, 0xFA, 0xAF); /* 64-bit user code: L=1 */
29-
gdt_set_gate(4, 0x0, 0xFFFFF, 0xF2, 0xCF); /* user data: 0xCF = 32-bit (L-bit must be 0 for data) */
31+
gdt_set_gate(
32+
4, 0x0, 0xFFFFF, 0xF2,
33+
0xCF); /* user data: 0xCF = 32-bit (L-bit must be 0 for data) */
3034
gp.limit = (sizeof(struct gdt_entry) * 5) - 1;
3135
gp.base = (uint64_t)&gdt_entries;
3236
}
3337

3438
void gdt_install();
3539

40+
#if 0 // デバッグ用 - 必要に応じて有効化
3641
void gdt_dump(void) {
3742
extern void printk(const char *fmt, ...);
3843
printk("[GDT DUMP] gp.base=0x%016lx gp.limit=0x%04x\n", gp.base,
@@ -48,3 +53,4 @@ void gdt_dump(void) {
4853
printk("\n");
4954
}
5055
}
56+
#endif

src/kernel/mem/vmem.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,7 @@ static vmem_phys2virt_fn phys2virt = NULL;
2020

2121
// 仮想アドレス→物理アドレス変換
2222
uint32_t vmem_virt_to_phys(uint32_t virt) {
23-
printk("vmem_virt_to_phys: virt=0x%x mode=%d\n", (unsigned)virt,
24-
(int)current_mode);
2523
if (current_mode == VMEM_MODE_IDENTITY) {
26-
printk("vmem_virt_to_phys: identity -> 0x%x\n", (unsigned)virt);
2724
return virt;
2825
}
2926
if (current_mode == VMEM_MODE_OFFSET) {

0 commit comments

Comments
 (0)