assignment10

assignment10
Fall Term 2012
SYSTEMS PROGRAMMING AND COMPUTER ARCHITECTURE
Assignment 10: Page table programming assignment
Assigned on: 6th Dec 2012
Due by:
13th Dec 2012
Task 1
In this assignment you will implement basic virtual memory functionality in C based on the
structure of a x86 32 page-table. x86 32 has a two-level page table. The first-level page table is
often referred to as the page-directory.
Avail
20
3
P=1
Page table physical base address
G
PS=0
D
A
CD
WT
U/S
R/W
If the present bit is set, the 32 bit page-directory entry looks like this:
1 1 1 1 1 1 1 1 1
20
3
P=1
Avail
A
CD
WT
U/S
R/W
Page table physical base address
G
PS=1
or for large pages (4 MiB):
1 1 1 1 1 1 1 1 1
Avail
20
3
P=1
Page physical base address
G
0
D
A
CD
WT
U/S
R/W
The 32 bit width second-level page-table format for entries having the present bit set is:
1 1 1 1 1 1 1 1 1
See Table 1 for a description of flags used in above figures.
The structure of a 32 bit virtual address is:
VPN1
31
VPN2
21
VPO
11
0
VPN 1 and 2 are the virtual page numbers used as indices for the first and second level page table,
whereas VPO is the virtual page offset which addresses the byte within the page.
We prepared a skeleton that can be used as a basis for the implementation. You will find it on
the course website as a tar archive. Download and extract that file. You will find the following
typedefs there:
Avail
G
PS
A
CD
WT
U/S
R/W
P
D
Bits available to system programmers
global page: not evicted from TLB on task switch
page size: 0 = 4 KiB, 1 = 4 MiB
accessed: set by hardware cleared by software
cache disabled
write-through
user or supervisor mode access
read-only or read-write access
page table or directory is present
dirty: set by MMU on writes
Table 1: Page table and page directory bits
Type
pde t
pte t
vaddr t
paddr t
Base type
uint32 t
uint32 t
uint32 t
uint32 t
Description
Entry in the page-directory (first-level page table)
Entry in the page-table (second-level)
Virtual address
Physical address
As a first step implement functions parse virt addr, parse pde, parse pt, set pde, set pt. These
functions are low-level functions to read and write the page-directory and page-table entries as
well as for extracting the page-table indices from a virtual address.
Task 2
Have a look at the skeletons for functions map large and map. These functions map physical pages
into the virtual address space by inserting entries to the first and second-level page tables. They
also set some attributes in these entries. At this point, you only have to handle the r/w flag.
For regular 4 KiB pages, map needs to touch both levels of the page-table hierarchy, whereas
map large (for 4 MiB mappings) only modifies the content of the page-directory. Mapping a large
page works by pointing the page-directory directly to a 4 MiB piece of memory. It needs to be
page aligned, as only the 20 uppermost bits of the physical address can be stored in the pagedirectory entry. The PS bit in the page-directory entry is used to distinguish large and regular
pages. Implement these two functions.
In case the page-directory or the appropriate page-table does not yet exist, you will have to allocate
some space for it. Have a look at and implement functions alloc pt and alloc pd. Remember: Both
the beginning of the page-table and the page-directory data-structures need to be page-aligned.
Do not forget to implement free pagetable to free all allocated memory again.
Task 3
Next, you are going to implement the unmap operation. It should work for both, 4 KiB and 4
MiB pages. The present bit in the appropriate page-directory or page-table entries should be set
to 0 by this operation.
2
Evaluation
You can use the ./correctness script in the handout archive to verify your solution. The program
will run your page-table implementation and compare it to the master solution. dropAddresses
is executed on your output first to remove all dynamic addresses from the page-table entries.
These are the addresses stored in the page-directory for regular 4 KiB pages. Then, the Unix diff
command is executed to compare the files.
Hints
Run make after extracting the archive we provide on the website to compile your page table
manipulation program. gcc will link against a static library libdump.a required to dump your page
table in a format we can parse with the ./correctness script. Your program will be compiled in 32
bit mode. As always you will have to install gcc-multilib for cross-compiling on 64 bit systems.
Hand In Instructions
Upload your source files to a subfolder assignment10 of your SVN folder.
3
Was this manual useful for you? yes no
Thank you for your participation!

* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project

Download PDF

advertising