Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/arch/x86_64/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ mod paging;
#[cfg(target_os = "none")]
mod physicalmem;
mod platform;
#[cfg(target_os = "none")]
mod stack;

pub use console::Console;

Expand Down
15 changes: 4 additions & 11 deletions src/arch/x86_64/platform/linux/entry.s
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

.code64

.set BOOT_STACK_SIZE, 4096

.extern loader_start # defined in linker script
.extern loader_end

Expand All @@ -16,8 +14,8 @@ _start:
cli # avoid any interrupt

# Initialize stack pointer
movabs rsp, OFFSET boot_stack
add rsp, BOOT_STACK_SIZE - 16
movabs rsp, OFFSET {stack}
add rsp, {stack_top_offset}

mov [boot_params], rsi

Expand Down Expand Up @@ -67,8 +65,8 @@ start64:
mov gs, ax
cld
# set default stack pointer
movabs rsp, OFFSET boot_stack
add rsp, BOOT_STACK_SIZE-16
movabs rsp, OFFSET {stack}
add rsp, {stack_top_offset}

# jump to the boot processors's C code
jmp {loader_main}
Expand All @@ -81,11 +79,6 @@ invalid:
boot_params:
.8byte 0

.align 4096
.global boot_stack
boot_stack:
.fill BOOT_STACK_SIZE, 1, 0xcd

# Bootstrap page tables are used during the initialization.
.align 4096
boot_pml4:
Expand Down
2 changes: 2 additions & 0 deletions src/arch/x86_64/platform/linux/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ mod entry {
core::arch::global_asm!(
include_str!("entry.s"),
loader_main = sym crate::os::loader_main,
stack = sym crate::arch::x86_64::stack::STACK,
stack_top_offset = const crate::arch::x86_64::stack::Stack::top_offset(),
gdt_ptr = sym crate::arch::x86_64::gdt::GDT_PTR,
kernel_code_selector = const crate::arch::x86_64::gdt::Gdt::kernel_code_selector().0,
kernel_data_selector = const crate::arch::x86_64::gdt::Gdt::kernel_data_selector().0,
Expand Down
15 changes: 4 additions & 11 deletions src/arch/x86_64/platform/multiboot/entry.s
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

.code32

.set BOOT_STACK_SIZE, 4096

.extern loader_start # defined in linker script
.extern loader_end

Expand Down Expand Up @@ -37,8 +35,8 @@ _start:
cli # avoid any interrupt

# Initialize stack pointer
mov esp, OFFSET boot_stack
add esp, BOOT_STACK_SIZE - 16
mov esp, OFFSET {stack}
add esp, {stack_top_offset}

# Interpret multiboot information
mov [mb_info], ebx
Expand Down Expand Up @@ -155,8 +153,8 @@ start64:
mov gs, eax
cld
# set default stack pointer
movabs rsp, OFFSET boot_stack
add rsp, BOOT_STACK_SIZE-16
movabs rsp, OFFSET {stack}
add rsp, {stack_top_offset}

# jump to the boot processors's C code
jmp {loader_main}
Expand All @@ -168,11 +166,6 @@ start64:
mb_info:
.8byte 0

.align 4096
.global boot_stack
boot_stack:
.fill BOOT_STACK_SIZE, 1, 0xcd

# Bootstrap page tables are used during the initialization.
.align 4096
boot_pml4:
Expand Down
2 changes: 2 additions & 0 deletions src/arch/x86_64/platform/multiboot/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ mod entry {
core::arch::global_asm!(
include_str!("entry.s"),
loader_main = sym crate::os::loader_main,
stack = sym crate::arch::x86_64::stack::STACK,
stack_top_offset = const crate::arch::x86_64::stack::Stack::top_offset(),
gdt_ptr = sym crate::arch::x86_64::gdt::GDT_PTR,
kernel_code_selector = const crate::arch::x86_64::gdt::Gdt::kernel_code_selector().0,
kernel_data_selector = const crate::arch::x86_64::gdt::Gdt::kernel_data_selector().0,
Expand Down
24 changes: 24 additions & 0 deletions src/arch/x86_64/stack.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
use core::cell::UnsafeCell;
use core::mem::{self, MaybeUninit};

#[repr(C, align(0x1000))]
pub struct Stack(UnsafeCell<[MaybeUninit<u8>; 0x1000]>);

unsafe impl Sync for Stack {}

impl Stack {
const fn new() -> Self {
let fill = if cfg!(debug_assertions) {
MaybeUninit::new(0xcd)
} else {
MaybeUninit::uninit()
};
Self(UnsafeCell::new([fill; _]))
}

pub const fn top_offset() -> u16 {
mem::size_of::<Self>() as u16 - 0x10
}
}

pub static STACK: Stack = Stack::new();