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
46 changes: 39 additions & 7 deletions src/arch/i686/linker.ld
Original file line number Diff line number Diff line change
@@ -1,17 +1,49 @@
ENTRY(_start)

SECTIONS {
. = 1M;

.boot :
SECTIONS
{
.boot BLOCK(4K) : ALIGN(4K)
{
/* ensure that the multiboot header is at the beginning */
KEEP(*(.multiboot_header))
}

.text :
. = 0x00100000;
.text BLOCK(4K) : ALIGN(4K)
{
_kernel_start = .;
*(.text)
}
/* Read-only data. */
.rodata BLOCK(4K) : ALIGN(4K)
{
*(.rodata)
}

/* Read-write data (initialized) */
.data BLOCK(4K) : ALIGN(4K)
{
*(.data)
}
.bss BLOCK(4K) : ALIGN(4K)
{
*(COMMON)
*(.bss)
}
.stab BLOCK(4K) : ALIGN(4K)
{
*(.stab)
}
.stabstr BLOCK(4K) : ALIGN(4K)
{
*(.stabstr)
}
.note BLOCK(4K) : ALIGN(4K)
{
*(.note)
}
.comment BLOCK(4K) : ALIGN(4K)
{
*(.comment)
}
_kernel_end = .;
}

8 changes: 7 additions & 1 deletion src/elsos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
#![no_std]
#![no_main]

mod utilities;
mod tools;
mod vga;
mod keyboard;
mod tty;
mod multiboot;
mod serial;
mod gdt;
mod memory;

use core::panic::PanicInfo;

Expand All @@ -20,6 +21,9 @@ static PATCHLEVEL: &str = env!("PATCHLEVEL");
static SUBLEVEL: &str = env!("SUBLEVEL");
static EXTRAVERSION: &str = env!("EXTRAVERSION");

use crate::multiboot::MULTIBOOT_MMAP;
use crate::multiboot::MULTIBOOT_MMAP_ENTRIES;

pub struct Settings
{
has_serial: bool,
Expand All @@ -40,6 +44,8 @@ pub extern "C" fn kernel_main(magic: u32, address: u32)
vga::cursor::Cursor::init(0, 15);
if multiboot::check_magic(magic) && multiboot::parse(address)
{
let mut alloc: memory::pageframe::Allocator = memory::pageframe::Allocator::new();
unsafe { alloc.read_grub_mmap(MULTIBOOT_MMAP, MULTIBOOT_MMAP_ENTRIES); }
init_serial();
logln!("\n");
logln!(" ::: :::::::: __ __ __ _ ____ ____ ");
Expand Down
156 changes: 78 additions & 78 deletions src/gdt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,62 +5,62 @@ use core::mem::size_of;
#[repr(C, packed)]
struct gdt_ptr
{
limit: u16,
base: u32
limit: u16,
base: u32
}

#[repr(C, packed)]
struct gdt_entry
{
limit0: u16,
base0: u16,
base1: u8,
access_byte: u8,
limit1_flags: u8,
base2: u8
limit0: u16,
base0: u16,
base1: u8,
access_byte: u8,
limit1_flags: u8,
base2: u8
}

#[repr(C, packed)]
struct gdt
{
null: gdt_entry,
kernel_code: gdt_entry,
kernel_data: gdt_entry,
null: gdt_entry,
kernel_code: gdt_entry,
kernel_data: gdt_entry,
kernel_stack: gdt_entry,
user_code: gdt_entry,
user_data: gdt_entry,
user_code: gdt_entry,
user_data: gdt_entry,
user_stack: gdt_entry,
}

static mut GDT_TABLE: gdt = gdt
{
null: gdt_entry
{
limit0: 0,
base0: 0,
base1: 0,
access_byte: 0x00,
limit1_flags: 0x00,
base2: 0
},
kernel_code: gdt_entry
{
limit0: 0xffff,
base0: 0,
base1: 0,
access_byte: 0b1001_1010,
limit1_flags: 0xcf,
base2: 0
},
kernel_data: gdt_entry
{
limit0: 0xffff,
base0: 0,
base1: 0,
access_byte: 0b1001_0010,
limit1_flags: 0xcf,
base2: 0
},
null: gdt_entry
{
limit0: 0,
base0: 0,
base1: 0,
access_byte: 0x00,
limit1_flags: 0x00,
base2: 0
},
kernel_code: gdt_entry
{
limit0: 0xffff,
base0: 0,
base1: 0,
access_byte: 0b1001_1010,
limit1_flags: 0xcf,
base2: 0
},
kernel_data: gdt_entry
{
limit0: 0xffff,
base0: 0,
base1: 0,
access_byte: 0b1001_0010,
limit1_flags: 0xcf,
base2: 0
},
kernel_stack: gdt_entry
{
limit0: 0xffff,
Expand All @@ -70,56 +70,56 @@ static mut GDT_TABLE: gdt = gdt
limit1_flags: 0xcf,
base2: 0
},
user_code: gdt_entry
{
limit0: 0xffff,
base0: 0,
base1: 0,
access_byte: 0b1111_1010,
limit1_flags: 0xcf,
base2: 0
},
user_data: gdt_entry
{
limit0: 0xffff,
base0: 0,
base1: 0,
access_byte: 0b1111_0010,
limit1_flags: 0xcf,
base2: 0
},
user_stack: gdt_entry
{
limit0: 0xffff,
base0: 0,
base1: 0,
access_byte: 0b1111_0110,
limit1_flags: 0xcf,
base2: 0
},
user_code: gdt_entry
{
limit0: 0xffff,
base0: 0,
base1: 0,
access_byte: 0b1111_1010,
limit1_flags: 0xcf,
base2: 0
},
user_data: gdt_entry
{
limit0: 0xffff,
base0: 0,
base1: 0,
access_byte: 0b1111_0010,
limit1_flags: 0xcf,
base2: 0
},
user_stack: gdt_entry
{
limit0: 0xffff,
base0: 0,
base1: 0,
access_byte: 0b1111_0110,
limit1_flags: 0xcf,
base2: 0
},
};

extern "C"
{
fn _gdt_flush();
fn memcpy(dst: *const u8, src: *const u8, size: usize);
fn _gdt_flush();
fn memcpy(dst: *const u8, src: *const u8, size: usize);
}

#[no_mangle]
static mut _gp: gdt_ptr = gdt_ptr
{
limit: 0,
base: 0x800
limit: 0,
base: 0x800
};

pub fn init_gdt()
{
let size = size_of::<gdt>() - 1;
unsafe
{
memcpy(0x800 as *const u8, (&GDT_TABLE as *const _) as *const u8, size);
_gp.limit = size as u16;
_gdt_flush();
}
let size = size_of::<gdt>() - 1;
unsafe
{
memcpy(0x800 as *const u8, (&GDT_TABLE as *const _) as *const u8, size);
_gp.limit = size as u16;
_gdt_flush();
}
}

4 changes: 2 additions & 2 deletions src/keyboard/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::tty;
use crate::utilities;
use crate::tools;

mod azerty;
mod qwerty;
Expand Down Expand Up @@ -54,7 +54,7 @@ pub fn get_scancodes()
let mut scancode: u8 = 0;
loop
{
let new_scancode = utilities::inb(KEYBOARD_DATA);
let new_scancode = tools::inb(KEYBOARD_DATA);

if new_scancode == scancode
{
Expand Down
8 changes: 4 additions & 4 deletions src/libc/libc.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#ifndef LIBC_H
# define LIBC_H

void *memset(void *b, int c, size_t len);
void *memcpy(void *dst, const void *src, size_t n);
void *memmove(void *dst, const void *src, size_t len);
int memcmp(const void *s1, const void *s2, size_t n);
void *memset(void *b, int c, size_t len);
void *memcpy(void *dst, const void *src, size_t n);
void *memmove(void *dst, const void *src, size_t len);
int memcmp(const void *s1, const void *s2, size_t n);

#endif
50 changes: 50 additions & 0 deletions src/memory/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
pub mod pageframe;

use core::ffi::c_void;
use crate::multiboot::MultibootTagMmap;

extern "C"
{
static _kernel_start: c_void;
static _kernel_end: c_void;
}

pub fn get_mem_size(mmap: *const MultibootTagMmap, mmap_size: usize) -> usize
{
static mut MEM_SIZE_BYTES: u64 = 0;
unsafe
{
if MEM_SIZE_BYTES > 0
{
return MEM_SIZE_BYTES as usize;
}
crate::logln!("\x1B[33mmmap: {:#x?}\x1B[39m", (*mmap).entries(mmap_size));
for mmap_entry in (*mmap).entries(mmap_size)
{
MEM_SIZE_BYTES += mmap_entry.len as u64;
}
if MEM_SIZE_BYTES > usize::MAX as u64
{
panic!("This version of ElsOS is in 32 bit, it only supports {}Mo of RAM, you have {}Mo installed", (usize::MAX / 1024) / 1024, (MEM_SIZE_BYTES / 1024) / 1024);
}
return MEM_SIZE_BYTES as usize;
}
}

pub fn get_largest_mem_seg(mmap: *const MultibootTagMmap, mmap_size: usize) -> usize
{
let mut largest_free_mem_seg: usize = 0;
let mut largest_free_mem_seg_size: usize = 0;
unsafe
{
for entry in (*mmap).entries(mmap_size)
{
if entry.len as usize > largest_free_mem_seg_size
{
largest_free_mem_seg_size = entry.len as usize;
largest_free_mem_seg = entry.addr as usize;
}
}
}
largest_free_mem_seg
}
Loading