arm.rs 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. use core::intrinsics;
  2. // NOTE This function and the one below are implemented using assembly because they using a custom
  3. // calling convention which can't be implemented using a normal Rust function
  4. #[naked]
  5. #[cfg_attr(not(test), no_mangle)]
  6. pub unsafe fn __aeabi_uidivmod() {
  7. asm!("push {lr}
  8. sub sp, sp, #4
  9. mov r2, sp
  10. bl __udivmodsi4
  11. ldr r1, [sp]
  12. add sp, sp, #4
  13. pop {pc}");
  14. intrinsics::unreachable();
  15. }
  16. #[naked]
  17. #[cfg_attr(not(test), no_mangle)]
  18. pub unsafe fn __aeabi_uldivmod() {
  19. asm!("push {r4, lr}
  20. sub sp, sp, #16
  21. add r4, sp, #8
  22. str r4, [sp]
  23. bl __udivmoddi4
  24. ldr r2, [sp, #8]
  25. ldr r3, [sp, #12]
  26. add sp, sp, #16
  27. pop {r4, pc}");
  28. intrinsics::unreachable();
  29. }
  30. extern "C" {
  31. fn memcpy(dest: *mut u8, src: *const u8, n: usize) -> *mut u8;
  32. fn memmove(dest: *mut u8, src: *const u8, n: usize) -> *mut u8;
  33. fn memset(dest: *mut u8, c: i32, n: usize) -> *mut u8;
  34. }
  35. // FIXME: The `*4` and `*8` variants should be defined as aliases.
  36. #[cfg_attr(not(test), no_mangle)]
  37. pub unsafe extern "C" fn __aeabi_memcpy(dest: *mut u8, src: *const u8, n: usize) {
  38. memcpy(dest, src, n);
  39. }
  40. #[cfg_attr(not(test), no_mangle)]
  41. pub unsafe extern "C" fn __aeabi_memcpy4(dest: *mut u8, src: *const u8, n: usize) {
  42. memcpy(dest, src, n);
  43. }
  44. #[cfg_attr(not(test), no_mangle)]
  45. pub unsafe extern "C" fn __aeabi_memcpy8(dest: *mut u8, src: *const u8, n: usize) {
  46. memcpy(dest, src, n);
  47. }
  48. #[cfg_attr(not(test), no_mangle)]
  49. pub unsafe extern "C" fn __aeabi_memmove(dest: *mut u8, src: *const u8, n: usize) {
  50. memmove(dest, src, n);
  51. }
  52. #[cfg_attr(not(test), no_mangle)]
  53. pub unsafe extern "C" fn __aeabi_memmove4(dest: *mut u8, src: *const u8, n: usize) {
  54. memmove(dest, src, n);
  55. }
  56. #[cfg_attr(not(test), no_mangle)]
  57. pub unsafe extern "C" fn __aeabi_memmove8(dest: *mut u8, src: *const u8, n: usize) {
  58. memmove(dest, src, n);
  59. }
  60. // Note the different argument order
  61. #[cfg_attr(not(test), no_mangle)]
  62. pub unsafe extern "C" fn __aeabi_memset(dest: *mut u8, n: usize, c: i32) {
  63. memset(dest, c, n);
  64. }
  65. #[cfg_attr(not(test), no_mangle)]
  66. pub unsafe extern "C" fn __aeabi_memset4(dest: *mut u8, n: usize, c: i32) {
  67. memset(dest, c, n);
  68. }
  69. #[cfg_attr(not(test), no_mangle)]
  70. pub unsafe extern "C" fn __aeabi_memset8(dest: *mut u8, n: usize, c: i32) {
  71. memset(dest, c, n);
  72. }
  73. #[cfg_attr(not(test), no_mangle)]
  74. pub unsafe extern "C" fn __aeabi_memclr(dest: *mut u8, n: usize) {
  75. memset(dest, 0, n);
  76. }
  77. #[cfg_attr(not(test), no_mangle)]
  78. pub unsafe extern "C" fn __aeabi_memclr4(dest: *mut u8, n: usize) {
  79. memset(dest, 0, n);
  80. }
  81. #[cfg_attr(not(test), no_mangle)]
  82. pub unsafe extern "C" fn __aeabi_memclr8(dest: *mut u8, n: usize) {
  83. memset(dest, 0, n);
  84. }