@@ -48,7 +48,9 @@ impl GlobalDescriptorTable {
48
48
limit : ( self . table . len ( ) * size_of :: < u64 > ( ) - 1 ) as u16 ,
49
49
} ;
50
50
51
- llvm_asm ! ( "lgdt ($0)" :: "r" ( & ptr) : "memory" ) ;
51
+ unsafe {
52
+ llvm_asm ! ( "lgdt ($0)" :: "r" ( & ptr) : "memory" ) ;
53
+ }
52
54
}
53
55
54
56
#[ inline]
@@ -87,6 +89,9 @@ bitflags! {
87
89
88
90
/// The DPL for this descriptor is Ring 3
89
91
const DPL_RING_3 = 3 << 45 ;
92
+
93
+ /// If set, limit is in 4k pages
94
+ const GRANULARITY = 1 << 55 ;
90
95
}
91
96
}
92
97
@@ -98,7 +103,7 @@ impl Descriptor {
98
103
99
104
let flags =
100
105
Flags :: USER_SEGMENT | Flags :: PRESENT | Flags :: EXECUTABLE | Flags :: READABLE_WRITABLE ;
101
- Descriptor ( flags. bits ( ) )
106
+ Descriptor ( flags. bits ( ) ) . with_flat_limit ( )
102
107
}
103
108
104
109
/// Creates a segment descriptor for a protected mode kernel data segment.
@@ -107,7 +112,7 @@ impl Descriptor {
107
112
use self :: DescriptorFlags as Flags ;
108
113
109
114
let flags = Flags :: USER_SEGMENT | Flags :: PRESENT | Flags :: READABLE_WRITABLE ;
110
- Descriptor ( flags. bits ( ) )
115
+ Descriptor ( flags. bits ( ) ) . with_flat_limit ( )
111
116
}
112
117
113
118
/// Creates a segment descriptor for a protected mode ring 3 data segment.
@@ -117,7 +122,7 @@ impl Descriptor {
117
122
118
123
let flags =
119
124
Flags :: USER_SEGMENT | Flags :: PRESENT | Flags :: READABLE_WRITABLE | Flags :: DPL_RING_3 ;
120
- Descriptor ( flags. bits ( ) )
125
+ Descriptor ( flags. bits ( ) ) . with_flat_limit ( )
121
126
}
122
127
123
128
/// Creates a segment descriptor for a protected mode ring 3 code segment.
@@ -130,7 +135,7 @@ impl Descriptor {
130
135
| Flags :: EXECUTABLE
131
136
| Flags :: DPL_RING_3
132
137
| Flags :: READABLE_WRITABLE ;
133
- Descriptor ( flags. bits ( ) )
138
+ Descriptor ( flags. bits ( ) ) . with_flat_limit ( )
134
139
}
135
140
136
141
/// Creates a TSS system descriptor for the given TSS.
@@ -152,6 +157,17 @@ impl Descriptor {
152
157
153
158
Descriptor ( val)
154
159
}
160
+
161
+ fn with_flat_limit ( mut self ) -> Self {
162
+ // limit_low
163
+ self . 0 . set_bits ( 0 ..16 , 0xffff ) ;
164
+ // limit high
165
+ self . 0 . set_bits ( 48 ..52 , 0xff ) ;
166
+ // granularity
167
+ self . 0 |= DescriptorFlags :: GRANULARITY . bits ( ) ;
168
+
169
+ self
170
+ }
155
171
}
156
172
157
173
#[ derive( Debug , Clone , Copy ) ]
@@ -224,7 +240,7 @@ pub struct Stack {
224
240
}
225
241
226
242
impl Stack {
227
- fn zero ( ) -> Self {
243
+ const fn zero ( ) -> Self {
228
244
Stack { esp : 0 , ss : 0 }
229
245
}
230
246
}
0 commit comments