英文:
Why does MAXVA in xv6 source code differ from the value in the xv6 textbook?
问题
MAXVA的值在MIT 6s081的xv6教材和xv6源代码中有不同定义。教材中表示最大地址为2^38 - 1 = 0x3fffffffff,而源代码中定义MAXVA为(1L << (9 + 9 + 9 + 12 - 1)),似乎缺少了-1。是否有人可以解释这个差异以及哪个是正确的?
以下截图来自xv6.pdf,描述了MAXVA,请查看黄色突出显示的句子:
以下代码片段来自(kernel/kernel/riscv.h:348):
// one beyond the highest possible virtual address.
// MAXVA is actually one bit less than the max allowed by
// Sv39, to avoid having to sign-extend virtual addresses
// that have the high bit set.
#define MAXVA (1L << (9 + 9 + 9 + 12 - 1))
英文:
Why is the MAXVA value defined differently in the xv6 textbook of MIT 6s081 and the xv6 source code? The textbook states that the maximum address is 2^38 - 1 = 0x3fffffffff, while the source code defines MAXVA as (1L << (9 + 9 + 9 + 12 - 1)), which seems to be missing the -1. Can anyone explain the discrepancy and which one is correct?
The following screenshot is from xv6.pdf describing MAXVA, look at the yellow highlighted sentence:
The following code snippet is from (kernel/kernel/riscv.h:348):
// one beyond the highest possible virtual address.
// MAXVA is actually one bit less than the max allowed by
// Sv39, to avoid having to sign-extend virtual addresses
// that have the high bit set.
#define MAXVA (1L << (9 + 9 + 9 + 12 - 1))
答案1
得分: 1
最后可用的地址为2^38-1
。
MAXVA
的目标是没有地址指向2^38
或更多。
这是如何使用MAXVA
的:
我们可以在vm.h
中检查:请注意,地址与MAXVA
比较时使用的是"大于或等于",而不仅仅是"大于"。
grep MAXVA -n vm.c -A 1
88: if(va >= MAXVA)
89- panic("walk");
--
114: if(va >= MAXVA)
115- return 0;
这也在risc.h中有解释,在第360、361行:
359 // one beyond the highest possible virtual address.
360 // MAXVA is actually one bit less than the max allowed by
361 // Sv39, to avoid having to sign-extend virtual addresses
362 // that have the high bit set.
363 #define MAXVA (1L << (9 + 9 + 9 + 12 - 1))
英文:
The last address available is 2^38-1
The goal of MAXVA
is that no address points to 2^38
or more.
That's how MAXVA
is used:
We can check that in vm.h
: Note that the address is compared to MAXVA
with "greater on equal", not just "greater than".
grep MAXVA -n vm.c -A 1
88: if(va >= MAXVA)
89- panic("walk");
--
114: if(va >= MAXVA)
115- return 0;
It's also explained in risc.h, the discrepancy you see is explained at lines 360, 361:
359 // one beyond the highest possible virtual address.
360 // MAXVA is actually one bit less than the max allowed by
361 // Sv39, to avoid having to sign-extend virtual addresses
362 // that have the high bit set.
363 #define MAXVA (1L << (9 + 9 + 9 + 12 - 1))
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论