为什么xv6源代码中的MAXVA值与xv6教材中的值不同?

huangapple go评论48阅读模式
英文:

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,请查看黄色突出显示的句子:
为什么xv6源代码中的MAXVA值与xv6教材中的值不同?

以下代码片段来自(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:
为什么xv6源代码中的MAXVA值与xv6教材中的值不同?

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 &lt;&lt; (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 &gt;= MAXVA)
89-    panic(&quot;walk&quot;);
--
114:  if(va &gt;= 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 &lt;&lt; (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 &gt;= MAXVA)
89-    panic(&quot;walk&quot;);
--
114:  if(va &gt;= 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 &lt;&lt; (9 + 9 + 9 + 12 - 1))

huangapple
  • 本文由 发表于 2023年5月7日 12:09:50
  • 转载请务必保留本文链接:https://go.coder-hub.com/76192161.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定