Metasepi team meeting #13: NetBSD driver using Haskell
Metasepi team meeting #13:
NetBSD driver using Haskell
Metasepi Project / Kiwamu Okabe
Who am I?
☆ Self employed software engineer
☆ Founder of Metasepi Project
☆ A developer of Ajhc Haskell compiler
☆ A Debian Maintainer
☆ 10 years' experience in developing
OS using NetBSD.
☆  Demo
☆  What is Ajhc?
☆  What is Metasepi?
☆  What is compiler to build OS
☆  NetBSD driver using Haskell
☆  Ajhc is the best?
☆  From Arafura to Bohai
☆ NetBSD audio driver play sound
☆ The driver's interrupt handler
rewrited using Haskell
☆ Watch the movie at following
☆ The source code at following
 What is Ajhc?
☆ Ajhc := Arafura designed jhc
☆ jhc := John's Haskell Compiler
☆ Jhc outputs binary that has lowmemory-footprint and runs fast.
☆ Good for embedded software.
Who is John?
☆ John Meacham
Why need Ajhc?
☆ GHC is de facto standard on Haskell.
☆ GHC := Glasgow Haskell Compiler
☆ Why need another Haskell compiler?
☆ To develop kernel named "Metasepi".
 What is Metasepi?
☆ Unix-like OS designed by strong type.
☆ Using ML or more strong type lang.
. . . and suchlike.
Why need Metasepi?
☆ We have already Linux or Windows.
☆ But the developers are suffering.
☆ If use the kernel changed by you,
☆ you will get many runtime error.
☆ Difficult even to reproduce it.
Doesn't OSS have good quality?
☆ "The Cathedral and the Bazaar"
☆ "Given enough eyeballs, all bugs are
☆ But if you develop your own product
☆ Less runtime errors.
Kernel wants type desperately
☆ Kernels are developed with C lang.
☆ Error on user space => SEGV
☆ Error on kernel space => Halt!
☆ Should design kernel with the
☆ C language is safe?
 What is compiler to build OS
☆ Need strong type.
☆ Need flexibility such as C language.
☆ Create it if there are not!
☆ From scratch? No thank you...
☆ Look for our compiler base.
Want POSIX free compiler
Programs to print "hoge" on terminal.
The lesser depends on POSIX, the
Jhc output has only 20 undef
$ nm hs.out | grep
How to build
☆ Install some packages
$ sudo apt-get install ffmpeg qemu gcc
☆ Install Ajhc and git clone
$ git clone https://github.com/metasepi/netbsd-arafura-s1.git
$ cd netbsd-arafura-s1
☆ Build QEMU image
$ make bootcd
Run the kernel
Run 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 ^C
This image contains utilities which may be needed
to get you out of a pinch.
Kick play.sh script to play sound
Debug in kernel
☆ Hardware state is sometime buggy
☆ Not only debug software
☆ but also hardware!
☆ Gap between Haskell and C code
☆ Can't debug pure Haskell code
☆ Need to debug generated C code
☆ Where is more better compiler?
 From Arafura to Bohai
☆ We are in Arafura iteration
☆ Arafura := Ajhc + Snatch + NetBSD
☆ Use "ATS" compiler on the next
☆ Let's start Bohai iteration!
☆ Bohai := ATS + Snatch + NetBSD
What is ATS language?
☆ Has syntax like ML
☆ Compiled into C
☆ Dependent type
☆ Linear type
☆ Without GC
☆ Without any runtime
Japan ATS User Group
☆ Translating ATS documents
☆ ATS propaganda in Japan
☆ Join us!
Hongwei said... (cont.)
☆ Hongwei Xi as ATS author
☆ Associate Professor
☆ at Boston University
Date: Mon Dec 23 11:40 JST 2013
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.
Hongwei said... (cont.)
I think I know first-handedly the dilemma you are currently
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
constantly to address all kinds of issues that keep popping
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 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.
A particular slide catching your eye?
Clipping is a handy way to collect important slides you want to go back to later.