Skip to content

Commit 1bb527a

Browse files
authored
Add more comments and make the src/arch/* files more consistent. (#43)
1 parent 4d48f8b commit 1bb527a

5 files changed

Lines changed: 41 additions & 17 deletions

File tree

src/arch/aarch64.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,20 +50,26 @@ pub(super) unsafe fn clone(
5050
}
5151

5252
/// Write a value to the platform thread-pointer register.
53-
#[cfg(feature = "origin-thread")]
53+
#[cfg(all(
54+
feature = "origin-thread",
55+
any(feature = "origin-start", feature = "external-start")
56+
))]
5457
#[inline]
5558
pub(super) unsafe fn set_thread_pointer(ptr: *mut c_void) {
56-
asm!("msr tpidr_el0,{0}", in(reg) ptr);
59+
asm!("msr tpidr_el0,{}", in(reg) ptr);
5760
debug_assert_eq!(get_thread_pointer(), ptr);
5861
}
5962

6063
/// Read the value of the platform thread-pointer register.
61-
#[cfg(feature = "origin-thread")]
64+
#[cfg(all(
65+
feature = "origin-thread",
66+
any(feature = "origin-start", feature = "external-start")
67+
))]
6268
#[inline]
6369
pub(super) fn get_thread_pointer() -> *mut c_void {
6470
let ptr;
6571
unsafe {
66-
asm!("mrs {0},tpidr_el0", out(reg) ptr, options(nostack, preserves_flags, readonly));
72+
asm!("mrs {},tpidr_el0", out(reg) ptr, options(nostack, preserves_flags, readonly));
6773
}
6874
ptr
6975
}

src/arch/arm.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,20 +51,26 @@ pub(super) unsafe fn clone(
5151
}
5252

5353
/// Write a value to the platform thread-pointer register.
54-
#[cfg(feature = "origin-thread")]
54+
#[cfg(all(
55+
feature = "origin-thread",
56+
any(feature = "origin-start", feature = "external-start")
57+
))]
5558
#[inline]
5659
pub(super) unsafe fn set_thread_pointer(ptr: *mut c_void) {
5760
rustix::runtime::arm_set_tls(ptr).expect("arm_set_tls");
5861
debug_assert_eq!(get_thread_pointer(), ptr);
5962
}
6063

6164
/// Read the value of the platform thread-pointer register.
62-
#[cfg(feature = "origin-thread")]
65+
#[cfg(all(
66+
feature = "origin-thread",
67+
any(feature = "origin-start", feature = "external-start")
68+
))]
6369
#[inline]
6470
pub(super) fn get_thread_pointer() -> *mut c_void {
6571
let ptr;
6672
unsafe {
67-
asm!("mrc p15,0,{0},c13,c0,3", out(reg) ptr);
73+
asm!("mrc p15,0,{},c13,c0,3", out(reg) ptr);
6874
}
6975
ptr
7076
}

src/arch/riscv64.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,20 +47,26 @@ pub(super) unsafe fn clone(
4747
}
4848

4949
/// Write a value to the platform thread-pointer register.
50-
#[cfg(feature = "origin-thread")]
50+
#[cfg(all(
51+
feature = "origin-thread",
52+
any(feature = "origin-start", feature = "external-start")
53+
))]
5154
#[inline]
5255
pub(super) unsafe fn set_thread_pointer(ptr: *mut c_void) {
53-
asm!("mv tp,{0}", in(reg) ptr);
56+
asm!("mv tp,{}", in(reg) ptr);
5457
debug_assert_eq!(get_thread_pointer(), ptr);
5558
}
5659

5760
/// Read the value of the platform thread-pointer register.
58-
#[cfg(feature = "origin-thread")]
61+
#[cfg(all(
62+
feature = "origin-thread",
63+
any(feature = "origin-start", feature = "external-start")
64+
))]
5965
#[inline]
6066
pub(super) fn get_thread_pointer() -> *mut c_void {
6167
let ptr;
6268
unsafe {
63-
asm!("mv {0},tp", out(reg) ptr, options(nostack, preserves_flags, readonly));
69+
asm!("mv {},tp", out(reg) ptr, options(nostack, preserves_flags, readonly));
6470
}
6571
ptr
6672
}

src/arch/x86.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,10 @@ pub(super) unsafe fn clone(
8989
}
9090

9191
/// Write a value to the platform thread-pointer register.
92-
#[cfg(feature = "origin-thread")]
92+
#[cfg(all(
93+
feature = "origin-thread",
94+
any(feature = "origin-start", feature = "external-start")
95+
))]
9396
#[inline]
9497
pub(super) unsafe fn set_thread_pointer(ptr: *mut c_void) {
9598
let mut user_desc = rustix::runtime::UserDesc {
@@ -113,12 +116,15 @@ pub(super) unsafe fn set_thread_pointer(ptr: *mut c_void) {
113116
}
114117

115118
/// Read the value of the platform thread-pointer register.
116-
#[cfg(feature = "origin-thread")]
119+
#[cfg(all(
120+
feature = "origin-thread",
121+
any(feature = "origin-start", feature = "external-start")
122+
))]
117123
#[inline]
118124
pub(super) fn get_thread_pointer() -> *mut c_void {
119125
let ptr;
120126
unsafe {
121-
asm!("mov {0},DWORD PTR gs:0", out(reg) ptr, options(nostack, preserves_flags, readonly));
127+
asm!("mov {},DWORD PTR gs:0", out(reg) ptr, options(nostack, preserves_flags, readonly));
122128
}
123129
ptr
124130
}

src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,9 @@ unsafe extern "C" fn _start() -> ! {
100100
#[cfg(target_arch = "x86")]
101101
asm!(
102102
"mov eax, esp", // Save the incoming `esp` value.
103-
"push ebp", // Pad for alignment.
104-
"push ebp", // Pad for alignment.
105-
"push ebp", // Pad for alignment.
103+
"push ebp", // Pad for stack pointer alignment.
104+
"push ebp", // Pad for stack pointer alignment.
105+
"push ebp", // Pad for stack pointer alignment.
106106
"push eax", // Pass saved the incoming `esp` as the arg to `entry`.
107107
"push ebp", // Set the return address to zero.
108108
"jmp {entry}", // Jump to `entry`.

0 commit comments

Comments
 (0)