8000 Add boilerplate for a page aligned SMP trampoline function · rust-osdev/bootloader@6cf8a79 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6cf8a79

Browse files
committed
Add boilerplate for a page aligned SMP trampoline function
1 parent f8ebd54 commit 6cf8a79

File tree

4 files changed

+19
-1
lines changed

4 files changed

+19
-1
lines changed

linker.ld

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,17 @@ SECTIONS {
2525
. = 0x7c00;
2626
_stack_end = .;
2727

28-
.bootloader :
28+
.bootloader_first_stage :
2929
{
3030
/* first stage */
3131
*(.boot-first-stage)
32+
}
3233

34+
.bootloader :
35+
{
3336
/* rest of bootloader */
3437
_rest_of_bootloader_start_addr = .;
38+
*(.smp_trampoline)
3539
*(.boot)
3640
*(.context_switch)
3741
*(.text .text.*)

src/bootinfo/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ pub struct BootInfo {
2929
/// the memory map before passing it to the kernel. Regions marked as usable can be freely
3030
/// used by the kernel.
3131
pub memory_map: MemoryMap,
32+
pub smp_trampoline: unsafe extern "C" fn() -> !,
3233
/// The virtual address of the recursively mapped level 4 page table.
3334
#[cfg(feature = "recursive_page_table")]
3435
pub recursive_page_table_addr: u64,
@@ -51,11 +52,13 @@ impl BootInfo {
5152
#[doc(hidden)]
5253
pub fn new(
5354
memory_map: MemoryMap,
55+
smp_trampoline: unsafe extern "C" fn() -> !,
5456
recursive_page_table_addr: u64,
5557
physical_memory_offset: u64,
5658
) -> Self {
5759
BootInfo {
5860
memory_map,
61+
smp_trampoline,
5962
#[cfg(feature = "recursive_page_table")]
6063
recursive_page_table_addr,
6164
#[cfg(feature = "map_physical_memory")]

src/main.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ global_asm!(include_str!("stage_1.s"));
3636
global_asm!(include_str!("stage_2.s"));
3737
global_asm!(include_str!("e820.s"));
3838
global_asm!(include_str!("stage_3.s"));
39+
global_asm!(include_str!("smp_trampoline.s"));
3940

4041
#[cfg(feature = "vga_320x200")]
4142
global_asm!(include_str!("video_mode/vga_320x200.s"));
@@ -84,6 +85,7 @@ extern "C" {
8485
static __bootloader_end: usize;
8586
static __bootloader_start: usize;
8687
static _p4: usize;
88+
fn _smp_trampoline() -> !;
8789
}
8890

8991
#[no_mangle]
@@ -324,6 +326,7 @@ fn bootloader_main(
324326
// Construct boot info structure.
325327
let mut boot_info = BootInfo::new(
326328
memory_map,
329+
_smp_trampoline,
327330
recursive_page_table_addr.as_u64(),
328331
physical_memory_offset,
329332
);

src/smp_trampoline.s

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.section .smp_trampoline, "awx"
2+
.global _smp_trampoline
3+
.intel_syntax noprefix
4+
.align 4096
5+
.code16
6+
7+
_smp_trampoline:
8+
jmp _smp_trampoline

0 commit comments

Comments
 (0)
0