From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1Iqd1i-0007l4-S7 for mharc-grub-devel@gnu.org; Fri, 09 Nov 2007 18:12:38 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Iqd1g-0007jz-Ur for grub-devel@gnu.org; Fri, 09 Nov 2007 18:12:37 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Iqd1e-0007iv-7x for grub-devel@gnu.org; Fri, 09 Nov 2007 18:12:36 -0500 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Iqd1e-0007ij-0J for grub-devel@gnu.org; Fri, 09 Nov 2007 18:12:34 -0500 Received: from mailout01.sul.t-online.de ([194.25.134.80] helo=mailout01.sul.t-online.com) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1Iqd1d-0001qf-NO for grub-devel@gnu.org; Fri, 09 Nov 2007 18:12:33 -0500 Received: from fwd26.aul.t-online.de by mailout01.sul.t-online.com with smtp id 1Iqd1c-0000Y8-01; Sat, 10 Nov 2007 00:12:32 +0100 Received: from [10.3.2.2] (G-H2pvZcYhj4pSeUWpJWv+gz-10J8INvjWQ70kJQx2Tfcdw4tXBmLCBkekV5DFwgj9@[217.235.206.191]) by fwd26.aul.t-online.de with esmtp id 1Iqd1c-10shPM0; Sat, 10 Nov 2007 00:12:32 +0100 Message-ID: <4734E963.20000@t-online.de> Date: Sat, 10 Nov 2007 00:12:35 +0100 From: Christian Franke User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070802 SeaMonkey/1.1.4 MIME-Version: 1.0 To: The development of GRUB 2 References: <471E4628.9030706@t-online.de> <87d4ujmrkm.fsf@xs4all.nl> In-Reply-To: <87d4ujmrkm.fsf@xs4all.nl> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-ID: G-H2pvZcYhj4pSeUWpJWv+gz-10J8INvjWQ70kJQx2Tfcdw4tXBmLCBkekV5DFwgj9 X-TOI-MSGID: cd6e35c8-9703-4aeb-bdbd-ef508ca5653d X-detected-kernel: by monty-python.gnu.org: Linux 2.6 (newer, 3) 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: Fri, 09 Nov 2007 23:12:37 -0000 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: $ 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 :-) Christian