Chapter 6. Project 1: Loading Executable Files

Table of Contents

1. Introduction
2. Required Reading
3. Project Synopsis
4. Loading the Executable
5. Testing Your Project

1. Introduction

In this project you will write code to parse an executable file in ELF format and pass the result of the parsing to a program laoder we provide.

2. Required Reading

This project will require you to understand the ELF executable format.

You will need to read the ELF Executable Format documentation. In this project, you will need to be able to parse the ELF program headers in order to find out how to load an executable file's text (code) and data into process memory.

3. Project Synopsis

This project will require you to change the src/geekos/elf.c. Your only task is to implement the Parse_ELF_Executable() function. This involves reading the program headers of an ELF executable to find the file offset, length, and user address for the executable's text and data segments. Based on this information, you should fill in the Exe_Format data structure passed as a parameter. This data structure will be used by the loader to determine how to load the executable. The loader is already implemented for you.

4. Loading the Executable

GeekOS, like other operating systems, uses files to store executable programs. These files are in ELF format. We have provided you with a simple read-only filesystem for this project, plus a test file that you will load. The test file is src/user/a.c, and after compilation and building, GeekOS will see it as /c/a.exe. When GeekOS boots up, it reads /c/a.exe into memory, calls your parsing code from Parse_ELF_Executable() and starts a kernel-mode thread that will run the a.exe code.

Loading ELF executables is fairly straightforward. You will need to locate the ELF program headers. These headers will describe the executable's text and data segments. As you parse the ELF executable, you will fill in the fields of an Exe_Format data structure, which is a high level representation of how to load data from the executable file into memory.

5. Testing Your Project

If you've done everthying correctly, when you start Bochs you should see this output:

Hi ! This is the first string
Hi ! This is the second string
Hi ! This is the third (and last) string
If you see this you're happy