From owner-freebsd-current@FreeBSD.ORG Mon Jul 9 03:27:32 2007 Return-Path: X-Original-To: freebsd-current@FreeBSD.org Delivered-To: freebsd-current@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 36AA016A46B for ; Mon, 9 Jul 2007 03:27:32 +0000 (UTC) (envelope-from zhouzhouyi@FreeBSD.org) Received: from ercist.iscas.ac.cn (ercist.iscas.ac.cn [124.16.138.3]) by mx1.freebsd.org (Postfix) with SMTP id BA14C13C4B9 for ; Mon, 9 Jul 2007 03:27:29 +0000 (UTC) (envelope-from zhouzhouyi@FreeBSD.org) Received: (qmail 55506 invoked by uid 98); 9 Jul 2007 02:58:19 -0000 Received: from 222.191.237.170 by ercist.iscas.ac.cn (envelope-from , uid 89) with qmail-scanner-1.25 (spamassassin: 3.1.0. Clear:RC:1(222.191.237.170):SA:0(0.0/10.0):. Processed in 1.014499 secs); 09 Jul 2007 02:58:19 -0000 X-Spam-Status: No, hits=0.0 required=10.0 X-Qmail-Scanner-Mail-From: zhouzhouyi@FreeBSD.org via ercist.iscas.ac.cn X-Qmail-Scanner: 1.25 (Clear:RC:1(222.191.237.170):SA:0(0.0/10.0):. Processed in 1.014499 secs) Received: from unknown (HELO zzy.H.qngy.gscas) (zhouzhouyi@ercist.iscas.ac.cn@222.191.237.170) by 0 with SMTP; 9 Jul 2007 02:58:17 -0000 Date: Mon, 9 Jul 2007 10:55:47 +0800 From: zhouyi zhou To: freebsd-hackers@FreeBSD.org Message-Id: <20070709105547.71827eb8.zhouzhouyi@FreeBSD.org> Organization: Institute of Software X-Mailer: Sylpheed version 1.0.4 (GTK+ 1.2.10; i386-portbld-freebsd5.4) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Cc: freebsd-current@FreeBSD.org Subject: rewrite src/sys/i386/i386/in_cksum.c X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 09 Jul 2007 03:27:32 -0000 Hey, Since FreeBSD update gcc from 3.4.x to 4.2.0, the FreeBSD gdb remote debugger in i386 platform will find the TCP/UPD checksum will not be computed right, when calling macro in_cksum which calls in_cksum_skip in src/sys/i386/i386/in_cksum.c in case of getting rid of -O flag supplied to gcc when compiling(The optimize will interfere with comfortable gdb debugging). The reason is for example in src/sys/i386/i386/in_cksum.c: 126 if (mlen >= 16) { 127 __asm volatile ("addl %1, %0" : "+r" (sum) : "g" (((const unsigned int *)w)[0 / 4])); 128 __asm volatile ("adcl %1, %0" : "+r" (sum) : "g" (((const unsigned int *)w)[4 / 4])); 129 __asm volatile ("adcl %1, %0" : "+r" (sum) : "g" (((const unsigned int *)w)[8 / 4])); 130 __asm volatile ("adcl %1, %0" : "+r" (sum) : "g" (((const unsigned int *)w)[12 / 4])); 131 __asm volatile ("adcl $0, %0" : "+r" (sum)); 132 w += 8; 133 mlen -= 16; 134 } This is OK with gcc-3.4.x, because the compiler will not insert add instructions between the _asm expressions, but in gcc-4.x.x case, the compiler will insert add instruction between the _asm expressions which will let carrage bit in eflags cleared. 0x0804877c : cmpl $0xf,0xffffffec(%ebp) 0x08048780 : jle 0x80487d0 0x08048782 : mov 0xffffffe4(%ebp),%eax 0x08048785 : mov (%eax),%eax 0x08048787 : mov 0xffffffe8(%ebp),%edx 0x0804878a : add %eax,%edx 0x0804878c : mov %edx,0xffffffe8(%ebp) 0x0804878f : mov 0xffffffe4(%ebp),%eax ---Type to continue, or q to quit--- 0x08048792 : add $0x4,%eax 0x08048795 : mov (%eax),%eax 0x08048797 : mov 0xffffffe8(%ebp),%edx 0x0804879a : adc %eax,%edx 0x0804879c : mov %edx,0xffffffe8(%ebp) 0x0804879f : mov 0xffffffe4(%ebp),%eax 0x080487a2 : add $0x8,%eax 0x080487a5 : mov (%eax),%eax 0x080487a7 : mov 0xffffffe8(%ebp),%edx 0x080487aa : adc %eax,%edx 0x080487ac : mov %edx,0xffffffe8(%ebp) 0x080487af : mov 0xffffffe4(%ebp),%eax 0x080487b2 : add $0xc,%eax 0x080487b5 : mov (%eax),%eax 0x080487b7 : mov 0xffffffe8(%ebp),%edx 0x080487ba : adc %eax,%edx 0x080487bc : mov %edx,0xffffffe8(%ebp) So, I suggest rewrite src/sys/i386/i386/in_cksum.c in following style, for example: --- in_cksum.c 2007-07-06 22:45:52.000000000 +0000 +++ in_cksum1.c 2007-07-07 00:18:25.000000000 +0000 @@ -124,11 +124,14 @@ mlen -= 32; } if (mlen >= 16) { - __asm volatile ("addl %1, %0" : "+r" (sum) : "g" (((const unsigned int *)w)[0 / 4])); - __asm volatile ("adcl %1, %0" : "+r" (sum) : "g" (((const unsigned int *)w)[4 / 4])); - __asm volatile ("adcl %1, %0" : "+r" (sum) : "g" (((const unsigned int *)w)[8 / 4])); - __asm volatile ("adcl %1, %0" : "+r" (sum) : "g" (((const unsigned int *)w)[12 / 4])); - __asm volatile ("adcl $0, %0" : "+r" (sum)); + __asm volatile ("addl %1, %0 \n" + "adcl %2, %0 \n" + "adcl %3, %0 \n" + "adcl %4, %0 \n" + "adcl $0, %0": "+r"(sum): "g" (((const unsigned int *)w)[0 / 4]), + "g" (((const unsigned int *)w)[4 / 4]), + "g" (((const unsigned int *)w)[8 / 4]), + "g" (((const unsigned int *)w)[12 / 4])); w += 8; mlen -= 16; } If someone is interested in it, he can lend me a hand to rewrite all of the similiar cases. Sincerely yours Zhouyi Zhou