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.
http://hackage.haskell.org/trac/haskell-prime/wiki/ForeignData
so if you do this
foreign import "volatile &periphBase" periphBase :: Ptr a = 0x40000000
it will automatically create the appropriate header and lds entries.
John
On Wed, Mar 6, 2013 at 7:05 AM, John Meacham
On Wed, Mar 6, 2013 at 6:43 AM, Kiwamu Okabe
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