commit
183ad55484
5 changed files with 214 additions and 219 deletions
|
|
@ -6,7 +6,7 @@
|
|||
#![allow(unused_features)]
|
||||
#![cfg_attr(thumb, no_main)]
|
||||
#![deny(dead_code)]
|
||||
#![feature(llvm_asm)]
|
||||
#![feature(test)]
|
||||
#![feature(lang_items)]
|
||||
#![feature(start)]
|
||||
#![feature(allocator_api)]
|
||||
|
|
@ -276,14 +276,9 @@ mod intrinsics {
|
|||
}
|
||||
|
||||
fn run() {
|
||||
use core::hint::black_box as bb;
|
||||
use intrinsics::*;
|
||||
|
||||
// A copy of "test::black_box". Used to prevent LLVM from optimizing away the intrinsics during LTO
|
||||
fn bb<T>(dummy: T) -> T {
|
||||
unsafe { llvm_asm!("" : : "r"(&dummy)) }
|
||||
dummy
|
||||
}
|
||||
|
||||
bb(aeabi_d2f(bb(2.)));
|
||||
bb(aeabi_d2i(bb(2.)));
|
||||
bb(aeabi_d2l(bb(2.)));
|
||||
|
|
|
|||
|
|
@ -9,135 +9,135 @@ use core::intrinsics;
|
|||
#[cfg(not(any(target_os = "ios", target_env = "msvc")))]
|
||||
#[naked]
|
||||
#[cfg_attr(not(feature = "mangled-names"), no_mangle)]
|
||||
pub unsafe fn __aeabi_uidivmod() {
|
||||
llvm_asm!("
|
||||
push {lr}
|
||||
sub sp, sp, #4
|
||||
mov r2, sp
|
||||
bl __udivmodsi4
|
||||
ldr r1, [sp]
|
||||
add sp, sp, #4
|
||||
pop {pc}
|
||||
" ::: "memory" : "volatile");
|
||||
intrinsics::unreachable();
|
||||
pub unsafe extern "C" fn __aeabi_uidivmod() {
|
||||
asm!(
|
||||
"push {{lr}}",
|
||||
"sub sp, sp, #4",
|
||||
"mov r2, sp",
|
||||
"bl __udivmodsi4",
|
||||
"ldr r1, [sp]",
|
||||
"add sp, sp, #4",
|
||||
"pop {{pc}}",
|
||||
options(noreturn)
|
||||
);
|
||||
}
|
||||
|
||||
#[cfg(target_os = "ios")]
|
||||
#[naked]
|
||||
#[cfg_attr(not(feature = "mangled-names"), no_mangle)]
|
||||
pub unsafe fn __aeabi_uidivmod() {
|
||||
llvm_asm!("
|
||||
push {lr}
|
||||
sub sp, sp, #4
|
||||
mov r2, sp
|
||||
bl ___udivmodsi4
|
||||
ldr r1, [sp]
|
||||
add sp, sp, #4
|
||||
pop {pc}
|
||||
" ::: "memory" : "volatile");
|
||||
intrinsics::unreachable();
|
||||
pub unsafe extern "C" fn __aeabi_uidivmod() {
|
||||
asm!(
|
||||
"push {{lr}}",
|
||||
"sub sp, sp, #4",
|
||||
"mov r2, sp",
|
||||
"bl ___udivmodsi4",
|
||||
"ldr r1, [sp]",
|
||||
"add sp, sp, #4",
|
||||
"pop {{pc}}",
|
||||
options(noreturn)
|
||||
);
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "ios"))]
|
||||
#[naked]
|
||||
#[cfg_attr(not(feature = "mangled-names"), no_mangle)]
|
||||
pub unsafe fn __aeabi_uldivmod() {
|
||||
llvm_asm!("
|
||||
push {r4, lr}
|
||||
sub sp, sp, #16
|
||||
add r4, sp, #8
|
||||
str r4, [sp]
|
||||
bl __udivmoddi4
|
||||
ldr r2, [sp, #8]
|
||||
ldr r3, [sp, #12]
|
||||
add sp, sp, #16
|
||||
pop {r4, pc}
|
||||
" ::: "memory" : "volatile");
|
||||
intrinsics::unreachable();
|
||||
pub unsafe extern "C" fn __aeabi_uldivmod() {
|
||||
asm!(
|
||||
"push {{r4, lr}}",
|
||||
"sub sp, sp, #16",
|
||||
"add r4, sp, #8",
|
||||
"str r4, [sp]",
|
||||
"bl __udivmoddi4",
|
||||
"ldr r2, [sp, #8]",
|
||||
"ldr r3, [sp, #12]",
|
||||
"add sp, sp, #16",
|
||||
"pop {{r4, pc}}",
|
||||
options(noreturn)
|
||||
);
|
||||
}
|
||||
|
||||
#[cfg(target_os = "ios")]
|
||||
#[naked]
|
||||
#[cfg_attr(not(feature = "mangled-names"), no_mangle)]
|
||||
pub unsafe fn __aeabi_uldivmod() {
|
||||
llvm_asm!("
|
||||
push {r4, lr}
|
||||
sub sp, sp, #16
|
||||
add r4, sp, #8
|
||||
str r4, [sp]
|
||||
bl ___udivmoddi4
|
||||
ldr r2, [sp, #8]
|
||||
ldr r3, [sp, #12]
|
||||
add sp, sp, #16
|
||||
pop {r4, pc}
|
||||
" ::: "memory" : "volatile");
|
||||
intrinsics::unreachable();
|
||||
pub unsafe extern "C" fn __aeabi_uldivmod() {
|
||||
asm!(
|
||||
"push {{r4, lr}}",
|
||||
"sub sp, sp, #16",
|
||||
"add r4, sp, #8",
|
||||
"str r4, [sp]",
|
||||
"bl ___udivmoddi4",
|
||||
"ldr r2, [sp, #8]",
|
||||
"ldr r3, [sp, #12]",
|
||||
"add sp, sp, #16",
|
||||
"pop {{r4, pc}}",
|
||||
options(noreturn)
|
||||
);
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "ios"))]
|
||||
#[naked]
|
||||
#[cfg_attr(not(feature = "mangled-names"), no_mangle)]
|
||||
pub unsafe fn __aeabi_idivmod() {
|
||||
llvm_asm!("
|
||||
push {r0, r1, r4, lr}
|
||||
bl __aeabi_idiv
|
||||
pop {r1, r2}
|
||||
muls r2, r2, r0
|
||||
subs r1, r1, r2
|
||||
pop {r4, pc}
|
||||
" ::: "memory" : "volatile");
|
||||
intrinsics::unreachable();
|
||||
pub unsafe extern "C" fn __aeabi_idivmod() {
|
||||
asm!(
|
||||
"push {{r0, r1, r4, lr}}",
|
||||
"bl __aeabi_idiv",
|
||||
"pop {{r1, r2}}",
|
||||
"muls r2, r2, r0",
|
||||
"subs r1, r1, r2",
|
||||
"pop {{r4, pc}}",
|
||||
options(noreturn)
|
||||
);
|
||||
}
|
||||
|
||||
#[cfg(target_os = "ios")]
|
||||
#[naked]
|
||||
#[cfg_attr(not(feature = "mangled-names"), no_mangle)]
|
||||
pub unsafe fn __aeabi_idivmod() {
|
||||
llvm_asm!("
|
||||
push {r0, r1, r4, lr}
|
||||
bl ___aeabi_idiv
|
||||
pop {r1, r2}
|
||||
muls r2, r2, r0
|
||||
subs r1, r1, r2
|
||||
pop {r4, pc}
|
||||
" ::: "memory" : "volatile");
|
||||
intrinsics::unreachable();
|
||||
pub unsafe extern "C" fn __aeabi_idivmod() {
|
||||
asm!(
|
||||
"push {{r0, r1, r4, lr}}",
|
||||
"bl ___aeabi_idiv",
|
||||
"pop {{r1, r2}}",
|
||||
"muls r2, r2, r0",
|
||||
"subs r1, r1, r2",
|
||||
"pop {{r4, pc}}",
|
||||
options(noreturn)
|
||||
);
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "ios"))]
|
||||
#[naked]
|
||||
#[cfg_attr(not(feature = "mangled-names"), no_mangle)]
|
||||
pub unsafe fn __aeabi_ldivmod() {
|
||||
llvm_asm!("
|
||||
push {r4, lr}
|
||||
sub sp, sp, #16
|
||||
add r4, sp, #8
|
||||
str r4, [sp]
|
||||
bl __divmoddi4
|
||||
ldr r2, [sp, #8]
|
||||
ldr r3, [sp, #12]
|
||||
add sp, sp, #16
|
||||
pop {r4, pc}
|
||||
" ::: "memory" : "volatile");
|
||||
intrinsics::unreachable();
|
||||
pub unsafe extern "C" fn __aeabi_ldivmod() {
|
||||
asm!(
|
||||
"push {{r4, lr}}",
|
||||
"sub sp, sp, #16",
|
||||
"add r4, sp, #8",
|
||||
"str r4, [sp]",
|
||||
"bl __divmoddi4",
|
||||
"ldr r2, [sp, #8]",
|
||||
"ldr r3, [sp, #12]",
|
||||
"add sp, sp, #16",
|
||||
"pop {{r4, pc}}",
|
||||
options(noreturn)
|
||||
);
|
||||
}
|
||||
|
||||
#[cfg(target_os = "ios")]
|
||||
#[naked]
|
||||
#[cfg_attr(not(feature = "mangled-names"), no_mangle)]
|
||||
pub unsafe fn __aeabi_ldivmod() {
|
||||
llvm_asm!("
|
||||
push {r4, lr}
|
||||
sub sp, sp, #16
|
||||
add r4, sp, #8
|
||||
str r4, [sp]
|
||||
bl ___divmoddi4
|
||||
ldr r2, [sp, #8]
|
||||
ldr r3, [sp, #12]
|
||||
add sp, sp, #16
|
||||
pop {r4, pc}
|
||||
" ::: "memory" : "volatile");
|
||||
intrinsics::unreachable();
|
||||
pub unsafe extern "C" fn __aeabi_ldivmod() {
|
||||
asm!(
|
||||
"push {{r4, lr}}",
|
||||
"sub sp, sp, #16",
|
||||
"add r4, sp, #8",
|
||||
"str r4, [sp]",
|
||||
"bl ___divmoddi4",
|
||||
"ldr r2, [sp, #8]",
|
||||
"ldr r3, [sp, #12]",
|
||||
"add sp, sp, #16",
|
||||
"pop {{r4, pc}}",
|
||||
options(noreturn)
|
||||
);
|
||||
}
|
||||
|
||||
// The following functions use weak linkage to allow users to override
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
#![cfg_attr(feature = "compiler-builtins", compiler_builtins)]
|
||||
#![cfg_attr(not(feature = "no-asm"), feature(asm))]
|
||||
#![feature(abi_unadjusted)]
|
||||
#![cfg_attr(not(feature = "no-asm"), feature(llvm_asm))]
|
||||
#![cfg_attr(not(feature = "no-asm"), feature(global_asm))]
|
||||
#![feature(cfg_target_has_atomic)]
|
||||
#![feature(compiler_builtins)]
|
||||
|
|
|
|||
|
|
@ -16,26 +16,27 @@ use core::intrinsics;
|
|||
))]
|
||||
#[naked]
|
||||
#[no_mangle]
|
||||
pub unsafe fn ___chkstk_ms() {
|
||||
llvm_asm!("
|
||||
push %ecx
|
||||
push %eax
|
||||
cmp $$0x1000,%eax
|
||||
lea 12(%esp),%ecx
|
||||
jb 1f
|
||||
2:
|
||||
sub $$0x1000,%ecx
|
||||
test %ecx,(%ecx)
|
||||
sub $$0x1000,%eax
|
||||
cmp $$0x1000,%eax
|
||||
ja 2b
|
||||
1:
|
||||
sub %eax,%ecx
|
||||
test %ecx,(%ecx)
|
||||
pop %eax
|
||||
pop %ecx
|
||||
ret" ::: "memory" : "volatile");
|
||||
intrinsics::unreachable();
|
||||
pub unsafe extern "C" fn ___chkstk_ms() {
|
||||
asm!(
|
||||
"push %ecx",
|
||||
"push %eax",
|
||||
"cmp $0x1000,%eax",
|
||||
"lea 12(%esp),%ecx",
|
||||
"jb 1f",
|
||||
"2:",
|
||||
"sub $0x1000,%ecx",
|
||||
"test %ecx,(%ecx)",
|
||||
"sub $0x1000,%eax",
|
||||
"cmp $0x1000,%eax",
|
||||
"ja 2b",
|
||||
"1:",
|
||||
"sub %eax,%ecx",
|
||||
"test %ecx,(%ecx)",
|
||||
"pop %eax",
|
||||
"pop %ecx",
|
||||
"ret",
|
||||
options(noreturn, att_syntax)
|
||||
);
|
||||
}
|
||||
|
||||
// FIXME: __alloca should be an alias to __chkstk
|
||||
|
|
@ -47,10 +48,11 @@ pub unsafe fn ___chkstk_ms() {
|
|||
))]
|
||||
#[naked]
|
||||
#[no_mangle]
|
||||
pub unsafe fn __alloca() {
|
||||
llvm_asm!("jmp ___chkstk // Jump to ___chkstk since fallthrough may be unreliable"
|
||||
::: "memory" : "volatile");
|
||||
intrinsics::unreachable();
|
||||
pub unsafe extern "C" fn __alloca() {
|
||||
asm!(
|
||||
"jmp ___chkstk", // Jump to ___chkstk since fallthrough may be unreliable"
|
||||
options(noreturn, att_syntax)
|
||||
);
|
||||
}
|
||||
|
||||
#[cfg(all(
|
||||
|
|
@ -61,27 +63,27 @@ pub unsafe fn __alloca() {
|
|||
))]
|
||||
#[naked]
|
||||
#[no_mangle]
|
||||
pub unsafe fn ___chkstk() {
|
||||
llvm_asm!("
|
||||
push %ecx
|
||||
cmp $$0x1000,%eax
|
||||
lea 8(%esp),%ecx // esp before calling this routine -> ecx
|
||||
jb 1f
|
||||
2:
|
||||
sub $$0x1000,%ecx
|
||||
test %ecx,(%ecx)
|
||||
sub $$0x1000,%eax
|
||||
cmp $$0x1000,%eax
|
||||
ja 2b
|
||||
1:
|
||||
sub %eax,%ecx
|
||||
test %ecx,(%ecx)
|
||||
|
||||
lea 4(%esp),%eax // load pointer to the return address into eax
|
||||
mov %ecx,%esp // install the new top of stack pointer into esp
|
||||
mov -4(%eax),%ecx // restore ecx
|
||||
push (%eax) // push return address onto the stack
|
||||
sub %esp,%eax // restore the original value in eax
|
||||
ret" ::: "memory" : "volatile");
|
||||
intrinsics::unreachable();
|
||||
pub unsafe extern "C" fn ___chkstk() {
|
||||
asm!(
|
||||
"push %ecx",
|
||||
"cmp $0x1000,%eax",
|
||||
"lea 8(%esp),%ecx", // esp before calling this routine -> ecx
|
||||
"jb 1f",
|
||||
"2:",
|
||||
"sub $0x1000,%ecx",
|
||||
"test %ecx,(%ecx)",
|
||||
"sub $0x1000,%eax",
|
||||
"cmp $0x1000,%eax",
|
||||
"ja 2b",
|
||||
"1:",
|
||||
"sub %eax,%ecx",
|
||||
"test %ecx,(%ecx)",
|
||||
"lea 4(%esp),%eax", // load pointer to the return address into eax
|
||||
"mov %ecx,%esp", // install the new top of stack pointer into esp
|
||||
"mov -4(%eax),%ecx", // restore ecx
|
||||
"push (%eax)", // push return address onto the stack
|
||||
"sub %esp,%eax", // restore the original value in eax
|
||||
"ret",
|
||||
options(noreturn, att_syntax)
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,77 +16,76 @@ use core::intrinsics;
|
|||
))]
|
||||
#[naked]
|
||||
#[no_mangle]
|
||||
pub unsafe fn ___chkstk_ms() {
|
||||
llvm_asm!("
|
||||
push %rcx
|
||||
push %rax
|
||||
cmp $$0x1000,%rax
|
||||
lea 24(%rsp),%rcx
|
||||
jb 1f
|
||||
2:
|
||||
sub $$0x1000,%rcx
|
||||
test %rcx,(%rcx)
|
||||
sub $$0x1000,%rax
|
||||
cmp $$0x1000,%rax
|
||||
ja 2b
|
||||
1:
|
||||
sub %rax,%rcx
|
||||
test %rcx,(%rcx)
|
||||
pop %rax
|
||||
pop %rcx
|
||||
ret" ::: "memory" : "volatile");
|
||||
intrinsics::unreachable();
|
||||
}
|
||||
|
||||
#[cfg(all(
|
||||
windows,
|
||||
target_env = "gnu",
|
||||
not(feature = "no-asm"),
|
||||
not(feature = "mangled-names")
|
||||
))]
|
||||
#[naked]
|
||||
#[no_mangle]
|
||||
pub unsafe fn __alloca() {
|
||||
llvm_asm!("mov %rcx,%rax // x64 _alloca is a normal function with parameter in rcx
|
||||
jmp ___chkstk // Jump to ___chkstk since fallthrough may be unreliable"
|
||||
::: "memory" : "volatile");
|
||||
intrinsics::unreachable();
|
||||
}
|
||||
|
||||
#[cfg(all(
|
||||
windows,
|
||||
target_env = "gnu",
|
||||
not(feature = "no-asm"),
|
||||
not(feature = "mangled-names")
|
||||
))]
|
||||
#[naked]
|
||||
#[no_mangle]
|
||||
pub unsafe fn ___chkstk() {
|
||||
llvm_asm!(
|
||||
"
|
||||
push %rcx
|
||||
cmp $$0x1000,%rax
|
||||
lea 16(%rsp),%rcx // rsp before calling this routine -> rcx
|
||||
jb 1f
|
||||
2:
|
||||
sub $$0x1000,%rcx
|
||||
test %rcx,(%rcx)
|
||||
sub $$0x1000,%rax
|
||||
cmp $$0x1000,%rax
|
||||
ja 2b
|
||||
1:
|
||||
sub %rax,%rcx
|
||||
test %rcx,(%rcx)
|
||||
|
||||
lea 8(%rsp),%rax // load pointer to the return address into rax
|
||||
mov %rcx,%rsp // install the new top of stack pointer into rsp
|
||||
mov -8(%rax),%rcx // restore rcx
|
||||
push (%rax) // push return address onto the stack
|
||||
sub %rsp,%rax // restore the original value in rax
|
||||
ret"
|
||||
::: "memory" : "volatile"
|
||||
pub unsafe extern "C" fn ___chkstk_ms() {
|
||||
asm!(
|
||||
"push %rcx",
|
||||
"push %rax",
|
||||
"cmp $0x1000,%rax",
|
||||
"lea 24(%rsp),%rcx",
|
||||
"jb 1f",
|
||||
"2:",
|
||||
"sub $0x1000,%rcx",
|
||||
"test %rcx,(%rcx)",
|
||||
"sub $0x1000,%rax",
|
||||
"cmp $0x1000,%rax",
|
||||
"ja 2b",
|
||||
"1:",
|
||||
"sub %rax,%rcx",
|
||||
"test %rcx,(%rcx)",
|
||||
"pop %rax",
|
||||
"pop %rcx",
|
||||
"ret",
|
||||
options(noreturn, att_syntax)
|
||||
);
|
||||
}
|
||||
|
||||
#[cfg(all(
|
||||
windows,
|
||||
target_env = "gnu",
|
||||
not(feature = "no-asm"),
|
||||
not(feature = "mangled-names")
|
||||
))]
|
||||
#[naked]
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn __alloca() {
|
||||
asm!(
|
||||
"mov %rcx,%rax", // x64 _alloca is a normal function with parameter in rcx
|
||||
"jmp ___chkstk", // Jump to ___chkstk since fallthrough may be unreliable"
|
||||
options(noreturn, att_syntax)
|
||||
);
|
||||
}
|
||||
|
||||
#[cfg(all(
|
||||
windows,
|
||||
target_env = "gnu",
|
||||
not(feature = "no-asm"),
|
||||
not(feature = "mangled-names")
|
||||
))]
|
||||
#[naked]
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn ___chkstk() {
|
||||
asm!(
|
||||
"push %rcx",
|
||||
"cmp $0x1000,%rax",
|
||||
"lea 16(%rsp),%rcx", // rsp before calling this routine -> rcx
|
||||
"jb 1f",
|
||||
"2:",
|
||||
"sub $0x1000,%rcx",
|
||||
"test %rcx,(%rcx)",
|
||||
"sub $0x1000,%rax",
|
||||
"cmp $0x1000,%rax",
|
||||
"ja 2b",
|
||||
"1:",
|
||||
"sub %rax,%rcx",
|
||||
"test %rcx,(%rcx)",
|
||||
"lea 8(%rsp),%rax", // load pointer to the return address into rax
|
||||
"mov %rcx,%rsp", // install the new top of stack pointer into rsp
|
||||
"mov -8(%rax),%rcx", // restore rcx
|
||||
"push (%rax)", // push return address onto the stack
|
||||
"sub %rsp,%rax", // restore the original value in rax
|
||||
"ret",
|
||||
options(noreturn, att_syntax)
|
||||
);
|
||||
intrinsics::unreachable();
|
||||
}
|
||||
|
||||
// HACK(https://github.com/rust-lang/rust/issues/62785): x86_64-unknown-uefi needs special LLVM
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue