System Architecture

(INFT12-212 and 72-212)
Lab Notes for Week 7: Introduction to Debian Linux on the MIPS CPU

1  Introduction

In the labs for the first half of the subject, we looked at writing and running single assembly language programs on a MIPS simulator. For the second half, we will be running a full operating system, with several programs in memory at the same time, on a MIPS simulator. We will look at a real set of system calls, the POSIX API, the concepts that an operating system provides (processes, files, memory management), and we will also introduce the C language.

For all of the above, we need a new emulator which can run a full operating system and deal with simulated disk drives. We are going to be using the Qemu emulator. And for the operating system, we will be using Debian Linux.

2  Installing and Running Qemu and Debian Linux on Windows

As with MARS, there is some setup and configuration to do, and you also need to get introduced to the new environment. Here are the instructions to get Qemu with Debian Linux running from your H: drive on the Bond PCs. You will be able to download and get it to work on your Windows machine with the same instructions.
  1. Download the Zip file qemu-win.zip and unzip it in your home (H:) drive. It will create a new folder called Qemu-win. Navigate into this folder, and you will see a bunch of files, one of which is called run.bat.
  2. Download this large file, lenny_mipsel.qcow2, into the Qemu-win folder. If you plan on running this on your own computer, copy it to a USB drive now so you won't have to download it over the Internet.
  3. To run the Qemu emulator, double-click on the run.bat file. You will see a black window open up with the writing:
    qemu-system-mipsel.exe -M malta -kernel vmlinux ...
    Ignore this window. In fact, you can minimise this window. Another window will be created, but it is fully minimised:
    Figs/qemu-minimised.png
  4. Click-drag the bottom-right corner of the window to increase its size. You should now see a white window like this:
    Figs/qemu-white.png
  5. Move your mouse inside the window and type control-alt-3. The window should change to one that has text in it, like this:
    Figs/qemu-console.png
    This is the Linux console, which we will be using for the rest of the subject. You can resize the window to increase or decrease the font size.

2.1  Installing and Running Qemu and Debian Linux on Ubuntu/Other Linux

  1. If you are running Linux on your system, then install the version of Qemu which simulates the MIPS CPU. For Ubuntu Linux, this is the qemu-kvm-extras package.
  2. Create a folder for Qemu somewhere, and download/copy these three files into the folder:
    1. lenny_mipsel.qcow2, the same as the one above
    2. vmlinux-2.6.26-1-4kc-malta, and
    3. run.sh
  3. Make the run.sh file executable, either from the GUI file manager, or with a chmod 755 run.sh on the command line.
  4. Run the run.sh file, and Qemu will start and create the console window. You will have to type control-alt-3 in the window to see the Linux console.

2.2  Mac OS X Users

Unfortunately, I haven't found a way of running Qemu on OS X yet. There is supposed to be an OS X version of Qemu, see the Qemu Links page, but I don't have a Mac to work out how to configure it. If anybody tries and succeeds, please send me the instructions.

3  Logging into and Using Linux

XXX
User: user prompt.
Root: root prompt.

4  Compiling Your First C Program

XXX
    #include <unistd.h>
    
    int main() 
    { 
      write(1, "Hello world\n", 12); 
      _exit(0); 
    }

5  Shutting Down Linux

XXX
# shutdown -h now
On Windows, watch out as it seems to reboot instead of shutting down. If you see messages like
    [17179572.244000] VFS: Mounted root (ext3 filesystem) readonly. 
    [17179572.248000] Freeing prom memory: 956k freed 
    [17179572.256000] Freeing unused kernel memory: 180k freed 
    INIT: version 2.86 booting 
    Starting the hotplug events dispatcher: udevd. 
    Synthesizing the initial hotplug events...done.

then quickly close the window (click on the X in the top-right corner) to kill Qemu manually.

6  Unix and Linux: History, Architecture, System Calls

Unix is not a single operating system, but rather a family of related systems which share a common API and a common philosophy. Originally designed at Bell Labs around 1969-1971, Unix was developed at the labs, reaching a design plateau around 1978 to 1980, with 7th Edition UNIX. In the 1980s, development of Unix moved to USL and the University of California, Berkeley, where things like virtual memory, improved filesystems and Internet support were added. Since then, many companies and organisations have taken on the continuing development of the systems.

6.1  Unix Philosophy

Applications should do one thing and one thing well. They should be designed so that applications can be joined together to make more powerful tools. Traditionally, the data stream between such applications was plain text.
Another philosophy is that "everything's a file". What this means is that most desired operations on the system can be done as if the object being manipulated was a file.
One final design philosophy was to keep the kernel of the system as small as possible, by only allowing code to run in kernel-mode if absolutely necessary. These days, this isn't quite true, but is still a goal to which many designers espouse. The original designers of Unix wrote in 1974:
The kernel is the only code that cannot be substituted by a user to his own liking. For this reason, the kernel should make as few real decisions as possible. This does not mean to allow the user a million options to do the same thing. Rather, it means to allow only one way to do one thing, but have that way be the least-common divisor of all the options that might have been provided.
What is or is not implemented in the kernel represents both a great responsibility and a great power. It is a soap-box platform on "the way things should be done." Even so, if "the way" is too radical, no one will follow it. Every important decision was weighed carefully. Throughout, simplicity has been substituted for efficiency.

6.2  Unix Kernel Structure

see pg. 7 of the lecture notes for a diagram.
Most Unix versions are still monolithic in design, generally because they are all derived from the early versions of Unix which was itself monolithic. Although this is seen as a disadvantage, it does not seem to have affected the stability of the system, and Unix has a general reputation of being more reliable and stable than NT, which is not monolithic. The monolithic design does not suffer from the cost of message copying and passing, but can make it more difficult for designers to change the system.
Until recently, most Unixes did not support such new OS concepts as memory mapping, threads and asynchronous I/O. Most major Unix flavours now support all three, and Unix was one of the first systems to provide native 64-bit support on the new 64-bit platforms (DEC Alpha, Sparc etc.)

6.3  The Unix API Set

To be called UNIX, you must meet an API specification set by the X/Open Group. This API is a superset of the API specified by the POSIX P1003.1 international standard. We will look at some of the system calls specified by POSIX in these tutorials.
The POSIX standard defines about 70 system calls in the following categories:
Processes
- 8 syscalls
File Operations
- 9 syscalls
File System & Permissions
- 30 operations
Signals
- 4 operations
Time Operations
- 4 operations
Misc. Operations
- 6 operations
Note from this list the lack of memory, window and networking system calls. All Unix systems have memory and networking syscalls (e.g. 6 memory and about 30 networking in BSD). Windows and GUIs are done at the application level with the X Windows system, and so there are no system calls to the kernel.
Of course, all Unix systems have many more system calls than the set above. These deal with the administration and management of the system e.g. mounting and unmounting disk devices etc. We will only cover some of the core POSIX API set in the following lab sessions.
Note: Of the 34 system calls defined by 1st Edition UNIX in 1971, 28 of those survive as system calls today, of which over 20 are commonly used.

7  Outlook for the Next Lab

In the next lab, we will look at XXX.


File translated from TEX by TTH, version 3.85.
On 25 Nov 2011, 11:15.