@@ -5,8 +5,8 @@ use crate::structures::gdt::SegmentSelector;
5
5
/// Reload code segment register.
6
6
///
7
7
/// 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
10
10
/// to reload cs and continue at 1:.
11
11
///
12
12
/// ## Safety
@@ -18,11 +18,15 @@ pub unsafe fn set_cs(sel: SegmentSelector) {
18
18
#[ cfg( feature = "inline_asm" ) ]
19
19
#[ inline( always) ]
20
20
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
+ ) ;
26
30
}
27
31
28
32
#[ cfg( not( feature = "inline_asm" ) ) ]
@@ -43,7 +47,7 @@ pub unsafe fn set_cs(sel: SegmentSelector) {
43
47
#[ inline]
44
48
pub unsafe fn load_ss ( sel : SegmentSelector ) {
45
49
#[ 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 ) ) ;
47
51
48
52
#[ cfg( not( feature = "inline_asm" ) ) ]
49
53
crate :: asm:: x86_64_asm_load_ss ( sel. 0 ) ;
@@ -58,7 +62,7 @@ pub unsafe fn load_ss(sel: SegmentSelector) {
58
62
#[ inline]
59
63
pub unsafe fn load_ds ( sel : SegmentSelector ) {
60
64
#[ 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 ) ) ;
62
66
63
67
#[ cfg( not( feature = "inline_asm" ) ) ]
64
68
crate :: asm:: x86_64_asm_load_ds ( sel. 0 ) ;
@@ -73,7 +77,7 @@ pub unsafe fn load_ds(sel: SegmentSelector) {
73
77
#[ inline]
74
78
pub unsafe fn load_es ( sel : SegmentSelector ) {
75
79
#[ 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 ) ) ;
77
81
78
82
#[ cfg( not( feature = "inline_asm" ) ) ]
79
83
crate :: asm:: x86_64_asm_load_es ( sel. 0 ) ;
@@ -88,7 +92,7 @@ pub unsafe fn load_es(sel: SegmentSelector) {
88
92
#[ inline]
89
93
pub unsafe fn load_fs ( sel : SegmentSelector ) {
90
94
#[ 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 ) ) ;
92
96
93
97
#[ cfg( not( feature = "inline_asm" ) ) ]
94
98
crate :: asm:: x86_64_asm_load_fs ( sel. 0 ) ;
@@ -103,7 +107,7 @@ pub unsafe fn load_fs(sel: SegmentSelector) {
103
107
#[ inline]
104
108
pub unsafe fn load_gs ( sel : SegmentSelector ) {
105
109
#[ 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 ) ) ;
107
111
108
112
#[ cfg( not( feature = "inline_asm" ) ) ]
109
113
crate :: asm:: x86_64_asm_load_gs ( sel. 0 ) ;
@@ -118,7 +122,7 @@ pub unsafe fn load_gs(sel: SegmentSelector) {
118
122
#[ inline]
119
123
pub unsafe fn swap_gs ( ) {
120
124
#[ cfg( feature = "inline_asm" ) ]
121
- llvm_asm ! ( "swapgs" :: : "memory" : "volatile" ) ;
125
+ asm ! ( "swapgs" , options ( nostack ) ) ;
122
126
123
127
#[ cfg( not( feature = "inline_asm" ) ) ]
124
128
crate :: asm:: x86_64_asm_swapgs ( ) ;
@@ -130,7 +134,7 @@ pub fn cs() -> SegmentSelector {
130
134
#[ cfg( feature = "inline_asm" ) ]
131
135
{
132
136
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 ) ) } ;
134
138
SegmentSelector ( segment)
135
139
}
136
140
@@ -155,7 +159,7 @@ pub unsafe fn wrfsbase(val: u64) {
155
159
#[ cfg( feature = "inline_asm" ) ]
156
160
#[ inline( always) ]
157
161
unsafe fn inner ( val : u64 ) {
158
- llvm_asm ! ( "wrfsbase $0" :: "r" ( val ) :: "volatile" )
162
+ asm ! ( "wrfsbase {}" , in ( reg ) val , options ( nomem , nostack ) ) ;
159
163
}
160
164
161
165
#[ cfg( not( feature = "inline_asm" ) ) ]
@@ -178,7 +182,7 @@ pub unsafe fn rdfsbase() -> u64 {
178
182
#[ inline( always) ]
179
183
unsafe fn inner ( ) -> u64 {
180
184
let val: u64 ;
181
- llvm_asm ! ( "rdfsbase $0" : "=r" ( val ) :: : "volatile" ) ;
185
+ asm ! ( "rdfsbase {}" , out ( reg ) val , options ( nomem , nostack ) ) ;
182
186
val
183
187
}
184
188
@@ -204,7 +208,7 @@ pub unsafe fn wrgsbase(val: u64) {
204
208
#[ cfg( feature = "inline_asm" ) ]
205
209
#[ inline( always) ]
206
210
unsafe fn inner ( val : u64 ) {
207
- llvm_asm ! ( "wrgsbase $0" :: "r" ( val ) :: "volatile" )
211
+ asm ! ( "wrgsbase {}" , in ( reg ) val , options ( nomem , nostack ) )
208
212
}
209
213
210
214
#[ cfg( not( feature = "inline_asm" ) ) ]
@@ -227,7 +231,7 @@ pub unsafe fn rdgsbase() -> u64 {
227
231
#[ inline( always) ]
228
232
unsafe fn inner ( ) -> u64 {
229
233
let val: u64 ;
230
- llvm_asm ! ( "rdgsbase $0" : "=r" ( val ) :: : "volatile" ) ;
234
+ asm ! ( "rdgsbase {}" , out ( reg ) val , options ( nomem , nostack ) ) ;
231
235
val
232
236
}
233
237
0 commit comments