blob: 7e48807b2fa198c4e2b8e7022df2218308a41b7c [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Ingo Molnar2c763972011-03-18 10:42:11 +01002 * Copyright 2002, 2003 Andi Kleen, SuSE Labs.
3 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 * This file is subject to the terms and conditions of the GNU General Public
5 * License. See the file COPYING in the main directory of this archive
6 * for more details. No warranty for anything given at all.
7 */
Jan Beulich8d379da2006-09-26 10:52:32 +02008#include <linux/linkage.h>
Jan Beulich8d379da2006-09-26 10:52:32 +02009#include <asm/errno.h>
H. Peter Anvin015e6f12012-04-20 12:19:51 -070010#include <asm/asm.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070011
12/*
13 * Checksum copy with exception handling.
Ingo Molnar2c763972011-03-18 10:42:11 +010014 * On exceptions src_err_ptr or dst_err_ptr is set to -EFAULT and the
Linus Torvalds1da177e2005-04-16 15:20:36 -070015 * destination is zeroed.
Ingo Molnar2c763972011-03-18 10:42:11 +010016 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070017 * Input
18 * rdi source
19 * rsi destination
20 * edx len (32bit)
Ingo Molnar2c763972011-03-18 10:42:11 +010021 * ecx sum (32bit)
Linus Torvalds1da177e2005-04-16 15:20:36 -070022 * r8 src_err_ptr (int)
23 * r9 dst_err_ptr (int)
24 *
25 * Output
26 * eax 64bit sum. undefined in case of exception.
Ingo Molnar2c763972011-03-18 10:42:11 +010027 *
28 * Wrappers need to take care of valid exception sum and zeroing.
Linus Torvalds1da177e2005-04-16 15:20:36 -070029 * They also should align source or destination to 8 bytes.
30 */
31
32 .macro source
3310:
H. Peter Anvin015e6f12012-04-20 12:19:51 -070034 _ASM_EXTABLE(10b, .Lbad_source)
Linus Torvalds1da177e2005-04-16 15:20:36 -070035 .endm
Ingo Molnar2c763972011-03-18 10:42:11 +010036
Linus Torvalds1da177e2005-04-16 15:20:36 -070037 .macro dest
3820:
H. Peter Anvin015e6f12012-04-20 12:19:51 -070039 _ASM_EXTABLE(20b, .Lbad_dest)
Linus Torvalds1da177e2005-04-16 15:20:36 -070040 .endm
Ingo Molnar2c763972011-03-18 10:42:11 +010041
Linus Torvalds1da177e2005-04-16 15:20:36 -070042 .macro ignore L=.Lignore
4330:
H. Peter Anvin015e6f12012-04-20 12:19:51 -070044 _ASM_EXTABLE(30b, \L)
Linus Torvalds1da177e2005-04-16 15:20:36 -070045 .endm
Ingo Molnar2c763972011-03-18 10:42:11 +010046
47
Jan Beulich8d379da2006-09-26 10:52:32 +020048ENTRY(csum_partial_copy_generic)
Ingo Molnar2c763972011-03-18 10:42:11 +010049 cmpl $3*64, %edx
50 jle .Lignore
Linus Torvalds1da177e2005-04-16 15:20:36 -070051
Ingo Molnar2c763972011-03-18 10:42:11 +010052.Lignore:
53 subq $7*8, %rsp
Ingo Molnar2c763972011-03-18 10:42:11 +010054 movq %rbx, 2*8(%rsp)
Ingo Molnar2c763972011-03-18 10:42:11 +010055 movq %r12, 3*8(%rsp)
Ingo Molnar2c763972011-03-18 10:42:11 +010056 movq %r14, 4*8(%rsp)
Ingo Molnar2c763972011-03-18 10:42:11 +010057 movq %r13, 5*8(%rsp)
Ingo Molnar2c763972011-03-18 10:42:11 +010058 movq %rbp, 6*8(%rsp)
Linus Torvalds1da177e2005-04-16 15:20:36 -070059
Ingo Molnar2c763972011-03-18 10:42:11 +010060 movq %r8, (%rsp)
61 movq %r9, 1*8(%rsp)
Linus Torvalds1da177e2005-04-16 15:20:36 -070062
Ingo Molnar2c763972011-03-18 10:42:11 +010063 movl %ecx, %eax
64 movl %edx, %ecx
Linus Torvalds1da177e2005-04-16 15:20:36 -070065
Ingo Molnar2c763972011-03-18 10:42:11 +010066 xorl %r9d, %r9d
67 movq %rcx, %r12
68
69 shrq $6, %r12
70 jz .Lhandle_tail /* < 64 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070071
72 clc
Ingo Molnar2c763972011-03-18 10:42:11 +010073
Linus Torvalds1da177e2005-04-16 15:20:36 -070074 /* main loop. clear in 64 byte blocks */
75 /* r9: zero, r8: temp2, rbx: temp1, rax: sum, rcx: saved length */
76 /* r11: temp3, rdx: temp4, r12 loopcnt */
77 /* r10: temp5, rbp: temp6, r14 temp7, r13 temp8 */
78 .p2align 4
79.Lloop:
80 source
Ingo Molnar2c763972011-03-18 10:42:11 +010081 movq (%rdi), %rbx
Linus Torvalds1da177e2005-04-16 15:20:36 -070082 source
Ingo Molnar2c763972011-03-18 10:42:11 +010083 movq 8(%rdi), %r8
Linus Torvalds1da177e2005-04-16 15:20:36 -070084 source
Ingo Molnar2c763972011-03-18 10:42:11 +010085 movq 16(%rdi), %r11
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 source
Ingo Molnar2c763972011-03-18 10:42:11 +010087 movq 24(%rdi), %rdx
Linus Torvalds1da177e2005-04-16 15:20:36 -070088
89 source
Ingo Molnar2c763972011-03-18 10:42:11 +010090 movq 32(%rdi), %r10
Linus Torvalds1da177e2005-04-16 15:20:36 -070091 source
Ingo Molnar2c763972011-03-18 10:42:11 +010092 movq 40(%rdi), %rbp
Linus Torvalds1da177e2005-04-16 15:20:36 -070093 source
Ingo Molnar2c763972011-03-18 10:42:11 +010094 movq 48(%rdi), %r14
Linus Torvalds1da177e2005-04-16 15:20:36 -070095 source
Ingo Molnar2c763972011-03-18 10:42:11 +010096 movq 56(%rdi), %r13
97
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 ignore 2f
99 prefetcht0 5*64(%rdi)
Ingo Molnar2c763972011-03-18 10:42:11 +01001002:
101 adcq %rbx, %rax
102 adcq %r8, %rax
103 adcq %r11, %rax
104 adcq %rdx, %rax
105 adcq %r10, %rax
106 adcq %rbp, %rax
107 adcq %r14, %rax
108 adcq %r13, %rax
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109
110 decl %r12d
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111
112 dest
Ingo Molnar2c763972011-03-18 10:42:11 +0100113 movq %rbx, (%rsi)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 dest
Ingo Molnar2c763972011-03-18 10:42:11 +0100115 movq %r8, 8(%rsi)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116 dest
Ingo Molnar2c763972011-03-18 10:42:11 +0100117 movq %r11, 16(%rsi)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118 dest
Ingo Molnar2c763972011-03-18 10:42:11 +0100119 movq %rdx, 24(%rsi)
120
121 dest
122 movq %r10, 32(%rsi)
123 dest
124 movq %rbp, 40(%rsi)
125 dest
126 movq %r14, 48(%rsi)
127 dest
128 movq %r13, 56(%rsi)
129
Linus Torvalds1da177e2005-04-16 15:20:36 -07001303:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131
Ingo Molnar2c763972011-03-18 10:42:11 +0100132 leaq 64(%rdi), %rdi
133 leaq 64(%rsi), %rsi
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134
Ingo Molnar2c763972011-03-18 10:42:11 +0100135 jnz .Lloop
136
137 adcq %r9, %rax
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138
Lucas De Marchi0d2eb442011-03-17 16:24:16 -0300139 /* do last up to 56 bytes */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140.Lhandle_tail:
141 /* ecx: count */
Ingo Molnar2c763972011-03-18 10:42:11 +0100142 movl %ecx, %r10d
143 andl $63, %ecx
144 shrl $3, %ecx
145 jz .Lfold
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146 clc
147 .p2align 4
Ingo Molnar2c763972011-03-18 10:42:11 +0100148.Lloop_8:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149 source
Ingo Molnar2c763972011-03-18 10:42:11 +0100150 movq (%rdi), %rbx
151 adcq %rbx, %rax
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152 decl %ecx
153 dest
Ingo Molnar2c763972011-03-18 10:42:11 +0100154 movq %rbx, (%rsi)
155 leaq 8(%rsi), %rsi /* preserve carry */
156 leaq 8(%rdi), %rdi
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157 jnz .Lloop_8
Ingo Molnar2c763972011-03-18 10:42:11 +0100158 adcq %r9, %rax /* add in carry */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159
160.Lfold:
161 /* reduce checksum to 32bits */
Ingo Molnar2c763972011-03-18 10:42:11 +0100162 movl %eax, %ebx
163 shrq $32, %rax
164 addl %ebx, %eax
165 adcl %r9d, %eax
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166
Ingo Molnar2c763972011-03-18 10:42:11 +0100167 /* do last up to 6 bytes */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168.Lhandle_7:
Ingo Molnar2c763972011-03-18 10:42:11 +0100169 movl %r10d, %ecx
170 andl $7, %ecx
171 shrl $1, %ecx
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172 jz .Lhandle_1
Ingo Molnar2c763972011-03-18 10:42:11 +0100173 movl $2, %edx
174 xorl %ebx, %ebx
175 clc
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176 .p2align 4
Ingo Molnar2c763972011-03-18 10:42:11 +0100177.Lloop_1:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178 source
Ingo Molnar2c763972011-03-18 10:42:11 +0100179 movw (%rdi), %bx
180 adcl %ebx, %eax
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181 decl %ecx
Dave Peterson92ed0222005-07-29 22:59:20 -0700182 dest
Ingo Molnar2c763972011-03-18 10:42:11 +0100183 movw %bx, (%rsi)
184 leaq 2(%rdi), %rdi
185 leaq 2(%rsi), %rsi
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186 jnz .Lloop_1
Ingo Molnar2c763972011-03-18 10:42:11 +0100187 adcl %r9d, %eax /* add in carry */
188
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189 /* handle last odd byte */
190.Lhandle_1:
Denys Vlasenko3e1aa7c2015-03-06 21:55:32 +0100191 testb $1, %r10b
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192 jz .Lende
Ingo Molnar2c763972011-03-18 10:42:11 +0100193 xorl %ebx, %ebx
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194 source
Ingo Molnar2c763972011-03-18 10:42:11 +0100195 movb (%rdi), %bl
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196 dest
Ingo Molnar2c763972011-03-18 10:42:11 +0100197 movb %bl, (%rsi)
198 addl %ebx, %eax
199 adcl %r9d, %eax /* carry */
200
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201.Lende:
Ingo Molnar2c763972011-03-18 10:42:11 +0100202 movq 2*8(%rsp), %rbx
Ingo Molnar2c763972011-03-18 10:42:11 +0100203 movq 3*8(%rsp), %r12
Ingo Molnar2c763972011-03-18 10:42:11 +0100204 movq 4*8(%rsp), %r14
Ingo Molnar2c763972011-03-18 10:42:11 +0100205 movq 5*8(%rsp), %r13
Ingo Molnar2c763972011-03-18 10:42:11 +0100206 movq 6*8(%rsp), %rbp
Ingo Molnar2c763972011-03-18 10:42:11 +0100207 addq $7*8, %rsp
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208 ret
209
210 /* Exception handlers. Very simple, zeroing is done in the wrappers */
211.Lbad_source:
Ingo Molnar2c763972011-03-18 10:42:11 +0100212 movq (%rsp), %rax
213 testq %rax, %rax
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214 jz .Lende
Ingo Molnar2c763972011-03-18 10:42:11 +0100215 movl $-EFAULT, (%rax)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216 jmp .Lende
Ingo Molnar2c763972011-03-18 10:42:11 +0100217
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218.Lbad_dest:
Ingo Molnar2c763972011-03-18 10:42:11 +0100219 movq 8(%rsp), %rax
220 testq %rax, %rax
221 jz .Lende
222 movl $-EFAULT, (%rax)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223 jmp .Lende
Jan Beulich8d379da2006-09-26 10:52:32 +0200224ENDPROC(csum_partial_copy_generic)