Skip to content

Commit 1e839c9

Browse files
Successfully load TSS
1 parent 3ad17ea commit 1e839c9

File tree

14 files changed

+68
-36
lines changed

14 files changed

+68
-36
lines changed

build.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ fn main() {
6363
);
6464

6565
// Inform cargo that we should rerun this on linker script changes
66+
//
67+
// This is NOT performed by default
6668
println!("cargo:rerun-if-changed=linker.ld");
6769
}
6870

src/panic.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
use core::panic::PanicInfo;
2-
use shared::println;
3-
use shared::utils;
2+
use shared::{println, instructions};
43

54
#[panic_handler]
65
pub fn panic(info: &PanicInfo) -> ! {
76
println!("[Panic] {}", info);
87

98
loop {
10-
utils::hlt()
9+
instructions::hlt()
1110
}
1211
}

src/protected/stage_3/src/lib.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#![no_std]
22

33
use shared::println;
4+
use shared::instructions;
45

56
mod panic;
67

@@ -15,5 +16,12 @@ pub extern "C" fn third_stage() -> ! {
1516

1617
println!("[Bootloader] [32] > 1MB");
1718

19+
// Load the TSS
20+
unsafe {
21+
instructions::ltr(0x2B)
22+
};
23+
24+
println!("[Bootloader] [32] Loaded TSS");
25+
1826
loop {}
1927
}

src/protected/stage_3/src/panic.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
use core::panic::PanicInfo;
22
use shared::println;
3-
use shared::utils;
3+
use shared::instructions;
44

55
#[panic_handler]
66
pub fn panic(info: &PanicInfo) -> ! {
77
println!("[Panic] {}", info);
88

99
loop {
10-
utils::hlt()
10+
instructions::hlt()
1111
}
1212
}

src/real/bootsector/src/errors.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
use super::console::real_mode_println;
2-
use shared::utils;
2+
use shared::instructions;
33

44
#[no_mangle]
55
extern "C" fn dap_load_failed() -> ! {
66
real_mode_println(b"[!] DAP Load Failed");
77
loop {
8-
utils::hlt()
8+
instructions::hlt()
99
}
1010
}
1111

1212
#[no_mangle]
1313
extern "C" fn no_int13h_extensions() -> ! {
1414
real_mode_println(b"[!] No int13h Extensions");
1515
loop {
16-
utils::hlt()
16+
instructions::hlt()
1717
}
1818
}

src/real/bootsector/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ mod errors;
77

88
use self::console::real_mode_println;
99
use core::panic::PanicInfo;
10-
use shared::{dap, linker_symbol, utils};
10+
use shared::{dap, linker_symbol, instructions};
1111

1212
extern "C" {
1313
fn second_stage() -> !;
@@ -49,6 +49,6 @@ fn panic(_info: &PanicInfo) -> ! {
4949
real_mode_println(b"[Panic]");
5050

5151
loop {
52-
utils::hlt()
52+
instructions::hlt()
5353
}
5454
}

src/real/stage_2/src/lib.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,17 @@ lazy_static! {
2424
static ref GDT: GlobalDescriptorTable = {
2525
let mut gdt = GlobalDescriptorTable::new();
2626

27+
// Set up kernel segments
2728
gdt.add_entry(Descriptor::kernel_code_segment());
2829
gdt.add_entry(Descriptor::kernel_data_segment());
2930

30-
gdt.add_entry(Descriptor::tss_segment(&TSS));
31+
// Set up user segments
32+
gdt.add_entry(Descriptor::user_code_segment());
33+
gdt.add_entry(Descriptor::user_data_segment());
3134

35+
// Set up the TSS
36+
gdt.add_entry(Descriptor::tss_segment(&*TSS));
37+
3238
gdt
3339
};
3440
}
@@ -43,11 +49,11 @@ pub fn second_stage() -> ! {
4349

4450
unsafe {
4551
GDT.load();
52+
53+
println!("[Bootloader] [16] Loaded GDT");
4654

4755
protected_mode_switch();
4856
}
49-
50-
unreachable!();
5157
}
5258

5359
fn enable_a20() {

src/real/stage_2/src/panic.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
use core::panic::PanicInfo;
22
use shared::println;
3-
use shared::utils;
3+
use shared::instructions;
44

55
#[panic_handler]
66
pub fn panic(info: &PanicInfo) -> ! {
77
println!("[Panic] {}", info);
88

99
loop {
10-
utils::hlt()
10+
instructions::hlt()
1111
}
1212
}

src/shared/src/instructions.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/// Performs a retf instruction, jumping to cs:eip
2+
///
3+
/// # Unsafety
4+
/// We make no guarantees that the cs and eip are valid, nor that they contain executable code
5+
#[inline(always)]
6+
pub unsafe fn retf(cs: u16, eip: u32) {
7+
asm!("push {0:x}
8+
push {1}
9+
retf",
10+
in(reg) cs, in(reg) eip);
11+
}
12+
13+
/// Loads a new value into the task state register
14+
///
15+
/// # Unsafety
16+
/// A bad value will cause undefined behaviour
17+
#[inline(always)]
18+
pub unsafe fn ltr(task_state: u16) {
19+
asm!("ltr {0:x}",
20+
in(reg) task_state,
21+
options(nostack)
22+
);
23+
}
24+
25+
/// Halts the processor
26+
#[inline(always)]
27+
pub fn hlt() {
28+
unsafe {
29+
asm!("hlt", options(nostack, nomem));
30+
}
31+
}

src/shared/src/instructions/assembly.s

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)