Skip to content
This repository was archived by the owner on Sep 15, 2025. It is now read-only.

Commit dae8532

Browse files
authored
Merge pull request #8 from ViktorPopp/logging
Improved logging system
2 parents 0346564 + 2687dba commit dae8532

File tree

11 files changed

+79
-49
lines changed

11 files changed

+79
-49
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
/ovmf
22
*.iso
33
*.hdd
4-
*.log
4+
*.log
5+
6+
docs/

.gitmodules

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,3 @@
22
path = limine
33
url = https://github.com/limine-bootloader/limine.git
44
branch = v9.x-binary
5-
[submodule "docs"]
6-
path = docs
7-
url = https://github.com/HexiumOS/Documentation.git

GNUmakefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,12 @@ ovmf/ovmf-vars-$(KARCH).fd:
8181
mkdir -p ovmf
8282
curl -Lo $@ https://github.com/osdev0/edk2-ovmf-nightly/releases/latest/download/ovmf-vars-$(KARCH).fd
8383

84+
#
85+
# Download the docs
86+
#
87+
docs:
88+
git clone https://github.com/HexiumOS/Documentation.git
89+
8490
#
8591
# Build the bootloader (Limine)
8692
#

docs

Lines changed: 0 additions & 1 deletion
This file was deleted.

kernel/src/arch/x86_64/gdt.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -99,14 +99,14 @@ pub static GDT: Mutex<GlobalDescriptorTable> = Mutex::new(GlobalDescriptorTable
9999
],
100100
});
101101

102-
pub fn init() {
102+
pub fn init() -> (u64, u8) {
103103
let gdt = GDT.lock();
104-
load(&*gdt, 0x08, 0x10);
105-
crate::trace!("Initialized GDT");
104+
load(&*gdt, 0x08, 0x10)
106105
}
107106

108-
// Loads the GDT and update the code and data segments
109-
pub fn load(gdt: &GlobalDescriptorTable, cs: u16, ds: u16) {
107+
/// Loads the GDT and update the code and data segments
108+
/// Returns a tuple containing loaded address and amount of entries
109+
pub fn load(gdt: &GlobalDescriptorTable, cs: u16, ds: u16) -> (u64, u8) {
110110
let gdt_ptr: DescriptorTablePointer = DescriptorTablePointer {
111111
limit: gdt.limit,
112112
base: gdt.entries.as_ptr() as u64,
@@ -119,7 +119,6 @@ pub fn load(gdt: &GlobalDescriptorTable, cs: u16, ds: u16) {
119119
options(nostack, preserves_flags),
120120
);
121121
}
122-
crate::debug!("Loaded GDT");
123122

124123
unsafe {
125124
asm!(
@@ -140,5 +139,5 @@ pub fn load(gdt: &GlobalDescriptorTable, cs: u16, ds: u16) {
140139
);
141140
}
142141

143-
crate::debug!("Updated segments registers");
142+
(gdt.entries.as_ptr() as u64, gdt.entries.len() as u8)
144143
}

kernel/src/arch/x86_64/idt.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,5 +323,4 @@ static IDT: Lazy<InterruptDescriptorTable> = Lazy::new(|| {
323323

324324
pub fn init() {
325325
IDT.load();
326-
crate::trace!("Initialized IDT");
327326
}

kernel/src/arch/x86_64/memory/heap.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::{
33
boot::HHDM_REQUEST,
44
memory::pmm::{FRAME_SIZE, alloc_contiguous},
55
},
6-
trace,
6+
info,
77
};
88
use core::{mem::MaybeUninit, slice};
99
use talc::{ErrOnOom, Talc, Talck};
@@ -32,8 +32,8 @@ pub fn init() {
3232
unsafe { talc.claim(span) }.unwrap();
3333
}
3434

35-
trace!(
36-
"Initialized heap memory at {:#x} with size of {:#x}",
35+
info!(
36+
"Heap initalized at {:#010x} (size {:#010x})",
3737
allocator_frame.unwrap().start_address().as_u64(),
3838
allocator_size
3939
);

kernel/src/arch/x86_64/memory/pmm.rs

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::{
33
addr::PhysAddr,
44
boot::{HHDM_REQUEST, MEMMAP_REQUEST},
55
},
6-
debug, trace,
6+
debug, info, println,
77
};
88
use limine::memory_map::EntryType;
99

@@ -46,27 +46,27 @@ pub fn create_bitmap_allocator() -> BitmapAllocator {
4646
let memmap = MEMMAP_REQUEST.get_response().unwrap();
4747
let hhdm = HHDM_REQUEST.get_response().unwrap().offset();
4848

49+
info!("Detecting physical memory");
50+
debug!("Usable memory regions:");
4951
let mut high: u64 = 0;
5052
for entry in memmap.entries() {
5153
if entry.entry_type == EntryType::USABLE {
5254
let top: u64 = entry.base + entry.length;
5355
if top > high {
5456
high = top;
5557
}
56-
debug!(
57-
"Found usable memory region from: {:#x} to {:#x}",
58-
entry.base, top
59-
);
58+
println!(" {:#010x} - {:#010x}", entry.base, top);
6059
}
6160
}
6261

6362
let frame_count = (high / FRAME_SIZE) as usize;
6463
let bitmap_size_bytes = (frame_count + 7) / 8;
6564
let bitmap_size_u64s = (bitmap_size_bytes + 7) / 8;
6665

67-
trace!(
68-
"Total frames: {}, bitmap size: {} bytes ({} u64s)",
69-
frame_count, bitmap_size_bytes, bitmap_size_u64s
66+
debug!("Total frames: {}", frame_count);
67+
debug!(
68+
"Bitmap size: {} ({} u64s)",
69+
bitmap_size_bytes, bitmap_size_u64s
7070
);
7171

7272
let mut best_region: Option<(u64, u64)> = None;
@@ -83,7 +83,7 @@ pub fn create_bitmap_allocator() -> BitmapAllocator {
8383

8484
let (bitmap_base, _) = best_region.expect("No suitable memory region found for bitmap");
8585

86-
trace!("Placing bitmap at physical address: {:#x}", bitmap_base);
86+
debug!("Bitmap placed at: {:#010x}", bitmap_base);
8787

8888
// Create the bitmap slice from the chosen memory region with HHDM added to the base
8989
let bitmap_ptr = (bitmap_base + hhdm) as *mut u64;
@@ -109,11 +109,11 @@ pub fn create_bitmap_allocator() -> BitmapAllocator {
109109
}
110110
}
111111
}
112-
113-
debug!("Freed frames {:#x} to {:#x}", start_frame, end_frame);
114112
}
115113
}
116114

115+
debug!("Freed frames in usable ranges");
116+
117117
let bitmap_start_frame = bitmap_base / FRAME_SIZE;
118118
let bitmap_end_frame = (bitmap_base + bitmap_size_bytes as u64 + FRAME_SIZE - 1) / FRAME_SIZE;
119119

@@ -129,11 +129,6 @@ pub fn create_bitmap_allocator() -> BitmapAllocator {
129129
}
130130
}
131131

132-
trace!(
133-
"Marked bitmap region frames {:#x} to {:#x} as used",
134-
bitmap_start_frame, bitmap_end_frame
135-
);
136-
137132
// Print memory information
138133
let total_memory = frame_count as u64 * FRAME_SIZE;
139134
let mut free_frames = 0usize;
@@ -146,11 +141,10 @@ pub fn create_bitmap_allocator() -> BitmapAllocator {
146141
}
147142
let free_memory = free_frames as u64 * FRAME_SIZE;
148143

149-
trace!(
150-
"Physical memory: total = {} MiB, free = {} MiB ({} frames free)",
144+
info!(
145+
"Total memory: {} MiB, usable: {} MiB",
151146
total_memory / 1024 / 1024,
152147
free_memory / 1024 / 1024,
153-
free_frames
154148
);
155149

156150
BitmapAllocator {

kernel/src/arch/x86_64/mod.rs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,6 @@ pub mod registers;
1111
pub mod stdext;
1212
pub mod writer;
1313

14-
pub fn init() {
15-
interrupts::disable();
16-
assert!(boot::BASE_REVISION.is_supported());
17-
writer::init();
18-
gdt::init();
19-
idt::init();
20-
memory::pmm::init();
21-
memory::heap::init();
22-
interrupts::enable();
23-
}
24-
2514
#[repr(C, packed)]
2615
struct DescriptorTablePointer {
2716
limit: u16,

kernel/src/arch/x86_64/writer.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@ pub fn init() {
4141
});
4242
}
4343
}
44-
45-
crate::trace!("Initialized Flanterm context");
4644
}
4745

4846
pub static FLANTERM_CTX: Lazy<Mutex<FlantermContext>> =

0 commit comments

Comments
 (0)