Christian Franke <[EMAIL PROTECTED]> 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



_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/grub-devel

Reply via email to