Skip to content

Commit a6f265e

Browse files
misc(kernel): bump limine crate to v2
Signed-off-by: Anhad Singh <[email protected]>
1 parent da9661a commit a6f265e

File tree

12 files changed

+121
-150
lines changed

12 files changed

+121
-150
lines changed

src/Cargo.lock

Lines changed: 10 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/aero_kernel/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ lai = { git = "https://github.com/aero-os/lai-rs" }
4040
uapi = { path = "../uapi" }
4141
cpio_reader = { git = "https://github.com/Andy-Python-Programmer/cpio_reader" }
4242
static_assertions = "1.1.0"
43-
lru = "0.12.1"
44-
bytemuck = "1.14.1"
45-
limine = { git = "https://github.com/limine-bootloader/limine-rs" }
43+
lru = "0.12.3"
44+
bytemuck = "1.15.0"
45+
limine = "0.2.0"
4646
num-traits = { version = "0.2", default-features = false }
4747
vte = { version = "0.13.0", features = ["ansi"] }
4848

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
1-
.macro pop_preserved
1+
pub macro pop_preserved() {
2+
"
23
pop r15
34
pop r14
45
pop r13
56
pop r12
67
pop rbp
78
pop rbx
8-
.endm
9+
"
10+
}
911

10-
.macro pop_scratch
12+
pub macro pop_scratch() {
13+
"
1114
pop r11
1215
pop r10
1316
pop r9
@@ -17,9 +20,11 @@
1720
pop rdx
1821
pop rcx
1922
pop rax
20-
.endm
23+
"
24+
}
2125

22-
.macro push_scratch
26+
pub macro push_scratch() {
27+
"
2328
push rcx
2429
push rdx
2530
push rdi
@@ -28,13 +33,16 @@
2833
push r9
2934
push r10
3035
push r11
31-
.endm
36+
"
37+
}
3238

33-
.macro push_preserved
39+
pub macro push_preserved() {
40+
"
3441
push rbx
3542
push rbp
3643
push r12
3744
push r13
3845
push r14
3946
push r15
40-
.endm
47+
"
48+
}

src/aero_kernel/src/arch/x86_64/mod.rs

Lines changed: 34 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ pub mod time;
3030
pub mod tls;
3131
pub mod user_copy;
3232

33+
mod asm_macros;
34+
35+
use core::cell::SyncUnsafeCell;
3336
use core::sync::atomic::Ordering;
3437

3538
use crate::acpi::aml;
@@ -42,32 +45,31 @@ use crate::{drivers, logger, rendy};
4245

4346
use raw_cpuid::CpuId;
4447

45-
use limine::*;
48+
use limine::request::*;
49+
use limine::smp::Cpu;
50+
4651
use spin::Once;
4752

4853
use self::interrupts::INTERRUPT_CONTROLLER;
4954

50-
static MEMMAP: MemmapRequest = MemmapRequest::new(0);
51-
static SMP: SmpRequest = SmpRequest::new(0);
52-
static KERNEL_FILE: KernelFileRequest = KernelFileRequest::new(0);
53-
static MODULES: ModuleRequest = ModuleRequest::new(0);
54-
static FRAMEBUFFER: FramebufferRequest = FramebufferRequest::new(0);
55-
static RSDP: RsdpRequest = RsdpRequest::new(0);
56-
static BOOT_TIME: BootTimeRequest = BootTimeRequest::new(0);
57-
static STACK: StackSizeRequest = StackSizeRequest::new(0).stack_size(0x1000 * 32); // 16KiB of stack for both the BSP and the APs
58-
static HHDM: HhdmRequest = HhdmRequest::new(0);
55+
static SMP: SyncUnsafeCell<SmpRequest> = SyncUnsafeCell::new(SmpRequest::new());
56+
static MEMMAP: SyncUnsafeCell<MemoryMapRequest> = SyncUnsafeCell::new(MemoryMapRequest::new());
57+
58+
static KERNEL_FILE: KernelFileRequest = KernelFileRequest::new();
59+
static MODULES: ModuleRequest = ModuleRequest::new();
60+
static FRAMEBUFFER: FramebufferRequest = FramebufferRequest::new();
61+
static RSDP: RsdpRequest = RsdpRequest::new();
62+
static BOOT_TIME: BootTimeRequest = BootTimeRequest::new();
63+
static STACK: StackSizeRequest = StackSizeRequest::new().with_size(0x1000 * 32); // 16KiB of stack for both the BSP and the APs
64+
static HHDM: HhdmRequest = HhdmRequest::new();
5965

6066
#[no_mangle]
6167
extern "C" fn arch_aero_main() -> ! {
6268
let kernel_file_resp = KERNEL_FILE
6369
.get_response()
64-
.get()
6570
.expect("limine: invalid kernel file response");
6671

67-
let kernel_file = kernel_file_resp
68-
.kernel_file
69-
.get()
70-
.expect("limine: invalid kernel file pointer");
72+
let kernel_file = kernel_file_resp.file();
7173

7274
// Before we start the initialization process, we need to make sure
7375
// the unwind info is available; just in case if there is a kernel
@@ -76,13 +78,10 @@ extern "C" fn arch_aero_main() -> ! {
7678
use crate::unwind::UnwindInfo;
7779
use xmas_elf::ElfFile;
7880

79-
let start = kernel_file
80-
.base
81-
.as_ptr()
82-
.expect("limine: invalid kernel file base");
81+
let start = kernel_file.addr();
8382

8483
// SAFETY: The bootloader will provide a valid pointer to the kernel file.
85-
let elf_slice = unsafe { core::slice::from_raw_parts(start, kernel_file.length as usize) };
84+
let elf_slice = unsafe { core::slice::from_raw_parts(start, kernel_file.size() as usize) };
8685
let elf = ElfFile::new(elf_slice).expect("limine: invalid kernel file");
8786

8887
UnwindInfo::new(elf)
@@ -91,22 +90,18 @@ extern "C" fn arch_aero_main() -> ! {
9190
crate::relocate_self();
9291

9392
unsafe {
94-
core::ptr::read_volatile(STACK.get_response().as_ptr().unwrap());
93+
core::ptr::read_volatile(STACK.get_response().unwrap());
9594
}
9695

9796
// SAFETY: We have exclusive access to the memory map.
98-
let memmap = MEMMAP
99-
.get_response()
100-
.get_mut()
101-
.expect("limine: invalid memmap response")
102-
.memmap_mut();
97+
let memmap = unsafe { &mut *MEMMAP.get() }.get_response_mut().unwrap();
10398

10499
unsafe {
105100
interrupts::disable_interrupts();
106101
}
107102

108103
unsafe {
109-
crate::PHYSICAL_MEMORY_OFFSET = VirtAddr::new(HHDM.get_response().get().unwrap().offset);
104+
crate::PHYSICAL_MEMORY_OFFSET = VirtAddr::new(HHDM.get_response().unwrap().offset());
110105
}
111106

112107
// Now that we have unwind info, we can initialize the COM ports. This
@@ -120,23 +115,11 @@ extern "C" fn arch_aero_main() -> ! {
120115

121116
let modules = MODULES
122117
.get_response()
123-
.get()
124118
.expect("limine: invalid modules response")
125119
.modules();
126120

127-
// Now, we need to parse the kernel command line so we can
128-
// setup the debug renderer.
129-
//
130-
// SAFETY: The `cmdline` is a valid, aligned, and NULL terminated string.
131-
let command_line = kernel_file
132-
.cmdline
133-
.to_str()
134-
.expect("limine: bad command line");
135-
136-
let command_line = cmdline::parse(
137-
command_line.to_str().expect("cmdline: invalid utf8"),
138-
modules,
139-
);
121+
let command_line = core::str::from_utf8(kernel_file.cmdline()).unwrap();
122+
let command_line = cmdline::parse(command_line, modules);
140123

141124
paging::init(memmap).unwrap();
142125
log::info!("loaded paging");
@@ -145,17 +128,17 @@ extern "C" fn arch_aero_main() -> ! {
145128
log::info!("loaded heap");
146129

147130
// SMP initialization.
148-
let smp_response = SMP.get_response().get_mut().unwrap();
149-
let bsp_lapic_id = smp_response.bsp_lapic_id;
131+
let smp_response = unsafe { &mut *SMP.get() }.get_response_mut().unwrap();
132+
let bsp_lapic_id = smp_response.bsp_lapic_id();
150133

151-
for cpu in smp_response.cpus().iter_mut() {
134+
for cpu in smp_response.cpus_mut() {
152135
apic::CPU_COUNT.fetch_add(1, Ordering::SeqCst);
153136

154137
if cpu.lapic_id == bsp_lapic_id {
155138
continue;
156139
}
157140

158-
cpu.goto_address = x86_64_aero_ap_main;
141+
cpu.goto_address.write(x86_64_aero_ap_main);
159142
}
160143

161144
gdt::init_boot();
@@ -165,10 +148,9 @@ extern "C" fn arch_aero_main() -> ! {
165148

166149
let framebuffer = FRAMEBUFFER
167150
.get_response()
168-
.get()
169151
.expect("limine: invalid framebuffer response")
170152
.framebuffers()
171-
.first()
153+
.next()
172154
.expect("limine: no framebuffer found!");
173155

174156
rendy::init(framebuffer, &command_line);
@@ -180,7 +162,7 @@ extern "C" fn arch_aero_main() -> ! {
180162
apic::init();
181163
log::info!("loaded APIC");
182164

183-
let rsdp = VirtAddr::new(RSDP.get_response().get().unwrap().address.as_ptr().unwrap() as u64);
165+
let rsdp = VirtAddr::new(RSDP.get_response().unwrap().address().addr() as u64);
184166

185167
acpi::init(rsdp);
186168
log::info!("loaded ACPI");
@@ -196,18 +178,16 @@ extern "C" fn arch_aero_main() -> ! {
196178

197179
syscall::init();
198180

199-
let boot_time = BOOT_TIME.get_response().get().unwrap();
200-
time::EPOCH.store(boot_time.boot_time as _, Ordering::SeqCst);
181+
let boot_time = BOOT_TIME.get_response().unwrap();
182+
time::EPOCH.store(boot_time.boot_time().as_secs() as usize, Ordering::SeqCst);
201183

202184
// Architecture init is done. Now we can initialize and start the init
203185
// process in the non-architecture specific part of the kernel.
204186
crate::aero_main();
205187
}
206188

207-
#[no_mangle]
208-
extern "C" fn x86_64_aero_ap_main(boot_info: *const SmpInfo) -> ! {
209-
let boot_info = unsafe { &*boot_info };
210-
let ap_id = boot_info.processor_id as usize;
189+
extern "C" fn x86_64_aero_ap_main(cpu: &Cpu) -> ! {
190+
let ap_id = cpu.id as usize;
211191

212192
log::debug!("booting CPU {}", ap_id);
213193

src/aero_kernel/src/arch/x86_64/syscall.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::userland::scheduler::{self, ExitStatus};
77
use crate::utils::sync::IrqGuard;
88

99
use super::interrupts::InterruptErrorStack;
10-
use super::io;
10+
use super::{asm_macros, io};
1111

1212
use core::mem::offset_of;
1313

@@ -16,8 +16,6 @@ const ARCH_SET_FS: usize = 0x1002;
1616
const ARCH_GET_FS: usize = 0x1003;
1717
const ARCH_GET_GS: usize = 0x1004;
1818

19-
core::arch::global_asm!(include_str!("./registers.S"));
20-
2119
/// 64-bit SYSCALL instruction entry point.
2220
///
2321
/// The instruction supports to to 6 arguments in registers.
@@ -56,8 +54,8 @@ unsafe extern "C" fn x86_64_syscall_handler() {
5654
"push rcx",
5755

5856
"push rax",
59-
"push_scratch",
60-
"push_preserved",
57+
asm_macros::push_scratch!(),
58+
asm_macros::push_preserved!(),
6159

6260
// push a fake error code to match with the layout of `InterruptErrorStack`
6361
"push 0",
@@ -71,8 +69,8 @@ unsafe extern "C" fn x86_64_syscall_handler() {
7169
// pop the fake error code
7270
"add rsp, 8",
7371

74-
"pop_preserved",
75-
"pop_scratch",
72+
asm_macros::pop_preserved!(),
73+
asm_macros::pop_scratch!(),
7674

7775
// cook the sysret frame
7876
"pop rcx",
@@ -123,8 +121,8 @@ unsafe extern "C" fn x86_64_sysenter_handler() {
123121
"and dword ptr [rsp], 0x300",
124122
"popfq",
125123
"push rax",
126-
"push_scratch",
127-
"push_preserved",
124+
asm_macros::push_scratch!(),
125+
asm_macros::push_preserved!(),
128126
"push 0",
129127
// Store the stack pointer (interrupt frame ptr) in `RBP` for safe keeping, and align the
130128
// stack as specified by the SysV calling convention.
@@ -136,8 +134,8 @@ unsafe extern "C" fn x86_64_sysenter_handler() {
136134
"call {x86_64_do_syscall}",
137135
// Reload the stack pointer, skipping the error code.
138136
"lea rsp, [rbp + 8]",
139-
"pop_preserved",
140-
"pop_scratch",
137+
asm_macros::pop_preserved!(),
138+
asm_macros::pop_scratch!(),
141139
// Pop the `IRET` frame into the registers expected by `SYSEXIT`.
142140
"pop rdx", // return `RIP` in `RDX`
143141
"add rsp, 8",

0 commit comments

Comments
 (0)