Xref: utzoo comp.protocols.tcp-ip:13341 comp.sources.wanted:13600 Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!uakari.primate.wisc.edu!aplcen!haven!ni.umd.edu!sayshell.umd.edu!louie From: louie@sayshell.umd.edu (Louis A. Mamakos) Newsgroups: comp.protocols.tcp-ip,comp.sources.wanted Subject: Re: Looking for in_cksum for 68k. Keywords: in_cksum, 68k Message-ID: <1990Oct12.170424.20226@ni.umd.edu> Date: 12 Oct 90 17:04:24 GMT References: <347@megadata.mega.oz.au> Sender: usenet@ni.umd.edu (USENET News System) Organization: The University of Maryland, College Park Lines: 56 Nntp-Posting-Host: sayshell.umd.edu In article <347@megadata.mega.oz.au> andrew@megadata.mega.oz.au (Andrew McRae) writes: >Does anyone have a 68000 specific in_cksum routine for >doing IP checksums? The is the checksum routing that I use in the Amiga port of the KA9Q TCP/IP package. It seems to work. louie ; ; Compute the 1's complement sum of data buffer. Called from C as ; ; unsigned short ; lcsum(buf, cnt) ; unsigned short *buf; ; unsigned short cnt; ; ; _lcsum: MOVE.L 4(A7),A0 ; get pointer to data block MOVE.L 8(A7),D1 ; get number of 16bit words to sum MOVE D2,A1 ; save D2 in a volitile register MOVE D1,D2 ; save a copy of the count LSR.L #1,D1 ; convert from words to longs MOVEQ.L #0,D0 ; D0 used to accumulate the sum, clear CC BRA.S endl ; jump to end of loop to start things off ; ; Take advantage of 68010 loop mode cache and add 2 words at a time until ; a carry propagates out. 68020 users win 'cause of instruction cache. ; loop: ADD.L (A0)+,D0 ; add two words in endl: DBCS D1,loop BCC.S done ; jump if done ADDQ.L #1,D0 ; add in carry BRA.S endl ; resume loop done: BTST #0,D2 ; was word count odd? BEQ.S done2 MOVEQ.L #0,D2 MOVE.W (A0),D2 ; get the last word ADD.L D2,D0 ; add it in BCC.S done2 ; did that cause a carry? ADDQ.L #1,D0 ; yes done2: MOVE.L A1,D2 ; restore register MOVE.L D0,D1 ; get copy of sum D0=ABCD D1=ABCD SWAP.W D1 ; into low order part of D1 D0=ABCD D1=CDAB AND.L #$FFFF,D1 ; zap (is this necessary?) D0=ABCD D1=00AB ADD.W D0,D1 ; two halfs of sum together MOVEQ.L #0,D0 ADDX.W D0,D1 ; get last carry MOVE.W D1,D0 RTS