Load GDT
This commit is contained in:
parent
5de81b0166
commit
37f8c7d1ae
2 changed files with 73 additions and 3 deletions
|
@ -1 +1,72 @@
|
|||
pub fn setup_gdt() {}
|
||||
use core::{arch::asm, mem::size_of};
|
||||
|
||||
#[repr(C)]
|
||||
struct GDTEntry {
|
||||
limit_low: u16,
|
||||
base_low: u16,
|
||||
base_middle: u8,
|
||||
access: u8,
|
||||
flags: u8,
|
||||
base_high: u8,
|
||||
}
|
||||
#[repr(C)]
|
||||
struct GDT {
|
||||
entries: [GDTEntry; 3],
|
||||
}
|
||||
|
||||
#[repr(C, packed)]
|
||||
struct GDTDescriptor {
|
||||
limit: u16,
|
||||
base: u64,
|
||||
}
|
||||
|
||||
const GDT: GDT = GDT {
|
||||
entries: [
|
||||
GDTEntry {
|
||||
limit_low: 0,
|
||||
base_low: 0,
|
||||
base_middle: 0,
|
||||
access: 0,
|
||||
flags: 0,
|
||||
base_high: 0,
|
||||
},
|
||||
GDTEntry {
|
||||
limit_low: 0,
|
||||
base_low: 0,
|
||||
base_middle: 0,
|
||||
access: 0x9a,
|
||||
flags: 0x20,
|
||||
base_high: 0,
|
||||
},
|
||||
GDTEntry {
|
||||
limit_low: 0,
|
||||
base_low: 0,
|
||||
base_middle: 0,
|
||||
access: 0x92,
|
||||
flags: 0,
|
||||
base_high: 0,
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
pub fn setup_gdt() {
|
||||
let gdt_descriptor = GDTDescriptor {
|
||||
limit: (size_of::<GDT>() - 1) as u16,
|
||||
base: GDT.entries.as_ptr() as u64,
|
||||
};
|
||||
unsafe {
|
||||
asm!("
|
||||
lgdt ({})
|
||||
push $8
|
||||
push $1f
|
||||
lretq
|
||||
1:
|
||||
mov $0x10, %ax
|
||||
mov %ax, %ds
|
||||
mov %ax, %es
|
||||
mov %ax, %fs
|
||||
mov %ax, %gs
|
||||
mov %ax, %ss
|
||||
", in(reg) &gdt_descriptor, out("rax") _, options(att_syntax));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,8 +21,7 @@ bitfield! {
|
|||
address, set_address: 63, 12;
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[repr(align(0x1000))]
|
||||
#[repr(C, align(0x1000))]
|
||||
struct PageTable {
|
||||
entries: [PageEntry; 512],
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue