A Port of the MINIX OS to the Powerpc Platform
Total Page:16
File Type:pdf, Size:1020Kb
MinixPPC A port of the MINIX OS to the PowerPC platform Creating a programming model for architecture independency Master Thesis Computer Science Ingmar A. Alting September 15, 2006 First reader and supervisor: Andrew S. Tanenbaum Dept. of Computer Science Faculty of Sciences Vrije Universiteit De Boelelaan 1081A 1081 HV Amsterdam, the Netherlands e-mail: [email protected] Second reader: Herbert Bos Dept. of Computer Science Faculty of Sciences Vrije Universiteit Amsterdam De Boelelaan 1081A 1081 HV Amsterdam, the Netherlands e-mail: [email protected] Thesis by: Ingmar A. Alting Weth. W. de Boerstraat 18 1788AT Den Helder, the Netherlands email: [email protected] Abstract The main goal of this project is to indicate what it means to port an operating system from one architecture to another, and provide a programming paradigm that would make future ports easy and fast. The “natively” supported architecture of MINIX is the IBM PC compatible, that's built around the Intel architecture. This is a CISC architecture with hardware support for easy stack usage. The choice for the POWER architecture could not have been further away as this is a RISC architecture, and completely” different in many ways. This thesis will focuses on the model created for creating portable system code. Not to be confused with portable programs using a “standard” API. It will describe the changes made and problems faced porting the MINIX code base. The places where changes are made can be viewed as hotspots. For every new architecture compatibility problems are to be expected there. Some hotspots are used as example and the solution taken for MinixPPC is presented to the reader. A number of problems were found at the start of the project. The MINIX OS is (still) us- ing the “old” a.out format for it's executables. There is no (recent) public compiler kit that is able to generate a.out format executables for the PowerPC. A utility program had to be written to convert a “minimum section count” Elf32 executable to a.out format. This way the installed compiler kit from host OS can be used, which is a recent version of the GNU/C compiler. Getting the kernel to load and executed by the “boot software” of the PowerPC architecture was the next challenge. With the aid of “Open Source” software a preliminary scheme is created until MinixPPC is able to compile itself. This introduces a new project of getting a recent version of the GCC compiler kit ported to MinixPPC. The following reasoning defines the choice for the driver model used in the creation of MinixPPC. 1) System dependencies are located inside devices drivers. Defining a method to create and develop device drivers that have isolated system dependencies contribute to the portability of the driver (this could isolate the whole driver). 2) The CPU is (just) a device. 3) Creating a device driver for the CPU isolates the CPU “functionality” from the rest of the system. 4) With every device hidden behind its driver, architecture dependent and independent code are separated. In principle the CPU could have multiple devices inside, for example MMU and timers. For MinixPPC a logical separation is made by creating two drivers for the CPU, the Memory and System driver. At the moment MinixPPC is able to boot, access a MINIX v3 file system and run pro- grams, but there are still problems. Not all system calls are debugged and the system must be thoroughly tested. The difficult part of the MinixPPC project is done, but there is more work ahead. There is working code and to some degree only “hard” work is needed, most of the figuring-out, and “trial-and-error” is done. i Preface I wrote this thesis to close my study “informatica” at the “vrije Universiteit” in Amster- dam, the Netherlands. It describes the port of the MINIX operating system from the IBM PC compatible designed around the Intel x86 architecture to a IBM PowerPC architecture designed around the POWER CPU. I got the possibility to get in touch with Andrew S. Tanenbaum who has made this project possible by providing me a Apple iBook G4. It is a very nice system build of high quality components. It passed the test of booting more than 30 times a day for about 5 months. As base for the port the MINIX v3.1.3rc1 code base, targeted to the Intel Architecture (IA) is used. At the time I was living in Amsterdam while my parents home is in Den Helder. As hard as it is, it was clear that I needed to focus all my energy into the project. The decision was made to return to Den Helder. I thank my parents who made that possible. If I didn't had the possibility to get to a nice and quiet place to do my “thing” I am sure nothing solid had come out of my fingers. I consider this project as a “crown” on my programming capabilities and computer ar- chitecture understanding, for now. Its a first step on the “path” I like to take. There where a couple of occasions when I had the feeling “O it works like this, hey it works!” In the end you can always re-read the workings in the documentation and find out it stood there already, but you only “really” understand some problems when you have programmed the implementation. I am lucky that there are several open source kernels for the Power PC architecture be- fore the project begun, • The Linux kernel • Several BSD flavours, NetBSD, FreeBSD and • XNU, the Darwin kernel used by Mac OS X Some of the people involved in these projects where still on forms and/or mailing lists to give tips and solutions faced in the early phases of the project. I learned that when doing a project like this one of the biggest qualities you must pos- sess is “patience.” Some bugs or programming errors appear under special circumstances and are not easily found. One day you update code in memory management, and after a day or two the changes become accepted. Then the problem occurs, to trace it back to the changes at the memory management code could take some time. Also driver development can take some time, especially when documentation is short or out of date. The develop- ment then becomes more of a “trail-and-error” approach to reverse engineer hardware. The environment where you are working on the project can help a lot. To have people around who understand programming problems in general can help. The interpretation of a piece of text about the workings of a part of the CPU could be interpreted in many ways but only one is correct. Just to be able to talk about it or about other problems your having could give extra views that would bring you closer to the actual workings or solution. As a bonus talking with other experts eases the mind and will build confidence. ii Content 1 1 Introduction...................................................................................... 1 1.1 About MINIX....................................................................................... 1 1.2 MINIX v3........................................................................................... 1 2 4 Porting an OS.................................................................................... 4 2.1 A complete system.............................................................................. 4 2.2 Creating portable code......................................................................... 5 2.2.1 Creating portable code from existing files........................................... 10 2.3 Driver programming model................................................................. 11 2.3.1 Clock system example..................................................................... 12 3 15 Knowing your architectures............................................................... 15 3.1 Start............................................................................................... 15 3.2 IBM PC compatible............................................................................ 16 3.3 PowerPC.......................................................................................... 17 3.3.1 Booting......................................................................................... 17 3.3.2 PowerPC CPU details....................................................................... 19 3.3.3 Memory management..................................................................... 21 3.3.3.1 Block Address Translation............................................................. 23 3.3.3.2 Page Address Translation.............................................................. 24 3.3.4 I/O............................................................................................... 27 3.3.5 Interrupts and exceptions................................................................ 28 3.3.5.1 Interrupts................................................................................... 29 3.3.5.2 Exceptions.................................................................................. 30 3.3.5.3 System call................................................................................. 31 3.3.5.4 Exception and interrupt return....................................................... 31 3.4 Software.......................................................................................... 31 4 35 Development environment................................................................ 35 4.1 Why................................................................................................ 35 4.2 Two computer setup.......................................................................... 35 5 37 MinixPPC........................................................................................