Barrelfish is not self-hosting at the moment, so programs to be run on it must be compiled alongside it. There are several examples of Barrelfish programs demonstrating various aspects of the API in usr/examples. The README in that folder explains exactly how to get them all running; this article is merely paraphrasing its contents.

This article assumes you have run though the steps in Getting Started, up through generating a Makefile.

Hello World

First we will get a basic Hello World program running on Barrelfish. The program is located in usr/examples/xmpl-hello.

Usually you need to create a directory under usr in which you place your source code and a Hakefile, which lists the source files to compile and a target. However, this is all done for us in this example.

To get Hake to include a target for the hello world program in the generated Makefile, we must first add the target to the symbolic_targets.mk file, located in the build directory. Open up build/symbolic_targets.mk and add the following line to the MODULES_COMMON variable:

/sbin/examples/xmpl-hello \

After this has been done, you will have to regenerate the Makefile like so:

cd build
../hake/hake.sh -s .. -a x86_64

Note: You will have to modify the -a argument above if you are not building for a 64-bit target.

Now we run make and the hello world program should be compiled. Finally, to run the hello world program once Barrelfish has booted, we need to append the following line to build/menu.lst:

module  /x86_64/sbin/examples/xmpl-hello

And now if we run make sim we should see a "Hello World" message displayed once fish has started.

In addition to running programs at boot, you can interactively run programs using the oncore program available in fish. So for the example above we could type the following into fish to run it:

oncore 0 x86_64/sbin/examples/xmpl-hello

Message-Passing Interfaces

The only other files you will need to interact with for running programs are .if files. These files specify interfaces used for message passing. The example program xmpl-rpc found in usr/examples/ shows how this works. An explanation of the message passing API can be found here: idc.pdf

All .if files that you wish to use must be added to the flounderGenDefs variable in the if/Hakefile. For the xmpl-rpc example, the change would look like this:

-- whereas these are using the new-style bindings
[ flounderGenDefs (options arch) f
      | f <- [ "bcast",
               "bench",
           ... 
               "xmplrpc"]
             arch <- allArchitectures
] ++

Coding styles

If you are planning to submit your code back to Barrelfish codebase then you may want to read and follow Barrelfish Coding Styles.

BarrelfishWiki: Programming_for_Barrelfish (last edited 2015-01-30 15:14:44 by Simon Gerber)