@@ -5,8 +5,8 @@ use crate::structures::gdt::SegmentSelector;
55/// Reload code segment register.
66///
77/// Note this is special since we can not directly move
8- /// to % cs. Instead we push the new segment selector
9- /// and return value on the stack and use lretq
8+ /// to cs. Instead we push the new segment selector
9+ /// and return value on the stack and use retf
1010/// to reload cs and continue at 1:.
1111///
1212/// ## Safety
@@ -18,11 +18,15 @@ pub unsafe fn set_cs(sel: SegmentSelector) {
1818 #[ cfg( feature = "inline_asm" ) ]
1919 #[ inline( always) ]
2020 unsafe fn inner ( sel : SegmentSelector ) {
21- llvm_asm ! ( "pushq $0; \
22- leaq 1f(%rip), %rax; \
23- pushq %rax; \
24- lretq; \
25- 1:" :: "ri" ( u64 :: from( sel. 0 ) ) : "rax" "memory" ) ;
21+ asm ! (
22+ "push {sel}" ,
23+ "lea {tmp}, [1f + rip]" ,
24+ "push {tmp}" ,
25+ "retfq" ,
26+ "1:" ,
27+ sel = in( reg) u64 :: from( sel. 0 ) ,
28+ tmp = lateout( reg) _,
29+ ) ;
2630 }
2731
2832 #[ cfg( not( feature = "inline_asm" ) ) ]
@@ -43,7 +47,7 @@ pub unsafe fn set_cs(sel: SegmentSelector) {
4347#[ inline]
4448pub unsafe fn load_ss ( sel : SegmentSelector ) {
4549 #[ cfg( feature = "inline_asm" ) ]
46- llvm_asm ! ( "movw $0, %ss " :: "r" ( sel. 0 ) : "memory" ) ;
50+ asm ! ( "mov ss, {0:x}" , in ( reg ) sel. 0 , options ( nostack ) ) ;
4751
4852 #[ cfg( not( feature = "inline_asm" ) ) ]
4953 crate :: asm:: x86_64_asm_load_ss ( sel. 0 ) ;
@@ -58,7 +62,7 @@ pub unsafe fn load_ss(sel: SegmentSelector) {
5862#[ inline]
5963pub unsafe fn load_ds ( sel : SegmentSelector ) {
6064 #[ cfg( feature = "inline_asm" ) ]
61- llvm_asm ! ( "movw $0, %ds " :: "r" ( sel. 0 ) : "memory" ) ;
65+ asm ! ( "mov ds, {0:x}" , in ( reg ) sel. 0 , options ( nostack ) ) ;
6266
6367 #[ cfg( not( feature = "inline_asm" ) ) ]
6468 crate :: asm:: x86_64_asm_load_ds ( sel. 0 ) ;
@@ -73,7 +77,7 @@ pub unsafe fn load_ds(sel: SegmentSelector) {
7377#[ inline]
7478pub unsafe fn load_es ( sel : SegmentSelector ) {
7579 #[ cfg( feature = "inline_asm" ) ]
76- llvm_asm ! ( "movw $0, %es " :: "r" ( sel. 0 ) : "memory" ) ;
80+ asm ! ( "mov es, {0:x}" , in ( reg ) sel. 0 , options ( nostack ) ) ;
7781
7882 #[ cfg( not( feature = "inline_asm" ) ) ]
7983 crate :: asm:: x86_64_asm_load_es ( sel. 0 ) ;
@@ -88,7 +92,7 @@ pub unsafe fn load_es(sel: SegmentSelector) {
8892#[ inline]
8993pub unsafe fn load_fs ( sel : SegmentSelector ) {
9094 #[ cfg( feature = "inline_asm" ) ]
91- llvm_asm ! ( "movw $0, %fs " :: "r" ( sel. 0 ) : "memory" ) ;
95+ asm ! ( "mov fs, {0:x}" , in ( reg ) sel. 0 , options ( nostack ) ) ;
9296
9397 #[ cfg( not( feature = "inline_asm" ) ) ]
9498 crate :: asm:: x86_64_asm_load_fs ( sel. 0 ) ;
@@ -103,7 +107,7 @@ pub unsafe fn load_fs(sel: SegmentSelector) {
103107#[ inline]
104108pub unsafe fn load_gs ( sel : SegmentSelector ) {
105109 #[ cfg( feature = "inline_asm" ) ]
106- llvm_asm ! ( "movw $0, %gs " :: "r" ( sel. 0 ) : "memory" ) ;
110+ asm ! ( "mov gs, {0:x}" , in ( reg ) sel. 0 , options ( nostack ) ) ;
107111
108112 #[ cfg( not( feature = "inline_asm" ) ) ]
109113 crate :: asm:: x86_64_asm_load_gs ( sel. 0 ) ;
@@ -118,7 +122,7 @@ pub unsafe fn load_gs(sel: SegmentSelector) {
118122#[ inline]
119123pub unsafe fn swap_gs ( ) {
120124 #[ cfg( feature = "inline_asm" ) ]
121- llvm_asm ! ( "swapgs" :: : "memory" : "volatile" ) ;
125+ asm ! ( "swapgs" , options ( nostack ) ) ;
122126
123127 #[ cfg( not( feature = "inline_asm" ) ) ]
124128 crate :: asm:: x86_64_asm_swapgs ( ) ;
@@ -130,7 +134,7 @@ pub fn cs() -> SegmentSelector {
130134 #[ cfg( feature = "inline_asm" ) ]
131135 {
132136 let segment: u16 ;
133- unsafe { llvm_asm ! ( "mov %cs, $0" : "=r" ( segment ) ) } ;
137+ unsafe { asm ! ( "mov {0:x}, cs" , out ( reg ) segment , options ( nostack , nomem ) ) } ;
134138 SegmentSelector ( segment)
135139 }
136140
@@ -155,7 +159,7 @@ pub unsafe fn wrfsbase(val: u64) {
155159 #[ cfg( feature = "inline_asm" ) ]
156160 #[ inline( always) ]
157161 unsafe fn inner ( val : u64 ) {
158- llvm_asm ! ( "wrfsbase $0" :: "r" ( val ) :: "volatile" )
162+ asm ! ( "wrfsbase {}" , in ( reg ) val , options ( nomem , nostack ) ) ;
159163 }
160164
161165 #[ cfg( not( feature = "inline_asm" ) ) ]
@@ -178,7 +182,7 @@ pub unsafe fn rdfsbase() -> u64 {
178182 #[ inline( always) ]
179183 unsafe fn inner ( ) -> u64 {
180184 let val: u64 ;
181- llvm_asm ! ( "rdfsbase $0" : "=r" ( val ) :: : "volatile" ) ;
185+ asm ! ( "rdfsbase {}" , out ( reg ) val , options ( nomem , nostack ) ) ;
182186 val
183187 }
184188
@@ -204,7 +208,7 @@ pub unsafe fn wrgsbase(val: u64) {
204208 #[ cfg( feature = "inline_asm" ) ]
205209 #[ inline( always) ]
206210 unsafe fn inner ( val : u64 ) {
207- llvm_asm ! ( "wrgsbase $0" :: "r" ( val ) :: "volatile" )
211+ asm ! ( "wrgsbase {}" , in ( reg ) val , options ( nomem , nostack ) )
208212 }
209213
210214 #[ cfg( not( feature = "inline_asm" ) ) ]
@@ -227,7 +231,7 @@ pub unsafe fn rdgsbase() -> u64 {
227231 #[ inline( always) ]
228232 unsafe fn inner ( ) -> u64 {
229233 let val: u64 ;
230- llvm_asm ! ( "rdgsbase $0" : "=r" ( val ) :: : "volatile" ) ;
234+ asm ! ( "rdgsbase {}" , out ( reg ) val , options ( nomem , nostack ) ) ;
231235 val
232236 }
233237
0 commit comments