Implement TSS
This commit is contained in:
parent
0983b36cc7
commit
36488ea49e
1 changed files with 43 additions and 0 deletions
|
@ -11,9 +11,31 @@ struct GDTEntry {
|
|||
flags: u8,
|
||||
base_high: u8,
|
||||
}
|
||||
#[repr(C, packed)]
|
||||
struct TSS {
|
||||
reserved1: u32,
|
||||
rsp: [u64; 3],
|
||||
reserved2: u64,
|
||||
ist: [u64; 7],
|
||||
reserved3: u64,
|
||||
reserved4: u16,
|
||||
iopb_offset: u16,
|
||||
}
|
||||
#[repr(C)]
|
||||
struct TSSDescriptor {
|
||||
limit_low: u16,
|
||||
base_low: u16,
|
||||
base_middle: u8,
|
||||
access: u8,
|
||||
flags: u8,
|
||||
base_high: u8,
|
||||
base_upper: u32,
|
||||
reserved: u32,
|
||||
}
|
||||
#[repr(C)]
|
||||
struct GDT {
|
||||
entries: [GDTEntry; 5],
|
||||
tss: TSSDescriptor,
|
||||
}
|
||||
#[repr(C, packed)]
|
||||
struct GDTDescriptor {
|
||||
|
@ -22,6 +44,15 @@ struct GDTDescriptor {
|
|||
}
|
||||
|
||||
pub fn setup_gdt() {
|
||||
let tss = Box::leak(Box::new(TSS {
|
||||
reserved1: 0,
|
||||
rsp: [0; 3],
|
||||
reserved2: 0,
|
||||
ist: [0; 7],
|
||||
reserved3: 0,
|
||||
reserved4: 0,
|
||||
iopb_offset: size_of::<TSS>() as u16,
|
||||
}));
|
||||
let gdt = Box::leak(Box::new(GDT {
|
||||
entries: [
|
||||
GDTEntry {
|
||||
|
@ -65,6 +96,16 @@ pub fn setup_gdt() {
|
|||
base_high: 0,
|
||||
},
|
||||
],
|
||||
tss: TSSDescriptor {
|
||||
limit_low: (size_of::<TSS>() - 1) as u16,
|
||||
base_low: tss as *const TSS as u16,
|
||||
base_middle: (tss as *const TSS as u64 >> 16) as u8,
|
||||
access: 0x89,
|
||||
flags: ((size_of::<TSS>() - 1) >> 16) as u8,
|
||||
base_high: (tss as *const TSS as u64 >> 24) as u8,
|
||||
base_upper: (tss as *const TSS as u64 >> 32) as u32,
|
||||
reserved: 0,
|
||||
},
|
||||
}));
|
||||
let gdt_descriptor = Box::leak(Box::new(GDTDescriptor {
|
||||
limit: (size_of::<GDT>() - 1) as u16,
|
||||
|
@ -83,6 +124,8 @@ pub fn setup_gdt() {
|
|||
mov %ax, %fs
|
||||
mov %ax, %gs
|
||||
mov %ax, %ss
|
||||
mov $0x28, %ax
|
||||
ltr %ax
|
||||
", in(reg) gdt_descriptor, out("rax") _, options(att_syntax));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue