-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move stack and bss initialization to start.rs
- Loading branch information
Showing
12 changed files
with
126 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,17 @@ | ||
// Implementations for x86. | ||
#[cfg(any(target_arch = "x86_64", target_arch = "x86"))] | ||
pub mod x86; | ||
|
||
// Export our platform-specific modules. | ||
#[cfg(any(target_arch = "x86_64", target_arch = "x86"))] | ||
pub use self::x86::{init, processor}; | ||
pub use self::x86::kernel::{init, processor}; | ||
|
||
#[cfg(all(target_arch = "x86", feature = "vga"))] | ||
pub use self::x86::vga; | ||
#[cfg(feature = "vga")] | ||
pub use self::x86::kernel::vga; | ||
|
||
#[cfg(not(all(target_arch = "x86", feature = "vga")))] | ||
pub use self::x86::serial; | ||
#[cfg(not(feature = "vga"))] | ||
pub use self::x86::kernel::serial; | ||
|
||
// Implementations for x86. | ||
// Export our platform-specific modules. | ||
#[cfg(any(target_arch = "x86_64", target_arch = "x86"))] | ||
pub mod x86; | ||
pub use self::x86::mm; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
pub mod processor; | ||
#[cfg(not(feature = "vga"))] | ||
pub mod serial; | ||
pub mod start; | ||
#[cfg(feature = "vga")] | ||
pub mod vga; | ||
|
||
#[cfg(target_arch = "x86")] | ||
core::arch::global_asm!(include_str!("entry.s")); | ||
|
||
pub fn init() { | ||
processor::cpu_init(); | ||
|
||
#[cfg(all(target_arch = "x86", feature = "vga"))] | ||
vga::init(); | ||
} |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
use crate::arch; | ||
use crate::arch::x86::kernel::processor::shutdown; | ||
|
||
extern "C" { | ||
pub fn main() -> i32; | ||
} | ||
|
||
#[cfg(target_arch = "x86")] | ||
extern "C" { | ||
static mut __bss_start: u8; | ||
static __bss_end: u8; | ||
} | ||
|
||
/// initialize bss section | ||
#[cfg(target_arch = "x86")] | ||
unsafe fn bss_init() { | ||
core::ptr::write_bytes( | ||
core::ptr::addr_of_mut!(__bss_start), | ||
0, | ||
core::ptr::addr_of!(__bss_end) as usize - core::ptr::addr_of!(__bss_start) as usize, | ||
); | ||
} | ||
|
||
#[cfg(not(test))] | ||
unsafe extern "C" fn entry() -> ! { | ||
arch::init(); | ||
|
||
#[cfg(target_arch = "x86")] | ||
bss_init(); | ||
|
||
let ret = main(); | ||
|
||
shutdown(ret) | ||
} | ||
|
||
#[cfg(not(test))] | ||
#[cfg(target_arch = "x86_64")] | ||
#[no_mangle] | ||
/// # Safety | ||
/// | ||
/// This function is the entry point of the kernel. | ||
/// The kernel itself should not call this function. | ||
pub unsafe extern "C" fn _start() -> ! { | ||
entry(); | ||
} | ||
|
||
#[cfg(not(test))] | ||
#[cfg(target_arch = "x86")] | ||
#[no_mangle] | ||
#[naked] | ||
/// # Safety | ||
/// | ||
/// This function is the entry point of the kernel. | ||
/// The kernel itself should not call this function. | ||
pub unsafe extern "C" fn _start() -> ! { | ||
use crate::arch::mm::{BOOT_STACK, BOOT_STACK_SIZE}; | ||
use core::arch::naked_asm; | ||
|
||
naked_asm!( | ||
"lea esp, {stack}", | ||
"add esp, {offset}", | ||
"jmp {entry}", | ||
stack = sym BOOT_STACK, | ||
offset = const BOOT_STACK_SIZE - 16, | ||
entry = sym entry, | ||
options(noreturn) | ||
); | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#[cfg(target_arch = "x86")] | ||
#[repr(C, align(64))] | ||
pub(crate) struct Aligned<T>(T); | ||
|
||
#[cfg(target_arch = "x86")] | ||
impl<T> Aligned<T> { | ||
/// Constructor. | ||
pub const fn new(t: T) -> Self { | ||
Self(t) | ||
} | ||
} | ||
|
||
#[cfg(target_arch = "x86")] | ||
pub(crate) const BOOT_STACK_SIZE: usize = 0x3000; | ||
#[cfg(target_arch = "x86")] | ||
#[link_section = ".data"] | ||
pub(crate) static mut BOOT_STACK: Aligned<[u8; BOOT_STACK_SIZE]> = | ||
Aligned::new([0; BOOT_STACK_SIZE]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,2 @@ | ||
pub mod processor; | ||
#[cfg(not(all(target_arch = "x86", feature = "vga")))] | ||
pub mod serial; | ||
#[cfg(target_arch = "x86_64")] | ||
pub mod start; | ||
#[cfg(all(target_arch = "x86", feature = "vga"))] | ||
pub mod vga; | ||
|
||
#[cfg(target_arch = "x86")] | ||
core::arch::global_asm!(include_str!("entry.s")); | ||
|
||
pub fn init() { | ||
processor::cpu_init(); | ||
|
||
#[cfg(all(target_arch = "x86", feature = "vga"))] | ||
vga::init(); | ||
} | ||
pub mod kernel; | ||
pub mod mm; |
This file was deleted.
Oops, something went wrong.