2017-07-04 10:11:34 +08:00
|
|
|
use core::intrinsics;
|
2016-12-18 12:01:47 +08:00
|
|
|
|
2016-08-19 00:20:24 +08:00
|
|
|
// NOTE This function and the ones below are implemented using assembly because they using a custom
|
2018-03-27 17:33:57 +08:00
|
|
|
// calling convention which can't be implemented using a normal Rust function.
|
|
|
|
// NOTE The only difference between the iOS and non-iOS versions of those functions is that the iOS
|
|
|
|
// versions use 3 leading underscores in the names of called functions instead of 2.
|
2018-07-06 02:20:34 +08:00
|
|
|
#[cfg(not(any(target_os = "ios", target_env = "msvc")))]
|
2016-08-11 12:40:35 +08:00
|
|
|
#[naked]
|
2017-06-25 03:44:00 +08:00
|
|
|
#[cfg_attr(not(feature = "mangled-names"), no_mangle)]
|
2016-08-13 16:51:54 +08:00
|
|
|
pub unsafe fn __aeabi_uidivmod() {
|
|
|
|
asm!("push {lr}
|
|
|
|
sub sp, sp, #4
|
|
|
|
mov r2, sp
|
|
|
|
bl __udivmodsi4
|
2016-08-14 00:29:38 +08:00
|
|
|
ldr r1, [sp]
|
|
|
|
add sp, sp, #4
|
2017-11-16 04:49:10 +08:00
|
|
|
pop {pc}" ::: "memory" : "volatile");
|
2016-08-11 12:40:35 +08:00
|
|
|
intrinsics::unreachable();
|
2016-08-11 08:12:37 +08:00
|
|
|
}
|
|
|
|
|
2018-03-27 17:33:57 +08:00
|
|
|
#[cfg(target_os = "ios")]
|
|
|
|
#[naked]
|
|
|
|
#[cfg_attr(not(feature = "mangled-names"), no_mangle)]
|
|
|
|
pub unsafe fn __aeabi_uidivmod() {
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(not(target_os = "ios"))]
|
2016-08-11 12:40:35 +08:00
|
|
|
#[naked]
|
2017-06-25 03:44:00 +08:00
|
|
|
#[cfg_attr(not(feature = "mangled-names"), no_mangle)]
|
2016-08-13 16:51:54 +08:00
|
|
|
pub unsafe fn __aeabi_uldivmod() {
|
2016-08-14 00:29:38 +08:00
|
|
|
asm!("push {r4, lr}
|
|
|
|
sub sp, sp, #16
|
|
|
|
add r4, sp, #8
|
|
|
|
str r4, [sp]
|
2016-08-13 16:51:54 +08:00
|
|
|
bl __udivmoddi4
|
2016-08-14 00:29:38 +08:00
|
|
|
ldr r2, [sp, #8]
|
|
|
|
ldr r3, [sp, #12]
|
|
|
|
add sp, sp, #16
|
2017-11-16 04:49:10 +08:00
|
|
|
pop {r4, pc}" ::: "memory" : "volatile");
|
2016-08-11 12:40:35 +08:00
|
|
|
intrinsics::unreachable();
|
2016-08-11 08:12:37 +08:00
|
|
|
}
|
|
|
|
|
2018-03-27 17:33:57 +08:00
|
|
|
#[cfg(target_os = "ios")]
|
|
|
|
#[naked]
|
|
|
|
#[cfg_attr(not(feature = "mangled-names"), no_mangle)]
|
|
|
|
pub unsafe 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}" ::: "memory" : "volatile");
|
|
|
|
intrinsics::unreachable();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(not(target_os = "ios"))]
|
2016-08-19 00:20:24 +08:00
|
|
|
#[naked]
|
2017-06-25 03:44:00 +08:00
|
|
|
#[cfg_attr(not(feature = "mangled-names"), no_mangle)]
|
2016-08-19 00:20:24 +08:00
|
|
|
pub unsafe fn __aeabi_idivmod() {
|
|
|
|
asm!("push {r0, r1, r4, lr}
|
2017-06-26 00:25:54 +08:00
|
|
|
bl __aeabi_idiv
|
2016-08-19 00:20:24 +08:00
|
|
|
pop {r1, r2}
|
|
|
|
muls r2, r2, r0
|
|
|
|
subs r1, r1, r2
|
2017-11-16 04:49:10 +08:00
|
|
|
pop {r4, pc}" ::: "memory" : "volatile");
|
2016-08-19 00:20:24 +08:00
|
|
|
intrinsics::unreachable();
|
|
|
|
}
|
|
|
|
|
2018-03-27 17:33:57 +08:00
|
|
|
#[cfg(target_os = "ios")]
|
|
|
|
#[naked]
|
|
|
|
#[cfg_attr(not(feature = "mangled-names"), no_mangle)]
|
|
|
|
pub unsafe 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}" ::: "memory" : "volatile");
|
|
|
|
intrinsics::unreachable();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(not(target_os = "ios"))]
|
2016-08-19 00:20:24 +08:00
|
|
|
#[naked]
|
2017-06-25 03:44:00 +08:00
|
|
|
#[cfg_attr(not(feature = "mangled-names"), no_mangle)]
|
2016-08-19 00:20:24 +08:00
|
|
|
pub unsafe 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
|
2017-11-16 04:49:10 +08:00
|
|
|
pop {r4, pc}" ::: "memory" : "volatile");
|
2016-08-19 00:20:24 +08:00
|
|
|
intrinsics::unreachable();
|
|
|
|
}
|
|
|
|
|
2018-03-27 17:33:57 +08:00
|
|
|
#[cfg(target_os = "ios")]
|
|
|
|
#[naked]
|
|
|
|
#[cfg_attr(not(feature = "mangled-names"), no_mangle)]
|
|
|
|
pub unsafe 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}" ::: "memory" : "volatile");
|
|
|
|
intrinsics::unreachable();
|
|
|
|
}
|
|
|
|
|
2016-08-08 14:20:39 +08:00
|
|
|
// FIXME: The `*4` and `*8` variants should be defined as aliases.
|
2016-08-08 04:58:05 +08:00
|
|
|
|
2017-07-01 07:06:25 +08:00
|
|
|
#[cfg(not(target_os = "ios"))]
|
2017-06-25 03:44:00 +08:00
|
|
|
#[cfg_attr(not(feature = "mangled-names"), no_mangle)]
|
2017-07-01 07:06:25 +08:00
|
|
|
#[cfg_attr(thumb, linkage = "weak")]
|
2017-02-07 22:41:26 +08:00
|
|
|
pub unsafe extern "aapcs" fn __aeabi_memcpy(dest: *mut u8, src: *const u8, n: usize) {
|
2017-07-04 10:11:34 +08:00
|
|
|
::mem::memcpy(dest, src, n);
|
2016-08-08 14:20:39 +08:00
|
|
|
}
|
2017-06-30 11:40:58 +08:00
|
|
|
|
2017-07-01 07:06:25 +08:00
|
|
|
#[cfg(not(target_os = "ios"))]
|
2017-06-25 03:44:00 +08:00
|
|
|
#[cfg_attr(not(feature = "mangled-names"), no_mangle)]
|
2017-07-01 07:06:25 +08:00
|
|
|
#[cfg_attr(thumb, linkage = "weak")]
|
2017-06-30 11:40:58 +08:00
|
|
|
pub unsafe extern "aapcs" fn __aeabi_memcpy4(dest: *mut u8, src: *const u8, mut n: usize) {
|
2019-07-13 16:55:54 +08:00
|
|
|
// We are guaranteed 4-alignment, so accessing at u32 is okay.
|
2017-06-30 11:40:58 +08:00
|
|
|
let mut dest = dest as *mut u32;
|
|
|
|
let mut src = src as *mut u32;
|
|
|
|
|
|
|
|
while n >= 4 {
|
2019-07-13 16:55:54 +08:00
|
|
|
*dest = *src;
|
2017-06-30 11:40:58 +08:00
|
|
|
dest = dest.offset(1);
|
|
|
|
src = src.offset(1);
|
|
|
|
n -= 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
__aeabi_memcpy(dest as *mut u8, src as *const u8, n);
|
2016-08-08 14:20:39 +08:00
|
|
|
}
|
2017-06-30 11:40:58 +08:00
|
|
|
|
2017-07-01 07:06:25 +08:00
|
|
|
#[cfg(not(target_os = "ios"))]
|
2017-06-25 03:44:00 +08:00
|
|
|
#[cfg_attr(not(feature = "mangled-names"), no_mangle)]
|
2017-07-01 07:06:25 +08:00
|
|
|
#[cfg_attr(thumb, linkage = "weak")]
|
2017-02-07 22:41:26 +08:00
|
|
|
pub unsafe extern "aapcs" fn __aeabi_memcpy8(dest: *mut u8, src: *const u8, n: usize) {
|
2017-06-30 11:40:58 +08:00
|
|
|
__aeabi_memcpy4(dest, src, n);
|
2016-08-08 04:58:05 +08:00
|
|
|
}
|
|
|
|
|
2017-07-01 07:06:25 +08:00
|
|
|
#[cfg(not(target_os = "ios"))]
|
2017-06-25 03:44:00 +08:00
|
|
|
#[cfg_attr(not(feature = "mangled-names"), no_mangle)]
|
2017-07-01 07:06:25 +08:00
|
|
|
#[cfg_attr(thumb, linkage = "weak")]
|
2017-02-07 22:41:26 +08:00
|
|
|
pub unsafe extern "aapcs" fn __aeabi_memmove(dest: *mut u8, src: *const u8, n: usize) {
|
2017-07-04 10:11:34 +08:00
|
|
|
::mem::memmove(dest, src, n);
|
2016-08-08 14:20:39 +08:00
|
|
|
}
|
2017-06-30 11:40:58 +08:00
|
|
|
|
2019-02-28 03:39:49 +08:00
|
|
|
#[cfg(not(any(target_os = "ios", target_env = "msvc")))]
|
2017-06-25 03:44:00 +08:00
|
|
|
#[cfg_attr(not(feature = "mangled-names"), no_mangle)]
|
2017-07-01 07:06:25 +08:00
|
|
|
#[cfg_attr(thumb, linkage = "weak")]
|
2017-02-07 22:41:26 +08:00
|
|
|
pub unsafe extern "aapcs" fn __aeabi_memmove4(dest: *mut u8, src: *const u8, n: usize) {
|
2017-06-30 11:40:58 +08:00
|
|
|
__aeabi_memmove(dest, src, n);
|
2016-08-08 14:20:39 +08:00
|
|
|
}
|
2017-06-30 11:40:58 +08:00
|
|
|
|
2019-02-28 03:39:49 +08:00
|
|
|
#[cfg(not(any(target_os = "ios", target_env = "msvc")))]
|
2017-06-25 03:44:00 +08:00
|
|
|
#[cfg_attr(not(feature = "mangled-names"), no_mangle)]
|
2017-07-01 07:06:25 +08:00
|
|
|
#[cfg_attr(thumb, linkage = "weak")]
|
2017-02-07 22:41:26 +08:00
|
|
|
pub unsafe extern "aapcs" fn __aeabi_memmove8(dest: *mut u8, src: *const u8, n: usize) {
|
2017-06-30 11:40:58 +08:00
|
|
|
__aeabi_memmove(dest, src, n);
|
2016-08-08 14:20:39 +08:00
|
|
|
}
|
2016-08-08 04:58:05 +08:00
|
|
|
|
2017-07-01 07:06:25 +08:00
|
|
|
#[cfg(not(target_os = "ios"))]
|
2017-06-25 03:44:00 +08:00
|
|
|
#[cfg_attr(not(feature = "mangled-names"), no_mangle)]
|
2017-07-01 07:06:25 +08:00
|
|
|
#[cfg_attr(thumb, linkage = "weak")]
|
2017-02-07 22:41:26 +08:00
|
|
|
pub unsafe extern "aapcs" fn __aeabi_memset(dest: *mut u8, n: usize, c: i32) {
|
2017-07-01 07:06:25 +08:00
|
|
|
// Note the different argument order
|
2017-07-04 10:11:34 +08:00
|
|
|
::mem::memset(dest, c, n);
|
2016-08-08 14:20:39 +08:00
|
|
|
}
|
2017-06-30 11:40:58 +08:00
|
|
|
|
2017-07-01 07:06:25 +08:00
|
|
|
#[cfg(not(target_os = "ios"))]
|
2017-06-25 03:44:00 +08:00
|
|
|
#[cfg_attr(not(feature = "mangled-names"), no_mangle)]
|
2017-07-01 07:06:25 +08:00
|
|
|
#[cfg_attr(thumb, linkage = "weak")]
|
2017-06-30 11:40:58 +08:00
|
|
|
pub unsafe extern "aapcs" fn __aeabi_memset4(dest: *mut u8, mut n: usize, c: i32) {
|
|
|
|
let mut dest = dest as *mut u32;
|
|
|
|
|
|
|
|
let byte = (c as u32) & 0xff;
|
|
|
|
let c = (byte << 24) | (byte << 16) | (byte << 8) | byte;
|
|
|
|
|
|
|
|
while n >= 4 {
|
2019-07-13 16:55:54 +08:00
|
|
|
*dest = c;
|
2017-06-30 11:40:58 +08:00
|
|
|
dest = dest.offset(1);
|
|
|
|
n -= 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
__aeabi_memset(dest as *mut u8, n, byte as i32);
|
2016-08-08 14:20:39 +08:00
|
|
|
}
|
2017-06-30 11:40:58 +08:00
|
|
|
|
2017-07-01 07:06:25 +08:00
|
|
|
#[cfg(not(target_os = "ios"))]
|
2017-06-25 03:44:00 +08:00
|
|
|
#[cfg_attr(not(feature = "mangled-names"), no_mangle)]
|
2017-07-01 07:06:25 +08:00
|
|
|
#[cfg_attr(thumb, linkage = "weak")]
|
2017-02-07 22:41:26 +08:00
|
|
|
pub unsafe extern "aapcs" fn __aeabi_memset8(dest: *mut u8, n: usize, c: i32) {
|
2017-06-30 11:40:58 +08:00
|
|
|
__aeabi_memset4(dest, n, c);
|
2016-08-08 04:58:05 +08:00
|
|
|
}
|
|
|
|
|
2017-07-01 07:06:25 +08:00
|
|
|
#[cfg(not(target_os = "ios"))]
|
2017-06-25 03:44:00 +08:00
|
|
|
#[cfg_attr(not(feature = "mangled-names"), no_mangle)]
|
2017-07-01 07:06:25 +08:00
|
|
|
#[cfg_attr(thumb, linkage = "weak")]
|
2017-02-07 22:41:26 +08:00
|
|
|
pub unsafe extern "aapcs" fn __aeabi_memclr(dest: *mut u8, n: usize) {
|
2017-06-30 11:40:58 +08:00
|
|
|
__aeabi_memset(dest, n, 0);
|
2016-08-08 14:20:39 +08:00
|
|
|
}
|
2017-06-30 11:40:58 +08:00
|
|
|
|
2019-02-28 03:39:49 +08:00
|
|
|
#[cfg(not(any(target_os = "ios", target_env = "msvc")))]
|
2017-06-25 03:44:00 +08:00
|
|
|
#[cfg_attr(not(feature = "mangled-names"), no_mangle)]
|
2017-07-01 07:06:25 +08:00
|
|
|
#[cfg_attr(thumb, linkage = "weak")]
|
2017-02-07 22:41:26 +08:00
|
|
|
pub unsafe extern "aapcs" fn __aeabi_memclr4(dest: *mut u8, n: usize) {
|
2017-06-30 11:40:58 +08:00
|
|
|
__aeabi_memset4(dest, n, 0);
|
2016-08-08 14:20:39 +08:00
|
|
|
}
|
2017-06-30 11:40:58 +08:00
|
|
|
|
2019-02-28 03:39:49 +08:00
|
|
|
#[cfg(not(any(target_os = "ios", target_env = "msvc")))]
|
2017-06-25 03:44:00 +08:00
|
|
|
#[cfg_attr(not(feature = "mangled-names"), no_mangle)]
|
2017-07-01 07:06:25 +08:00
|
|
|
#[cfg_attr(thumb, linkage = "weak")]
|
2017-02-07 22:41:26 +08:00
|
|
|
pub unsafe extern "aapcs" fn __aeabi_memclr8(dest: *mut u8, n: usize) {
|
2017-06-30 11:40:58 +08:00
|
|
|
__aeabi_memset4(dest, n, 0);
|
2016-08-08 14:20:39 +08:00
|
|
|
}
|