History

Changes to support ARM architecture

fst committed 15 years agomaster

Commit 26df2d31 parent f14b9fe2 files · +547 −0Browse files

Unified · Split

2 files
  1. ARMMods +546 −0
  2. series +1 −0
ARMMods+546−0
@@ -0,0 +1,546 @@
1Changes to support ARM architecture
2
3diff -r 9c9f289188ff Make.unix
4--- a/Make.unix Sun Jan 02 18:33:44 2011 -0500
5+++ b/Make.unix Tue Feb 22 18:06:58 2011 +0000
6@@ -19,5 +19,5 @@
7 all: default
8
9 libmachdep.a:
10- arch=`uname -m|sed 's/i.86/386/;s/Power Macintosh/power/; s/x86_64/amd64/'`; \
11+ arch=`uname -m|sed 's/i.86/386/;s/Power Macintosh/power/;s/x86_64/amd64/;s/arm.*/arm/'`; \
12 (cd posix-$$arch && make)
13diff -r 9c9f289188ff posix-arm/Makefile
14--- /dev/null Thu Jan 01 00:00:00 1970 +0000
15+++ b/posix-arm/Makefile Tue Feb 22 18:06:58 2011 +0000
16@@ -0,0 +1,25 @@
17+ROOT=..
18+include ../Make.config
19+LIB=../libmachdep.a
20+
21+OFILES=\
22+ getcallerpc.$O\
23+ md5block.$O\
24+ sha1block.$O\
25+ tas.$O
26+
27+default: $(LIB)
28+$(LIB): $(OFILES)
29+ $(AR) r $(LIB) $(OFILES)
30+ $(RANLIB) $(LIB)
31+
32+%.$O: %.c
33+ $(CC) $(CFLAGS) $*.c
34+
35+%.$O: %.s
36+ $(AS) -o $*.$O $*.s
37+
38+%.s: %.spp
39+ cpp $*.spp >$*.s
40+
41+
42diff -r 9c9f289188ff posix-arm/getcallerpc.c
43--- /dev/null Thu Jan 01 00:00:00 1970 +0000
44+++ b/posix-arm/getcallerpc.c Tue Feb 22 18:06:58 2011 +0000
45@@ -0,0 +1,8 @@
46+#include "u.h"
47+#include "libc.h"
48+
49+uintptr
50+getcallerpc(void *a)
51+{
52+ return 0;
53+}
54diff -r 9c9f289188ff posix-arm/md5block.c
55--- /dev/null Thu Jan 01 00:00:00 1970 +0000
56+++ b/posix-arm/md5block.c Tue Feb 22 18:06:58 2011 +0000
57@@ -0,0 +1,268 @@
58+#include <u.h>
59+#include <libc.h>
60+#include <libsec.h>
61+
62+/*
63+ * rfc1321 requires that I include this. The code is new. The constants
64+ * all come from the rfc (hence the copyright). We trade a table for the
65+ * macros in rfc. The total size is a lot less. -- presotto
66+ *
67+ * Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All
68+ * rights reserved.
69+ *
70+ * License to copy and use this software is granted provided that it
71+ * is identified as the "RSA Data Security, Inc. MD5 Message-Digest
72+ * Algorithm" in all material mentioning or referencing this software
73+ * or this function.
74+ *
75+ * License is also granted to make and use derivative works provided
76+ * that such works are identified as "derived from the RSA Data
77+ * Security, Inc. MD5 Message-Digest Algorithm" in all material
78+ * mentioning or referencing the derived work.
79+ *
80+ * RSA Data Security, Inc. makes no representations concerning either
81+ * the merchantability of this software or the suitability of this
82+ * software forany particular purpose. It is provided "as is"
83+ * without express or implied warranty of any kind.
84+ * These notices must be retained in any copies of any part of this
85+ * documentation and/or software.
86+ */
87+
88+/*
89+ * Rotate ammounts used in the algorithm
90+ */
91+enum
92+{
93+ S11= 7,
94+ S12= 12,
95+ S13= 17,
96+ S14= 22,
97+
98+ S21= 5,
99+ S22= 9,
100+ S23= 14,
101+ S24= 20,
102+
103+ S31= 4,
104+ S32= 11,
105+ S33= 16,
106+ S34= 23,
107+
108+ S41= 6,
109+ S42= 10,
110+ S43= 15,
111+ S44= 21,
112+};
113+
114+static u32int md5tab[] =
115+{
116+ /* round 1 */
117+/*[0]*/ 0xd76aa478,
118+ 0xe8c7b756,
119+ 0x242070db,
120+ 0xc1bdceee,
121+ 0xf57c0faf,
122+ 0x4787c62a,
123+ 0xa8304613,
124+ 0xfd469501,
125+ 0x698098d8,
126+ 0x8b44f7af,
127+ 0xffff5bb1,
128+ 0x895cd7be,
129+ 0x6b901122,
130+ 0xfd987193,
131+ 0xa679438e,
132+ 0x49b40821,
133+
134+ /* round 2 */
135+/*[16]*/0xf61e2562,
136+ 0xc040b340,
137+ 0x265e5a51,
138+ 0xe9b6c7aa,
139+ 0xd62f105d,
140+ 0x2441453,
141+ 0xd8a1e681,
142+ 0xe7d3fbc8,
143+ 0x21e1cde6,
144+ 0xc33707d6,
145+ 0xf4d50d87,
146+ 0x455a14ed,
147+ 0xa9e3e905,
148+ 0xfcefa3f8,
149+ 0x676f02d9,
150+ 0x8d2a4c8a,
151+
152+ /* round 3 */
153+/*[32]*/0xfffa3942,
154+ 0x8771f681,
155+ 0x6d9d6122,
156+ 0xfde5380c,
157+ 0xa4beea44,
158+ 0x4bdecfa9,
159+ 0xf6bb4b60,
160+ 0xbebfbc70,
161+ 0x289b7ec6,
162+ 0xeaa127fa,
163+ 0xd4ef3085,
164+ 0x4881d05,
165+ 0xd9d4d039,
166+ 0xe6db99e5,
167+ 0x1fa27cf8,
168+ 0xc4ac5665,
169+
170+ /* round 4 */
171+/*[48]*/0xf4292244,
172+ 0x432aff97,
173+ 0xab9423a7,
174+ 0xfc93a039,
175+ 0x655b59c3,
176+ 0x8f0ccc92,
177+ 0xffeff47d,
178+ 0x85845dd1,
179+ 0x6fa87e4f,
180+ 0xfe2ce6e0,
181+ 0xa3014314,
182+ 0x4e0811a1,
183+ 0xf7537e82,
184+ 0xbd3af235,
185+ 0x2ad7d2bb,
186+ 0xeb86d391,
187+};
188+
189+static void decode(u32int*, uchar*, ulong);
190+extern void _md5block(uchar *p, ulong len, u32int *s);
191+
192+void
193+_md5block(uchar *p, ulong len, u32int *s)
194+{
195+ u32int a, b, c, d, sh;
196+ u32int *t;
197+ uchar *end;
198+ u32int x[16];
199+
200+ for(end = p+len; p < end; p += 64){
201+ a = s[0];
202+ b = s[1];
203+ c = s[2];
204+ d = s[3];
205+
206+ decode(x, p, 64);
207+
208+ t = md5tab;
209+ sh = 0;
210+ for(; sh != 16; t += 4){
211+ a += ((c ^ d) & b) ^ d;
212+ a += x[sh] + t[0];
213+ a = (a << S11) | (a >> (32 - S11));
214+ a += b;
215+
216+ d += ((b ^ c) & a) ^ c;
217+ d += x[sh + 1] + t[1];
218+ d = (d << S12) | (d >> (32 - S12));
219+ d += a;
220+
221+ c += ((a ^ b) & d) ^ b;
222+ c += x[sh + 2] + t[2];
223+ c = (c << S13) | (c >> (32 - S13));
224+ c += d;
225+
226+ b += ((d ^ a) & c) ^ a;
227+ b += x[sh + 3] + t[3];
228+ b = (b << S14) | (b >> (32 - S14));
229+ b += c;
230+
231+ sh += 4;
232+ }
233+ sh = 1;
234+ for(; sh != 1+20*4; t += 4){
235+ a += ((b ^ c) & d) ^ c;
236+ a += x[sh & 0xf] + t[0];
237+ a = (a << S21) | (a >> (32 - S21));
238+ a += b;
239+
240+ d += ((a ^ b) & c) ^ b;
241+ d += x[(sh + 5) & 0xf] + t[1];
242+ d = (d << S22) | (d >> (32 - S22));
243+ d += a;
244+
245+ c += ((d ^ a) & b) ^ a;
246+ c += x[(sh + 10) & 0xf] + t[2];
247+ c = (c << S23) | (c >> (32 - S23));
248+ c += d;
249+
250+ b += ((c ^ d) & a) ^ d;
251+ b += x[(sh + 15) & 0xf] + t[3];
252+ b = (b << S24) | (b >> (32 - S24));
253+ b += c;
254+
255+ sh += 20;
256+ }
257+ sh = 5;
258+ for(; sh != 5+12*4; t += 4){
259+ a += b ^ c ^ d;
260+ a += x[sh & 0xf] + t[0];
261+ a = (a << S31) | (a >> (32 - S31));
262+ a += b;
263+
264+ d += a ^ b ^ c;
265+ d += x[(sh + 3) & 0xf] + t[1];
266+ d = (d << S32) | (d >> (32 - S32));
267+ d += a;
268+
269+ c += d ^ a ^ b;
270+ c += x[(sh + 6) & 0xf] + t[2];
271+ c = (c << S33) | (c >> (32 - S33));
272+ c += d;
273+
274+ b += c ^ d ^ a;
275+ b += x[(sh + 9) & 0xf] + t[3];
276+ b = (b << S34) | (b >> (32 - S34));
277+ b += c;
278+
279+ sh += 12;
280+ }
281+ sh = 0;
282+ for(; sh != 28*4; t += 4){
283+ a += c ^ (b | ~d);
284+ a += x[sh & 0xf] + t[0];
285+ a = (a << S41) | (a >> (32 - S41));
286+ a += b;
287+
288+ d += b ^ (a | ~c);
289+ d += x[(sh + 7) & 0xf] + t[1];
290+ d = (d << S42) | (d >> (32 - S42));
291+ d += a;
292+
293+ c += a ^ (d | ~b);
294+ c += x[(sh + 14) & 0xf] + t[2];
295+ c = (c << S43) | (c >> (32 - S43));
296+ c += d;
297+
298+ b += d ^ (c | ~a);
299+ b += x[(sh + 21) & 0xf] + t[3];
300+ b = (b << S44) | (b >> (32 - S44));
301+ b += c;
302+
303+ sh += 28;
304+ }
305+
306+ s[0] += a;
307+ s[1] += b;
308+ s[2] += c;
309+ s[3] += d;
310+ }
311+}
312+
313+/*
314+ * decodes input (uchar) into output (u32int). Assumes len is
315+ * a multiple of 4.
316+ */
317+static void
318+decode(u32int *output, uchar *input, ulong len)
319+{
320+ uchar *e;
321+
322+ for(e = input+len; input < e; input += 4)
323+ *output++ = input[0] | (input[1] << 8) |
324+ (input[2] << 16) | (input[3] << 24);
325+}
326diff -r 9c9f289188ff posix-arm/sha1block.c
327--- /dev/null Thu Jan 01 00:00:00 1970 +0000
328+++ b/posix-arm/sha1block.c Tue Feb 22 18:06:58 2011 +0000
329@@ -0,0 +1,189 @@
330+#include <u.h>
331+#include <libc.h>
332+#include <libsec.h>
333+
334+void
335+_sha1block(uchar *p, ulong len, u32int *s)
336+{
337+ u32int a, b, c, d, e, x;
338+ uchar *end;
339+ u32int *wp, *wend;
340+ u32int w[80];
341+
342+ /* at this point, we have a multiple of 64 bytes */
343+ for(end = p+len; p < end;){
344+ a = s[0];
345+ b = s[1];
346+ c = s[2];
347+ d = s[3];
348+ e = s[4];
349+
350+ wend = w + 15;
351+ for(wp = w; wp < wend; wp += 5){
352+ wp[0] = (p[0]<<24) | (p[1]<<16) | (p[2]<<8) | p[3];
353+ e += ((a<<5) | (a>>27)) + wp[0];
354+ e += 0x5a827999 + (((c^d)&b)^d);
355+ b = (b<<30)|(b>>2);
356+
357+ wp[1] = (p[4]<<24) | (p[5]<<16) | (p[6]<<8) | p[7];
358+ d += ((e<<5) | (e>>27)) + wp[1];
359+ d += 0x5a827999 + (((b^c)&a)^c);
360+ a = (a<<30)|(a>>2);
361+
362+ wp[2] = (p[8]<<24) | (p[9]<<16) | (p[10]<<8) | p[11];
363+ c += ((d<<5) | (d>>27)) + wp[2];
364+ c += 0x5a827999 + (((a^b)&e)^b);
365+ e = (e<<30)|(e>>2);
366+
367+ wp[3] = (p[12]<<24) | (p[13]<<16) | (p[14]<<8) | p[15];
368+ b += ((c<<5) | (c>>27)) + wp[3];
369+ b += 0x5a827999 + (((e^a)&d)^a);
370+ d = (d<<30)|(d>>2);
371+
372+ wp[4] = (p[16]<<24) | (p[17]<<16) | (p[18]<<8) | p[19];
373+ a += ((b<<5) | (b>>27)) + wp[4];
374+ a += 0x5a827999 + (((d^e)&c)^e);
375+ c = (c<<30)|(c>>2);
376+
377+ p += 20;
378+ }
379+
380+ wp[0] = (p[0]<<24) | (p[1]<<16) | (p[2]<<8) | p[3];
381+ e += ((a<<5) | (a>>27)) + wp[0];
382+ e += 0x5a827999 + (((c^d)&b)^d);
383+ b = (b<<30)|(b>>2);
384+
385+ x = wp[-2] ^ wp[-7] ^ wp[-13] ^ wp[-15];
386+ wp[1] = (x<<1) | (x>>31);
387+ d += ((e<<5) | (e>>27)) + wp[1];
388+ d += 0x5a827999 + (((b^c)&a)^c);
389+ a = (a<<30)|(a>>2);
390+
391+ x = wp[-1] ^ wp[-6] ^ wp[-12] ^ wp[-14];
392+ wp[2] = (x<<1) | (x>>31);
393+ c += ((d<<5) | (d>>27)) + wp[2];
394+ c += 0x5a827999 + (((a^b)&e)^b);
395+ e = (e<<30)|(e>>2);
396+
397+ x = wp[0] ^ wp[-5] ^ wp[-11] ^ wp[-13];
398+ wp[3] = (x<<1) | (x>>31);
399+ b += ((c<<5) | (c>>27)) + wp[3];
400+ b += 0x5a827999 + (((e^a)&d)^a);
401+ d = (d<<30)|(d>>2);
402+
403+ x = wp[1] ^ wp[-4] ^ wp[-10] ^ wp[-12];
404+ wp[4] = (x<<1) | (x>>31);
405+ a += ((b<<5) | (b>>27)) + wp[4];
406+ a += 0x5a827999 + (((d^e)&c)^e);
407+ c = (c<<30)|(c>>2);
408+
409+ wp += 5;
410+ p += 4;
411+
412+ wend = w + 40;
413+ for(; wp < wend; wp += 5){
414+ x = wp[-3] ^ wp[-8] ^ wp[-14] ^ wp[-16];
415+ wp[0] = (x<<1) | (x>>31);
416+ e += ((a<<5) | (a>>27)) + wp[0];
417+ e += 0x6ed9eba1 + (b^c^d);
418+ b = (b<<30)|(b>>2);
419+
420+ x = wp[-2] ^ wp[-7] ^ wp[-13] ^ wp[-15];
421+ wp[1] = (x<<1) | (x>>31);
422+ d += ((e<<5) | (e>>27)) + wp[1];
423+ d += 0x6ed9eba1 + (a^b^c);
424+ a = (a<<30)|(a>>2);
425+
426+ x = wp[-1] ^ wp[-6] ^ wp[-12] ^ wp[-14];
427+ wp[2] = (x<<1) | (x>>31);
428+ c += ((d<<5) | (d>>27)) + wp[2];
429+ c += 0x6ed9eba1 + (e^a^b);
430+ e = (e<<30)|(e>>2);
431+
432+ x = wp[0] ^ wp[-5] ^ wp[-11] ^ wp[-13];
433+ wp[3] = (x<<1) | (x>>31);
434+ b += ((c<<5) | (c>>27)) + wp[3];
435+ b += 0x6ed9eba1 + (d^e^a);
436+ d = (d<<30)|(d>>2);
437+
438+ x = wp[1] ^ wp[-4] ^ wp[-10] ^ wp[-12];
439+ wp[4] = (x<<1) | (x>>31);
440+ a += ((b<<5) | (b>>27)) + wp[4];
441+ a += 0x6ed9eba1 + (c^d^e);
442+ c = (c<<30)|(c>>2);
443+ }
444+
445+ wend = w + 60;
446+ for(; wp < wend; wp += 5){
447+ x = wp[-3] ^ wp[-8] ^ wp[-14] ^ wp[-16];
448+ wp[0] = (x<<1) | (x>>31);
449+ e += ((a<<5) | (a>>27)) + wp[0];
450+ e += 0x8f1bbcdc + ((b&c)|((b|c)&d));
451+ b = (b<<30)|(b>>2);
452+
453+ x = wp[-2] ^ wp[-7] ^ wp[-13] ^ wp[-15];
454+ wp[1] = (x<<1) | (x>>31);
455+ d += ((e<<5) | (e>>27)) + wp[1];
456+ d += 0x8f1bbcdc + ((a&b)|((a|b)&c));
457+ a = (a<<30)|(a>>2);
458+
459+ x = wp[-1] ^ wp[-6] ^ wp[-12] ^ wp[-14];
460+ wp[2] = (x<<1) | (x>>31);
461+ c += ((d<<5) | (d>>27)) + wp[2];
462+ c += 0x8f1bbcdc + ((e&a)|((e|a)&b));
463+ e = (e<<30)|(e>>2);
464+
465+ x = wp[0] ^ wp[-5] ^ wp[-11] ^ wp[-13];
466+ wp[3] = (x<<1) | (x>>31);
467+ b += ((c<<5) | (c>>27)) + wp[3];
468+ b += 0x8f1bbcdc + ((d&e)|((d|e)&a));
469+ d = (d<<30)|(d>>2);
470+
471+ x = wp[1] ^ wp[-4] ^ wp[-10] ^ wp[-12];
472+ wp[4] = (x<<1) | (x>>31);
473+ a += ((b<<5) | (b>>27)) + wp[4];
474+ a += 0x8f1bbcdc + ((c&d)|((c|d)&e));
475+ c = (c<<30)|(c>>2);
476+ }
477+
478+ wend = w + 80;
479+ for(; wp < wend; wp += 5){
480+ x = wp[-3] ^ wp[-8] ^ wp[-14] ^ wp[-16];
481+ wp[0] = (x<<1) | (x>>31);
482+ e += ((a<<5) | (a>>27)) + wp[0];
483+ e += 0xca62c1d6 + (b^c^d);
484+ b = (b<<30)|(b>>2);
485+
486+ x = wp[-2] ^ wp[-7] ^ wp[-13] ^ wp[-15];
487+ wp[1] = (x<<1) | (x>>31);
488+ d += ((e<<5) | (e>>27)) + wp[1];
489+ d += 0xca62c1d6 + (a^b^c);
490+ a = (a<<30)|(a>>2);
491+
492+ x = wp[-1] ^ wp[-6] ^ wp[-12] ^ wp[-14];
493+ wp[2] = (x<<1) | (x>>31);
494+ c += ((d<<5) | (d>>27)) + wp[2];
495+ c += 0xca62c1d6 + (e^a^b);
496+ e = (e<<30)|(e>>2);
497+
498+ x = wp[0] ^ wp[-5] ^ wp[-11] ^ wp[-13];
499+ wp[3] = (x<<1) | (x>>31);
500+ b += ((c<<5) | (c>>27)) + wp[3];
501+ b += 0xca62c1d6 + (d^e^a);
502+ d = (d<<30)|(d>>2);
503+
504+ x = wp[1] ^ wp[-4] ^ wp[-10] ^ wp[-12];
505+ wp[4] = (x<<1) | (x>>31);
506+ a += ((b<<5) | (b>>27)) + wp[4];
507+ a += 0xca62c1d6 + (c^d^e);
508+ c = (c<<30)|(c>>2);
509+ }
510+
511+ /* save state */
512+ s[0] += a;
513+ s[1] += b;
514+ s[2] += c;
515+ s[3] += d;
516+ s[4] += e;
517+ }
518+}
519diff -r 9c9f289188ff posix-arm/tas.c
520--- /dev/null Thu Jan 01 00:00:00 1970 +0000
521+++ b/posix-arm/tas.c Tue Feb 22 18:06:58 2011 +0000
522@@ -0,0 +1,24 @@
523+#include "u.h"
524+#include "libc.h"
525+
526+int
527+tas(long *x)
528+{
529+ int v;
530+
531+ __asm__(
532+ "swp %0, %1, [%2]"
533+ : "=&r" (v)
534+ : "r" (1), "r" (x)
535+ : "memory"
536+ );
537+ switch(v) {
538+ case 0:
539+ case 1:
540+ return v;
541+ default:
542+ print("canlock: corrupted 0x%lux\n", v);
543+ return 1;
544+ }
545+}
546+
series+1−0
@@ -1 +1,2 @@
1ARMMods
1# Placed by Bitbucket2# Placed by Bitbucket