Class Exercise 4.2: Paged Memory Management

Level 1: The physical address of the mynext variable of Process No. 1

The task of this level:

1. When process No. 1 calls the function output_char for the first time, what is the physical address of its mynext variable?

2. When process No. 1 calls the function output_char for the second time, what is the physical address of its mynext variable?

First, find out its linear address in gdb mode (since the first and second operations are roughly the same, only the first time will be explained in detail)

The method of finding the linear address has been solved in 4.1, and the linear address obtained this time is 0x402282c

How to calculate the physical address corresponding to a linear address

In x86 CPU, if the paging address translation mechanism is enabled, the linear address will be converted into a physical address through the page directory and page table. The overall process is as follows:

The specific process is to first find the corresponding page directory entry in the page directory with the high 10 bits of the linear address as an index, then find the corresponding page table entry in the page table with the middle 10 bits of the linear address as an index, and finally save the page table Add the start address of the page frame in the entry to the lower 12 bits of the linear address (offset within the page) to get the final physical address.

Next, switch to dbg mode and set the breakpoint to the function address first.

The starting address of the page directory is stored in the CR3 register, and the value of CR3 can be viewed through the creg command

Then check its physical address according to the index provided by the linear address

According to 10, 10, and 12 digits, 0000010000 0000100010 100000101100 can be obtained

Director = 16 Table = 34 Offset = 0x82c

The first step is to find the corresponding page directory entry, 0xffe027, take 0xffe000 as the starting address of the frame

The second step is to find the corresponding page table entry, 0x22065, and take 0x22000 as the starting address of the frame

Finally, add the starting address of the page frame in the page table entry and the low 12 bits of the linear address (offset within the page) to get the final physical address. That is, 0x22000+0x82c=0x2282c

Final answer:

When process No. 1 calls the function output_char for the first time, what is the physical address of its mynext variable? (0x2282c)

2. When process No. 1 calls the function output_char for the second time, what is the physical address of its mynext variable? (0xffc82c)

Level 2: The physical address of the mynext variable of process 0

The task of this level:

1. When process 0 calls the function output_char for the first time, what is the physical address of its mynext variable?

2. When process 0 calls the function output_char for the second time, what is the physical address of its mynext variable?

This level is basically the same as the previous level, the only two points that have changed, one is that the breakpoint in gdb mode should hit line 172, and the breakpoint in dbg mode should hit the corresponding 0x69d9

Another difference is that this time I did not do it in gdb mode when I was looking for the linear address, but in dbg mode (the value of ds is known)

The above is based on:

In bochsdbg, how to view the value at a logical address

You can use the x command to view directly, similar to the following:

The rest of the operations are similar to the first level and will not be repeated here.

Final answer:

When process 1.0 calls the function output_char for the first time, what is the physical address of its mynext variable? (0x2282c)

When process 2.0 calls the function output_char for the second time, what is the physical address of its mynext variable? (0x2282c)

Guess you like

Origin blog.csdn.net/z671514087/article/details/128387386