forked from dmoisset/os-implementation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathelfparsingproject.html
53 lines (52 loc) · 5.97 KB
/
elfparsingproject.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Chapter 6. Project 1: Loading Executable Files</title><meta name="generator" content="DocBook XSL Stylesheets V1.64.1"><link rel="home" href="index.html" title="Hacking GeekOS"><link rel="up" href="index.html" title="Hacking GeekOS"><link rel="previous" href="introproject.html" title="Chapter 5. Project 0: Getting Started"><link rel="next" href="usermodeproject.html" title="Chapter 7. Project 2: Adding Processes"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Chapter 6. Project 1: Loading Executable Files</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="introproject.html">Prev</a> </td><th width="60%" align="center"> </th><td width="20%" align="right"> <a accesskey="n" href="usermodeproject.html">Next</a></td></tr></table><hr></div><div class="chapter" lang="en"><div class="titlepage"><div><div><h2 class="title"><a name="elfparsingproject"></a>Chapter 6. Project 1: Loading Executable Files</h2></div></div><div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><span class="sect1"><a href="elfparsingproject.html#project1_intro">1. Introduction</a></span></dt><dt><span class="sect1"><a href="elfparsingproject.html#project1_requiredreading">2. Required Reading</a></span></dt><dt><span class="sect1"><a href="elfparsingproject.html#project1_synopsis">3. Project Synopsis</a></span></dt><dt><span class="sect1"><a href="elfparsingproject.html#project1_exeloading">4. Loading the Executable</a></span></dt><dt><span class="sect1"><a href="elfparsingproject.html#project1_testing">5. Testing Your Project</a></span></dt></dl></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="project1_intro"></a>1. Introduction</h2></div></div><div></div></div><p>
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.
</p></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="project1_requiredreading"></a>2. Required Reading</h2></div></div><div></div></div><p>
This project will require you to understand
the ELF executable format.
</p><p>
You will need to read the
<a href="http://www.x86.org/ftp/manuals/tools/elf.pdf" target="_top">ELF Executable Format</a>
documentation. In this project, you will need to be able to parse the
ELF <span class="emphasis"><em>program headers</em></span> in order to find out how to
load an executable file's text (code) and data into process memory.
</p></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="project1_synopsis"></a>3. Project Synopsis</h2></div></div><div></div></div><p>
This project will require you to change the <tt class="filename">src/geekos/elf.c</tt>.
Your only task is to implement the
<tt class="literal">Parse_ELF_Executable()</tt> 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 <tt class="literal">Exe_Format</tt> 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.
</p></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="project1_exeloading"></a>4. Loading the Executable</h2></div></div><div></div></div><p>
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 <tt class="filename">src/user/a.c</tt>, and after
compilation and building, GeekOS will see it as
<tt class="filename">/c/a.exe</tt>.
When GeekOS boots up, it reads <tt class="filename">/c/a.exe</tt> into
memory, calls your parsing code from
<tt class="literal">Parse_ELF_Executable()</tt>
and starts a kernel-mode thread that will run the
<tt class="filename">a.exe</tt> code.
</p><p>
Loading ELF executables is fairly straightforward. You will need to
locate the ELF program headers. These headers will describe the executable's
<span class="emphasis"><em>text</em></span> and <span class="emphasis"><em>data</em></span> segments.
<sup>[<a name="id2965490" href="#ftn.id2965490">1</a>]</sup>
As you parse the ELF executable, you will fill in the fields of
an <tt class="literal">Exe_Format</tt> data structure, which is a high level
representation of how to load data from the executable file into
memory.
</p></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="project1_testing"></a>5. Testing Your Project</h2></div></div><div></div></div><p>
If you've done everthying correctly, when you start Bochs you should see this output:
</p><pre class="screen">
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
</pre><p>
</p></div><div class="footnotes"><br><hr width="100" align="left"><div class="footnote"></div></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="introproject.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="index.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="usermodeproject.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Chapter 5. Project 0: Getting Started </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> Chapter 7. Project 2: Adding Processes</td></tr></table></div></body></html>