[jhc] [BUG] Poke should use volatile.

Kiwamu Okabe kiwamu at gmail.com
Fri Feb 22 14:11:00 CET 2013


Hi.

I think poke function should use volatile on C language side.
If not, the code created with jhc cannot write raw memory.

diff --git a/src/C/FromGrin2.hs b/src/C/FromGrin2.hs
index 46e1a08..d4508bd 100644
--- a/src/C/FromGrin2.hs
+++ b/src/C/FromGrin2.hs
@@ -712,7 +712,7 @@ convertPrim p vs ty
     | (Poke t) <- p, [v,x] <- vs = do
         v' <- convertVal v
         x' <- convertVal x
-        return $ expressionRaw ("*((" <> (opTyToC' t) <+> "*)" <>
(parens $ renderG v') <> text ") = " <> renderG x')
+        return $ expressionRaw ("*((volatile " <> (opTyToC' t) <+>
"*)" <> (parens $ renderG v') <> text ") = " <> renderG x')
     | (AddrOf _ t) <- p, [] <- vs = do
         rt <- convertTypes ty
         return . cast rt $ expressionRaw ('&':unpackPS t)

I found it when use jhc to program Cortex-M3.

  https://gitorious.org/metasepi/demo-cortex-m3

Regards,
--
Kiwamu Okabe



More information about the jhc mailing list