《操作系统》的实验代码。
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

71 rivejä
2.5 KiB

9 vuotta sitten
  1. This fun little homework tests if you understand how a multi-level page table
  2. works. And yes, there is some debate over the use of the term fun in the
  3. previous sentence. The program is called:
  4. paging-multilevel-translate.py
  5. Some basic assumptions:
  6. - The page size is an unrealistically-small 32 bytes
  7. - The virtual address space for the process in question (assume there is
  8. only one) is 1024 pages, or 32 KB
  9. - physical memory consists of 128 pages
  10. Thus, a virtual address needs 15 bits (5 for the offset, 10 for the VPN).
  11. A physical address requires 12 bits (5 offset, 7 for the PFN).
  12. The system assumes a multi-level page table. Thus, the upper five bits of a virtual
  13. address are used to index into a page directory; the page directory entry (PDE), if valid,
  14. points to a page of the page table. Each page table page holds 32 page-table entries
  15. (PTEs). Each PTE, if valid, holds the desired translation (physical frame number, or PFN)
  16. of the virtual page in question.
  17. The format of a PTE is thus:
  18. VALID | PFN6 ... PFN0
  19. and is thus 8 bits or 1 byte.
  20. The format of a PDE is essentially identical:
  21. VALID | PT6 ... PT0
  22. You are given two pieces of information to begin with.
  23. First, you are given the value of the page directory base register (PDBR),
  24. which tells you which page the page directory is located upon.
  25. Second, you are given a complete dump of each page of memory. A page dump
  26. looks like this:
  27. page 0: 08 00 01 15 11 1d 1d 1c 01 17 15 14 16 1b 13 0b ...
  28. page 1: 19 05 1e 13 02 16 1e 0c 15 09 06 16 00 19 10 03 ...
  29. page 2: 1d 07 11 1b 12 05 07 1e 09 1a 18 17 16 18 1a 01 ...
  30. ...
  31. which shows the 32 bytes found on pages 0, 1, 2, and so forth. The first byte
  32. (0th byte) on page 0 has the value 0x08, the second is 0x00, the third 0x01,
  33. and so forth.
  34. You are then given a list of virtual addresses to translate.
  35. Use the PDBR to find the relevant page table entries for this virtual page.
  36. Then find if it is valid. If so, use the translation to form a final physical
  37. address. Using this address, you can find the VALUE that the memory reference
  38. is looking for.
  39. Of course, the virtual address may not be valid and thus generate a fault.
  40. Some useful options:
  41. -s SEED, --seed=SEED the random seed
  42. -n NUM, --addresses=NUM number of virtual addresses to generate
  43. -c, --solve compute answers for me
  44. Change the seed to get different problems, as always.
  45. Change the number of virtual addresses generated to do more translations
  46. for a given memory dump.
  47. Use -c (or --solve) to show the solutions.