Skip to content

Commit 5ddb55d

Browse files
x86_64: make use of limine SMP feature
Now that we have switched to the limine boot protocol. We can make use of the limine SMP feature to boot the APs for us. This means that we can get rid of our SMP trampoline (this should make build times a bit faster) and removes unwanted mess from the kernel which should be in the bootloader (if a bootloader is responsible to boot the BSP then it should be for the other APs as-well). We also remove the conventional memory reservation (1st page which was before used to boot up the APs). Limine ❤️! Signed-off-by: Andy-Python-Programmer <[email protected]>
1 parent e8ceeaa commit 5ddb55d

File tree

10 files changed

+34
-359
lines changed

10 files changed

+34
-359
lines changed

aero.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,7 @@ def run_in_emulator(args, iso_path):
509509
qemu_args = ['-cdrom', iso_path,
510510
'-M', 'q35',
511511
'-m', '9800M',
512-
'-smp', '5',
512+
'-smp', '1',
513513
'-serial', 'stdio']
514514

515515
if args.bios == 'uefi':

src/Cargo.lock

Lines changed: 2 additions & 2 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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ bit_field = "0.10.1"
3333
log = "0.4.14"
3434
raw-cpuid = "10.0.0"
3535
xmas-elf = "0.8.0"
36-
hashbrown = { version = "0.12.3" }
36+
hashbrown = "0.11.2"
3737
rustc-demangle = "0.1.20"
3838
intrusive-collections = "0.9.2"
3939
serde_json = { version = "1.0", default-features = false, features = ["alloc"] }

src/aero_kernel/build.rs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ use std::error::Error;
2323
use std::ffi::OsString;
2424
use std::fs::DirEntry;
2525
use std::path::Path;
26-
use std::process::Command;
2726

2827
//this is all magic, yes dont ever let anyone see this shit
2928

@@ -55,23 +54,6 @@ fn main() -> Result<(), Box<dyn Error>> {
5554
let path = entry.path();
5655

5756
match path.extension() {
58-
Some(ext) if ext.eq(&OsString::from("real")) => {
59-
let object_os = path.file_name().expect("Failed to get file name");
60-
let object_file = object_os.to_str().expect("Invalid UTF-8 for file name");
61-
62-
let success = Command::new("nasm")
63-
.arg("-f")
64-
.arg("bin")
65-
.arg("-o")
66-
.arg(format!("../target/{}.bin", object_file))
67-
.arg(format!("{}", path.display()))
68-
.status()
69-
.expect("Failed to assemble real source file")
70-
.success();
71-
72-
assert!(success);
73-
}
74-
7557
Some(ext) if ext.eq(&OsString::from("inc")) => {
7658
let path = path
7759
.to_str()

src/aero_kernel/src/acpi/madt.rs

Lines changed: 3 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -17,37 +17,17 @@
1717
* along with Aero. If not, see <https://www.gnu.org/licenses/>.
1818
*/
1919

20-
use core::alloc::Layout;
2120
use core::mem;
2221

23-
use core::sync::atomic::Ordering;
24-
25-
use alloc::alloc::alloc_zeroed;
26-
2722
use alloc::vec::Vec;
28-
use bit_field::BitField;
2923
use spin::RwLock;
3024

31-
use crate::apic;
32-
use crate::apic::ApicType;
33-
use crate::arch::controlregs;
34-
use crate::arch::interrupts;
35-
3625
use crate::apic::IoApicHeader;
37-
use crate::apic::CPU_COUNT;
38-
use crate::mem::paging;
39-
use crate::utils::io;
4026

4127
use super::sdt::Sdt;
4228

4329
pub(super) const SIGNATURE: &str = "APIC";
4430

45-
extern "C" {
46-
fn smp_prepare_trampoline() -> u16;
47-
fn smp_prepare_launch(page_table: u64, stack_top: u64, ap_id: u64, mode: u32);
48-
fn smp_check_ap_flag() -> bool;
49-
}
50-
5131
pub static IO_APICS: RwLock<Vec<&'static IoApicHeader>> = RwLock::new(Vec::new());
5232
pub static ISOS: RwLock<Vec<&'static MadtIntSrcOverride>> = RwLock::new(Vec::new());
5333

@@ -60,106 +40,15 @@ pub struct Madt {
6040

6141
impl Madt {
6242
pub(super) fn init(&'static self) {
63-
return;
64-
log::debug!("storing AP trampoline at 0x1000");
43+
// log::debug!("storing AP trampoline at 0x1000");
6544

66-
let page_index = unsafe { smp_prepare_trampoline() };
45+
// let page_index = unsafe { smp_prepare_trampoline() };
6746

6847
for entry in self.iter() {
6948
match entry {
70-
MadtEntry::LocalApic(local_apic) => {
71-
// Make sure that we can actually start the application processor.
72-
if (!((local_apic.flags & 1) ^ ((local_apic.flags >> 1) & 1))) == 1 {
73-
log::warn!("Unable to start AP{}", local_apic.apic_id);
74-
continue;
75-
}
76-
77-
// Increase the CPU count.
78-
CPU_COUNT.fetch_add(1, Ordering::SeqCst);
79-
80-
// Do not restart the BSP.
81-
if local_apic.apic_id == apic::get_bsp_id() as u8 {
82-
continue;
83-
}
84-
85-
let page_table = controlregs::read_cr3_raw();
86-
let stack_top = unsafe {
87-
let layout = Layout::from_size_align_unchecked(4096 * 16, 4096);
88-
let raw = alloc_zeroed(layout);
89-
90-
raw.add(layout.size())
91-
};
92-
93-
let mode = if paging::level_5_paging_enabled() {
94-
1 << 1
95-
} else {
96-
0 << 1
97-
};
98-
99-
unsafe {
100-
smp_prepare_launch(
101-
page_table,
102-
stack_top as u64,
103-
local_apic.apic_id as u64,
104-
mode,
105-
);
106-
}
107-
108-
apic::mark_ap_ready(false);
109-
110-
let mut bsp = apic::get_local_apic();
111-
112-
// Send the init IPI.
113-
unsafe {
114-
if bsp.apic_type() == ApicType::X2apic {
115-
bsp.set_icr(((local_apic.apic_id as u64) << 32) | 0x4500);
116-
} else {
117-
let mut value = 0u64;
118-
119-
value.set_bits(..32, (local_apic.apic_id as u64) << 24);
120-
value.set_bits(32.., 0x4500);
121-
122-
bsp.set_icr(value);
123-
}
124-
}
125-
126-
io::delay(5000);
127-
128-
// Send the startup IPI.
129-
unsafe {
130-
if bsp.apic_type() == ApicType::X2apic {
131-
bsp.set_icr(
132-
((local_apic.apic_id as u64) << 32) | (page_index | 0x4600) as u64,
133-
);
134-
} else {
135-
let mut value = 0u64;
136-
137-
value.set_bits(..32, (local_apic.apic_id as u64) << 24);
138-
value.set_bits(32.., (page_index | 0x4600) as u64);
139-
140-
bsp.set_icr(value);
141-
}
142-
}
143-
144-
unsafe {
145-
// Wait for the AP to be ready.
146-
for _ in 0..100 {
147-
if smp_check_ap_flag() {
148-
break;
149-
}
150-
151-
io::delay(10000)
152-
}
153-
}
154-
155-
// Wait for the trampoline to be ready.
156-
while !apic::ap_ready() {
157-
interrupts::pause();
158-
}
159-
}
160-
16149
MadtEntry::IoApic(e) => IO_APICS.write().push(e),
16250
MadtEntry::IntSrcOverride(e) => ISOS.write().push(e),
51+
_ => {}
16352
}
16453
}
16554
}

src/aero_kernel/src/acpi/smp_trampoline.asm

Lines changed: 0 additions & 66 deletions
This file was deleted.

0 commit comments

Comments
 (0)