Skip to content

Commit

Permalink
Non static gdt idt
Browse files Browse the repository at this point in the history
  • Loading branch information
mrgian committed Mar 29, 2023
1 parent ff838b7 commit af06203
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 60 deletions.
21 changes: 0 additions & 21 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions bootloader/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,3 @@ authors.workspace = true
edition.workspace = true

[dependencies]

[dependencies.lazy_static]
version = "1.4.0"
features = ["spin_no_std"]
4 changes: 1 addition & 3 deletions bootloader/src/gdt.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use core::arch::asm;
use core::mem::size_of;



const GDT_ENTRIES: usize = 3;

#[repr(C, packed)]
Expand Down Expand Up @@ -83,7 +81,7 @@ impl GlobalDescriptorTable {
}

//load gdt using lgdt instruction
pub fn load(&'static self) {
pub fn load(&self) {
let descriptor = GdtDescriptor {
size: (GDT_ENTRIES * size_of::<GdtEnrty>() - 1) as u16, //calculate size of gdt
offset: self, //pointer to gdt
Expand Down
15 changes: 4 additions & 11 deletions bootloader/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
#![no_std]
#![no_main]

#[macro_use]
extern crate lazy_static;

use core::arch::asm;
use core::panic::PanicInfo;

Expand All @@ -24,10 +21,6 @@ const KERNEL_SIZE: u16 = 2048; //kernel size in sectors
const KERNEL_BUFFER: u16 = 0xbe00; //buffer location for copy
const KERNEL_TARGET: u32 = 0x0010_0000; //where to put kernel in memory

lazy_static!{
static ref GDT: GlobalDescriptorTable = GlobalDescriptorTable::new();
}

#[panic_handler]
fn panic(info: &PanicInfo) -> ! {
println!("PANIC! Info: {}", info);
Expand All @@ -51,8 +44,8 @@ pub extern "C" fn _start() -> ! {

//load dgt
println!("[!] Loading Global Descriptor Table...");
//let gdt = GlobalDescriptorTable::new();
GDT.load();
let gdt = GlobalDescriptorTable::new();
gdt.load();

//switch to protected mode
println!("[!] Switching to 32bit protected mode and jumping to kernel...");
Expand Down Expand Up @@ -115,8 +108,8 @@ fn unreal_mode() {
}

//load gdt
//let gdt = GlobalDescriptorTable::new();
GDT.load();
let gdt = GlobalDescriptorTable::new();
gdt.load();

unsafe {
//backup cr0 register
Expand Down
4 changes: 0 additions & 4 deletions kernel/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,3 @@ authors.workspace = true
edition.workspace = true

[dependencies]

[dependencies.lazy_static]
version = "1.4.0"
features = ["spin_no_std"]
4 changes: 1 addition & 3 deletions kernel/src/idt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl InterruptDescriptorTable {
}

//load idt using lidt instruction
pub fn load(&'static self) {
pub fn load(&self) {
let descriptor = IdtDescriptor {
size: (IDT_ENTRIES * size_of::<IdtEntry>() - 1) as u16, //calculate size of idt
offset: self, //pointer to idt
Expand Down Expand Up @@ -122,8 +122,6 @@ pub extern "C" fn exception_handler(int: u32) {
println!("EXCEPTION!");
}
}

//loop {}
}

#[naked]
Expand Down
17 changes: 3 additions & 14 deletions kernel/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
#![no_main]
#![feature(naked_functions)]

#[macro_use]
extern crate lazy_static;

use core::arch::asm;
use core::panic::PanicInfo;

Expand All @@ -14,15 +11,6 @@ mod print;
mod idt;
use idt::InterruptDescriptorTable;

lazy_static!{
static ref IDT: InterruptDescriptorTable = {
let mut idt = InterruptDescriptorTable::new();
idt.add_exceptions();

idt
};
}

//1MiB. TODO: Get those from linker
const KERNEL_START: u32 = 0x0010_0000;
const KERNEL_SIZE: u32 = 0x0010_0000;
Expand All @@ -42,8 +30,9 @@ pub extern "C" fn _start() -> ! {

println!("Welcome to Felix {}!", VERSION);

//let mut idt = InterruptDescriptorTable::new();
IDT.load();
let mut idt = InterruptDescriptorTable::new();
idt.add_exceptions();
idt.load();

//generates invalid opcode exception
unsafe {
Expand Down

0 comments on commit af06203

Please sign in to comment.