1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
|
From e6def544358afd5648a428d2e02c147a1f901048 Mon Sep 17 00:00:00 2001
From: Szabolcs Nagy <nsz@port70.net>
Date: Tue, 21 Feb 2017 00:07:34 +0000
Subject: [PATCH 51/51] fix arm run-time abi string functions
in arm rtabi these __aeabi_* functions have special abi (they are
only allowed to clobber r0,r1,r2,r3,ip,lr,cpsr), so they cannot
be simple wrappers around normal string functions (which may
clobber other registers), the safest solution is to write them in
asm, a minimalistic implementation works because these are not
supposed to be emitted by compilers or used in general.
---
src/string/arm/__aeabi_memclr.c | 9 --------
src/string/arm/__aeabi_memcpy.c | 9 --------
src/string/arm/__aeabi_memcpy.s | 45 ++++++++++++++++++++++++++++++++++++++++
src/string/arm/__aeabi_memmove.c | 9 --------
src/string/arm/__aeabi_memset.c | 9 --------
src/string/arm/__aeabi_memset.s | 31 +++++++++++++++++++++++++++
6 files changed, 76 insertions(+), 36 deletions(-)
delete mode 100644 src/string/arm/__aeabi_memclr.c
delete mode 100644 src/string/arm/__aeabi_memcpy.c
create mode 100644 src/string/arm/__aeabi_memcpy.s
delete mode 100644 src/string/arm/__aeabi_memmove.c
delete mode 100644 src/string/arm/__aeabi_memset.c
create mode 100644 src/string/arm/__aeabi_memset.s
diff --git a/src/string/arm/__aeabi_memclr.c b/src/string/arm/__aeabi_memclr.c
deleted file mode 100644
index a25306d7..00000000
--- a/src/string/arm/__aeabi_memclr.c
+++ /dev/null
@@ -1,9 +0,0 @@
-#include <string.h>
-#include "libc.h"
-
-void __aeabi_memclr(void *dest, size_t n)
-{
- memset(dest, 0, n);
-}
-weak_alias(__aeabi_memclr, __aeabi_memclr4);
-weak_alias(__aeabi_memclr, __aeabi_memclr8);
diff --git a/src/string/arm/__aeabi_memcpy.c b/src/string/arm/__aeabi_memcpy.c
deleted file mode 100644
index 4ae5c777..00000000
--- a/src/string/arm/__aeabi_memcpy.c
+++ /dev/null
@@ -1,9 +0,0 @@
-#include <string.h>
-#include "libc.h"
-
-void __aeabi_memcpy(void *restrict dest, const void *restrict src, size_t n)
-{
- memcpy(dest, src, n);
-}
-weak_alias(__aeabi_memcpy, __aeabi_memcpy4);
-weak_alias(__aeabi_memcpy, __aeabi_memcpy8);
diff --git a/src/string/arm/__aeabi_memcpy.s b/src/string/arm/__aeabi_memcpy.s
new file mode 100644
index 00000000..3a527e41
--- /dev/null
+++ b/src/string/arm/__aeabi_memcpy.s
@@ -0,0 +1,45 @@
+.syntax unified
+
+.global __aeabi_memcpy8
+.global __aeabi_memcpy4
+.global __aeabi_memcpy
+.global __aeabi_memmove8
+.global __aeabi_memmove4
+.global __aeabi_memmove
+
+.type __aeabi_memcpy8,%function
+.type __aeabi_memcpy4,%function
+.type __aeabi_memcpy,%function
+.type __aeabi_memmove8,%function
+.type __aeabi_memmove4,%function
+.type __aeabi_memmove,%function
+
+__aeabi_memmove8:
+__aeabi_memmove4:
+__aeabi_memmove:
+ cmp r0, r1
+ bls 3f
+ cmp r2, #0
+ beq 2f
+ adds r0, r0, r2
+ adds r2, r1, r2
+1: subs r2, r2, #1
+ ldrb r3, [r2]
+ subs r0, r0, #1
+ strb r3, [r0]
+ cmp r1, r2
+ bne 1b
+2: bx lr
+__aeabi_memcpy8:
+__aeabi_memcpy4:
+__aeabi_memcpy:
+3: cmp r2, #0
+ beq 2f
+ adds r2, r1, r2
+1: ldrb r3, [r1]
+ adds r1, r1, #1
+ strb r3, [r0]
+ adds r0, r0, #1
+ cmp r1, r2
+ bne 1b
+2: bx lr
diff --git a/src/string/arm/__aeabi_memmove.c b/src/string/arm/__aeabi_memmove.c
deleted file mode 100644
index 951e7d39..00000000
--- a/src/string/arm/__aeabi_memmove.c
+++ /dev/null
@@ -1,9 +0,0 @@
-#include <string.h>
-#include "libc.h"
-
-void __aeabi_memmove(void *dest, const void *src, size_t n)
-{
- memmove(dest, src, n);
-}
-weak_alias(__aeabi_memmove, __aeabi_memmove4);
-weak_alias(__aeabi_memmove, __aeabi_memmove8);
diff --git a/src/string/arm/__aeabi_memset.c b/src/string/arm/__aeabi_memset.c
deleted file mode 100644
index 89299757..00000000
--- a/src/string/arm/__aeabi_memset.c
+++ /dev/null
@@ -1,9 +0,0 @@
-#include <string.h>
-#include "libc.h"
-
-void __aeabi_memset(void *dest, size_t n, int c)
-{
- memset(dest, c, n);
-}
-weak_alias(__aeabi_memset, __aeabi_memset4);
-weak_alias(__aeabi_memset, __aeabi_memset8);
diff --git a/src/string/arm/__aeabi_memset.s b/src/string/arm/__aeabi_memset.s
new file mode 100644
index 00000000..f9f60583
--- /dev/null
+++ b/src/string/arm/__aeabi_memset.s
@@ -0,0 +1,31 @@
+.syntax unified
+
+.global __aeabi_memclr8
+.global __aeabi_memclr4
+.global __aeabi_memclr
+.global __aeabi_memset8
+.global __aeabi_memset4
+.global __aeabi_memset
+
+.type __aeabi_memclr8,%function
+.type __aeabi_memclr4,%function
+.type __aeabi_memclr,%function
+.type __aeabi_memset8,%function
+.type __aeabi_memset4,%function
+.type __aeabi_memset,%function
+
+__aeabi_memclr8:
+__aeabi_memclr4:
+__aeabi_memclr:
+ movs r2, #0
+__aeabi_memset8:
+__aeabi_memset4:
+__aeabi_memset:
+ cmp r1, #0
+ beq 2f
+ adds r1, r0, r1
+1: strb r2, [r0]
+ adds r0, r0, #1
+ cmp r1, r0
+ bne 1b
+2: bx lr
--
2.13.1
|