Computer Labs 2012/2013 - 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 privileged 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 privileged 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 privileged 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 a non-authorized program leads in most cases to the abnormal termination of that program. Actually, Minix 3 allows the system administrator to specify which kernel calls each privileged 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 privileged 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, to help you jump 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.

Furthermore, you can access the VMware Player's Minix 3 installation via a "remote" access as described in the annex.

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 lcom.

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: lcom.

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

Privileged 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, privileged 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 an administrator to specify which kernel calls privileged programs can execute and which resources they can access in those calls. The permissions of a privileged program are specified in a file with that program's name in the /etc/system.conf.d directory. For each lab, you will be given the permissions required by your program, and you will have to create the corresponding file.

For security reasons, only the system administrator, i.e. the user root, can add files to the /etc/system.conf.d/ directory.

5. Program Execution

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

For example, to run the privileged 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:

Annex: "Remote" Access

To access the Minix 3 installation on the VMware Player you may find it convenient to use "remote" access. I.e. rather than using the terminals of the VMware Player, you may use a terminal on Linux and use the ssh utility to login on Minix 3 as follows:

$ ssh lcom@<ip_address>

where <ip_address> is the IP address of the VMware Player. To find out this IP address you can use the command ifconfig on a terminal of the VMware Player.

$ ifconfig

After loggin in, you can issue the Minix 3 commands from the Linux terminal, as if you were using the virtual terminals on VMware Player.

This approach has several advantages. First, you can use a much larger number of terminals than the 4 virtual terminals available via VMwarePlayer. Second, the use of these remote terminals is more convenient than that of local terminals: there is no need for special key combinations to get/release the focus and you can use standard copy/paste to copy commands from one Linux window to another window.

On the other hand, in order to see the output generated by the printf() statements of privileged processes you need to execute the following command on a remote terminal:

$ tail -f /var/log/messages