Skip to content

Commit a91fa97

Browse files
Update tree
1 parent 0f410d5 commit a91fa97

File tree

11 files changed

+112
-131
lines changed

11 files changed

+112
-131
lines changed

.cargo/config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
target = "i8086-bootloader.json"
33

44
[alias]
5-
bbuild = "build -Zbuild-std=core"
5+
xbuild = "build -Zbuild-std=core"

src/protected/Cargo.lock

Lines changed: 0 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/protected/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
[workspace]
22
members = [
3-
"v86",
43
"stage_3"
54
]
65

src/protected/stage_3/src/lib.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,8 @@ use shared::println;
66
mod panic;
77

88
#[no_mangle]
9-
pub extern "C" fn third_stage() {
10-
unsafe {
11-
llvm_asm!("mov bx, 0x0
12-
mov ds, bx
13-
mov es, bx" ::: "bx" : "intel", "volatile");
14-
}
9+
pub extern "C" fn third_stage() -> ! {
10+
println!("X");
1511

16-
println!("Stage 3");
12+
loop {}
1713
}

src/protected/v86/Cargo.toml

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

src/protected/v86/src/lib.rs

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

src/real/bootsector/src/lib.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use core::panic::PanicInfo;
1010
use shared::{dap, linker_symbol, utils};
1111

1212
extern "C" {
13-
fn second_stage();
13+
fn second_stage() -> !;
1414
}
1515
global_asm!(include_str!("bootstrap.s"));
1616

@@ -26,13 +26,10 @@ extern "C" fn rust_start(disk_number: u16) -> ! {
2626
linker_symbol!(_rest_of_bootloader_end) - linker_symbol!(_rest_of_bootloader_start),
2727
);
2828

29-
unsafe { dap.perform_load(disk_number) };
30-
31-
unsafe { second_stage() };
32-
33-
loop {
34-
utils::hlt();
35-
}
29+
unsafe {
30+
dap.perform_load(disk_number);
31+
second_stage();
32+
};
3633
}
3734

3835
fn check_int13h_extensions(disk_number: u16) {

src/real/stage_2/src/lib.rs

Lines changed: 45 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![feature(llvm_asm)]
1+
#![feature(global_asm, llvm_asm)]
22
#![no_std]
33

44
// FIXME
@@ -13,9 +13,11 @@ use lazy_static::lazy_static;
1313
mod panic;
1414

1515
extern "C" {
16-
fn third_stage();
16+
fn protected_mode_switch() -> !;
1717
}
1818

19+
global_asm!(include_str!("protected_mode.s"));
20+
1921
lazy_static! {
2022
static ref TSS: TaskStateSegment = {
2123
let mut tss = TaskStateSegment::new();
@@ -26,6 +28,7 @@ lazy_static! {
2628
};
2729
static ref GDT: GlobalDescriptorTable = {
2830
let mut gdt = GlobalDescriptorTable::new();
31+
2932
gdt.add_entry(Descriptor::kernel_code_segment());
3033
gdt.add_entry(Descriptor::kernel_data_segment());
3134
gdt.add_entry(Descriptor::user_code_segment());
@@ -38,15 +41,19 @@ lazy_static! {
3841
}
3942

4043
#[no_mangle]
41-
pub fn second_stage() {
44+
pub fn second_stage() -> ! {
4245
println!("Stage 2");
4346

44-
enter_protected_mode();
45-
46-
loop {};
47+
unsafe {
48+
//GDT.load();
49+
50+
println!("Switching to Protected Mode");
51+
52+
protected_mode_switch();
53+
}
4754
}
4855

49-
fn enter_protected_mode() {
56+
fn enter_protected_mode() -> ! {
5057
unsafe {
5158
GDT.load();
5259
}
@@ -57,14 +64,42 @@ fn enter_protected_mode() {
5764

5865
println!("A20 On");
5966

67+
6068
unsafe {
61-
llvm_asm!("cli
69+
llvm_asm!("cli" :::: "intel", "volatile");
70+
}
71+
72+
println!("Interrupts off");
6273

63-
mov eax, cr0
74+
let ds: u16;
75+
let es: u16;
76+
77+
unsafe {
78+
llvm_asm!("mov ax, ds
79+
mov bx, es"
80+
: "={ax}"(ds), "={bx}"(es)
81+
::: "intel", "volatile");
82+
}
83+
84+
println!("Segments stored");
85+
86+
unsafe {
87+
llvm_asm!("mov bx, 0x0
88+
mov ds, bx
89+
mov es, bx" ::: "bx" : "intel", "volatile");
90+
}
91+
92+
println!("Segments set");
93+
94+
unsafe {
95+
llvm_asm!("mov eax, cr0
6496
or al, 1
6597
mov cr0, eax
6698
67-
jmp third_stage" ::: "eax" : "intel", "volatile");
99+
push dx
100+
push cx
101+
102+
jmp third_stage" :: "{dx}"(ds), "{cx}"(es) :: "intel", "volatile");
68103
}
69104

70105
unreachable!();

src/real/stage_2/src/protected_mode.s

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
.intel_syntax noprefix
2+
.code16
3+
4+
protected_mode_switch:
5+
cli
6+
7+
lgdt [gdt32info]
8+
9+
mov eax, cr0
10+
or al, 1
11+
mov cr0, eax
12+
13+
push 0x8
14+
lea eax, [protected_mode]
15+
push eax
16+
retf
17+
18+
protected_mode:
19+
mov bx, 0x10
20+
mov ds, bx
21+
mov es, bx
22+
23+
jmp third_stage
24+
25+
gdt32info:
26+
.word gdt32_end - gdt32 - 1 # last byte in table
27+
.word gdt32 # start of table
28+
29+
gdt32:
30+
# entry 0 is always unused
31+
.quad 0
32+
codedesc:
33+
.byte 0xff
34+
.byte 0xff
35+
.byte 0
36+
.byte 0
37+
.byte 0
38+
.byte 0x9a
39+
.byte 0xcc
40+
.byte 0
41+
datadesc:
42+
.byte 0xff
43+
.byte 0xff
44+
.byte 0
45+
.byte 0
46+
.byte 0
47+
.byte 0x92
48+
.byte 0xcc
49+
.byte 0
50+
gdt32_end:

src/shared/src/console.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ lazy_static! {
99
/// Used by the `print!` and `println!` macros.
1010
pub static ref WRITER: Mutex<Writer> = Mutex::new(Writer {
1111
column_position: 0,
12-
color_code: ColorCode::new(Color::Yellow, Color::Black),
12+
color_code: ColorCode::new(Color::Red, Color::Black),
1313
buffer: unsafe { &mut *(0xb8000 as *mut Buffer) },
1414
});
1515
}
@@ -153,7 +153,7 @@ impl fmt::Write for Writer {
153153
/// Like the `print!` macro in the standard library, but prints to the VGA text buffer.
154154
#[macro_export]
155155
macro_rules! print {
156-
($($arg:tt)*) => ($crate::console::vga::_print(format_args!($($arg)*)));
156+
($($arg:tt)*) => ($crate::console::_print(format_args!($($arg)*)));
157157
}
158158

159159
/// Like the `println!` macro in the standard library, but prints to the VGA text buffer.

0 commit comments

Comments
 (0)