eXpOS: An Experimental Operating System from India

0
2217

An operating system is also a program that includes over millions of lines of source code. A cursory glance over the Internet tells us that a typical Linux operating system like Ubuntu or Debian has over 12 million lines of source code. But this enormous volume of source code poses a huge challenge to a person teaching the concepts of operating systems. Developed in India, eXpOS is an educational operating system that addresses this challenge.

How does a teacher approach the task of dividing an operating system into meaningful sub-units and providing useful information about them to the students? Of course, there are some operating systems that are very small, with just a few lines of source code. For example, KolibriOS is an operating system with a GUI (graphical user interface) that requires only about 2MB of disk space and less than 10MB of RAM to run. So, is it wise to use such a tiny, lightweight operating system to teach the concepts? Yes, it is. Some academicians believe such an approach is the right one. An operating system called MINIX (a UNIX-like OS) is an excellent example for this approach, wherein a real, yet minimal operating system is used to teach the concepts. Older versions of MINIX were developed by Dr Andrew S. Tanenbaum of Vrije Universiteit Amsterdam in the Netherlands, solely for educational purposes. But from MINIX 3 onwards, the objective has changed to include the creation of a highly reliable and secure micro-kernel operating system.

But there is also a second school of thought on teaching various concepts in computer science, in general, and operating systems in particular. People who support this second school of thought believe in using abstract entities to teach concepts in computer science. An excellent example is a project called ‘From Nand to Tetris’ developed by Dr Noam Nisan (Hebrew University of Jerusalem) and Dr Shimon Schocken (IDC Herzliya, Israel). This project involves the development of a simulated computer called ‘Hack’ starting from simulated NAND gates, and is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.

Notice that Hack is not a computing system with tangible hardware. It is a computer system simulated on your existing computer system. A person developing the game Tetris (a popular tile-matching puzzle) on top of the simulated Hack computer system developed from scratch learns a lot about the actual development of a real computer. So, in this project, instead of developing a physical computer from basic hardware, a student develops a simulated computer from basic simulated components to learn about various aspects of computer science.

Figure 1: Successful installation of eXpOS packages

Now let us discuss a bit more about the working of this project such as the simulated hardware, the machine language, assembly language, the operating system, etc. As we mentioned earlier, the simulated computer is called Hack, a 16-bit machine with its own CPU. The project also deals with a Hardware Description Language to describe the chips of the Hack computer. The Hack computer also has an assembly language of its own. The operating system running on a Hack computer is called Jack. There is a high-level programming language, also called Jack, associated with the Jack OS. The project culminates with the development of application programs on top of the Jack OS, including the popular video game called Tetris. The URL https://www.nand2tetris.org/copy-of-talks shows a number of interesting applications developed using Jack, the programming language.

Though we have already mentioned the project ‘From Nand to Tetris’, in this article we will be focusing on the workings of an educational operating system that is similar to this project. This is an experimental operating system called eXpOS developed by Dr Murali Krishnan K. and his team from the National Institute of Technology, Calicut (NIT-C). eXpOS has many advantages over the Jack OS from the project ‘From Nand to Tetris’ as far as teaching operating system concepts is concerned. Jack runs on a simulated computer called Hack, which is developed from basic logic gates and has some additional complexity. eXpOS runs on top of a simulated string based architecture called eXperimental String Machine (XSM). A high-level programming language called Experimental Language (EXPL), a system programming language called Systems Programming Language (SPL) and an assembly language called XSM Assembly Language have been used to develop eXpOS and its associated application programs.

Figure 2: Output of the program msg.xsm

eXpOS has a built-in compiler for the high-level programming language EXPL. A detailed manual and course on the development of the EXPL compiler is available at the URL https://silcnitc.github.io/. This course was also developed by Dr Murali Krishnan K. and his team from NIT-C. At the URL given earlier, the step-by-step development of the EXPL compiler is given, which is a good learning material for people interested in learning compiler design. However, we will be focusing on the operating system eXpOS, the first of its kind from India.

Before we proceed any further, do note that eXpOS works on top of a simulated hardware called XSM architecture and cannot be installed on real hardware. Similarly, the high-level programming language EXPL, the system programming language SPL and the XSM assembly language only work on eXpOS and XSM architecture, and cannot be used on any real operating system or real hardware. This architecture-neutral behaviour of the XSM machine might look like a weakness to casual observers but, in reality, eXpOS draws a lot of its strength from this simplified XSM architecture. Because of this simplified XSM machine, the development of eXpOS is relatively easy compared with the development of any lightweight operating system. But how can we compare eXpOS with the popular Hack computer. In order to develop a Hack computer, we have to start with simulated NAND gates and proceed forward, whereas eXpOS works on a simulated XSM machine which is supported by experimental programming languages like EXPL, SPL and XSM assembly language. The project ‘From Nand to Tetris’ covers the entirety of computer science, whereas the project eXpOS teaches just one core field of computer science — operating systems. Thus, even though the two projects share the same philosophy, they are in no way related and the emphasis of eXpOS on teaching operating systems concepts alone makes it absolutely relevant.

The details of the course on eXpOS are available at the URL http://exposnitc.github.io/. There is a detailed roadmap on this URL about the step-by-step development of the operating system eXpOS. It was derived from an earlier experimental operating system called XOS, also developed by the same team from NIT-C. Figure 1 in the previous page is the logo of eXpOS.

eXpOS and all the associated learning material are licensed under the Creative Commons Attribution-NonCommercial 4.0 International License. The development of eXpOS is done in 28 stages, which are divided into three phases. The first phase involves Stages 1 to 12 and helps you to get familiar with the installation, the bootstrap loading process, the XEXE executable file format, the system programming language SPL, the high-level language EXPL, etc. The second phase involves Stages 13 to 19 and implements the scheduler of the operating system, hardware operations like disk interrupt handling and exception handling, and manages the console input. The third and final phase involves Stages 20 to 28 and implements system calls for process creation, termination and synchronisation, file creation, deletion, read and write, etc. Stage 28 of the third phase also enables eXpOS to support a two-core machine.

You need to install Flex (a lexical analyser generator), GNU Bison (a parser generator), tar (a utility for archive management) and make (a tool for build automation) before proceeding with the installation of eXpOS. You also need to install the package libreadline-dev before installing eXpOS. This library is available in Linux operating systems like Ubuntu, Debian, etc. This is where I had some difficulty with eXpOS. The package readline-dev is not available in Linux operating systems like Fedora. I have tried with equivalent packages like readline-devel on Fedora. But so far, I have been unable to install eXpOS on Fedora, and I will be very happy if somebody could help me do so. Stage 1 of the eXpOS roadmap provides the detailed steps to install the necessary tools to develop eXpOS. You can download the compressed installation file from the link provided in Stage 1, and unzip it with the utility tar. Figure 1 shows the terminal when the installation of the eXpOS packages have been completed successfully with the utility make.

Figure 3: Output of the program count.spl

After a successful execution, the directory named myexpos will contain the following sub-directories — expl, spl, xfs-interface and xsm. The directory expl has the files associated with the EXPL compiler. The directory spl has the files associated with the SPL compiler. The directory xfs-interface contains the files associated with the XFS interface. And the directory xsm contains the files associated with the eXperimental String Machine (XSM).

It is impossible to summarise all the details regarding eXpOS in this short article. So let us try to understand how eXpOS works by running three programs written in the following three programming languages — XSM assembly language, SPL system programming language and EXPL high-level programming language. Please note that in order to run these programs, we have to develop different modules of the operating system eXpOS, itself. But we will only explore the three programs and their execution to understand the power of eXpOS.

First, let us consider the XSM assembly language program called msg.xsm shown below. The program tries to print the string ‘ABCDEFGHIJKLMNOP’.

MOV R0, “ABCDEFGHIJKLMNOP”
MOV R16, R0
PORT P1, R16
OUT
HALT

Notice that the XSM assembly language is similar to the Intel syntax of the x86 assembly language. This program can be executed after developing eXpOS up to Stage 3. Notice that in this stage, the program can only be executed as the OS start-up code. We can create the program file msg.xsm using some text editor, and then save it to the computer in which we are simulating the eXperimental String Machine (XSM). A string based simulated file system called Experimental File System (eXpFS) is used by eXpOS to save files. The XFS interface is used to transfer files from the real file system to the simulated file system, eXpFS. After loading the program msg.xsm to eXpFS as OS start-up code, we can run the XSM machine with the command xsm. Figure 2 shows the output of the program msg.xsm. In this figure, we can see that the string printed is ‘ABCDEFGHIJKLM’ and not ‘ABCDEFGHIJKLMNOP’. This gives us a hint about the capacity of the string-based storage of the eXpFS file system.

Now, let us consider the SPL program called count.spl shown below. The program count.spl, which prints the numbers from 1 to 10, can be executed after developing the eXpOS up to Stage 4.

alias count R0;
count = 1;
while(count <= 10) do
print count;
count = count + 1;
endwhile;

Notice that the XSM machine cannot execute SPL programs directly; so we will use the SPL compiler to compile the program count.spl to obtain the XSM assembly language program count.xsm. This assembly program is also loaded as OS start-up code to the eXpFS file system by using the XFS interface for execution. Figure 3 shows the output of the program count.spl. Notice that SPL is the programming language used to develop eXpOS.

Finally, let us consider an EXPL program called prime.expl.

int main()
{
decl
int num,fl,ct,temp;
enddecl
begin
num=2;
while ( num <= 50 ) do
fl=0;
ct=2;
while (ct < num) do
if ((num % ct) == 0) then
fl=1;
break;
endif;
ct = ct + 1;
endwhile;
if (fl == 0) then
temp = exposcall ( “Write” , -2, num );
endif;
num = num + 1;
endwhile;
return 0;
end
}
Figure 4: Output of the program prime.expl

This program, which prints the prime numbers between 1 and 50, can be executed after developing eXpOS up to Stage 11. By now, you will have an OS start-up code capable of handling console output, a primitive exception handler and a simple exit system call implementation. Notice that all these modules will be further developed in later stages. As mentioned earlier, the XSM machine can only execute XSM assembly code. So, we use the EXPL compiler to compile the program prime.expl to obtain the XSM assembly language program prime.xsm. Figure 4 shows the output of the program prime.expl when executed.

So far, we have only seen the execution of three programs on top of the built-in XSM machine. But in the later stages, we will add more modules to eXpOS so that more complicated application programs can be developed and executed on eXpOS. The sample EXPL programs provided by the development team include programs for bubble sort, quick sort, binary search tree creation, linked list creation, etc.

Now let us discuss a bit about the modules in a fully developed eXpOS after all the 28 stages. Modules in eXpOS are used to perform certain logical tasks. They cannot be invoked from user programs. They are executed only in kernel mode. There will be an OS start-up code and boot module to load operating system data structures. The scheduler module is used for context switching between multiple processes. Device manager module and resource manager module are responsible for handling resources like the terminal, disk, etc. eXpOS also has a process manager module, timer module, pager module and memory manager module — just like any other typical operating system. It also has modules for exception handling and interrupt handling.

What I have covered in the article is the absolute minimum, but I urge students, young IT professionals and teachers of computer science to go through the detailed roadmap and explore eXpOS further. Completing all the 28 stages for the development of eXpOS might require some patience but I am sure that, in the end, you will be rewarded for your efforts. I also urge you to write far more complicated SPL and EXPL programs to test the limitations and vulnerabilities of eXpOS. Apart from NIT-C, a few other premier institutes in India have already shown interest in making eXpOS a part of their curriculum. I believe more and more institutes will join the team, and the use of eXpOS in Indian academia will rapidly increase in the coming years. I have used material from the roadmap for eXpOS for writing this article, and I thank the development team of the OS.

LEAVE A REPLY

Please enter your comment!
Please enter your name here