[jhc] [BUG] Poke should use volatile.

Kiwamu Okabe kiwamu at gmail.com
Thu Mar 7 02:29:22 CET 2013


Hi, John.
Thank's for your advice.

On Thu, Mar 7, 2013 at 12:05 AM, John Meacham <john at repetae.net> wrote:
> As a quick test that won't require modifying jhc, add
>
> extern volatile void physicalAddress;
> to your rts header
> and compile adding the flag "-Wl,--defsym=physicalAddress=0"
>
> then in your haskell code where you want to do hardware register access do
>
> foreign import "&physicalAddress" physicalAddress :: Ptr Word32
>
> and use physicalAddress instead of nullPtr in your code as the base,
> by going through the volatile physicalAddress it will know not to
> optimize it away, whereas it knows that 'nullPtr' is actually zero
> which is why it was causing issues. So you would have
>
> periphBase     = physicalAddress  `plusPtr` 0x40000000
>
> then you won't have to modify the poke and peek primitives.

It's good.
My application controls memory mapped IO with the patch
extern_volatile.patch (attached).

But I have more question.
Ajhc with your patch outputs hs_main.c file (attached) from Main.hs
file (attached).

--- In hs_main.c
static wptr_t A_STD A_MALLOC
fW$__fMain_ledOff(gc_t gc,uint16_t v691543073)
{
        *((uint16_t *)(1207963688 +
((uintptr_t)&jhc_physicalAddress))) = v691543073;
        return SET_RAW_TAG(CJhc_Prim_Prim_$LR);
}
--------

It casts &jhc_physicalAddress with uintptr_t.
Does it strip the volatile type?
If not, extern volatile method resolves my problem perfectly.

Thank's.
--
Kiwamu Okabe
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Main.hs
Type: application/octet-stream
Size: 1224 bytes
Desc: not available
URL: <http://www.haskell.org/pipermail/jhc/attachments/20130307/0ae6b925/attachment-0002.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: hs_main.c
Type: text/x-csrc
Size: 23139 bytes
Desc: not available
URL: <http://www.haskell.org/pipermail/jhc/attachments/20130307/0ae6b925/attachment-0001.c>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: extern_volatile.patch
Type: application/octet-stream
Size: 1831 bytes
Desc: not available
URL: <http://www.haskell.org/pipermail/jhc/attachments/20130307/0ae6b925/attachment-0003.obj>


More information about the jhc mailing list