3 Your first hello world

As DROPS is a multi-server system, programs are seen as servers, offering some services to other programs. Our infrastructure reflects this by using packages for managing different programs. A package typically contains a server, libraries and include files to be exported.

Your first hello world program does not offer any service to clients, nonetheless we say it is a server (without any clients, though). Let's name it hiworld. You create the package by creating a directory called hiworld in l4/pkg:

~/src/l4/pkg> mkdir hiworld

This directory is called package dir and will be referenced as $(PKGDIR). Switch to the directory and use the template provided by BID to create the basic directory structure together with some Makefiles:

~/src/l4/pkg/hiworld> ../../mk/tmpl/inst

This results in a couple of directories and a makefile to be created. The makefile is ready to use and builds your whole package when doing make. A first look into it shows the basic scheme of all BID-makefiles: After setting $(PKGDIR) and $(L4DIR) you add your commands, and finally a macro-file is included. We refer to the macro-file as role file, as this file determines a distinct role of the current directory. The purpose of $(PKGDIR) is just to propagate various make commands, which is achieved by the subdir role. Fortunately, its default behavior meets our needs, and we need no additional commands.

As you want to create a server, switch into the server/ directory. There is already another makefile, very similar to the one you just looked at. Note the modified $(PKGDIR) assignment, as the package dir is one level up now. Go ahead into the src/ directory, where you finally place your source code.

The makefile prepared in this directory creates executable binaries. Optionally, it uploads them to your file-server (tftp at TUD), so you can boot it right afterwards over the network. If you did not do it already, this is a good time to fix the paths for later uploading the binaries to your file server (see Section 5 for details).

The makefile in server/src expects your code in the file main.c (which we could change, of course), so edit this file.

~/src/l4/pkg/hiworld/server/src> xemacs main.c

The file prepared already has an empty main() function. Add a printf("Hi world"):

hiworld/server/src/main.c
int main(int argc, char**argv){
  printf("Hi world\n"); 
  return 0;
}

Compile the program:

~/src/l4/pkg/hiworld/server/src> make O=/path/to/builddir

This will create a directory (OBJ-x86_586-l4v2/) in the build directory where all compiled files will go. You will find the compiled binary in this directory, its name is the name of the package: hiworld. The binary is also installed into $(L4DIR)/bin. If you did the setup for installing the binaries (see Section 5), it should be installed on your file server this way, and hence is ready for booting over the network already. To execute it, boot L4 together with the essential servers. Use the following menu.lst file after adapting the paths to the binaries.

menu.lst
title Hi world
  kernel (nd)/tftpboot/yourname/bin/x86_586/l4v2/bootstrap
  modaddr 0x02000000
  module (nd)/tftpboot/yourname/bin/fiasco -nokdb -nowait
  module (nd)/tftpboot/yourname/bin/x86_586/l4v2/sigma0
  module (nd)/tftpboot/yourname/bin/x86_586/l4v2/roottask
  module (nd)/tftpboot/yourname/bin/x86_586/l4v2/log
  module (nd)/tftpboot/yourname/bin/x86_586/l4v2/names
  module (nd)/tftpboot/yourname/bin/x86_586/l4v2/dm_phys
  module (nd)/tftpboot/yourname/bin/x86_586/l4v2/hiworld

If all went right (you installed an L4 version 2 micro-kernel named fiasco into $(L4DIR)/bin, and installed all the other binaries as well; your boot loader found all the files; your test machine executed the micro kernel and the applications), you should see the 'Hi world' near the bottom of the screen attached to your test node.

You may also run your application using Fiasco-UX (refer to Section 6 for instructions on building and using). The respective start script is:

hello
#! /bin/bash

. ${0%/*}/generic.inc

fiasco \
	-l names                        \
	-l log                          \
	-l dm_phys                      \
	-l hiworld

In this section we

L4 Checker 2012-04-11