blob: 87c9471be8b65aa527c5805369430b2e49cee961 [file] [log] [blame]
Thomas Gleixnerd2912cb2019-06-04 10:11:33 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
3 * linux/arch/arm/lib/csumpartial.S
4 *
5 * Copyright (C) 1995-1998 Russell King
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 */
7#include <linux/linkage.h>
8#include <asm/assembler.h>
9
10 .text
11
12/*
13 * Function: __u32 csum_partial(const char *src, int len, __u32 sum)
14 * Params : r0 = buffer, r1 = len, r2 = checksum
15 * Returns : r0 = new checksum
16 */
17
18buf .req r0
19len .req r1
20sum .req r2
21td0 .req r3
22td1 .req r4 @ save before use
23td2 .req r5 @ save before use
24td3 .req lr
25
Nicolas Pitre8adbb372005-11-11 21:51:49 +000026.Lzero: mov r0, sum
Linus Torvalds1da177e2005-04-16 15:20:36 -070027 add sp, sp, #4
28 ldr pc, [sp], #4
29
30 /*
31 * Handle 0 to 7 bytes, with any alignment of source and
32 * destination pointers. Note that when we get here, C = 0
33 */
Nicolas Pitre8adbb372005-11-11 21:51:49 +000034.Lless8: teq len, #0 @ check for zero count
35 beq .Lzero
Linus Torvalds1da177e2005-04-16 15:20:36 -070036
37 /* we must have at least one byte. */
38 tst buf, #1 @ odd address?
Russell Kingaf36bef2005-11-10 11:40:53 +000039 movne sum, sum, ror #8
Stefan Agnere44fc382019-02-18 00:57:38 +010040 ldrbne td0, [buf], #1
Linus Torvalds1da177e2005-04-16 15:20:36 -070041 subne len, len, #1
Stefan Agnere44fc382019-02-18 00:57:38 +010042 adcsne sum, sum, td0, put_byte_1
Linus Torvalds1da177e2005-04-16 15:20:36 -070043
Nicolas Pitre8adbb372005-11-11 21:51:49 +000044.Lless4: tst len, #6
45 beq .Lless8_byte
Linus Torvalds1da177e2005-04-16 15:20:36 -070046
47 /* we are now half-word aligned */
48
Nicolas Pitre8adbb372005-11-11 21:51:49 +000049.Lless8_wordlp:
Linus Torvalds1da177e2005-04-16 15:20:36 -070050#if __LINUX_ARM_ARCH__ >= 4
51 ldrh td0, [buf], #2
52 sub len, len, #2
53#else
54 ldrb td0, [buf], #1
55 ldrb td3, [buf], #1
56 sub len, len, #2
57#ifndef __ARMEB__
58 orr td0, td0, td3, lsl #8
59#else
60 orr td0, td3, td0, lsl #8
61#endif
62#endif
63 adcs sum, sum, td0
64 tst len, #6
Nicolas Pitre8adbb372005-11-11 21:51:49 +000065 bne .Lless8_wordlp
Linus Torvalds1da177e2005-04-16 15:20:36 -070066
Nicolas Pitre8adbb372005-11-11 21:51:49 +000067.Lless8_byte: tst len, #1 @ odd number of bytes
Stefan Agnere44fc382019-02-18 00:57:38 +010068 ldrbne td0, [buf], #1 @ include last byte
69 adcsne sum, sum, td0, put_byte_0 @ update checksum
Linus Torvalds1da177e2005-04-16 15:20:36 -070070
Nicolas Pitre8adbb372005-11-11 21:51:49 +000071.Ldone: adc r0, sum, #0 @ collect up the last carry
Linus Torvalds1da177e2005-04-16 15:20:36 -070072 ldr td0, [sp], #4
73 tst td0, #1 @ check buffer alignment
74 movne r0, r0, ror #8 @ rotate checksum by 8 bits
75 ldr pc, [sp], #4 @ return
76
Nicolas Pitre8adbb372005-11-11 21:51:49 +000077.Lnot_aligned: tst buf, #1 @ odd address
Stefan Agnere44fc382019-02-18 00:57:38 +010078 ldrbne td0, [buf], #1 @ make even
Linus Torvalds1da177e2005-04-16 15:20:36 -070079 subne len, len, #1
Stefan Agnere44fc382019-02-18 00:57:38 +010080 adcsne sum, sum, td0, put_byte_1 @ update checksum
Linus Torvalds1da177e2005-04-16 15:20:36 -070081
82 tst buf, #2 @ 32-bit aligned?
83#if __LINUX_ARM_ARCH__ >= 4
Stefan Agnere44fc382019-02-18 00:57:38 +010084 ldrhne td0, [buf], #2 @ make 32-bit aligned
Linus Torvalds1da177e2005-04-16 15:20:36 -070085 subne len, len, #2
86#else
Stefan Agnere44fc382019-02-18 00:57:38 +010087 ldrbne td0, [buf], #1
88 ldrbne ip, [buf], #1
Linus Torvalds1da177e2005-04-16 15:20:36 -070089 subne len, len, #2
90#ifndef __ARMEB__
91 orrne td0, td0, ip, lsl #8
92#else
93 orrne td0, ip, td0, lsl #8
94#endif
95#endif
Stefan Agnere44fc382019-02-18 00:57:38 +010096 adcsne sum, sum, td0 @ update checksum
Russell King6ebbf2c2014-06-30 16:29:12 +010097 ret lr
Linus Torvalds1da177e2005-04-16 15:20:36 -070098
99ENTRY(csum_partial)
100 stmfd sp!, {buf, lr}
101 cmp len, #8 @ Ensure that we have at least
Nicolas Pitre8adbb372005-11-11 21:51:49 +0000102 blo .Lless8 @ 8 bytes to copy.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103
Russell Kingaf36bef2005-11-10 11:40:53 +0000104 tst buf, #1
105 movne sum, sum, ror #8
106
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107 adds sum, sum, #0 @ C = 0
108 tst buf, #3 @ Test destination alignment
Nicolas Pitre8adbb372005-11-11 21:51:49 +0000109 blne .Lnot_aligned @ align destination, return here
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110
1111: bics ip, len, #31
112 beq 3f
113
114 stmfd sp!, {r4 - r5}
1152: ldmia buf!, {td0, td1, td2, td3}
116 adcs sum, sum, td0
117 adcs sum, sum, td1
118 adcs sum, sum, td2
119 adcs sum, sum, td3
120 ldmia buf!, {td0, td1, td2, td3}
121 adcs sum, sum, td0
122 adcs sum, sum, td1
123 adcs sum, sum, td2
124 adcs sum, sum, td3
125 sub ip, ip, #32
126 teq ip, #0
127 bne 2b
128 ldmfd sp!, {r4 - r5}
129
1303: tst len, #0x1c @ should not change C
Nicolas Pitre8adbb372005-11-11 21:51:49 +0000131 beq .Lless4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132
1334: ldr td0, [buf], #4
134 sub len, len, #4
135 adcs sum, sum, td0
136 tst len, #0x1c
137 bne 4b
Nicolas Pitre8adbb372005-11-11 21:51:49 +0000138 b .Lless4
Catalin Marinas93ed3972008-08-28 11:22:32 +0100139ENDPROC(csum_partial)