Converting virtual adress to page table entry
I am reading Modern Operating Systems 3rd Edition by A.S Tanenbaum, and I've come to the chapter on virtual memory management. I've been stuck on a part for some time now, and I can't get my head around it. Either, it's a typo in the book, or I have misunderstood something.
Suppose we have a multi-level page table with two levels, where we map 32-bit virtual addresses to physical memory frames.
10 | 10 | 12 meaning we have a top level page table with 1024 entries, and a page size of 4096 bytes or 4KB. Entry 0 of the top level page table points to the text segment page table, entry 1 to the data segment, and the 1023 entry to the stack page table.
As an example, consider the 32-bit virtual address 0x00403004
(4,206,596 decimal), which is 12,292 bytes into the data. This virtual
address corresponds to PT 1 = 1, PT2 = 2 , and Offset = 4. The MMU
first uses PT1 to index into the top-level page table and obtain entry
1, which corresponds to addresses 4M to 8M. It then uses PT2 to index
https://www.pinkwinds.com/dresses/long-gown-dresses.html
Am I missing something, or is this a typo in the book stating PT2 = 2 , when it actually should be PT2 = 3? As the text later says, the MMU uses the PT2 index to extract entry 3. Where does the "12,292 bytes into the data" come from? How is that derived from the virtual address? I understand it has something to do with the offset, but I can't figure out how it's done. As far as I have understood, the physical address is derived as a combination of the frame number from the second page table, and the offset. I see that the 12,292 is a result of 3*4096+4 (PT2 entry * page size + offset) . Is this correct?