@@ -20,6 +20,17 @@ use core::mem;
2020use super :: exception:: entry:: init_idt;
2121use super :: machine:: { GDT , GdtEntry , GdtPointer , ProcCtrl , TSS } ;
2222
23+ /// See AMD64 Architecture Programmer's Manual, Volume 2: System Programming
24+ /// Section 4: Segmented Virtual Memory
25+ /// §4.6: Descriptor Tables
26+ /// for the functions of the GDT.
27+ ///
28+ /// Hyperlight's GDT consists of:
29+ /// - A null first entry, which is architecturally required
30+ /// - A single code segment descriptor, used for all code accesses
31+ /// - A single data segment descriptor, used for all data accesses
32+ /// - A TSS System descriptor that outlines the location of the TSS
33+ /// (see [`init_tss`], below)
2334#[ repr( C ) ]
2435struct HyperlightGDT {
2536 null : GdtEntry ,
@@ -68,6 +79,14 @@ unsafe fn init_gdt(pc: *mut ProcCtrl) {
6879 }
6980}
7081
82+ /// Hyperlight's TSS contains only a single IST entry, which is used
83+ /// to set up the stack switch to the exception stack whenever we take
84+ /// an exception (including page faults, which are important, since
85+ /// the fault might be due to needing to grow the stack!)
86+ ///
87+ /// This function sets up the TSS and then points the processor at the
88+ /// system segment descriptor, initialized in [`init_gdt`] above,
89+ /// which describes the location of the TSS.
7190unsafe fn init_tss ( pc : * mut ProcCtrl ) {
7291 unsafe {
7392 let tss_ptr = & raw mut ( * pc) . tss ;
@@ -77,7 +96,6 @@ unsafe fn init_tss(pc: *mut ProcCtrl) {
7796 - hyperlight_common:: layout:: SCRATCH_TOP_EXN_STACK_OFFSET
7897 + 1 ;
7998 ist1_ptr. write_volatile ( exn_stack. to_ne_bytes ( ) ) ;
80- // see init_gdt: 0x18 points to the tss set up above
8199 asm ! (
82100 "ltr ax" ,
83101 in( "ax" ) core:: mem:: offset_of!( HyperlightGDT , tss) ,
0 commit comments