《操作系统》的实验代码。
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

98 wiersze
4.0 KiB

  1. This program allows you to see how address translations are performed in a
  2. system with base and bounds registers. As before, there are two steps to
  3. running the program to test out your understanding of base and bounds. First,
  4. run without the -c flag to generate a set of translations and see if you can
  5. correctly perform the address translations yourself. Then, when done, run with
  6. the -c flag to check your answers.
  7. In this homework, we will assume a slightly different address space than our
  8. canonical one with a heap and stack at opposite ends of the space. Rather, we
  9. will assume that the address space has a code section, then a fixed-sized
  10. (small) stack, and a heap that grows downward right after, looking something
  11. like you see in the Figure below. In this configuration, there is only one
  12. direction of growth, towards higher regions of the address space.
  13. -------------- 0KB
  14. | Code |
  15. -------------- 2KB
  16. | Stack |
  17. -------------- 4KB
  18. | Heap |
  19. | | |
  20. | v |
  21. -------------- 7KB
  22. | (free) |
  23. | ... |
  24. In the figure, the bounds register would be set to 7~KB, as that represents
  25. the end of the address space. References to any address within the bounds
  26. would be considered legal; references above this value are out of bounds and
  27. thus the hardware would raise an exception.
  28. To run with the default flags, type relocation.py at the command line. The
  29. result should be something like this:
  30. prompt> ./relocation.py
  31. ...
  32. Base-and-Bounds register information:
  33. Base : 0x00003082 (decimal 12418)
  34. Limit : 472
  35. Virtual Address Trace
  36. VA 0: 0x01ae (decimal:430) -> PA or violation?
  37. VA 1: 0x0109 (decimal:265) -> PA or violation?
  38. VA 2: 0x020b (decimal:523) -> PA or violation?
  39. VA 3: 0x019e (decimal:414) -> PA or violation?
  40. VA 4: 0x0322 (decimal:802) -> PA or violation?
  41. For each virtual address, either write down the physical address it
  42. translates to OR write down that it is an out-of-bounds address
  43. (a segmentation violation). For this problem, you should assume a
  44. simple virtual address space of a given size.
  45. As you can see, the homework simply generates randomized virtual
  46. addresses. For each, you should determine whether it is in bounds, and if so,
  47. determine to which physical address it translates. Running with -c (the
  48. "compute this for me" flag) gives us the results of these translations, i.e.,
  49. whether they are valid or not, and if valid, the resulting physical
  50. addresses. For convenience, all numbers are given both in hex and decimal.
  51. prompt> ./relocation.py -c
  52. ...
  53. Virtual Address Trace
  54. VA 0: 0x01ae (decimal:430) -> VALID: 0x00003230 (dec:12848)
  55. VA 1: 0x0109 (decimal:265) -> VALID: 0x0000318b (dec:12683)
  56. VA 2: 0x020b (decimal:523) -> SEGMENTATION VIOLATION
  57. VA 3: 0x019e (decimal:414) -> VALID: 0x00003220 (dec:12832)
  58. VA 4: 0x0322 (decimal:802) -> SEGMENTATION VIOLATION
  59. ]
  60. With a base address of 12418 (decimal), address 430 is within bounds (i.e., it
  61. is less than the limit register of 472) and thus translates to 430 added to
  62. 12418 or 12848. A few of the addresses shown above are out of bounds (523,
  63. 802), as they are in excess of the bounds. Pretty simple, no? Indeed, that is
  64. one of the beauties of base and bounds: it's so darn simple!
  65. There are a few flags you can use to control what's going on better:
  66. prompt> ./relocation.py -h
  67. Usage: relocation.py [options]
  68. Options:
  69. -h, --help show this help message and exit
  70. -s SEED, --seed=SEED the random seed
  71. -a ASIZE, --asize=ASIZE address space size (e.g., 16, 64k, 32m)
  72. -p PSIZE, --physmem=PSIZE physical memory size (e.g., 16, 64k)
  73. -n NUM, --addresses=NUM # of virtual addresses to generate
  74. -b BASE, --b=BASE value of base register
  75. -l LIMIT, --l=LIMIT value of limit register
  76. -c, --compute compute answers for me
  77. ]
  78. In particular, you can control the virtual address-space size (-a), the size
  79. of physical memory (-p), the number of virtual addresses to generate (-n), and
  80. the values of the base and bounds registers for this process (-b and -l,
  81. respectively).