root/arch/i386/lib/checksum.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. csum_partial
  2. csum_partial_copyffs

   1 /*
   2  * INET         An implementation of the TCP/IP protocol suite for the LINUX
   3  *              operating system.  INET is implemented using the  BSD Socket
   4  *              interface as the means of communication with the user level.
   5  *
   6  *              IP/TCP/UDP checksumming routines
   7  *
   8  * Authors:     Jorge Cwik, <jorge@laser.satlink.net>
   9  *              Arnt Gulbrandsen, <agulbra@nvg.unit.no>
  10  *              Lots of code moved from tcp.c and ip.c; see those files
  11  *              for more names.
  12  *
  13  *              This program is free software; you can redistribute it and/or
  14  *              modify it under the terms of the GNU General Public License
  15  *              as published by the Free Software Foundation; either version
  16  *              2 of the License, or (at your option) any later version.
  17  */
  18 
  19 #include <net/checksum.h>
  20 
  21 /*
  22  * computes a partial checksum, e.g. for TCP/UDP fragments
  23  */
  24 
  25 unsigned int csum_partial(unsigned char * buff, int len, unsigned int sum) {
     /* [previous][next][first][last][top][bottom][index][help] */
  26 #ifdef __i386__
  27         __asm__("
  28             movl %%ecx, %%edx
  29             cld
  30             shrl $5, %%ecx
  31             jz 2f
  32             orl %%ecx, %%ecx
  33 1:          movl (%%esi), %%eax
  34             adcl %%eax, %%ebx
  35             movl 4(%%esi), %%eax
  36             adcl %%eax, %%ebx
  37             movl 8(%%esi), %%eax
  38             adcl %%eax, %%ebx
  39             movl 12(%%esi), %%eax
  40             adcl %%eax, %%ebx
  41             movl 16(%%esi), %%eax
  42             adcl %%eax, %%ebx
  43             movl 20(%%esi), %%eax
  44             adcl %%eax, %%ebx
  45             movl 24(%%esi), %%eax
  46             adcl %%eax, %%ebx
  47             movl 28(%%esi), %%eax
  48             adcl %%eax, %%ebx
  49             lea 32(%%esi), %%esi
  50             dec %%ecx
  51             jne 1b
  52             adcl $0, %%ebx
  53 2:          movl %%edx, %%ecx
  54             andl $28, %%ecx
  55             je 4f
  56             shrl $2, %%ecx
  57             orl %%ecx, %%ecx
  58 3:          adcl (%%esi), %%ebx
  59             lea 4(%%esi), %%esi
  60             dec %%ecx
  61             jne 3b
  62             adcl $0, %%ebx
  63 4:          movl $0, %%eax
  64             testw $2, %%dx
  65             je 5f
  66             lodsw
  67             addl %%eax, %%ebx
  68             adcl $0, %%ebx
  69             movw $0, %%ax
  70 5:          test $1, %%edx
  71             je 6f
  72             lodsb
  73             addl %%eax, %%ebx
  74             adcl $0, %%ebx
  75 6:          "
  76         : "=b"(sum)
  77         : "0"(sum), "c"(len), "S"(buff)
  78         : "ax", "bx", "cx", "dx", "si" );
  79 #else
  80 #error Not implemented for this CPU
  81 #endif
  82         return(sum);
  83 }
  84 
  85 
  86 
  87 /*
  88  * copy from fs while checksumming, otherwise like csum_partial
  89  */
  90 
  91 unsigned int csum_partial_copyffs( char *src, char *dst, 
     /* [previous][next][first][last][top][bottom][index][help] */
  92                                   int len, int sum) {
  93 #ifdef __i386__
  94     __asm__("
  95         push %%ds
  96         push %%es
  97         movw %%ds, %%dx
  98         movw %%dx, %%es
  99         movw %%fs, %%dx
 100         movw %%dx, %%ds
 101         cld
 102         cmpl $32, %%ecx
 103         jb 2f
 104         pushl %%ecx
 105         shrl $5, %%ecx
 106         orl %%ecx, %%ecx
 107 1:      movl (%%esi), %%eax
 108         movl 4(%%esi), %%edx
 109         adcl %%eax, %%ebx
 110         movl %%eax, %%es:(%%edi)
 111         adcl %%edx, %%ebx
 112         movl %%edx, %%es:4(%%edi)
 113 
 114         movl 8(%%esi), %%eax
 115         movl 12(%%esi), %%edx
 116         adcl %%eax, %%ebx
 117         movl %%eax, %%es:8(%%edi)
 118         adcl %%edx, %%ebx
 119         movl %%edx, %%es:12(%%edi)
 120 
 121         movl 16(%%esi), %%eax
 122         movl 20(%%esi), %%edx
 123         adcl %%eax, %%ebx
 124         movl %%eax, %%es:16(%%edi)
 125         adcl %%edx, %%ebx
 126         movl %%edx, %%es:20(%%edi)
 127 
 128         movl 24(%%esi), %%eax
 129         movl 28(%%esi), %%edx
 130         adcl %%eax, %%ebx
 131         movl %%eax, %%es:24(%%edi)
 132         adcl %%edx, %%ebx
 133         movl %%edx, %%es:28(%%edi)
 134 
 135         lea 32(%%esi), %%esi
 136         lea 32(%%edi), %%edi
 137         dec %%ecx
 138         jne 1b
 139         adcl $0, %%ebx
 140         popl %%ecx
 141 2:      movl %%ecx, %%edx
 142         andl $28, %%ecx
 143         je 4f
 144         shrl $2, %%ecx
 145         orl %%ecx, %%ecx
 146 3:      movl (%%esi), %%eax
 147         adcl %%eax, %%ebx
 148         movl %%eax, %%es:(%%edi)
 149         lea 4(%%esi), %%esi
 150         lea 4(%%edi), %%edi
 151         dec %%ecx
 152         jne 3b
 153         adcl $0, %%ebx
 154 4:      movl $0, %%eax
 155         testl $2, %%edx
 156         je 5f
 157         lodsw
 158         stosw
 159         addl %%eax, %%ebx
 160         movw $0, %%ax
 161         adcl %%eax, %%ebx
 162 5:      test $1, %%edx
 163         je 6f
 164         lodsb
 165         stosb
 166         addl %%eax, %%ebx
 167         adcl $0, %%ebx
 168 6:      pop %%es
 169         pop %%ds
 170         "
 171         : "=b"(sum)
 172         : "0"(sum), "c"(len), "S"(src), "D"(dst)
 173         : "ax", "bx", "cx", "dx", "si", "di" );
 174 #else
 175 #error Not implemented for this CPU
 176 #endif
 177     return(sum);
 178 }
 179 
 180 
 181 

/* [previous][next][first][last][top][bottom][index][help] */