metasepi team meeting #13: netbsd driver using haskell

43
Metasepi team meeting #13: NetBSD driver using Haskell Metasepi team meeting #13: NetBSD driver using Haskell Metasepi team meeting #13: NetBSD driver using Haskell Metasepi team meeting #13: NetBSD driver using Haskell Metasepi team meeting #13: NetBSD driver using Haskell Metasepi Project / Kiwamu Okabe Metasepi Project / Kiwamu Okabe Metasepi Project / Kiwamu Okabe Metasepi Project / Kiwamu Okabe Metasepi Project / Kiwamu Okabe

Upload: kiwamu-okabe

Post on 28-Jan-2015

117 views

Category:

Technology


8 download

DESCRIPTION

Metasepi team meeting #13: NetBSD driver using Haskell

TRANSCRIPT

Page 1: Metasepi team meeting #13: NetBSD driver using Haskell

Metasepi team meeting #13: NetBSD driver using HaskellMetasepi team meeting #13: NetBSD driver using HaskellMetasepi team meeting #13: NetBSD driver using HaskellMetasepi team meeting #13: NetBSD driver using HaskellMetasepi team meeting #13:NetBSD driver using Haskell

Metasepi Project / Kiwamu OkabeMetasepi Project / Kiwamu OkabeMetasepi Project / Kiwamu OkabeMetasepi Project / Kiwamu OkabeMetasepi Project / Kiwamu Okabe

Page 2: Metasepi team meeting #13: NetBSD driver using Haskell

Who am I?Who am I?Who am I?Who am I?Who am I?

☆ http://www.masterq.net/☆ http://www.masterq.net/☆ http://www.masterq.net/☆ http://www.masterq.net/☆ http://www.masterq.net/

☆ Self employed software engineer☆ Self employed software engineer☆ Self employed software engineer☆ Self employed software engineer☆ Self employed software engineer

☆ Founder of Metasepi Project☆ Founder of Metasepi Project☆ Founder of Metasepi Project☆ Founder of Metasepi Project☆ Founder of Metasepi Project

☆ A developer of Ajhc Haskell compiler☆ A developer of Ajhc Haskell compiler☆ A developer of Ajhc Haskell compiler☆ A developer of Ajhc Haskell compiler☆ A developer of Ajhc Haskell compiler

☆ A Debian Maintainer☆ A Debian Maintainer☆ A Debian Maintainer☆ A Debian Maintainer☆ A Debian Maintainer

☆ 10 years' experience in developing OS using NetBSD.☆ 10 years' experience in developing OS using NetBSD.☆ 10 years' experience in developing OS using NetBSD.☆ 10 years' experience in developing OS using NetBSD.☆ 10 years' experience in developing OS using NetBSD.

Page 3: Metasepi team meeting #13: NetBSD driver using Haskell

AgendaAgendaAgendaAgendaAgenda

☆ [1] Demo☆ [1] Demo☆ [1] Demo☆ [1] Demo☆ [1] Demo

☆ [2] What is Ajhc?☆ [2] What is Ajhc?☆ [2] What is Ajhc?☆ [2] What is Ajhc?☆ [2] What is Ajhc?

☆ [3] What is Metasepi?☆ [3] What is Metasepi?☆ [3] What is Metasepi?☆ [3] What is Metasepi?☆ [3] What is Metasepi?

☆ [4] What is compiler to build OS☆ [4] What is compiler to build OS☆ [4] What is compiler to build OS☆ [4] What is compiler to build OS☆ [4] What is compiler to build OS

☆ [5] NetBSD driver using Haskell☆ [5] NetBSD driver using Haskell☆ [5] NetBSD driver using Haskell☆ [5] NetBSD driver using Haskell☆ [5] NetBSD driver using Haskell

☆ [6] Ajhc is the best?☆ [6] Ajhc is the best?☆ [6] Ajhc is the best?☆ [6] Ajhc is the best?☆ [6] Ajhc is the best?

☆ [7] From Arafura to Bohai☆ [7] From Arafura to Bohai☆ [7] From Arafura to Bohai☆ [7] From Arafura to Bohai☆ [7] From Arafura to Bohai

Page 4: Metasepi team meeting #13: NetBSD driver using Haskell

[1] Demo[1] Demo[1] Demo[1] Demo[1] Demo

☆ NetBSD audio driver play sound☆ NetBSD audio driver play sound☆ NetBSD audio driver play sound☆ NetBSD audio driver play sound☆ NetBSD audio driver play sound

☆ The driver's interrupt handler rewrited using Haskell☆ The driver's interrupt handler rewrited using Haskell☆ The driver's interrupt handler rewrited using Haskell☆ The driver's interrupt handler rewrited using Haskell☆ The driver's interrupt handler rewrited using Haskell

☆ Watch the movie at following☆ Watch the movie at following☆ Watch the movie at following☆ Watch the movie at following☆ Watch the movie at following

http://bitly.com/netbsdajhchttp://bitly.com/netbsdajhchttp://bitly.com/netbsdajhchttp://bitly.com/netbsdajhchttp://bitly.com/netbsdajhc

☆ The source code at following☆ The source code at following☆ The source code at following☆ The source code at following☆ The source code at following

github.com/metasepi/netbsd-arafura-s1github.com/metasepi/netbsd-arafura-s1github.com/metasepi/netbsd-arafura-s1github.com/metasepi/netbsd-arafura-s1github.com/metasepi/netbsd-arafura-s1

Page 5: Metasepi team meeting #13: NetBSD driver using Haskell

Demo architectureDemo architectureDemo architectureDemo architectureDemo architecture

Page 6: Metasepi team meeting #13: NetBSD driver using Haskell

[2] What is Ajhc?[2] What is Ajhc?[2] What is Ajhc?[2] What is Ajhc?[2] What is Ajhc?

http://ajhc.metasepi.org/http://ajhc.metasepi.org/http://ajhc.metasepi.org/http://ajhc.metasepi.org/http://ajhc.metasepi.org/

☆ Ajhc := Arafura designed jhc☆ Ajhc := Arafura designed jhc☆ Ajhc := Arafura designed jhc☆ Ajhc := Arafura designed jhc☆ Ajhc := Arafura designed jhc

☆ jhc := John's Haskell Compiler☆ jhc := John's Haskell Compiler☆ jhc := John's Haskell Compiler☆ jhc := John's Haskell Compiler☆ jhc := John's Haskell Compiler

☆ http://repetae.net/computer/jhc/☆ http://repetae.net/computer/jhc/☆ http://repetae.net/computer/jhc/☆ http://repetae.net/computer/jhc/☆ http://repetae.net/computer/jhc/

☆ Jhc outputs binary that has low-memory-footprint and runs fast.☆ Jhc outputs binary that has low-memory-footprint and runs fast.☆ Jhc outputs binary that has low-memory-footprint and runs fast.☆ Jhc outputs binary that has low-memory-footprint and runs fast.☆ Jhc outputs binary that has low-memory-footprint and runs fast.

☆ Good for embedded software.☆ Good for embedded software.☆ Good for embedded software.☆ Good for embedded software.☆ Good for embedded software.

Page 7: Metasepi team meeting #13: NetBSD driver using Haskell

Who is John?Who is John?Who is John?Who is John?Who is John?

☆ John Meacham☆ John Meacham☆ John Meacham☆ John Meacham☆ John Meacham

☆ http://repetae.net/☆ http://repetae.net/☆ http://repetae.net/☆ http://repetae.net/☆ http://repetae.net/

Page 8: Metasepi team meeting #13: NetBSD driver using Haskell

Why need Ajhc?Why need Ajhc?Why need Ajhc?Why need Ajhc?Why need Ajhc?

☆ GHC is de facto standard on Haskell.☆ GHC is de facto standard on Haskell.☆ GHC is de facto standard on Haskell.☆ GHC is de facto standard on Haskell.☆ GHC is de facto standard on Haskell.

☆ GHC := Glasgow Haskell Compiler☆ GHC := Glasgow Haskell Compiler☆ GHC := Glasgow Haskell Compiler☆ GHC := Glasgow Haskell Compiler☆ GHC := Glasgow Haskell Compiler

☆ http://www.haskell.org/ghc/☆ http://www.haskell.org/ghc/☆ http://www.haskell.org/ghc/☆ http://www.haskell.org/ghc/☆ http://www.haskell.org/ghc/

☆ Why need another Haskell compiler?☆ Why need another Haskell compiler?☆ Why need another Haskell compiler?☆ Why need another Haskell compiler?☆ Why need another Haskell compiler?

☆ To develop kernel named "Metasepi".☆ To develop kernel named "Metasepi".☆ To develop kernel named "Metasepi".☆ To develop kernel named "Metasepi".☆ To develop kernel named "Metasepi".

Page 9: Metasepi team meeting #13: NetBSD driver using Haskell

[3] What is Metasepi?[3] What is Metasepi?[3] What is Metasepi?[3] What is Metasepi?[3] What is Metasepi?

http://metasepi.org/http://metasepi.org/http://metasepi.org/http://metasepi.org/http://metasepi.org/

☆ Unix-like OS designed by strong type.☆ Unix-like OS designed by strong type.☆ Unix-like OS designed by strong type.☆ Unix-like OS designed by strong type.☆ Unix-like OS designed by strong type.

☆ Using ML or more strong type lang.☆ Using ML or more strong type lang.☆ Using ML or more strong type lang.☆ Using ML or more strong type lang.☆ Using ML or more strong type lang.

Haskell http://www.haskell.org/Haskell http://www.haskell.org/Haskell http://www.haskell.org/Haskell http://www.haskell.org/Haskell http://www.haskell.org/

OCaml http://caml.inria.fr/OCaml http://caml.inria.fr/OCaml http://caml.inria.fr/OCaml http://caml.inria.fr/OCaml http://caml.inria.fr/

MLton http://mlton.org/MLton http://mlton.org/MLton http://mlton.org/MLton http://mlton.org/MLton http://mlton.org/

. . . and suchlike.. . . and suchlike.. . . and suchlike.. . . and suchlike.. . . and suchlike.

Page 10: Metasepi team meeting #13: NetBSD driver using Haskell

Why need Metasepi?Why need Metasepi?Why need Metasepi?Why need Metasepi?Why need Metasepi?

☆ We have already Linux or Windows.☆ We have already Linux or Windows.☆ We have already Linux or Windows.☆ We have already Linux or Windows.☆ We have already Linux or Windows.

☆ But the developers are suffering.☆ But the developers are suffering.☆ But the developers are suffering.☆ But the developers are suffering.☆ But the developers are suffering.

☆ If use the kernel changed by you,☆ If use the kernel changed by you,☆ If use the kernel changed by you,☆ If use the kernel changed by you,☆ If use the kernel changed by you,

☆ you will get many runtime error.☆ you will get many runtime error.☆ you will get many runtime error.☆ you will get many runtime error.☆ you will get many runtime error.

☆ Difficult even to reproduce it.☆ Difficult even to reproduce it.☆ Difficult even to reproduce it.☆ Difficult even to reproduce it.☆ Difficult even to reproduce it.

Page 11: Metasepi team meeting #13: NetBSD driver using Haskell

Doesn't OSS have good quality?Doesn't OSS have good quality?Doesn't OSS have good quality?Doesn't OSS have good quality?Doesn't OSS have good quality?

☆ "The Cathedral and the Bazaar"☆ "The Cathedral and the Bazaar"☆ "The Cathedral and the Bazaar"☆ "The Cathedral and the Bazaar"☆ "The Cathedral and the Bazaar"

☆ "Given enough eyeballs, all bugs are shallow."☆ "Given enough eyeballs, all bugs are shallow."☆ "Given enough eyeballs, all bugs are shallow."☆ "Given enough eyeballs, all bugs are shallow."☆ "Given enough eyeballs, all bugs are shallow."http://cruel.org/freeware/cathedral.htmlhttp://cruel.org/freeware/cathedral.htmlhttp://cruel.org/freeware/cathedral.htmlhttp://cruel.org/freeware/cathedral.htmlhttp://cruel.org/freeware/cathedral.html

☆ But if you develop your own product reusing OSS...☆ But if you develop your own product reusing OSS...☆ But if you develop your own product reusing OSS...☆ But if you develop your own product reusing OSS...☆ But if you develop your own product reusing OSS...

Page 12: Metasepi team meeting #13: NetBSD driver using Haskell

Low quality out of OSS umbrellaLow quality out of OSS umbrellaLow quality out of OSS umbrellaLow quality out of OSS umbrellaLow quality out of OSS umbrella

Page 13: Metasepi team meeting #13: NetBSD driver using Haskell

Type safetyType safetyType safetyType safetyType safety

☆ Less runtime errors.☆ Less runtime errors.☆ Less runtime errors.☆ Less runtime errors.☆ Less runtime errors.

☆ "数理科学的バグ撲滅方法論のすすめ"☆ "数理科学的バグ撲滅方法論のすすめ"☆ "数理科学的バグ撲滅方法論のすすめ"☆ "数理科学的バグ撲滅方法論のすすめ"☆ "数理科学的バグ撲滅方法論のすすめ"http://itpro.nikkeibp.co.jp/article/COLUMN/20060915/248230/http://itpro.nikkeibp.co.jp/article/COLUMN/20060915/248230/http://itpro.nikkeibp.co.jp/article/COLUMN/20060915/248230/http://itpro.nikkeibp.co.jp/article/COLUMN/20060915/248230/http://itpro.nikkeibp.co.jp/article/COLUMN/20060915/248230/

Page 14: Metasepi team meeting #13: NetBSD driver using Haskell

Kernel wants type desperatelyKernel wants type desperatelyKernel wants type desperatelyKernel wants type desperatelyKernel wants type desperately

☆ Kernels are developed with C lang.☆ Kernels are developed with C lang.☆ Kernels are developed with C lang.☆ Kernels are developed with C lang.☆ Kernels are developed with C lang.

☆ Error on user space => SEGV☆ Error on user space => SEGV☆ Error on user space => SEGV☆ Error on user space => SEGV☆ Error on user space => SEGV

☆ Error on kernel space => Halt!☆ Error on kernel space => Halt!☆ Error on kernel space => Halt!☆ Error on kernel space => Halt!☆ Error on kernel space => Halt!

☆ Should design kernel with the greatest care.☆ Should design kernel with the greatest care.☆ Should design kernel with the greatest care.☆ Should design kernel with the greatest care.☆ Should design kernel with the greatest care.

☆ C language is safe?☆ C language is safe?☆ C language is safe?☆ C language is safe?☆ C language is safe?

Page 15: Metasepi team meeting #13: NetBSD driver using Haskell

[4] What is compiler to build OS[4] What is compiler to build OS[4] What is compiler to build OS[4] What is compiler to build OS[4] What is compiler to build OS

☆ Need strong type.☆ Need strong type.☆ Need strong type.☆ Need strong type.☆ Need strong type.

☆ Need flexibility such as C language.☆ Need flexibility such as C language.☆ Need flexibility such as C language.☆ Need flexibility such as C language.☆ Need flexibility such as C language.

☆ Create it if there are not!☆ Create it if there are not!☆ Create it if there are not!☆ Create it if there are not!☆ Create it if there are not!

☆ From scratch? No thank you...☆ From scratch? No thank you...☆ From scratch? No thank you...☆ From scratch? No thank you...☆ From scratch? No thank you...

☆ Look for our compiler base.☆ Look for our compiler base.☆ Look for our compiler base.☆ Look for our compiler base.☆ Look for our compiler base.

Page 16: Metasepi team meeting #13: NetBSD driver using Haskell

Want POSIX free compilerWant POSIX free compilerWant POSIX free compilerWant POSIX free compilerWant POSIX free compiler

Programs to print "hoge" on terminal.Programs to print "hoge" on terminal.Programs to print "hoge" on terminal.Programs to print "hoge" on terminal.Programs to print "hoge" on terminal.

The lesser depends on POSIX, the smaller values.The lesser depends on POSIX, the smaller values.The lesser depends on POSIX, the smaller values.The lesser depends on POSIX, the smaller values.The lesser depends on POSIX, the smaller values.

Page 17: Metasepi team meeting #13: NetBSD driver using Haskell

Jhc output has only 20 undefJhc output has only 20 undefJhc output has only 20 undefJhc output has only 20 undefJhc output has only 20 undef$ nm hs.out | grep "U " U _IO_putc@@GLIBC_2.2.5 U __libc_start_main@@GLIBC_2.2.5 U _setjmp@@GLIBC_2.2.5 U abort@@GLIBC_2.2.5 U ctime@@GLIBC_2.2.5 U exit@@GLIBC_2.2.5 U fflush@@GLIBC_2.2.5 U fprintf@@GLIBC_2.2.5 U fputc@@GLIBC_2.2.5 U fputs@@GLIBC_2.2.5 U free@@GLIBC_2.2.5 U fwrite@@GLIBC_2.2.5 U getenv@@GLIBC_2.2.5 U malloc@@GLIBC_2.2.5 U memset@@GLIBC_2.2.5 U posix_memalign@@GLIBC_2.2.5 U realloc@@GLIBC_2.2.5 U setlocale@@GLIBC_2.2.5 U sysconf@@GLIBC_2.2.5 U times@@GLIBC_2.2.5

$ nm hs.out | grep "U " U _IO_putc@@GLIBC_2.2.5 U __libc_start_main@@GLIBC_2.2.5 U _setjmp@@GLIBC_2.2.5 U abort@@GLIBC_2.2.5 U ctime@@GLIBC_2.2.5 U exit@@GLIBC_2.2.5 U fflush@@GLIBC_2.2.5 U fprintf@@GLIBC_2.2.5 U fputc@@GLIBC_2.2.5 U fputs@@GLIBC_2.2.5 U free@@GLIBC_2.2.5 U fwrite@@GLIBC_2.2.5 U getenv@@GLIBC_2.2.5 U malloc@@GLIBC_2.2.5 U memset@@GLIBC_2.2.5 U posix_memalign@@GLIBC_2.2.5 U realloc@@GLIBC_2.2.5 U setlocale@@GLIBC_2.2.5 U sysconf@@GLIBC_2.2.5 U times@@GLIBC_2.2.5

$ nm hs.out | grep "U " U _IO_putc@@GLIBC_2.2.5 U __libc_start_main@@GLIBC_2.2.5 U _setjmp@@GLIBC_2.2.5 U abort@@GLIBC_2.2.5 U ctime@@GLIBC_2.2.5 U exit@@GLIBC_2.2.5 U fflush@@GLIBC_2.2.5 U fprintf@@GLIBC_2.2.5 U fputc@@GLIBC_2.2.5 U fputs@@GLIBC_2.2.5 U free@@GLIBC_2.2.5 U fwrite@@GLIBC_2.2.5 U getenv@@GLIBC_2.2.5 U malloc@@GLIBC_2.2.5 U memset@@GLIBC_2.2.5 U posix_memalign@@GLIBC_2.2.5 U realloc@@GLIBC_2.2.5 U setlocale@@GLIBC_2.2.5 U sysconf@@GLIBC_2.2.5 U times@@GLIBC_2.2.5

$ nm hs.out | grep "U " U _IO_putc@@GLIBC_2.2.5 U __libc_start_main@@GLIBC_2.2.5 U _setjmp@@GLIBC_2.2.5 U abort@@GLIBC_2.2.5 U ctime@@GLIBC_2.2.5 U exit@@GLIBC_2.2.5 U fflush@@GLIBC_2.2.5 U fprintf@@GLIBC_2.2.5 U fputc@@GLIBC_2.2.5 U fputs@@GLIBC_2.2.5 U free@@GLIBC_2.2.5 U fwrite@@GLIBC_2.2.5 U getenv@@GLIBC_2.2.5 U malloc@@GLIBC_2.2.5 U memset@@GLIBC_2.2.5 U posix_memalign@@GLIBC_2.2.5 U realloc@@GLIBC_2.2.5 U setlocale@@GLIBC_2.2.5 U sysconf@@GLIBC_2.2.5 U times@@GLIBC_2.2.5

$ nm hs.out | grep "U " U _IO_putc@@GLIBC_2.2.5 U __libc_start_main@@GLIBC_2.2.5 U _setjmp@@GLIBC_2.2.5 U abort@@GLIBC_2.2.5 U ctime@@GLIBC_2.2.5 U exit@@GLIBC_2.2.5 U fflush@@GLIBC_2.2.5 U fprintf@@GLIBC_2.2.5 U fputc@@GLIBC_2.2.5 U fputs@@GLIBC_2.2.5 U free@@GLIBC_2.2.5 U fwrite@@GLIBC_2.2.5 U getenv@@GLIBC_2.2.5 U malloc@@GLIBC_2.2.5 U memset@@GLIBC_2.2.5 U posix_memalign@@GLIBC_2.2.5 U realloc@@GLIBC_2.2.5 U setlocale@@GLIBC_2.2.5 U sysconf@@GLIBC_2.2.5 U times@@GLIBC_2.2.5

Page 18: Metasepi team meeting #13: NetBSD driver using Haskell

Jhc is translator to C languageJhc is translator to C languageJhc is translator to C languageJhc is translator to C languageJhc is translator to C language

Page 19: Metasepi team meeting #13: NetBSD driver using Haskell

Easy to cross buildEasy to cross buildEasy to cross buildEasy to cross buildEasy to cross build

Page 20: Metasepi team meeting #13: NetBSD driver using Haskell

Survive burning outSurvive burning outSurvive burning outSurvive burning outSurvive burning out

Let's develop with dogfooding style. (The method is called "Snatch".)Let's develop with dogfooding style. (The method is called "Snatch".)Let's develop with dogfooding style. (The method is called "Snatch".)Let's develop with dogfooding style. (The method is called "Snatch".)Let's develop with dogfooding style. (The method is called "Snatch".)

Page 21: Metasepi team meeting #13: NetBSD driver using Haskell

[5] NetBSD driver using Haskell[5] NetBSD driver using Haskell[5] NetBSD driver using Haskell[5] NetBSD driver using Haskell[5] NetBSD driver using Haskell

☆ Snatch target: HD Audio driver☆ Snatch target: HD Audio driver☆ Snatch target: HD Audio driver☆ Snatch target: HD Audio driver☆ Snatch target: HD Audio driversys/dev/pci/hdaudio |-- Makefile |-- ceareg.h |-- eldreg.h |-- files.hdaudio |-- hdafg.c |-- hdafg_dd.c |-- hdafg_dd.h |-- hdaudio.c |-- hdaudio_config.h |-- hdaudio_ids.c |-- hdaudio_ids.h |-- hdaudio_mixer.h |-- hdaudio_pci.c |-- hdaudio_pci.h |-- hdaudioio.h |-- hdaudioreg.h |-- hdaudiovar.h `-- hdmireg.h

sys/dev/pci/hdaudio |-- Makefile |-- ceareg.h |-- eldreg.h |-- files.hdaudio |-- hdafg.c |-- hdafg_dd.c |-- hdafg_dd.h |-- hdaudio.c |-- hdaudio_config.h |-- hdaudio_ids.c |-- hdaudio_ids.h |-- hdaudio_mixer.h |-- hdaudio_pci.c |-- hdaudio_pci.h |-- hdaudioio.h |-- hdaudioreg.h |-- hdaudiovar.h `-- hdmireg.h

sys/dev/pci/hdaudio |-- Makefile |-- ceareg.h |-- eldreg.h |-- files.hdaudio |-- hdafg.c |-- hdafg_dd.c |-- hdafg_dd.h |-- hdaudio.c |-- hdaudio_config.h |-- hdaudio_ids.c |-- hdaudio_ids.h |-- hdaudio_mixer.h |-- hdaudio_pci.c |-- hdaudio_pci.h |-- hdaudioio.h |-- hdaudioreg.h |-- hdaudiovar.h `-- hdmireg.h

sys/dev/pci/hdaudio |-- Makefile |-- ceareg.h |-- eldreg.h |-- files.hdaudio |-- hdafg.c |-- hdafg_dd.c |-- hdafg_dd.h |-- hdaudio.c |-- hdaudio_config.h |-- hdaudio_ids.c |-- hdaudio_ids.h |-- hdaudio_mixer.h |-- hdaudio_pci.c |-- hdaudio_pci.h |-- hdaudioio.h |-- hdaudioreg.h |-- hdaudiovar.h `-- hdmireg.h

sys/dev/pci/hdaudio |-- Makefile |-- ceareg.h |-- eldreg.h |-- files.hdaudio |-- hdafg.c |-- hdafg_dd.c |-- hdafg_dd.h |-- hdaudio.c |-- hdaudio_config.h |-- hdaudio_ids.c |-- hdaudio_ids.h |-- hdaudio_mixer.h |-- hdaudio_pci.c |-- hdaudio_pci.h |-- hdaudioio.h |-- hdaudioreg.h |-- hdaudiovar.h `-- hdmireg.h

Page 22: Metasepi team meeting #13: NetBSD driver using Haskell

Rewrited the driver entirety?Rewrited the driver entirety?Rewrited the driver entirety?Rewrited the driver entirety?Rewrited the driver entirety?

☆ No, partly☆ No, partly☆ No, partly☆ No, partly☆ No, partly

Page 23: Metasepi team meeting #13: NetBSD driver using Haskell

Where is Haskell code? (cont.)Where is Haskell code? (cont.)Where is Haskell code? (cont.)Where is Haskell code? (cont.)Where is Haskell code? (cont.)netbsd-arafura-s1 # <= based on NetBSD original source tree|-- BUILDING|-- GNUmakefile # <= Wrapper for building kernel|-- Makefile|-- Makefile.inc-- snip --|-- metasepi| |-- sound| | |-- Epopsan-signal.mp3| | `-- TheMojitoofFluorescence.mp3| `-- sys| |-- conf| | `-- files.haskell| |-- hsdummy # <= C code to support Ajhc runtime| `-- hssrc # <= Haskell code located| |-- Arch| | `-- I386| | |-- I386| | | `-- BusDma.hs| | `-- Include| | |-- BusDefs.hs| | |-- Cpu.hs| | `-- Types.hs

netbsd-arafura-s1 # <= based on NetBSD original source tree|-- BUILDING|-- GNUmakefile # <= Wrapper for building kernel|-- Makefile|-- Makefile.inc-- snip --|-- metasepi| |-- sound| | |-- Epopsan-signal.mp3| | `-- TheMojitoofFluorescence.mp3| `-- sys| |-- conf| | `-- files.haskell| |-- hsdummy # <= C code to support Ajhc runtime| `-- hssrc # <= Haskell code located| |-- Arch| | `-- I386| | |-- I386| | | `-- BusDma.hs| | `-- Include| | |-- BusDefs.hs| | |-- Cpu.hs| | `-- Types.hs

netbsd-arafura-s1 # <= based on NetBSD original source tree|-- BUILDING|-- GNUmakefile # <= Wrapper for building kernel|-- Makefile|-- Makefile.inc-- snip --|-- metasepi| |-- sound| | |-- Epopsan-signal.mp3| | `-- TheMojitoofFluorescence.mp3| `-- sys| |-- conf| | `-- files.haskell| |-- hsdummy # <= C code to support Ajhc runtime| `-- hssrc # <= Haskell code located| |-- Arch| | `-- I386| | |-- I386| | | `-- BusDma.hs| | `-- Include| | |-- BusDefs.hs| | |-- Cpu.hs| | `-- Types.hs

netbsd-arafura-s1 # <= based on NetBSD original source tree|-- BUILDING|-- GNUmakefile # <= Wrapper for building kernel|-- Makefile|-- Makefile.inc-- snip --|-- metasepi| |-- sound| | |-- Epopsan-signal.mp3| | `-- TheMojitoofFluorescence.mp3| `-- sys| |-- conf| | `-- files.haskell| |-- hsdummy # <= C code to support Ajhc runtime| `-- hssrc # <= Haskell code located| |-- Arch| | `-- I386| | |-- I386| | | `-- BusDma.hs| | `-- Include| | |-- BusDefs.hs| | |-- Cpu.hs| | `-- Types.hs

netbsd-arafura-s1 # <= based on NetBSD original source tree|-- BUILDING|-- GNUmakefile # <= Wrapper for building kernel|-- Makefile|-- Makefile.inc-- snip --|-- metasepi| |-- sound| | |-- Epopsan-signal.mp3| | `-- TheMojitoofFluorescence.mp3| `-- sys| |-- conf| | `-- files.haskell| |-- hsdummy # <= C code to support Ajhc runtime| `-- hssrc # <= Haskell code located| |-- Arch| | `-- I386| | |-- I386| | | `-- BusDma.hs| | `-- Include| | |-- BusDefs.hs| | |-- Cpu.hs| | `-- Types.hs

Page 24: Metasepi team meeting #13: NetBSD driver using Haskell

Where is Haskell code? (cont.)Where is Haskell code? (cont.)Where is Haskell code? (cont.)Where is Haskell code? (cont.)Where is Haskell code? (cont.)| |-- Dev| | |-- Auconv.hs| | |-- AudioIf.hs| | |-- Ic| | | |-- Ac97reg.hs| | | `-- Ac97var.hs| | `-- Pci| | |-- Auich| | | |-- Intr.hs| | | `-- Ptr.hs| | |-- Auich.hs| | |-- Auichreg.hs| | `-- Hdaudio| | |-- Hdaudio.hs| | |-- Hdaudioreg.hs| | `-- Hdaudiovar.hs| |-- Kern| | |-- KernMutex.hs| | |-- SubrKmem.hs| | `-- SubrPrf.hs| |-- Lib| | `-- Libkern| | `-- Libkern.hs

| |-- Dev| | |-- Auconv.hs| | |-- AudioIf.hs| | |-- Ic| | | |-- Ac97reg.hs| | | `-- Ac97var.hs| | `-- Pci| | |-- Auich| | | |-- Intr.hs| | | `-- Ptr.hs| | |-- Auich.hs| | |-- Auichreg.hs| | `-- Hdaudio| | |-- Hdaudio.hs| | |-- Hdaudioreg.hs| | `-- Hdaudiovar.hs| |-- Kern| | |-- KernMutex.hs| | |-- SubrKmem.hs| | `-- SubrPrf.hs| |-- Lib| | `-- Libkern| | `-- Libkern.hs

| |-- Dev| | |-- Auconv.hs| | |-- AudioIf.hs| | |-- Ic| | | |-- Ac97reg.hs| | | `-- Ac97var.hs| | `-- Pci| | |-- Auich| | | |-- Intr.hs| | | `-- Ptr.hs| | |-- Auich.hs| | |-- Auichreg.hs| | `-- Hdaudio| | |-- Hdaudio.hs| | |-- Hdaudioreg.hs| | `-- Hdaudiovar.hs| |-- Kern| | |-- KernMutex.hs| | |-- SubrKmem.hs| | `-- SubrPrf.hs| |-- Lib| | `-- Libkern| | `-- Libkern.hs

| |-- Dev| | |-- Auconv.hs| | |-- AudioIf.hs| | |-- Ic| | | |-- Ac97reg.hs| | | `-- Ac97var.hs| | `-- Pci| | |-- Auich| | | |-- Intr.hs| | | `-- Ptr.hs| | |-- Auich.hs| | |-- Auichreg.hs| | `-- Hdaudio| | |-- Hdaudio.hs| | |-- Hdaudioreg.hs| | `-- Hdaudiovar.hs| |-- Kern| | |-- KernMutex.hs| | |-- SubrKmem.hs| | `-- SubrPrf.hs| |-- Lib| | `-- Libkern| | `-- Libkern.hs

| |-- Dev| | |-- Auconv.hs| | |-- AudioIf.hs| | |-- Ic| | | |-- Ac97reg.hs| | | `-- Ac97var.hs| | `-- Pci| | |-- Auich| | | |-- Intr.hs| | | `-- Ptr.hs| | |-- Auich.hs| | |-- Auichreg.hs| | `-- Hdaudio| | |-- Hdaudio.hs| | |-- Hdaudioreg.hs| | `-- Hdaudiovar.hs| |-- Kern| | |-- KernMutex.hs| | |-- SubrKmem.hs| | `-- SubrPrf.hs| |-- Lib| | `-- Libkern| | `-- Libkern.hs

Page 25: Metasepi team meeting #13: NetBSD driver using Haskell

Where is Haskell code?Where is Haskell code?Where is Haskell code?Where is Haskell code?Where is Haskell code?| |-- Main.hs| |-- Metasepi| | `-- EitherIO.hs| `-- Sys| |-- Audioio.hs| |-- Bus.hs| |-- Device.hs| |-- Errno.hs| |-- Proc.hs| `-- Types.hs|-- regress|-- rescue|-- sbin|-- share|-- sys|-- tests|-- tools|-- travis-ci|-- usr.bin|-- usr.sbin`-- x11

| |-- Main.hs| |-- Metasepi| | `-- EitherIO.hs| `-- Sys| |-- Audioio.hs| |-- Bus.hs| |-- Device.hs| |-- Errno.hs| |-- Proc.hs| `-- Types.hs|-- regress|-- rescue|-- sbin|-- share|-- sys|-- tests|-- tools|-- travis-ci|-- usr.bin|-- usr.sbin`-- x11

| |-- Main.hs| |-- Metasepi| | `-- EitherIO.hs| `-- Sys| |-- Audioio.hs| |-- Bus.hs| |-- Device.hs| |-- Errno.hs| |-- Proc.hs| `-- Types.hs|-- regress|-- rescue|-- sbin|-- share|-- sys|-- tests|-- tools|-- travis-ci|-- usr.bin|-- usr.sbin`-- x11

| |-- Main.hs| |-- Metasepi| | `-- EitherIO.hs| `-- Sys| |-- Audioio.hs| |-- Bus.hs| |-- Device.hs| |-- Errno.hs| |-- Proc.hs| `-- Types.hs|-- regress|-- rescue|-- sbin|-- share|-- sys|-- tests|-- tools|-- travis-ci|-- usr.bin|-- usr.sbin`-- x11

| |-- Main.hs| |-- Metasepi| | `-- EitherIO.hs| `-- Sys| |-- Audioio.hs| |-- Bus.hs| |-- Device.hs| |-- Errno.hs| |-- Proc.hs| `-- Types.hs|-- regress|-- rescue|-- sbin|-- share|-- sys|-- tests|-- tools|-- travis-ci|-- usr.bin|-- usr.sbin`-- x11

Page 26: Metasepi team meeting #13: NetBSD driver using Haskell

How to buildHow to buildHow to buildHow to buildHow to build

☆ Install some packages☆ Install some packages☆ Install some packages☆ Install some packages☆ Install some packages$ sudo apt-get install ffmpeg qemu gcc$ sudo apt-get install ffmpeg qemu gcc$ sudo apt-get install ffmpeg qemu gcc$ sudo apt-get install ffmpeg qemu gcc$ sudo apt-get install ffmpeg qemu gcc

☆ Install Ajhc and git clone☆ Install Ajhc and git clone☆ Install Ajhc and git clone☆ Install Ajhc and git clone☆ Install Ajhc and git clone$ git clone https://github.com/metasepi/netbsd-arafura-s1.git$ cd netbsd-arafura-s1$ git clone https://github.com/metasepi/netbsd-arafura-s1.git$ cd netbsd-arafura-s1$ git clone https://github.com/metasepi/netbsd-arafura-s1.git$ cd netbsd-arafura-s1$ git clone https://github.com/metasepi/netbsd-arafura-s1.git$ cd netbsd-arafura-s1$ git clone https://github.com/metasepi/netbsd-arafura-s1.git$ cd netbsd-arafura-s1

☆ Build QEMU image☆ Build QEMU image☆ Build QEMU image☆ Build QEMU image☆ Build QEMU image$ make bootcd$ make bootcd$ make bootcd$ make bootcd$ make bootcd

Page 27: Metasepi team meeting #13: NetBSD driver using Haskell

Run the kernelRun the kernelRun the kernelRun the kernelRun the kernel

Run kernel on qemuRun kernel on qemuRun kernel on qemuRun kernel on qemuRun kernel on qemu$ make qemu

>> NetBSD/x86 BIOS Boot, Revision 5.9 (from NetBSD 6.1.1_PATCH)>> Memory: 639/1047544 k--snip--Created tmpfs /dev (1490944 byte, 2880 inodes)erase ^?, werase ^W, kill ^U, intr ^CThis image contains utilities which may be neededto get you out of a pinch.#

$ make qemu

>> NetBSD/x86 BIOS Boot, Revision 5.9 (from NetBSD 6.1.1_PATCH)>> Memory: 639/1047544 k--snip--Created tmpfs /dev (1490944 byte, 2880 inodes)erase ^?, werase ^W, kill ^U, intr ^CThis image contains utilities which may be neededto get you out of a pinch.#

$ make qemu

>> NetBSD/x86 BIOS Boot, Revision 5.9 (from NetBSD 6.1.1_PATCH)>> Memory: 639/1047544 k--snip--Created tmpfs /dev (1490944 byte, 2880 inodes)erase ^?, werase ^W, kill ^U, intr ^CThis image contains utilities which may be neededto get you out of a pinch.#

$ make qemu

>> NetBSD/x86 BIOS Boot, Revision 5.9 (from NetBSD 6.1.1_PATCH)>> Memory: 639/1047544 k--snip--Created tmpfs /dev (1490944 byte, 2880 inodes)erase ^?, werase ^W, kill ^U, intr ^CThis image contains utilities which may be neededto get you out of a pinch.#

$ make qemu

>> NetBSD/x86 BIOS Boot, Revision 5.9 (from NetBSD 6.1.1_PATCH)>> Memory: 639/1047544 k--snip--Created tmpfs /dev (1490944 byte, 2880 inodes)erase ^?, werase ^W, kill ^U, intr ^CThis image contains utilities which may be neededto get you out of a pinch.#

Kick play.sh script to play soundKick play.sh script to play soundKick play.sh script to play soundKick play.sh script to play soundKick play.sh script to play sound# ./play.sh# ./play.sh# ./play.sh# ./play.sh# ./play.sh

Page 28: Metasepi team meeting #13: NetBSD driver using Haskell

Build processBuild processBuild processBuild processBuild process

Page 29: Metasepi team meeting #13: NetBSD driver using Haskell

How to call C (figure)How to call C (figure)How to call C (figure)How to call C (figure)How to call C (figure)

Page 30: Metasepi team meeting #13: NetBSD driver using Haskell

How to call C (code)How to call C (code)How to call C (code)How to call C (code)How to call C (code)-- File: metasepi/sys/hssrc/Sys/Bus.hsbusSpaceRead4 = c_bus_space_read_4busSpaceWrite4 = c_bus_space_write_4foreign import ccall "hs_extern.h bus_space_read_4" c_bus_space_read_4 :: BusSpaceTagT -> BusSpaceHandleT -> BusSizeT -> IO Word32foreign import ccall "hs_extern.h bus_space_write_4" c_bus_space_write_4 :: BusSpaceTagT -> BusSpaceHandleT -> BusSizeT -> Word32 -> IO ()

-- File: metasepi/sys/hssrc/Sys/Bus.hsbusSpaceRead4 = c_bus_space_read_4busSpaceWrite4 = c_bus_space_write_4foreign import ccall "hs_extern.h bus_space_read_4" c_bus_space_read_4 :: BusSpaceTagT -> BusSpaceHandleT -> BusSizeT -> IO Word32foreign import ccall "hs_extern.h bus_space_write_4" c_bus_space_write_4 :: BusSpaceTagT -> BusSpaceHandleT -> BusSizeT -> Word32 -> IO ()

-- File: metasepi/sys/hssrc/Sys/Bus.hsbusSpaceRead4 = c_bus_space_read_4busSpaceWrite4 = c_bus_space_write_4foreign import ccall "hs_extern.h bus_space_read_4" c_bus_space_read_4 :: BusSpaceTagT -> BusSpaceHandleT -> BusSizeT -> IO Word32foreign import ccall "hs_extern.h bus_space_write_4" c_bus_space_write_4 :: BusSpaceTagT -> BusSpaceHandleT -> BusSizeT -> Word32 -> IO ()

-- File: metasepi/sys/hssrc/Sys/Bus.hsbusSpaceRead4 = c_bus_space_read_4busSpaceWrite4 = c_bus_space_write_4foreign import ccall "hs_extern.h bus_space_read_4" c_bus_space_read_4 :: BusSpaceTagT -> BusSpaceHandleT -> BusSizeT -> IO Word32foreign import ccall "hs_extern.h bus_space_write_4" c_bus_space_write_4 :: BusSpaceTagT -> BusSpaceHandleT -> BusSizeT -> Word32 -> IO ()

-- File: metasepi/sys/hssrc/Sys/Bus.hsbusSpaceRead4 = c_bus_space_read_4busSpaceWrite4 = c_bus_space_write_4foreign import ccall "hs_extern.h bus_space_read_4" c_bus_space_read_4 ::BusSpaceTagT -> BusSpaceHandleT -> BusSizeT -> IO Word32

foreign import ccall "hs_extern.h bus_space_write_4" c_bus_space_write_4 ::BusSpaceTagT -> BusSpaceHandleT -> BusSizeT -> Word32 -> IO ()

-- File: metasepi/sys/hssrc/Arch/I386/Include/BusDefs.hstype BusSizeT = CSizenewtype {-# CTYPE "struct bus_space_tag" #-} BusSpaceTag = BusSpaceTag ()type BusSpaceTagT = Ptr BusSpaceTagtype BusSpaceHandleT = VaddrT

-- File: metasepi/sys/hssrc/Arch/I386/Include/BusDefs.hstype BusSizeT = CSizenewtype {-# CTYPE "struct bus_space_tag" #-} BusSpaceTag = BusSpaceTag ()type BusSpaceTagT = Ptr BusSpaceTagtype BusSpaceHandleT = VaddrT

-- File: metasepi/sys/hssrc/Arch/I386/Include/BusDefs.hstype BusSizeT = CSizenewtype {-# CTYPE "struct bus_space_tag" #-} BusSpaceTag = BusSpaceTag ()type BusSpaceTagT = Ptr BusSpaceTagtype BusSpaceHandleT = VaddrT

-- File: metasepi/sys/hssrc/Arch/I386/Include/BusDefs.hstype BusSizeT = CSizenewtype {-# CTYPE "struct bus_space_tag" #-} BusSpaceTag = BusSpaceTag ()type BusSpaceTagT = Ptr BusSpaceTagtype BusSpaceHandleT = VaddrT

-- File: metasepi/sys/hssrc/Arch/I386/Include/BusDefs.hstype BusSizeT = CSizenewtype {-# CTYPE "struct bus_space_tag" #-} BusSpaceTag =BusSpaceTag ()type BusSpaceTagT = Ptr BusSpaceTagtype BusSpaceHandleT = VaddrT

Page 31: Metasepi team meeting #13: NetBSD driver using Haskell

Trace pointer chainTrace pointer chainTrace pointer chainTrace pointer chainTrace pointer chain/* C code */static intauich_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);

// -- snip --

/* C code */static intauich_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);

// -- snip --

/* C code */static intauich_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);

// -- snip --

/* C code */static intauich_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);

// -- snip --

/* C code */static intauich_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);

// -- snip --

-- Haskell codeauichOpen :: Ptr AuichSoftc -> Int -> IO IntauichOpen sc flags = do mutexp <- p_AuichSoftc_sc_intr_lock sc codecif <- peek =<< p_AuichSoftc_codec_if sc lock <- peek =<< p_Ac97CodecIfVtbl_lock =<< peek =<< p_Ac97CodecIf_vtbl codecif mutexSpinExit mutexp call_Ac97CodecIfVtbl_lock lock codecif-- snip --

-- Haskell codeauichOpen :: Ptr AuichSoftc -> Int -> IO IntauichOpen sc flags = do mutexp <- p_AuichSoftc_sc_intr_lock sc codecif <- peek =<< p_AuichSoftc_codec_if sc lock <- peek =<< p_Ac97CodecIfVtbl_lock =<< peek =<< p_Ac97CodecIf_vtbl codecif mutexSpinExit mutexp call_Ac97CodecIfVtbl_lock lock codecif-- snip --

-- Haskell codeauichOpen :: Ptr AuichSoftc -> Int -> IO IntauichOpen sc flags = do mutexp <- p_AuichSoftc_sc_intr_lock sc codecif <- peek =<< p_AuichSoftc_codec_if sc lock <- peek =<< p_Ac97CodecIfVtbl_lock =<< peek =<< p_Ac97CodecIf_vtbl codecif mutexSpinExit mutexp call_Ac97CodecIfVtbl_lock lock codecif-- snip --

-- Haskell codeauichOpen :: Ptr AuichSoftc -> Int -> IO IntauichOpen sc flags = do mutexp <- p_AuichSoftc_sc_intr_lock sc codecif <- peek =<< p_AuichSoftc_codec_if sc lock <- peek =<< p_Ac97CodecIfVtbl_lock =<< peek =<< p_Ac97CodecIf_vtbl codecif mutexSpinExit mutexp call_Ac97CodecIfVtbl_lock lock codecif-- snip --

-- Haskell codeauichOpen :: Ptr AuichSoftc -> Int -> IO IntauichOpen sc flags = do mutexp <- p_AuichSoftc_sc_intr_lock sc codecif <- peek =<< p_AuichSoftc_codec_if sc lock <- peek =<< p_Ac97CodecIfVtbl_lock =<< peek =<<p_Ac97CodecIf_vtbl codecif mutexSpinExit mutexp call_Ac97CodecIfVtbl_lock lock codecif-- snip --

Page 32: Metasepi team meeting #13: NetBSD driver using Haskell

But need assistant code!But need assistant code!But need assistant code!But need assistant code!But need assistant code!

Page 33: Metasepi team meeting #13: NetBSD driver using Haskell

Tool to generate the codeTool to generate the codeTool to generate the codeTool to generate the codeTool to generate the code

https://github.com/ajhc/struct2hshttps://github.com/ajhc/struct2hshttps://github.com/ajhc/struct2hshttps://github.com/ajhc/struct2hshttps://github.com/ajhc/struct2hs

☆ Generate Haskell code scanning C☆ Generate Haskell code scanning C☆ Generate Haskell code scanning C☆ Generate Haskell code scanning C☆ Generate Haskell code scanning C$ struct2hs sys/dev/pci/auich_extern_SNATCHED.h | tail offsetOf_Pdevinit_pdev_attach :: Intp_Pdevinit_pdev_attach :: Ptr Pdevinit -> IO (Ptr (Ptr (FunPtr (Int -> IO ()))))p_Pdevinit_pdev_attach p = return $ plusPtr p $ offsetOf_Pdevinit_pdev_attachforeign import ccall "dynamic" call_Pdevinit_pdev_attach :: FunPtr (Int -> IO ()) -> Int -> IO ()foreign import primitive "const.offsetof(struct pdevinit, pdev_count)" offsetOf_Pdevinit_pdev_count :: Intp_Pdevinit_pdev_count :: Ptr Pdevinit -> IO (Ptr Int)p_Pdevinit_pdev_count p = return $ plusPtr p $ offsetOf_Pdevinit_pdev_count

$ struct2hs sys/dev/pci/auich_extern_SNATCHED.h | tail offsetOf_Pdevinit_pdev_attach :: Intp_Pdevinit_pdev_attach :: Ptr Pdevinit -> IO (Ptr (Ptr (FunPtr (Int -> IO ()))))p_Pdevinit_pdev_attach p = return $ plusPtr p $ offsetOf_Pdevinit_pdev_attachforeign import ccall "dynamic" call_Pdevinit_pdev_attach :: FunPtr (Int -> IO ()) -> Int -> IO ()foreign import primitive "const.offsetof(struct pdevinit, pdev_count)" offsetOf_Pdevinit_pdev_count :: Intp_Pdevinit_pdev_count :: Ptr Pdevinit -> IO (Ptr Int)p_Pdevinit_pdev_count p = return $ plusPtr p $ offsetOf_Pdevinit_pdev_count

$ struct2hs sys/dev/pci/auich_extern_SNATCHED.h | tail offsetOf_Pdevinit_pdev_attach :: Intp_Pdevinit_pdev_attach :: Ptr Pdevinit -> IO (Ptr (Ptr (FunPtr (Int -> IO ()))))p_Pdevinit_pdev_attach p = return $ plusPtr p $ offsetOf_Pdevinit_pdev_attachforeign import ccall "dynamic" call_Pdevinit_pdev_attach :: FunPtr (Int -> IO ()) -> Int -> IO ()foreign import primitive "const.offsetof(struct pdevinit, pdev_count)" offsetOf_Pdevinit_pdev_count :: Intp_Pdevinit_pdev_count :: Ptr Pdevinit -> IO (Ptr Int)p_Pdevinit_pdev_count p = return $ plusPtr p $ offsetOf_Pdevinit_pdev_count

$ struct2hs sys/dev/pci/auich_extern_SNATCHED.h | tail offsetOf_Pdevinit_pdev_attach :: Intp_Pdevinit_pdev_attach :: Ptr Pdevinit -> IO (Ptr (Ptr (FunPtr (Int -> IO ()))))p_Pdevinit_pdev_attach p = return $ plusPtr p $ offsetOf_Pdevinit_pdev_attachforeign import ccall "dynamic" call_Pdevinit_pdev_attach :: FunPtr (Int -> IO ()) -> Int -> IO ()foreign import primitive "const.offsetof(struct pdevinit, pdev_count)" offsetOf_Pdevinit_pdev_count :: Intp_Pdevinit_pdev_count :: Ptr Pdevinit -> IO (Ptr Int)p_Pdevinit_pdev_count p = return $ plusPtr p $ offsetOf_Pdevinit_pdev_count

$ struct2hs sys/dev/pci/auich_extern_SNATCHED.h | tail offsetOf_Pdevinit_pdev_attach :: Intp_Pdevinit_pdev_attach :: Ptr Pdevinit -> IO (Ptr (Ptr (FunPtr (Int -> IO ()))))p_Pdevinit_pdev_attach p = return $ plusPtr p $ offsetOf_Pdevinit_pdev_attachforeign import ccall "dynamic" call_Pdevinit_pdev_attach :: FunPtr (Int -> IO ()) -> Int -> IO ()foreign import primitive "const.offsetof(struct pdevinit, pdev_count)" offsetOf_Pdevinit_pdev_count :: Intp_Pdevinit_pdev_count :: Ptr Pdevinit -> IO (Ptr Int)p_Pdevinit_pdev_count p = return $ plusPtr p $ offsetOf_Pdevinit_pdev_count

Page 34: Metasepi team meeting #13: NetBSD driver using Haskell

[6] Ajhc is the best?[6] Ajhc is the best?[6] Ajhc is the best?[6] Ajhc is the best?[6] Ajhc is the best?

☆ No.☆ No.☆ No.☆ No.☆ No.

☆ Depended on GC☆ Depended on GC☆ Depended on GC☆ Depended on GC☆ Depended on GC

☆ Too buggy compiler☆ Too buggy compiler☆ Too buggy compiler☆ Too buggy compiler☆ Too buggy compiler

https://github.com/ajhc/ajhc/issueshttps://github.com/ajhc/ajhc/issueshttps://github.com/ajhc/ajhc/issueshttps://github.com/ajhc/ajhc/issueshttps://github.com/ajhc/ajhc/issues

☆ Can't use MonadTrans☆ Can't use MonadTrans☆ Can't use MonadTrans☆ Can't use MonadTrans☆ Can't use MonadTrans

☆ Debug hard for strong optimization☆ Debug hard for strong optimization☆ Debug hard for strong optimization☆ Debug hard for strong optimization☆ Debug hard for strong optimization

Page 35: Metasepi team meeting #13: NetBSD driver using Haskell

Before compiling (Haskell)Before compiling (Haskell)Before compiling (Haskell)Before compiling (Haskell)Before compiling (Haskell)hdaudioIntr :: Ptr HdaudioSoftc -> IO InthdaudioIntr sc = do intsts <- hdaRead4 sc e_HDAUDIO_MMIO_INTSTS if intsts .&. e_HDAUDIO_INTSTS_GIS /= 0 then hdaudioIntr' sc intsts else return 0

hdaudioIntr' :: Ptr HdaudioSoftc -> Word32 -> IO InthdaudioIntr' sc intsts = do when (intsts .&. e_HDAUDIO_INTSTS_CIS /= 0) $ do rirbsts <- hdaRead1 sc e_HDAUDIO_MMIO_RIRBSTS when (rirbsts .&. e_HDAUDIO_RIRBSTS_RINTFL /= 0) $ do mutexp <- p_HdaudioSoftc_sc_corb_mtx sc mutexEnter mutexp hdaudioRirbDequeue sc True mutexExit mutexp when (rirbsts .&. (e_HDAUDIO_RIRBSTS_RIRBOIS .|. e_HDAUDIO_RIRBSTS_RINTFL) /= 0) $ hdaWrite1 sc e_HDAUDIO_MMIO_RIRBSTS rirbsts hdaWrite4 sc e_HDAUDIO_MMIO_INTSTS e_HDAUDIO_INTSTS_CIS when (intsts .&. e_HDAUDIO_INTSTS_SIS_MASK /= 0) $ do mutexp <- p_HdaudioSoftc_sc_stream_mtx sc-- snip --

hdaudioIntr :: Ptr HdaudioSoftc -> IO InthdaudioIntr sc = do intsts <- hdaRead4 sc e_HDAUDIO_MMIO_INTSTS if intsts .&. e_HDAUDIO_INTSTS_GIS /= 0 then hdaudioIntr' sc intsts else return 0

hdaudioIntr' :: Ptr HdaudioSoftc -> Word32 -> IO InthdaudioIntr' sc intsts = do when (intsts .&. e_HDAUDIO_INTSTS_CIS /= 0) $ do rirbsts <- hdaRead1 sc e_HDAUDIO_MMIO_RIRBSTS when (rirbsts .&. e_HDAUDIO_RIRBSTS_RINTFL /= 0) $ do mutexp <- p_HdaudioSoftc_sc_corb_mtx sc mutexEnter mutexp hdaudioRirbDequeue sc True mutexExit mutexp when (rirbsts .&. (e_HDAUDIO_RIRBSTS_RIRBOIS .|. e_HDAUDIO_RIRBSTS_RINTFL) /= 0) $ hdaWrite1 sc e_HDAUDIO_MMIO_RIRBSTS rirbsts hdaWrite4 sc e_HDAUDIO_MMIO_INTSTS e_HDAUDIO_INTSTS_CIS when (intsts .&. e_HDAUDIO_INTSTS_SIS_MASK /= 0) $ do mutexp <- p_HdaudioSoftc_sc_stream_mtx sc-- snip --

hdaudioIntr :: Ptr HdaudioSoftc -> IO InthdaudioIntr sc = do intsts <- hdaRead4 sc e_HDAUDIO_MMIO_INTSTS if intsts .&. e_HDAUDIO_INTSTS_GIS /= 0 then hdaudioIntr' sc intsts else return 0

hdaudioIntr' :: Ptr HdaudioSoftc -> Word32 -> IO InthdaudioIntr' sc intsts = do when (intsts .&. e_HDAUDIO_INTSTS_CIS /= 0) $ do rirbsts <- hdaRead1 sc e_HDAUDIO_MMIO_RIRBSTS when (rirbsts .&. e_HDAUDIO_RIRBSTS_RINTFL /= 0) $ do mutexp <- p_HdaudioSoftc_sc_corb_mtx sc mutexEnter mutexp hdaudioRirbDequeue sc True mutexExit mutexp when (rirbsts .&. (e_HDAUDIO_RIRBSTS_RIRBOIS .|. e_HDAUDIO_RIRBSTS_RINTFL) /= 0) $ hdaWrite1 sc e_HDAUDIO_MMIO_RIRBSTS rirbsts hdaWrite4 sc e_HDAUDIO_MMIO_INTSTS e_HDAUDIO_INTSTS_CIS when (intsts .&. e_HDAUDIO_INTSTS_SIS_MASK /= 0) $ do mutexp <- p_HdaudioSoftc_sc_stream_mtx sc-- snip --

hdaudioIntr :: Ptr HdaudioSoftc -> IO InthdaudioIntr sc = do intsts <- hdaRead4 sc e_HDAUDIO_MMIO_INTSTS if intsts .&. e_HDAUDIO_INTSTS_GIS /= 0 then hdaudioIntr' sc intsts else return 0

hdaudioIntr' :: Ptr HdaudioSoftc -> Word32 -> IO InthdaudioIntr' sc intsts = do when (intsts .&. e_HDAUDIO_INTSTS_CIS /= 0) $ do rirbsts <- hdaRead1 sc e_HDAUDIO_MMIO_RIRBSTS when (rirbsts .&. e_HDAUDIO_RIRBSTS_RINTFL /= 0) $ do mutexp <- p_HdaudioSoftc_sc_corb_mtx sc mutexEnter mutexp hdaudioRirbDequeue sc True mutexExit mutexp when (rirbsts .&. (e_HDAUDIO_RIRBSTS_RIRBOIS .|. e_HDAUDIO_RIRBSTS_RINTFL) /= 0) $ hdaWrite1 sc e_HDAUDIO_MMIO_RIRBSTS rirbsts hdaWrite4 sc e_HDAUDIO_MMIO_INTSTS e_HDAUDIO_INTSTS_CIS when (intsts .&. e_HDAUDIO_INTSTS_SIS_MASK /= 0) $ do mutexp <- p_HdaudioSoftc_sc_stream_mtx sc-- snip --

hdaudioIntr :: Ptr HdaudioSoftc -> IO InthdaudioIntr sc = do intsts <- hdaRead4 sc e_HDAUDIO_MMIO_INTSTSif intsts .&. e_HDAUDIO_INTSTS_GIS /= 0 then hdaudioIntr' sc

intstselse return 0

hdaudioIntr' :: Ptr HdaudioSoftc -> Word32 -> IO InthdaudioIntr' sc intsts = do when (intsts .&. e_HDAUDIO_INTSTS_CIS /= 0) $ do rirbsts <- hdaRead1 sc e_HDAUDIO_MMIO_RIRBSTS when (rirbsts .&. e_HDAUDIO_RIRBSTS_RINTFL /= 0) $ do mutexp <- p_HdaudioSoftc_sc_corb_mtx sc mutexEnter mutexp hdaudioRirbDequeue sc True mutexExit mutexp when (rirbsts .&. (e_HDAUDIO_RIRBSTS_RIRBOIS .|.e_HDAUDIO_RIRBSTS_RINTFL) /= 0) $ hdaWrite1 sc e_HDAUDIO_MMIO_RIRBSTS rirbsts hdaWrite4 sc e_HDAUDIO_MMIO_INTSTS e_HDAUDIO_INTSTS_CIS when (intsts .&. e_HDAUDIO_INTSTS_SIS_MASK /= 0) $ do mutexp <- p_HdaudioSoftc_sc_stream_mtx sc-- snip --

Page 36: Metasepi team meeting #13: NetBSD driver using Haskell

After compiling (C language)After compiling (C language)After compiling (C language)After compiling (C language)After compiling (C language)

Page 37: Metasepi team meeting #13: NetBSD driver using Haskell

Debug in kernelDebug in kernelDebug in kernelDebug in kernelDebug in kernel

☆ Hardware state is sometime buggy☆ Hardware state is sometime buggy☆ Hardware state is sometime buggy☆ Hardware state is sometime buggy☆ Hardware state is sometime buggy

☆ Not only debug software☆ Not only debug software☆ Not only debug software☆ Not only debug software☆ Not only debug software

☆ but also hardware!☆ but also hardware!☆ but also hardware!☆ but also hardware!☆ but also hardware!

☆ Gap between Haskell and C code☆ Gap between Haskell and C code☆ Gap between Haskell and C code☆ Gap between Haskell and C code☆ Gap between Haskell and C code

☆ Can't debug pure Haskell code☆ Can't debug pure Haskell code☆ Can't debug pure Haskell code☆ Can't debug pure Haskell code☆ Can't debug pure Haskell code

☆ Need to debug generated C code☆ Need to debug generated C code☆ Need to debug generated C code☆ Need to debug generated C code☆ Need to debug generated C code

☆ Where is more better compiler?☆ Where is more better compiler?☆ Where is more better compiler?☆ Where is more better compiler?☆ Where is more better compiler?

Page 38: Metasepi team meeting #13: NetBSD driver using Haskell

[7] From Arafura to Bohai[7] From Arafura to Bohai[7] From Arafura to Bohai[7] From Arafura to Bohai[7] From Arafura to Bohai

☆ We are in Arafura iteration☆ We are in Arafura iteration☆ We are in Arafura iteration☆ We are in Arafura iteration☆ We are in Arafura iteration

☆ Arafura := Ajhc + Snatch + NetBSD☆ Arafura := Ajhc + Snatch + NetBSD☆ Arafura := Ajhc + Snatch + NetBSD☆ Arafura := Ajhc + Snatch + NetBSD☆ Arafura := Ajhc + Snatch + NetBSD

☆ Use "ATS" compiler on the next☆ Use "ATS" compiler on the next☆ Use "ATS" compiler on the next☆ Use "ATS" compiler on the next☆ Use "ATS" compiler on the next

☆ Let's start Bohai iteration!☆ Let's start Bohai iteration!☆ Let's start Bohai iteration!☆ Let's start Bohai iteration!☆ Let's start Bohai iteration!

☆ Bohai := ATS + Snatch + NetBSD☆ Bohai := ATS + Snatch + NetBSD☆ Bohai := ATS + Snatch + NetBSD☆ Bohai := ATS + Snatch + NetBSD☆ Bohai := ATS + Snatch + NetBSD

Page 39: Metasepi team meeting #13: NetBSD driver using Haskell

What is ATS language?What is ATS language?What is ATS language?What is ATS language?What is ATS language?

http://www.ats-lang.org/http://www.ats-lang.org/http://www.ats-lang.org/http://www.ats-lang.org/http://www.ats-lang.org/

☆ Has syntax like ML☆ Has syntax like ML☆ Has syntax like ML☆ Has syntax like ML☆ Has syntax like ML

☆ Compiled into C☆ Compiled into C☆ Compiled into C☆ Compiled into C☆ Compiled into C

☆ Dependent type☆ Dependent type☆ Dependent type☆ Dependent type☆ Dependent type

☆ Linear type☆ Linear type☆ Linear type☆ Linear type☆ Linear type

☆ Without GC☆ Without GC☆ Without GC☆ Without GC☆ Without GC

☆ Without any runtime☆ Without any runtime☆ Without any runtime☆ Without any runtime☆ Without any runtime

Page 40: Metasepi team meeting #13: NetBSD driver using Haskell

Japan ATS User GroupJapan ATS User GroupJapan ATS User GroupJapan ATS User GroupJapan ATS User Group

http://jats-ug.metasepi.org/http://jats-ug.metasepi.org/http://jats-ug.metasepi.org/http://jats-ug.metasepi.org/http://jats-ug.metasepi.org/

☆ Translating ATS documents☆ Translating ATS documents☆ Translating ATS documents☆ Translating ATS documents☆ Translating ATS documents

☆ ATS propaganda in Japan☆ ATS propaganda in Japan☆ ATS propaganda in Japan☆ ATS propaganda in Japan☆ ATS propaganda in Japan

☆ Join us!☆ Join us!☆ Join us!☆ Join us!☆ Join us!

Page 41: Metasepi team meeting #13: NetBSD driver using Haskell

Hongwei said... (cont.)Hongwei said... (cont.)Hongwei said... (cont.)Hongwei said... (cont.)Hongwei said... (cont.)

☆ Hongwei Xi as ATS author☆ Hongwei Xi as ATS author☆ Hongwei Xi as ATS author☆ Hongwei Xi as ATS author☆ Hongwei Xi as ATS author

☆ Associate Professor☆ Associate Professor☆ Associate Professor☆ Associate Professor☆ Associate Professor

☆ at Boston University☆ at Boston University☆ at Boston University☆ at Boston University☆ at Boston UniversityDate: Mon Dec 23 11:40 JST 2013

Hi Metasepi-chan,

I spent quite some time today browsing metasepi.org.

I am really interested in your Metasepi project, partly because I myself wanted to implement NetBSD in ATS about 5 years ago. Unfortunately, I never had time to get the project started as I needed to spend so much time on ATS2. By the way, I had planned to use the very same approach which you call "Snatch". I had also considered Minix but I chose NetBSD because it was a real OS.

Date: Mon Dec 23 11:40 JST 2013

Hi Metasepi-chan,

I spent quite some time today browsing metasepi.org.

I am really interested in your Metasepi project, partly because I myself wanted to implement NetBSD in ATS about 5 years ago. Unfortunately, I never had time to get the project started as I needed to spend so much time on ATS2. By the way, I had planned to use the very same approach which you call "Snatch". I had also considered Minix but I chose NetBSD because it was a real OS.

Date: Mon Dec 23 11:40 JST 2013

Hi Metasepi-chan,

I spent quite some time today browsing metasepi.org.

I am really interested in your Metasepi project, partly because I myself wanted to implement NetBSD in ATS about 5 years ago. Unfortunately, I never had time to get the project started as I needed to spend so much time on ATS2. By the way, I had planned to use the very same approach which you call "Snatch". I had also considered Minix but I chose NetBSD because it was a real OS.

Date: Mon Dec 23 11:40 JST 2013

Hi Metasepi-chan,

I spent quite some time today browsing metasepi.org.

I am really interested in your Metasepi project, partly because I myself wanted to implement NetBSD in ATS about 5 years ago. Unfortunately, I never had time to get the project started as I needed to spend so much time on ATS2. By the way, I had planned to use the very same approach which you call "Snatch". I had also considered Minix but I chose NetBSD because it was a real OS.

Date: Mon Dec 23 11:40 JST 2013

Hi Metasepi-chan,

I spent quite some time today browsing metasepi.org.

I am really interested in your Metasepi project, partly because I myself wanted to implement NetBSD in ATS about 5 years ago. Unfortunately, I never had time to get the project started as I needed to spend so much time on ATS2. By the way, I had planned to use the very same approach which you call "Snatch". I had also considered Minix but I chose NetBSD because it was a real OS.

Page 42: Metasepi team meeting #13: NetBSD driver using Haskell

Hongwei said... (cont.)Hongwei said... (cont.)Hongwei said... (cont.)Hongwei said... (cont.)Hongwei said... (cont.)I think I know first-handedly the dilemma you are currently in. On one hand, you want to be able to fully focus on writing the kernel. On the other hand, you also need to add features to Ajhc constantly to address all kinds of issues that keep popping up, which undoubtedly makes it very difficult for you to focus.

I would highly recommend that you use ATS to implement NetBSD kernel. Unlike jhc, there is no semantics gap between ATS and C. In particular, they both use the same native unboxed data representation. Once you become familiar with ATS, you can readily visualize the C code that your ATS source is to be compiled into. ATS is truly an ideal language for the kind of "Snatch" approach you want to take to re-write NetBSD. If you take the lead, then I will be happy to "chip in" :)

I also spent some time reading documentation on jhc. Personally, I feel that there is simply too much uncertainty to use it in real kernel implementation. Features like GC could make the kernel highly unpredictable, scaring away potential users.

I think I know first-handedly the dilemma you are currently in. On one hand, you want to be able to fully focus on writing the kernel. On the other hand, you also need to add features to Ajhc constantly to address all kinds of issues that keep popping up, which undoubtedly makes it very difficult for you to focus.

I would highly recommend that you use ATS to implement NetBSD kernel. Unlike jhc, there is no semantics gap between ATS and C. In particular, they both use the same native unboxed data representation. Once you become familiar with ATS, you can readily visualize the C code that your ATS source is to be compiled into. ATS is truly an ideal language for the kind of "Snatch" approach you want to take to re-write NetBSD. If you take the lead, then I will be happy to "chip in" :)

I also spent some time reading documentation on jhc. Personally, I feel that there is simply too much uncertainty to use it in real kernel implementation. Features like GC could make the kernel highly unpredictable, scaring away potential users.

I think I know first-handedly the dilemma you are currently in. On one hand, you want to be able to fully focus on writing the kernel. On the other hand, you also need to add features to Ajhc constantly to address all kinds of issues that keep popping up, which undoubtedly makes it very difficult for you to focus.

I would highly recommend that you use ATS to implement NetBSD kernel. Unlike jhc, there is no semantics gap between ATS and C. In particular, they both use the same native unboxed data representation. Once you become familiar with ATS, you can readily visualize the C code that your ATS source is to be compiled into. ATS is truly an ideal language for the kind of "Snatch" approach you want to take to re-write NetBSD. If you take the lead, then I will be happy to "chip in" :)

I also spent some time reading documentation on jhc. Personally, I feel that there is simply too much uncertainty to use it in real kernel implementation. Features like GC could make the kernel highly unpredictable, scaring away potential users.

I think I know first-handedly the dilemma you are currently in. On one hand, you want to be able to fully focus on writing the kernel. On the other hand, you also need to add features to Ajhc constantly to address all kinds of issues that keep popping up, which undoubtedly makes it very difficult for you to focus.

I would highly recommend that you use ATS to implement NetBSD kernel. Unlike jhc, there is no semantics gap between ATS and C. In particular, they both use the same native unboxed data representation. Once you become familiar with ATS, you can readily visualize the C code that your ATS source is to be compiled into. ATS is truly an ideal language for the kind of "Snatch" approach you want to take to re-write NetBSD. If you take the lead, then I will be happy to "chip in" :)

I also spent some time reading documentation on jhc. Personally, I feel that there is simply too much uncertainty to use it in real kernel implementation. Features like GC could make the kernel highly unpredictable, scaring away potential users.

I think I know first-handedly the dilemma you are currently in. On one hand, you want to be able to fully focus on writing the kernel. On the other hand, you also need to add features to Ajhc constantly to address all kinds of issues that keep popping up, which undoubtedly makes it very difficult for you to focus.

I would highly recommend that you use ATS to implement NetBSD kernel. Unlike jhc, there is no semantics gap between ATS and C. In particular, they both use the same native unboxed data representation. Once you become familiar with ATS, you can readily visualize the C code that your ATS source is to be compiled into. ATS is truly an ideal language for the kind of "Snatch" approach you want to take to re-write NetBSD. If you take the lead, then I will be happy to "chip in" :)

I also spent some time reading documentation on jhc. Personally, I feel that there is simply too much uncertainty to use it in real kernel implementation. Features like GC could make the kernel highly unpredictable, scaring away potential users.

Page 43: Metasepi team meeting #13: NetBSD driver using Haskell

Hongwei said...Hongwei said...Hongwei said...Hongwei said...Hongwei said...I think that we both believe C is the right language for systems programming. The problem with C is that it is too difficult to write correct C programs. ATS is designed to allow the programmer to correctly write the kind of C programs he or she wanted to write in the first place. While jhc generates C code, the kind of C code it generates may not be suited for kernel. This is what I call a semantics gap.

I write this message in the hope that we could join effort in doing something that has not been done up to now: Writing a real kernel in (largely) functional style that can truly deliever safety-wise as well as performance-wise.

Cheers,

--Hongwei

I think that we both believe C is the right language for systems programming. The problem with C is that it is too difficult to write correct C programs. ATS is designed to allow the programmer to correctly write the kind of C programs he or she wanted to write in the first place. While jhc generates C code, the kind of C code it generates may not be suited for kernel. This is what I call a semantics gap.

I write this message in the hope that we could join effort in doing something that has not been done up to now: Writing a real kernel in (largely) functional style that can truly deliever safety-wise as well as performance-wise.

Cheers,

--Hongwei

I think that we both believe C is the right language for systems programming. The problem with C is that it is too difficult to write correct C programs. ATS is designed to allow the programmer to correctly write the kind of C programs he or she wanted to write in the first place. While jhc generates C code, the kind of C code it generates may not be suited for kernel. This is what I call a semantics gap.

I write this message in the hope that we could join effort in doing something that has not been done up to now: Writing a real kernel in (largely) functional style that can truly deliever safety-wise as well as performance-wise.

Cheers,

--Hongwei

I think that we both believe C is the right language for systems programming. The problem with C is that it is too difficult to write correct C programs. ATS is designed to allow the programmer to correctly write the kind of C programs he or she wanted to write in the first place. While jhc generates C code, the kind of C code it generates may not be suited for kernel. This is what I call a semantics gap.

I write this message in the hope that we could join effort in doing something that has not been done up to now: Writing a real kernel in (largely) functional style that can truly deliever safety-wise as well as performance-wise.

Cheers,

--Hongwei

I think that we both believe C is the right language for systems programming. The problem with C is that it is too difficult to write correct C programs. ATS is designed to allow the programmer to correctly write the kind of C programs he or she wanted to write in the first place. While jhc generates C code, the kind of C code it generates may not be suited for kernel. This is what I call a semantics gap.

I write this message in the hope that we could join effort in doing something that has not been done up to now: Writing a real kernel in (largely) functional style that can truly deliever safety-wise as well as performance-wise.

Cheers,

--Hongwei