hc
2024-09-20 a36159eec6ca17402b0e146b86efaf76568dc353
kernel/arch/x86/lib/checksum_32.S
....@@ -1,3 +1,4 @@
1
+/* SPDX-License-Identifier: GPL-2.0-or-later */
12 /*
23 * INET An implementation of the TCP/IP protocol suite for the LINUX
34 * operating system. INET is implemented using the BSD Socket
....@@ -18,11 +19,6 @@
1819 * handling.
1920 * Andi Kleen, add zeroing on error
2021 * converted to pure assembler
21
- *
22
- * This program is free software; you can redistribute it and/or
23
- * modify it under the terms of the GNU General Public License
24
- * as published by the Free Software Foundation; either version
25
- * 2 of the License, or (at your option) any later version.
2622 */
2723
2824 #include <linux/linkage.h>
....@@ -50,7 +46,7 @@
5046 * Fortunately, it is easy to convert 2-byte alignment to 4-byte
5147 * alignment for the unrolled loop.
5248 */
53
-ENTRY(csum_partial)
49
+SYM_FUNC_START(csum_partial)
5450 pushl %esi
5551 pushl %ebx
5652 movl 20(%esp),%eax # Function arg: unsigned int sum
....@@ -131,14 +127,14 @@
131127 8:
132128 popl %ebx
133129 popl %esi
134
- ret
135
-ENDPROC(csum_partial)
130
+ RET
131
+SYM_FUNC_END(csum_partial)
136132
137133 #else
138134
139135 /* Version for PentiumII/PPro */
140136
141
-ENTRY(csum_partial)
137
+SYM_FUNC_START(csum_partial)
142138 pushl %esi
143139 pushl %ebx
144140 movl 20(%esp),%eax # Function arg: unsigned int sum
....@@ -157,7 +153,7 @@
157153 negl %ebx
158154 lea 45f(%ebx,%ebx,2), %ebx
159155 testl %esi, %esi
160
- JMP_NOSPEC %ebx
156
+ JMP_NOSPEC ebx
161157
162158 # Handle 2-byte-aligned regions
163159 20: addw (%esi), %ax
....@@ -249,60 +245,49 @@
249245 90:
250246 popl %ebx
251247 popl %esi
252
- ret
253
-ENDPROC(csum_partial)
248
+ RET
249
+SYM_FUNC_END(csum_partial)
254250
255251 #endif
256252 EXPORT_SYMBOL(csum_partial)
257253
258254 /*
259255 unsigned int csum_partial_copy_generic (const char *src, char *dst,
260
- int len, int sum, int *src_err_ptr, int *dst_err_ptr)
256
+ int len)
261257 */
262258
263259 /*
264260 * Copy from ds while checksumming, otherwise like csum_partial
265
- *
266
- * The macros SRC and DST specify the type of access for the instruction.
267
- * thus we can call a custom exception handler for all access types.
268
- *
269
- * FIXME: could someone double-check whether I haven't mixed up some SRC and
270
- * DST definitions? It's damn hard to trigger all cases. I hope I got
271
- * them all but there's no guarantee.
272261 */
273262
274
-#define SRC(y...) \
263
+#define EXC(y...) \
275264 9999: y; \
276
- _ASM_EXTABLE(9999b, 6001f)
277
-
278
-#define DST(y...) \
279
- 9999: y; \
280
- _ASM_EXTABLE(9999b, 6002f)
265
+ _ASM_EXTABLE_UA(9999b, 6001f)
281266
282267 #ifndef CONFIG_X86_USE_PPRO_CHECKSUM
283268
284269 #define ARGBASE 16
285270 #define FP 12
286271
287
-ENTRY(csum_partial_copy_generic)
272
+SYM_FUNC_START(csum_partial_copy_generic)
288273 subl $4,%esp
289274 pushl %edi
290275 pushl %esi
291276 pushl %ebx
292
- movl ARGBASE+16(%esp),%eax # sum
293277 movl ARGBASE+12(%esp),%ecx # len
294278 movl ARGBASE+4(%esp),%esi # src
295279 movl ARGBASE+8(%esp),%edi # dst
296280
281
+ movl $-1, %eax # sum
297282 testl $2, %edi # Check alignment.
298283 jz 2f # Jump if alignment is ok.
299284 subl $2, %ecx # Alignment uses up two bytes.
300285 jae 1f # Jump if we had at least two bytes.
301286 addl $2, %ecx # ecx was < 2. Deal with it.
302287 jmp 4f
303
-SRC(1: movw (%esi), %bx )
288
+EXC(1: movw (%esi), %bx )
304289 addl $2, %esi
305
-DST( movw %bx, (%edi) )
290
+EXC( movw %bx, (%edi) )
306291 addl $2, %edi
307292 addw %bx, %ax
308293 adcl $0, %eax
....@@ -310,34 +295,34 @@
310295 movl %ecx, FP(%esp)
311296 shrl $5, %ecx
312297 jz 2f
313
- testl %esi, %esi
314
-SRC(1: movl (%esi), %ebx )
315
-SRC( movl 4(%esi), %edx )
298
+ testl %esi, %esi # what's wrong with clc?
299
+EXC(1: movl (%esi), %ebx )
300
+EXC( movl 4(%esi), %edx )
316301 adcl %ebx, %eax
317
-DST( movl %ebx, (%edi) )
302
+EXC( movl %ebx, (%edi) )
318303 adcl %edx, %eax
319
-DST( movl %edx, 4(%edi) )
304
+EXC( movl %edx, 4(%edi) )
320305
321
-SRC( movl 8(%esi), %ebx )
322
-SRC( movl 12(%esi), %edx )
306
+EXC( movl 8(%esi), %ebx )
307
+EXC( movl 12(%esi), %edx )
323308 adcl %ebx, %eax
324
-DST( movl %ebx, 8(%edi) )
309
+EXC( movl %ebx, 8(%edi) )
325310 adcl %edx, %eax
326
-DST( movl %edx, 12(%edi) )
311
+EXC( movl %edx, 12(%edi) )
327312
328
-SRC( movl 16(%esi), %ebx )
329
-SRC( movl 20(%esi), %edx )
313
+EXC( movl 16(%esi), %ebx )
314
+EXC( movl 20(%esi), %edx )
330315 adcl %ebx, %eax
331
-DST( movl %ebx, 16(%edi) )
316
+EXC( movl %ebx, 16(%edi) )
332317 adcl %edx, %eax
333
-DST( movl %edx, 20(%edi) )
318
+EXC( movl %edx, 20(%edi) )
334319
335
-SRC( movl 24(%esi), %ebx )
336
-SRC( movl 28(%esi), %edx )
320
+EXC( movl 24(%esi), %ebx )
321
+EXC( movl 28(%esi), %edx )
337322 adcl %ebx, %eax
338
-DST( movl %ebx, 24(%edi) )
323
+EXC( movl %ebx, 24(%edi) )
339324 adcl %edx, %eax
340
-DST( movl %edx, 28(%edi) )
325
+EXC( movl %edx, 28(%edi) )
341326
342327 lea 32(%esi), %esi
343328 lea 32(%edi), %edi
....@@ -349,9 +334,9 @@
349334 andl $0x1c, %edx
350335 je 4f
351336 shrl $2, %edx # This clears CF
352
-SRC(3: movl (%esi), %ebx )
337
+EXC(3: movl (%esi), %ebx )
353338 adcl %ebx, %eax
354
-DST( movl %ebx, (%edi) )
339
+EXC( movl %ebx, (%edi) )
355340 lea 4(%esi), %esi
356341 lea 4(%edi), %edi
357342 dec %edx
....@@ -361,39 +346,24 @@
361346 jz 7f
362347 cmpl $2, %ecx
363348 jb 5f
364
-SRC( movw (%esi), %cx )
349
+EXC( movw (%esi), %cx )
365350 leal 2(%esi), %esi
366
-DST( movw %cx, (%edi) )
351
+EXC( movw %cx, (%edi) )
367352 leal 2(%edi), %edi
368353 je 6f
369354 shll $16,%ecx
370
-SRC(5: movb (%esi), %cl )
371
-DST( movb %cl, (%edi) )
355
+EXC(5: movb (%esi), %cl )
356
+EXC( movb %cl, (%edi) )
372357 6: addl %ecx, %eax
373358 adcl $0, %eax
374359 7:
375
-5000:
376360
377361 # Exception handler:
378362 .section .fixup, "ax"
379363
380364 6001:
381
- movl ARGBASE+20(%esp), %ebx # src_err_ptr
382
- movl $-EFAULT, (%ebx)
383
-
384
- # zero the complete destination - computing the rest
385
- # is too much work
386
- movl ARGBASE+8(%esp), %edi # dst
387
- movl ARGBASE+12(%esp), %ecx # len
388
- xorl %eax,%eax
389
- rep ; stosb
390
-
391
- jmp 5000b
392
-
393
-6002:
394
- movl ARGBASE+24(%esp), %ebx # dst_err_ptr
395
- movl $-EFAULT,(%ebx)
396
- jmp 5000b
365
+ xorl %eax, %eax
366
+ jmp 7b
397367
398368 .previous
399369
....@@ -401,33 +371,33 @@
401371 popl %esi
402372 popl %edi
403373 popl %ecx # equivalent to addl $4,%esp
404
- ret
405
-ENDPROC(csum_partial_copy_generic)
374
+ RET
375
+SYM_FUNC_END(csum_partial_copy_generic)
406376
407377 #else
408378
409379 /* Version for PentiumII/PPro */
410380
411381 #define ROUND1(x) \
412
- SRC(movl x(%esi), %ebx ) ; \
382
+ EXC(movl x(%esi), %ebx ) ; \
413383 addl %ebx, %eax ; \
414
- DST(movl %ebx, x(%edi) ) ;
384
+ EXC(movl %ebx, x(%edi) ) ;
415385
416386 #define ROUND(x) \
417
- SRC(movl x(%esi), %ebx ) ; \
387
+ EXC(movl x(%esi), %ebx ) ; \
418388 adcl %ebx, %eax ; \
419
- DST(movl %ebx, x(%edi) ) ;
389
+ EXC(movl %ebx, x(%edi) ) ;
420390
421391 #define ARGBASE 12
422392
423
-ENTRY(csum_partial_copy_generic)
393
+SYM_FUNC_START(csum_partial_copy_generic)
424394 pushl %ebx
425395 pushl %edi
426396 pushl %esi
427397 movl ARGBASE+4(%esp),%esi #src
428398 movl ARGBASE+8(%esp),%edi #dst
429399 movl ARGBASE+12(%esp),%ecx #len
430
- movl ARGBASE+16(%esp),%eax #sum
400
+ movl $-1, %eax #sum
431401 # movl %ecx, %edx
432402 movl %ecx, %ebx
433403 movl %esi, %edx
....@@ -440,10 +410,10 @@
440410 andl $-32,%edx
441411 lea 3f(%ebx,%ebx), %ebx
442412 testl %esi, %esi
443
- JMP_NOSPEC %ebx
413
+ JMP_NOSPEC ebx
444414 1: addl $64,%esi
445415 addl $64,%edi
446
- SRC(movb -32(%edx),%bl) ; SRC(movb (%edx),%bl)
416
+ EXC(movb -32(%edx),%bl) ; EXC(movb (%edx),%bl)
447417 ROUND1(-64) ROUND(-60) ROUND(-56) ROUND(-52)
448418 ROUND (-48) ROUND(-44) ROUND(-40) ROUND(-36)
449419 ROUND (-32) ROUND(-28) ROUND(-24) ROUND(-20)
....@@ -457,37 +427,28 @@
457427 jz 7f
458428 cmpl $2, %edx
459429 jb 5f
460
-SRC( movw (%esi), %dx )
430
+EXC( movw (%esi), %dx )
461431 leal 2(%esi), %esi
462
-DST( movw %dx, (%edi) )
432
+EXC( movw %dx, (%edi) )
463433 leal 2(%edi), %edi
464434 je 6f
465435 shll $16,%edx
466436 5:
467
-SRC( movb (%esi), %dl )
468
-DST( movb %dl, (%edi) )
437
+EXC( movb (%esi), %dl )
438
+EXC( movb %dl, (%edi) )
469439 6: addl %edx, %eax
470440 adcl $0, %eax
471441 7:
472442 .section .fixup, "ax"
473
-6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
474
- movl $-EFAULT, (%ebx)
475
- # zero the complete destination (computing the rest is too much work)
476
- movl ARGBASE+8(%esp),%edi # dst
477
- movl ARGBASE+12(%esp),%ecx # len
478
- xorl %eax,%eax
479
- rep; stosb
480
- jmp 7b
481
-6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
482
- movl $-EFAULT, (%ebx)
443
+6001: xorl %eax, %eax
483444 jmp 7b
484445 .previous
485446
486447 popl %esi
487448 popl %edi
488449 popl %ebx
489
- ret
490
-ENDPROC(csum_partial_copy_generic)
450
+ RET
451
+SYM_FUNC_END(csum_partial_copy_generic)
491452
492453 #undef ROUND
493454 #undef ROUND1