File tree Expand file tree Collapse file tree 14 files changed +68
-36
lines changed Expand file tree Collapse file tree 14 files changed +68
-36
lines changed Original file line number Diff line number Diff line change @@ -63,6 +63,8 @@ fn main() {
63
63
) ;
64
64
65
65
// Inform cargo that we should rerun this on linker script changes
66
+ //
67
+ // This is NOT performed by default
66
68
println ! ( "cargo:rerun-if-changed=linker.ld" ) ;
67
69
}
68
70
Original file line number Diff line number Diff line change 1
1
use core:: panic:: PanicInfo ;
2
- use shared:: println;
3
- use shared:: utils;
2
+ use shared:: { println, instructions} ;
4
3
5
4
#[ panic_handler]
6
5
pub fn panic ( info : & PanicInfo ) -> ! {
7
6
println ! ( "[Panic] {}" , info) ;
8
7
9
8
loop {
10
- utils :: hlt ( )
9
+ instructions :: hlt ( )
11
10
}
12
11
}
Original file line number Diff line number Diff line change 1
1
#![ no_std]
2
2
3
3
use shared:: println;
4
+ use shared:: instructions;
4
5
5
6
mod panic;
6
7
@@ -15,5 +16,12 @@ pub extern "C" fn third_stage() -> ! {
15
16
16
17
println ! ( "[Bootloader] [32] > 1MB" ) ;
17
18
19
+ // Load the TSS
20
+ unsafe {
21
+ instructions:: ltr ( 0x2B )
22
+ } ;
23
+
24
+ println ! ( "[Bootloader] [32] Loaded TSS" ) ;
25
+
18
26
loop { }
19
27
}
Original file line number Diff line number Diff line change 1
1
use core:: panic:: PanicInfo ;
2
2
use shared:: println;
3
- use shared:: utils ;
3
+ use shared:: instructions ;
4
4
5
5
#[ panic_handler]
6
6
pub fn panic ( info : & PanicInfo ) -> ! {
7
7
println ! ( "[Panic] {}" , info) ;
8
8
9
9
loop {
10
- utils :: hlt ( )
10
+ instructions :: hlt ( )
11
11
}
12
12
}
Original file line number Diff line number Diff line change 1
1
use super :: console:: real_mode_println;
2
- use shared:: utils ;
2
+ use shared:: instructions ;
3
3
4
4
#[ no_mangle]
5
5
extern "C" fn dap_load_failed ( ) -> ! {
6
6
real_mode_println ( b"[!] DAP Load Failed" ) ;
7
7
loop {
8
- utils :: hlt ( )
8
+ instructions :: hlt ( )
9
9
}
10
10
}
11
11
12
12
#[ no_mangle]
13
13
extern "C" fn no_int13h_extensions ( ) -> ! {
14
14
real_mode_println ( b"[!] No int13h Extensions" ) ;
15
15
loop {
16
- utils :: hlt ( )
16
+ instructions :: hlt ( )
17
17
}
18
18
}
Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ mod errors;
7
7
8
8
use self :: console:: real_mode_println;
9
9
use core:: panic:: PanicInfo ;
10
- use shared:: { dap, linker_symbol, utils } ;
10
+ use shared:: { dap, linker_symbol, instructions } ;
11
11
12
12
extern "C" {
13
13
fn second_stage ( ) -> !;
@@ -49,6 +49,6 @@ fn panic(_info: &PanicInfo) -> ! {
49
49
real_mode_println ( b"[Panic]" ) ;
50
50
51
51
loop {
52
- utils :: hlt ( )
52
+ instructions :: hlt ( )
53
53
}
54
54
}
Original file line number Diff line number Diff line change @@ -24,11 +24,17 @@ lazy_static! {
24
24
static ref GDT : GlobalDescriptorTable = {
25
25
let mut gdt = GlobalDescriptorTable :: new( ) ;
26
26
27
+ // Set up kernel segments
27
28
gdt. add_entry( Descriptor :: kernel_code_segment( ) ) ;
28
29
gdt. add_entry( Descriptor :: kernel_data_segment( ) ) ;
29
30
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( ) ) ;
31
34
35
+ // Set up the TSS
36
+ gdt. add_entry( Descriptor :: tss_segment( & * TSS ) ) ;
37
+
32
38
gdt
33
39
} ;
34
40
}
@@ -43,11 +49,11 @@ pub fn second_stage() -> ! {
43
49
44
50
unsafe {
45
51
GDT . load ( ) ;
52
+
53
+ println ! ( "[Bootloader] [16] Loaded GDT" ) ;
46
54
47
55
protected_mode_switch ( ) ;
48
56
}
49
-
50
- unreachable ! ( ) ;
51
57
}
52
58
53
59
fn enable_a20 ( ) {
Original file line number Diff line number Diff line change 1
1
use core:: panic:: PanicInfo ;
2
2
use shared:: println;
3
- use shared:: utils ;
3
+ use shared:: instructions ;
4
4
5
5
#[ panic_handler]
6
6
pub fn panic ( info : & PanicInfo ) -> ! {
7
7
println ! ( "[Panic] {}" , info) ;
8
8
9
9
loop {
10
- utils :: hlt ( )
10
+ instructions :: hlt ( )
11
11
}
12
12
}
Original file line number Diff line number Diff line change
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
+ }
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments