[jhc] [BUG] Poke should use volatile.

John Meacham john at repetae.net
Wed Mar 6 23:59:20 CET 2013

okay figured out a cleaner way to do it.

include the attached header file and add the arm-addresses.lds file to
the gcc or ld command line. Then you can foreign import the pointers.

If you can verify this works then I can implement it as part of the
ForeignData proposal with a volatile extension and have the compiler
automatically take these steps.


so if you do this
foreign import "volatile &periphBase" periphBase :: Ptr a = 0x40000000

it will automatically create the appropriate header and lds entries.


On Wed, Mar 6, 2013 at 7:05 AM, John Meacham <john at repetae.net> wrote:
> On Wed, Mar 6, 2013 at 6:43 AM, Kiwamu Okabe <kiwamu at gmail.com> wrote:
>> How do I write the code with extern volatile style?
> 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.
>     John
-------------- next part --------------
A non-text attachment was scrubbed...
Name: arm-addresses.h
Type: text/x-chdr
Size: 128 bytes
Desc: not available
URL: <http://www.haskell.org/pipermail/jhc/attachments/20130306/3a7d46e5/attachment-0001.h>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: arm-addresses.lds
Type: application/octet-stream
Size: 143 bytes
Desc: not available
URL: <http://www.haskell.org/pipermail/jhc/attachments/20130306/3a7d46e5/attachment-0001.obj>

More information about the jhc mailing list