[Haskell-cafe] [Help] Trying to rewrite the NetBSD kernel using Haskell language.
Kiwamu Okabe
kiwamu at debian.or.jp
Mon Jan 20 13:55:36 UTC 2014
Hi Haskell hackers,
We start trying to rewrite NetBSD kernel using Haskell language.
https://github.com/metasepi/netbsd-arafura-s1
But we find some problems.
Could you have any ideas for them?
## Status
* Trying rewrite AC''97 sound driver using Haskell
* Before rewriting. (C language)
https://github.com/metasepi/netbsd-arafura-s1/blob/d1b19c686de5573ef8a8342a38b18102476aa1d4/sys/dev/pci/auich.c#L917
* After rewriting. (Haskell language)
https://github.com/metasepi/netbsd-arafura-s1/blob/d1b19c686de5573ef8a8342a38b18102476aa1d4/metasepi/sys/hssrc/Dev/Pci/Auich.hs#L7
* Have rewrited 2 functions, auich_open() and auich_close()
* Not yet touch Haskell heap
## Problems
Some time, C programmer writes following code.
~~~
static int
auich_open(void *addr, int flags)
{
struct auich_softc *sc;
sc = (struct auich_softc *)addr;
mutex_spin_exit(&sc->sc_intr_lock);
sc->codec_if->vtbl->lock(sc->codec_if);
~~~
Note the line "sc->codec_if->vtbl->lock(sc->codec_if);".
It traces pointer tree regionally.
Haskell's Strorable class is not good for the use case,
because it copies the entire pointer tree!
We avoid the problem using following messy code.
https://github.com/metasepi/netbsd-arafura-s1/blob/d1b19c686de5573ef8a8342a38b18102476aa1d4/metasepi/sys/hssrc/Dev/Pci/Auich.hs#L28
~~~
auichOpen :: Ptr AuichSoftc -> Int -> IO Int
auichOpen sc flags = do
mutexp <- p_AuichSoftc_sc_intr_lock sc
codeif <- peek =<< p_AuichSoftc_codec_if sc
lock <- peek =<< p_Ac97CodecIfVtbl_lock =<< peek =<< p_Ac97CodecIf_vtbl codeif
mutexSpinExit mutexp
call_Ac97CodecIfVtbl_lock lock codeif
-- snip --
p_AuichSoftc_sc_intr_lock :: Ptr AuichSoftc -> IO (Ptr KmutexT)
p_AuichSoftc_sc_intr_lock p = return $ plusPtr p
offsetOf_AuichSoftc_sc_intr_lock
p_AuichSoftc_codec_if :: Ptr AuichSoftc -> IO (Ptr (Ptr Ac97CodecIf))
p_AuichSoftc_codec_if p = return $ plusPtr p offsetOf_AuichSoftc_codec_if
p_Ac97CodecIf_vtbl :: Ptr Ac97CodecIf -> IO (Ptr (Ptr Ac97CodecIfVtbl))
p_Ac97CodecIf_vtbl p = return $ plusPtr p offsetOf_Ac97CodecIf_vtbl
p_Ac97CodecIfVtbl_lock :: Ptr Ac97CodecIfVtbl -> IO (Ptr (FunPtr
Ac97CodecIfVtbl_lock))
p_Ac97CodecIfVtbl_lock p = return $ plusPtr p offsetOf_Ac97CodecIfVtbl_lock
~~~
Haskell world has the answer for it already?
Best regards,
--
Kiwamu Okabe
More information about the Haskell-Cafe
mailing list