Skip to content

Commit

Permalink
Add docs, setup stack, fix a bug in multibootheader
Browse files Browse the repository at this point in the history
  • Loading branch information
roblabla committed Mar 14, 2018
1 parent fd4e913 commit 5cc1bcc
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
10 changes: 9 additions & 1 deletion link.T
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,15 @@ SECTIONS {
}

.text : {
*(.text)
*(.text .text.*)
}

.rodata : {
*(.rodata .rodata.*)
}

.data.rel.ro : {
*(.data.rel.ro.local.*) *(data.rel.ro .data.rel.ro.*)
}

/DISCARD/ : {
Expand Down
27 changes: 24 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
#![feature(lang_items, start, asm, global_asm, compiler_builtins_lib)]
//! KFS
//!
//! A small kernel written in rust for shit and giggles. Also, hopefully the
//! last project I'll do before graduating from 42 >_>'.
//!
//! Currently doesn't do much, besides booting and printing Hello World on the
//! screen. But hey, that's a start.

#![feature(lang_items, start, asm, global_asm, compiler_builtins_lib, repr_transparent, naked_functions)]
#![cfg_attr(target_os = "none", no_std)]
#![cfg_attr(target_os = "none", no_main)]

Expand Down Expand Up @@ -29,9 +37,22 @@ fn main() {
PrintAttribute::new(Color::Yellow, Color::Pink, true));
}

#[no_mangle]
pub static mut STACK: [u8; 4096 * 4] = [0; 4096 * 4];

#[cfg(target_os = "none")]
#[no_mangle]
#[naked]
pub unsafe extern fn start() -> ! {
asm!("lea eax, STACK" : : : : "intel");
asm!("add eax, 16383" : : : : "intel");
common_start();
}

/// CRT0 starts here.
#[cfg(target_os = "none")]
#[no_mangle]
pub extern fn start() -> ! {
extern "C" fn common_start() -> ! {
// Do whatever is necessary to have a proper environment here.
main();
// Die !
Expand All @@ -47,7 +68,7 @@ pub extern fn start() -> ! {
#[cfg(target_os = "none")]
#[lang = "panic_fmt"] #[no_mangle] pub extern fn panic_fmt() -> ! { loop {} }

#[repr(packed)]
#[repr(C, packed)]
#[allow(dead_code)]
pub struct MultiBootHeader {
magic: u32,
Expand Down

0 comments on commit 5cc1bcc

Please sign in to comment.