[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH] Fix eisa_mmap evaluation, add memory existence check
From: |
Marco Gerards |
Subject: |
Re: [PATCH] Fix eisa_mmap evaluation, add memory existence check |
Date: |
Sat, 10 Nov 2007 16:59:06 +0100 |
User-agent: |
Gnus/5.110006 (No Gnus v0.6) Emacs/21.4 (gnu/linux) |
Christian Franke <address@hidden> 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
Re: [PATCH] Fix eisa_mmap evaluation, add memory existence check, Robert Millan, 2007/11/18