Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A proper way to set pmp registers #7

Closed
duskmoon314 opened this issue Aug 23, 2021 · 3 comments
Closed

A proper way to set pmp registers #7

duskmoon314 opened this issue Aug 23, 2021 · 3 comments
Labels
help wanted Extra attention is needed

Comments

@duskmoon314
Copy link
Member

Now rustsbi-qemu doesn't allow S mode software use devices provided by qemu because we havn't set pmp registers for them.

Noticed that qemu provides more than one board, and they have different MMIO. We need to discuss how to set pmp registers properly.

现在 rustsbi-qemu 不允许 S 态软件使用 qemu 提供的设备,因为我们没有为它们设置 pmp 寄存器。

注意到 qemu 提供了不止一种板子,而且它们有不同的 MMIO。我们需要讨论如何正确设置 pmp 寄存器。


If anyone who wonder how to use devices in qemu, here is an example of using uart0 (uart0_mmio base 0x10000000 lenth 0x100) in virt machine:

如果任何人想知道如何使用 qemu 的外设,下面是使用 virt 的 uart0 (uart0_mmio 基址 0x10000000 长度 0x100) 的一个例子:

fn set_pmp() {
    unsafe {
        asm!(
-            "li     {tmp}, ((0x08 << 16) | (0x1F << 8) | (0x1F << 0))", // 0 = NAPOT,ARWX; 1 = NAPOT,ARWX; 2 = TOR,A;
+            "li     {tmp}, ((0x08 << 24) | (0x1F << 16) | (0x1F << 8) | (0x1F << 0))", // 0 = NAPOT,ARWX; 1 = NAPOT,ARWX; 2 = TOR,A;
            "csrw   0x3A0, {tmp}",
            "li     {tmp}, ((0x0000000080000000 >> 2) | 0x3ffff)", // 0 = 0x0000000080000000-0x000000008001ffff
            "csrw   0x3B0, {tmp}",
            "li     {tmp}, ((0x0000000080200000 >> 2) | 0x1fffff)", // 1 = 0x0000000080200000-0x000000008021ffff
            "csrw   0x3B1, {tmp}",
+            "li     {tmp}, ((0x0000000010000000 >> 2) | 0x3f)",
+            "csrw   0x3B2, {tmp}",
            "sfence.vma",
            tmp = out(reg) _
        )
    };
}
@duskmoon314 duskmoon314 added the help wanted Extra attention is needed label Aug 23, 2021
@luojia65
Copy link
Member

Yes, a proper method to implement this feature is to design a set of macros and structures to handle it thoroughly. A complete API set would be (for example):

rustsbi::pmp! {
    0: (0x80000000, 0x8fffffff) => rwx;
    1: (0x10001000, 0x10001fff) => rw;
    2: tor => _;
}

It requires to add a new macro into rustsbi crate. Thanks for mention!

@luojia65
Copy link
Member

最好的方法是解析a1(opaque)寄存器的内容,也就是解释设备树,然后根据树的内容去分配pmp的值。opensbi是这样做的:https://github.com/riscv-software-src/opensbi/blob/bd355213bfbb209c047e8cc0df56936f6705477f/lib/utils/fdt/fdt_domain.c#L436。
因为qemu平台的a1可能性很多,它可以由qemu外面的软件去配置,只按固定的地址分配空间实用性就比较局促了。目前临时的做法可以去掉pmp限制,或者按照自己的需求去硬编码。

@YdrMaster YdrMaster mentioned this issue Jun 9, 2022
18 tasks
@YdrMaster
Copy link
Member

done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants