You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by "g2gps (via GitHub)" <gi...@apache.org> on 2023/02/24 05:14:48 UTC

[GitHub] [nuttx] g2gps opened a new pull request, #8643: risc-v: SV32 MMU support for qemu-rv (WIP)

g2gps opened a new pull request, #8643:
URL: https://github.com/apache/nuttx/pull/8643

   I'm working on implementing SV32 support (from #8602). I've opened a PR for my current WIP as a draft, as the implementation is not working as expected. 
   
   With my current implantation, I'm able to go through the mapping for the IO, kflash, ksram and pgram sections and enable the MMU, in  `qemu_rv_mm_init()`. From there, execution continues into and through `nx_start`, until ` nxmsg_initialize`. At which point the program falls over when accessing the global variable `g_msgfreelist` members.
   
   On inspecting with GDB, I can see that the initial values for the list have changed from when they were originally set with `struct list_node g_msgfreelist = LIST_INITIAL_VALUE(g_msgfreelist);`. Curiously, these changes occur during the both before and after the MMU is enabled. Including if I set the values again, just before using them (like this):
   ```
   void nxmsg_initialize(void)
   {
     FAR struct msgbuf_s *msg;
     g_msgfreelist.next = &g_msgfreelist;
     g_msgfreelist.prev = &g_msgfreelist;
   
   
     msg = (FAR struct msgbuf_s *)kmm_malloc(sizeof(*msg) *
                                             CONFIG_PREALLOC_MQ_MSGS);
     if (msg)
       {
         int i;
         for (i = 0; i < CONFIG_PREALLOC_MQ_MSGS; i++)
           {
             list_add_tail(&g_msgfreelist, &msg->node);
             msg++;
           }
       }
   }
   
   ```
   Obviously, something is incorrect either which the MMU mapping, or the linker script setup. However, I can't seem to see the issue. Possibly @pussuw  could give me some pointers?
   
   If you want to build locally, I'm using the compiler suggested in the readme (`https://static.dev.sifive.com/dev-tools/riscv64-unknown-elf-gcc-8.3.0-2019.08.0-x86_64-linux-ubuntu14.tar.gz`). I'm building like this:
   ```
   make distclean
   /tools/configure.sh rv-virt:knsh32
   make -j 16
   make export
   cd ../apps
   ./tools/mkimport.sh -z -x ../nuttx/nuttx-export-*.tar.gz
   make import
   cd ../nuttx
   ```
   Then running qemu with:
   ```
   qemu-system-riscv32 -semihosting -s -S -M virt,aclint=on -cpu rv32 -smp 1 -bios none -kernel nuttx -nographic -serial mon:stdio
   ```
   I'm then using `gdb-multiarch` to debug.
   
   You'll need to apply the following to the 'apps' repo, in order to get the correct elf format, when linking. This would have to be amended as a separate PR, once resolved.
   ```
   diff --git a/import/Make.defs b/import/Make.defs
   index 0405e412b..7b6fb7ed5 100644
   --- a/import/Make.defs
   +++ b/import/Make.defs
   @@ -90,5 +90,6 @@ endif
    
    # ELF module definitions
    
   -LDELFFLAGS = -r -e _start -Bstatic
   +LDELFFLAGS = -melf32lriscv
   +LDELFFLAGS += -r -e _start -Bstatic
    LDELFFLAGS += $(addprefix -T,$(call CONVERT_PATH,$(TOPDIR)/scripts/gnu-elf.ld))
   ```
   
   Keep in mind that i've 'hacked in' support, to try and get things going, there isn't support for both SV32 and SV39 ATM.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nuttx] pussuw commented on a diff in pull request #8643: risc-v: SV32 MMU support for qemu-rv (WIP)

Posted by "pussuw (via GitHub)" <gi...@apache.org>.
pussuw commented on code in PR #8643:
URL: https://github.com/apache/nuttx/pull/8643#discussion_r1116628601


##########
boards/risc-v/qemu-rv/rv-virt/scripts/ld-kernel.script:
##########
@@ -20,9 +20,9 @@
 
 MEMORY
 {
-    kflash (rx) : ORIGIN = 0x80000000, LENGTH = 2048K   /* w/ cache */
-    ksram (rwx) : ORIGIN = 0x80200000, LENGTH = 2048K   /* w/ cache */
-    pgram (rwx) : ORIGIN = 0x80400000, LENGTH = 4096K   /* w/ cache */
+    kflash (rx) : ORIGIN = 0x80000000, LENGTH = 1024K   /* w/ cache */

Review Comment:
   The alignment requirement is reflected here as well. The minimum alignment for these is 4M for Sv32!



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nuttx] lucasssvaz commented on a diff in pull request #8643: risc-v: SV32 MMU support for qemu-rv

Posted by "lucasssvaz (via GitHub)" <gi...@apache.org>.
lucasssvaz commented on code in PR #8643:
URL: https://github.com/apache/nuttx/pull/8643#discussion_r1151293818


##########
boards/risc-v/qemu-rv/rv-virt/configs/knsh32/defconfig:
##########


Review Comment:
   Please, normalize your defconfig by running `./tools/refresh.sh --silent rv-virt:knsh32`



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nuttx] masayuki2009 commented on pull request #8643: risc-v: SV32 MMU support for qemu-rv (WIP)

Posted by "masayuki2009 (via GitHub)" <gi...@apache.org>.
masayuki2009 commented on PR #8643:
URL: https://github.com/apache/nuttx/pull/8643#issuecomment-1447333663

   @g2gps 
   
   ```
   ====================================================================================
   Configuration/Tool: rv-virt/knsh32
   ------------------------------------------------------------------------------------
     Cleaning...
     Configuring...
   .config:99:warning: symbol value '1000CONFIG_APPS_DIR="../apps"' invalid for USEC_PER_TICK
     Building NuttX...
   In file included from chip/qemu_rv_mm_init.c:30:
   chip/qemu_rv_mm_init.c: In function 'qemu_rv_mm_init':
   Error: chip/qemu_rv_mm_init.c:302:9: error: format '%lx' expects argument of type 'long unsigned int', but argument 3 has type 'uintptr_t' {aka 'unsigned int'} [-Werror=format=]
     302 |   binfo("mmu_enable: satp=%lx\n", g_kernel_pgt_pbase);
         |         ^~~~~~~~~~~~~~~~~~~~~~~~  ~~~~~~~~~~~~~~~~~~
         |                                   |
         |                                   uintptr_t {aka unsigned int}
   chip/qemu_rv_mm_init.c:302:29: note: format string is defined here
     302 |   binfo("mmu_enable: satp=%lx\n", g_kernel_pgt_pbase);
         |                           ~~^
         |                             |
         |                             long unsigned int
         |                           %x
   cc1: all warnings being treated as errors
   make[1]: *** [Makefile:135: qemu_rv_mm_init.o] Error 1
   make[1]: Target 'libkarch.a' not remade because of errors.
   make: *** [tools/LibTargets.mk:53: arch/risc-v/src/libkarch.a] Error 2
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nuttx] pussuw commented on pull request #8643: risc-v: SV32 MMU support for qemu-rv (WIP)

Posted by "pussuw (via GitHub)" <gi...@apache.org>.
pussuw commented on PR #8643:
URL: https://github.com/apache/nuttx/pull/8643#issuecomment-1442876177

   One common source of such issues is the config values, like ram start and size
   ```
   CONFIG_RAM_SIZE=1048576
   CONFIG_RAM_START=0x80100000
   ```
   
   Another error in your config is that your user heap and pgpool virtual addresses overlap
   ```
   CONFIG_ARCH_HEAP_VBASE=0xC0200000
   CONFIG_ARCH_PGPOOL_VBASE=0xC0200000
   ```
   
   Seems like you have some happy debugging to do!


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nuttx] g2gps commented on pull request #8643: risc-v: SV32 MMU support for qemu-rv

Posted by "g2gps (via GitHub)" <gi...@apache.org>.
g2gps commented on PR #8643:
URL: https://github.com/apache/nuttx/pull/8643#issuecomment-1485985579

   @pussuw I can see this build is failing for macos, `sim/dynconns` configuration. Is it that a result of these changes, or is there another issue here?
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nuttx] pussuw commented on a diff in pull request #8643: risc-v: SV32 MMU support for qemu-rv (WIP)

Posted by "pussuw (via GitHub)" <gi...@apache.org>.
pussuw commented on code in PR #8643:
URL: https://github.com/apache/nuttx/pull/8643#discussion_r1116626676


##########
arch/risc-v/src/common/riscv_mmu.h:
##########
@@ -112,9 +101,46 @@
 
 #define RV_MMU_SECTION_ALIGN        (RV_MMU_L2_PAGE_SIZE)
 #define RV_MMU_SECTION_ALIGN_MASK   (RV_MMU_SECTION_ALIGN - 1)
+
+/* Sv32 has:
+ * - 4K page size
+ * - 2 page table levels
+ * - 10-bit VPN width
+ */
+
+#elif CONFIG_ARCH_MMU_TYPE_SV32
+#define RV_MMU_PPN_WIDTH        22
+#define RV_MMU_ASID_WIDTH       9
+#define RV_MMU_MODE_WIDTH       1
+#define RV_MMU_PTE_PPN_MASK     (((1ul << RV_MMU_PPN_WIDTH) - 1) << RV_MMU_PTE_PADDR_SHIFT)
+#define RV_MMU_VPN_WIDTH        (10)
+#define RV_MMU_VPN_MASK         ((1ul << RV_MMU_VPN_WIDTH) - 1)
+#define RV_MMU_PT_LEVELS        (2)
+#define RV_MMU_SATP_MODE        (SATP_MODE_SV32)
+#define RV_MMU_L1_PAGE_SIZE     (0x400000)   /* 4M */
+#define RV_MMU_L2_PAGE_SIZE     (0x1000)     /* 4K */
+
+#define RV_MMU_SECTION_ALIGN        (RV_MMU_L2_PAGE_SIZE)

Review Comment:
   This should be L1 page size, the alignment requirement comes from the page table alignment requirement. If you want to describe a section of continuous memory, you need to start the physical memory described by the  page table at a certain alignment.
   
   In the case of Sv39 the requirement is either 1G or 2M, with Sv32 the requirement is 4M.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nuttx] pussuw commented on pull request #8643: risc-v: SV32 MMU support for qemu-rv

Posted by "pussuw (via GitHub)" <gi...@apache.org>.
pussuw commented on PR #8643:
URL: https://github.com/apache/nuttx/pull/8643#issuecomment-1486222238

   CI is broken for everyone, this is one fix in review https://github.com/apache/nuttx/pull/8913


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nuttx] g2gps commented on pull request #8643: risc-v: SV32 MMU support for qemu-rv (WIP)

Posted by "g2gps (via GitHub)" <gi...@apache.org>.
g2gps commented on PR #8643:
URL: https://github.com/apache/nuttx/pull/8643#issuecomment-1455222306

   @masayuki2009 Thanks, I'd overlooked that.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nuttx] g2gps commented on pull request #8643: risc-v: SV32 MMU support for qemu-rv (WIP)

Posted by "g2gps (via GitHub)" <gi...@apache.org>.
g2gps commented on PR #8643:
URL: https://github.com/apache/nuttx/pull/8643#issuecomment-1445778135

   Thanks @pussuw, that pointed me what seems to be in the right direction. 
   
   I have a working implementation with both SV32 and SV39 currently. At least, I can run through the steps in `boards/risc-v/qemu-rv/rv-virt/README.txt`, and execute  applications from the file system.
   
   Possibly there is something else which could be done to test the functionality? As it stands, I'll need to get some direction on #8666 before anything can be finalised. Any feedback would be welcome.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nuttx] lucasssvaz commented on pull request #8643: risc-v: SV32 MMU support for qemu-rv

Posted by "lucasssvaz (via GitHub)" <gi...@apache.org>.
lucasssvaz commented on PR #8643:
URL: https://github.com/apache/nuttx/pull/8643#issuecomment-1486979187

   @g2gps Please rebase your branch to the latest commit.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nuttx] masayuki2009 merged pull request #8643: risc-v: SV32 MMU support for qemu-rv

Posted by "masayuki2009 (via GitHub)" <gi...@apache.org>.
masayuki2009 merged PR #8643:
URL: https://github.com/apache/nuttx/pull/8643


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org