Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1IqsjG-0004pT-8g for mharc-grub-devel@gnu.org; Sat, 10 Nov 2007 10:58:38 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1IqsjE-0004lM-C9 for grub-devel@gnu.org; Sat, 10 Nov 2007 10:58:36 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1IqsjC-0004hg-Tv for grub-devel@gnu.org; Sat, 10 Nov 2007 10:58:35 -0500 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1IqsjC-0004hV-KJ for grub-devel@gnu.org; Sat, 10 Nov 2007 10:58:34 -0500 Received: from smtp-vbr11.xs4all.nl ([194.109.24.31]) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1IqsjC-00073o-50 for grub-devel@gnu.org; Sat, 10 Nov 2007 10:58:34 -0500 Received: from localhost.localdomain (249-174.surfsnel.dsl.internl.net [145.99.174.249]) by smtp-vbr11.xs4all.nl (8.13.8/8.13.8) with ESMTP id lAAFwWoD017717 for ; Sat, 10 Nov 2007 16:58:32 +0100 (CET) (envelope-from mgerards@xs4all.nl) From: Marco Gerards To: The development of GRUB 2 References: <471E4628.9030706@t-online.de> <87d4ujmrkm.fsf@xs4all.nl> <4734E963.20000@t-online.de> Mail-Copies-To: mgerards@xs4all.nl Date: Sat, 10 Nov 2007 16:59:06 +0100 In-Reply-To: <4734E963.20000@t-online.de> (Christian Franke's message of "Sat, 10 Nov 2007 00:12:35 +0100") Message-ID: <87zlxmgkhh.fsf@xs4all.nl> User-Agent: Gnus/5.110006 (No Gnus v0.6) Emacs/21.4 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Virus-Scanned: by XS4ALL Virus Scanner X-detected-kernel: by monty-python.gnu.org: FreeBSD 4.6-4.9 Subject: Re: [PATCH] Fix eisa_mmap evaluation, add memory existence check X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: The development of GRUB 2 List-Id: The development of GRUB 2 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 10 Nov 2007 15:58:36 -0000 Christian Franke writes: > Marco Gerards wrote: >> ... >>> +static int >>> +addr_is_valid (grub_addr_t addr) >>> +{ >>> + volatile unsigned char * p = (volatile unsigned char *)addr; >>> >> >> Why volatile? I have the feeling it is not needed. >> >> >>> + unsigned char x, y; >>> + x = *p; >>> + *p = x ^ 0xcf; >>> + y = *p; >>> + *p = x; >>> + return y == (x ^ 0xcf); >>> +} >>> >> >> > > volatile is necessary here to tell the complier that the memory > address might not behave like regular memory. Otherwise, the optimizer > might legitimately remove memory accesses and then constant > propagation detects an unchanged value. > > gcc actually does a very good job here. Result with volatile removed: I think this is just normal memory, not memory mapped hardware. Or perhaps I am misunderstanding something here. > > $ gcc -S -O -fomit-frame-pointer init.c && cat init.s > ... > addr_is_valid: > movl $1, %eax > ret > ... > > > aka: > > static int > addr_is_valid (grub_addr_t addr) > { > return 1; > } > > > This is at least a proof that the original function returns the > correct result when real memory is present :-) :-) -- Marco