Computer Labs 2011/2012 - 1st Semester
LCOM's Development Environment and Process


1. Introduction

In LCOM you will develop programs that interface with I/O devices at the hardware (HW) level. To facilitate this development we will use the Minix 3 operating system.

In most modern computer architectures, access to I/O devices at the HW level is restricted, requiring the execution of priviledged instructions. Modern operating systems take advantage of this capability to prevent user level programs from accessing I/O devices. This is important to prevent user level programs from affecting, either accidentally or intentionally, the normal operation of a computer system.

Minix 3 is a modern operating system that allows special programs such as device drivers, i.e. code that provides access to I/O devices, to execute as user level programs. This is achieved by exposing the priviledged instructions needed by device drivers (and by other code that is usually part of the operating system kernel) as kernel calls. Execution of these calls is however controlled: attempt to execute them by non-authorized programs leads in most cases to the abnormal termination of the program. Actually, Minix 3 allows the system administrator to specify which kernel calls each special program can invoke and which computer resources can be used in those calls.

In LCOM, we will take advantage of these features of Minix 3, to develop user-level programs that access I/O devices using their HW interface: you will develop them as special user-level Minix 3 programs. Although we use the mechanisms offered by Minix 3 for the development of device drivers, the programs that you will develop are significantly different from Minix 3 device drivers. The latter are general programs that provide a uniform API that allows application programs to access I/O devices.

The purpose of this note is to provide you with information regarding the development environment and process that you will use in LCOM, so that you can start.

2. Development Environment

In the lab, each PC has two Minix 3 installations:

The two installations are otherwise identical. They have only a command line interface: although Minix 3 also has a graphical interface based on X11, at the time of writing only a few X11 applications have been ported to Minix 3.

Minix 3 supports the concept of virtual terminals (VT). I.e. it is possible to use Minix 3 as if it had more than one terminal. The first virtual terminal is known as the console and is used by Minix 3 to output debugging information. All terminals have their own shell, a command line interface, which can be used to issue commands to Minix 3. You can select the virtual terminal to use by typing Alt+F1, Alt+F2, Alt+F3 and so on. The default Minix 3 configuration, supports up to 4 virtual terminals.

You can take advantage of this feature, and use multiple VT simultaneously. You can be logged in in each VT using either identical accounts or different accounts.

Nevertheless, for the sake of convenience, we suggest that you use the installation on the virtual machine for development: you can use Eclipse's Remote System Explorer (RSE) plugin, running on Linux, to write code remotely, i.e. in the VM Player installation. This allows you not only to use a modern integrated development environment (IDE) but also not to lose your development session if you need to reboot Minix 3.

The disk partition installation will be used only to demonstrate your programs, after you have developed and tested them in the VM Player.

3. User Accounts

So that you can develop your code we have created the necessary accounts in both Linux and Minix 3.

3.1 Linux Account

The VMware Player with Minix 3 is installed in a Linux operating system. So that you can start that Minix 3 installation, you need to first log in Linux. For that, we have created the user account lcom whose password is lcom2011.

3.2 Minix 3 Accounts

Both Minix 3 installations have two accounts. A normal user account, lcom, and the system administration account, root. Both accounts have the same password: lcom2011.

As a rule, you should use the lcom account. The root account should be used if you cannot do what you need with the lcom account. Thus, source code writing and compilation should be done using the lcom account. Program installation and running must be done using the root account.

4. Development Process

To facilitate the development of your programs, we will take advantage of the building system already in place in Minix 3 for developing device drivers.

This means that the development process that you will follow is typical of the development of large programs. First, you'll write the code, them compile it, install it, and finally test it. Of course, we recommend that you do the development of your programs incrementally. That is, rather than executing the above sequence only once, you should implement the functionality required for each lab gradually and test it as you implement it.

In the following paragraphs, we provide some Minix 3 specific details relative to each of the phases of the development process.

4.1 Coding

In Minix 3, the source code of device drivers is maintained in the directory /usr/src/drivers/. Because you will develop programs that need to use the HW interface of I/O devices just like device drivers, to take advantage of the building system already in place, in each lab you will use a different subdirectory under this directory. For example, the code that you'll have to develop for the first lab should be in the /usr/src/drivers/lab1/ subdirectory.

As mentioned above, we suggest that you use Eclipse with the RSE plugin, running on Linux, to edit your source files in Minix 3.

4.2 Compiling

Special user-level programs must be linked with some libraries. To automate the process, you'll use the make utility. This is a program that makes compilation of large programs more efficient, by limiting compilation only to the source files that have been modified.

Make uses an input file, usually named Makefile or makefile, which must specify the dependencies between the program to be compiled and the modules used to build it.

We will review the make utility and Makefiles in more detail later in the course. For now, all you need to know is that in the different labs you'll use a Makefile similar to those used by most Minix 3 device drivers.

Once the Makefile has been created, compilation of your program can be achieved by giving the command:

$ make

Note that $ is the shell prompt for a non-root user. That is, you should compile your program as user lcom.

4.3 Installing

By convention, special programs are placed in directory /usr/sbin/. To install your program under that directory, all you need is to execute the following command:

# make install

Note that # is the shell prompt for the root user. That is, to install your program in /usr/sbin/ you must be root. To become root, you can log in as user root. Alternatively, you can execute the su command as follows:

$ su

assuming that you have previously logged in as user lcom.

4.4 Configuring

As mentioned above, Minix 3 allows to specify which kernel calls special programs can execute and which resources they can access in those calls. The permissions of a special program are specified in the file /etc/system.conf. For each lab, you will be given the permissions required by your program, and you will have to add them to that file.

For security reasons, /etc/system.conf can be edited only by the system administrator, i.e. the user root.

5. Program Execution

To execute a Minix 3 special program you need to use the service utility. This program parses /etc/system.conf to determine the permissions that the special program should have, and requests the ressurrection server (RS) to create a process that is given those permissions and that executes the special program specified.

For example, to run the special program /usr/sbin/lcom which takes no arguments, you can execute the command:

# service run /usr/sbin/lcom

To stop that program later you can execute the command:

# service stop lcom

6. Further Reading

In Minix 3, like in all Unix-like system, you can get on-line help about almost any command available by means of the man utility. For example, to learn how to use the su utility, you can give the command:

$ man su

You can also find on Minix 3's site some resources that can help you using better Minix 3. The following are some starting points that may be useful: