rt-thread/bsp/qemu-virt64-riscv
Shell 65c9947225
[libcpu] rv64: support for ARCH_REMAP_KERNEL (#9067)
* [libcpu] support for ARCH_REMAP_KERNEL

These changes introduce support for the ARCH_REMAP_KERNEL configuration,
which isolates kernel space in high virtual address regions. This feature
is necessary to enhance memory protection and management by segregating
user and kernel spaces more effectively.

Changes:
- Updated conditional macros to check for ARCH_REMAP_KERNEL instead of
  ARCH_KERNEL_IN_HIGH_VA in board initialization files to reflect the new
  configuration option.
- Modified qemu-virt64-riscv Kconfig and SConstruct files to include and
  utilize ARCH_REMAP_KERNEL.
- Created a new linker script `link_smart.lds` for smart linking in qemu-virt64-riscv.
- Updated rtconfig.py to use a more flexible execution path setup.
- Enhanced user address space definitions in `lwp_arch.h` to support the
  new virtual address mappings.
- Adjusted kernel memory initialization and mapping logic in `c906/mmu.c`
  and `virt64/mmu.c` to account for high virtual address regions.
- Added Kconfig option to enable ARCH_REMAP_KERNEL for RISCV64 architectures.
- Enhanced memory setup functions to support new mapping scheme, including
  updates to early page table setup and address relocation logic.

These modifications ensure that the system can utilize high memory
addresses for the kernel, improving memory isolation and system stability.

Signed-off-by: Shell <smokewood@qq.com>

* fixup: CI run failed

* bsp: default config without using smart

* fixup: static checks

* restore rt_hw_mmu_kernel_map_init for D1

---------

Signed-off-by: Shell <smokewood@qq.com>
2024-06-18 11:15:59 +08:00
..
applications [time]时钟框架重构 (#7794) 2023-07-17 20:11:58 +08:00
driver [libcpu] rv64: support for ARCH_REMAP_KERNEL (#9067) 2024-06-18 11:15:59 +08:00
.config [libcpu] rv64: support for ARCH_REMAP_KERNEL (#9067) 2024-06-18 11:15:59 +08:00
.gitignore sync branch rt-smart. (#6641) 2022-12-03 12:07:44 +08:00
Kconfig [libcpu] rv64: support for ARCH_REMAP_KERNEL (#9067) 2024-06-18 11:15:59 +08:00
README.md sync branch rt-smart. (#6641) 2022-12-03 12:07:44 +08:00
README_ZH.md [bsp][readme] 增加scons --exec-path=xxx 命令的使用说明 2022-10-10 09:42:44 +08:00
README_ch.md sync branch rt-smart. (#6641) 2022-12-03 12:07:44 +08:00
SConscript [bsp] rename qemu-riscv-virt64 to qemu-virt64-riscv 2022-05-25 10:05:23 +08:00
SConstruct [libcpu] rv64: support for ARCH_REMAP_KERNEL (#9067) 2024-06-18 11:15:59 +08:00
link.lds format link scripts 2023-01-08 22:52:13 -05:00
link_smart.lds [libcpu] rv64: support for ARCH_REMAP_KERNEL (#9067) 2024-06-18 11:15:59 +08:00
link_stacksize.lds format link scripts 2023-01-08 22:52:13 -05:00
qemu-dbg.sh [rt-smart] kernel virtual memory management layer (#6809) 2023-01-08 21:08:55 -05:00
qemu-dumpdtb.sh [bsp] rename qemu-riscv-virt64 to qemu-virt64-riscv 2022-05-25 10:05:23 +08:00
qemu-nographic-smode.sh [bsp] rename qemu-riscv-virt64 to qemu-virt64-riscv 2022-05-25 10:05:23 +08:00
qemu-nographic.bat sync branch rt-smart. (#6641) 2022-12-03 12:07:44 +08:00
qemu-nographic.sh 修复 qemu 挂载 elm 文件系统失败 2023-09-26 13:23:48 +08:00
qemu-v-dbg.sh [rt-smart] kernel virtual memory management layer (#6809) 2023-01-08 21:08:55 -05:00
qemu-v-nographic.sh 修复 qemu 挂载 elm 文件系统失败 2023-09-26 13:23:48 +08:00
rtconfig.h [libcpu] rv64: support for ARCH_REMAP_KERNEL (#9067) 2024-06-18 11:15:59 +08:00
rtconfig.py [libcpu] rv64: support for ARCH_REMAP_KERNEL (#9067) 2024-06-18 11:15:59 +08:00
smart-env.bat sync branch rt-smart. (#6641) 2022-12-03 12:07:44 +08:00

README.md

RT-Smart QEMU SYSTEM RISC-V RV64 BSP

English | 中文

1. Introduction

QEMU can emulate both 32-bit and 64-bit RISC-V CPUs. Use the qemu-system-riscv64 executable to simulate a 64-bit RISC-V machine, qemu-system-riscv32 executable to simulate a 32-bit RISC-V machine.

QEMU has generally good support for RISC-V guests. It has support for several different machines. The reason we support so many is that RISC-V hardware is much more widely varying than x86 hardware. RISC-V CPUs are generally built into “system-on-chip” (SoC) designs created by many different companies with different devices, and these SoCs are then built into machines which can vary still further even if they use the same SoC.

For most boards the CPU type is fixed (matching what the hardware has), so typically you dont need to specify the CPU type by hand, except for special cases like the virt board.

2. Building

It's tedious to properly build a kernel since each RISC-V toolchain is specified to one RISC-V ISA. So you have to use different toolchain for different RISC-V ISAs. Here we focus on 2 types of ISA: rv64imafdcv and rv64imac.

If you are not sure what kinds of ISA you need, then rv64imac should satisfied your case most time. Given a riscv toolchain, you can check the ISA it supports like this:

root@a9025fd90fd4:/home/rtthread-smart# riscv64-unknown-linux-musl-gcc -v
Using built-in specs.
COLLECT_GCC=riscv64-unknown-linux-musl-gcc
COLLECT_LTO_WRAPPER=/home/rtthread-smart/tools/gnu_gcc/riscv64-linux-musleabi_for_x86_64-pc-linux-gnu/bin/../libexec/gcc/riscv64-unknown-linux-musl/10.1.0/lto-wrapper
Target: riscv64-unknown-linux-musl
Configured with: /builds/alliance/risc-v-toolchain/riscv-gcc/configure --target=riscv64-unknown-linux-musl --prefix=/builds/alliance/risc-v-toolchain/install-native/ --with-sysroot=/builds/alliance/risc-v-toolchain/install-native//riscv64-unknown-linux-musl --with-system-zlib --enable-shared --enable-tls --enable-languages=c,c++ --disable-libmudflap --disable-libssp --disable-libquadmath --disable-libsanitizer --disable-nls --disable-bootstrap --src=/builds/alliance/risc-v-toolchain/riscv-gcc --disable-multilib --with-abi=lp64 --with-arch=rv64imac --with-tune=rocket 'CFLAGS_FOR_TARGET=-O2   -mcmodel=medany -march=rv64imac -mabi=lp64 -D __riscv_soft_float' 'CXXFLAGS_FOR_TARGET=-O2   -mcmodel=medany -march=rv64imac -mabi=lp64 -D __riscv_soft_float'
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 10.1.0 (GCC) 

The -march=*** is what you are looking for. And the -mabi=*** is also an important message to configure compiling script.

Steps to build kernel:

  1. in $RTT_ROOT/bsp/qemu-virt64-riscv/rtconfig.py:40, make sure -march=*** and -mabi=*** is identical to your toolchain
  2. if your -march contains characters v/d/f, then: configure kernel by typing scons --menuconfig and select Using RISC-V Vector Extension / Enable FPU
  3. scons

3. Execution

It's recommended to clone the latest QEMU release and build it locally. Make sure QEMU is ready by typing qemu-system-riscv64 --version in your shell.

Using qemu-nographic.sh or qemu-nographic.bat to start simulation.

if your -march contains characters v, using qemu-v-nographic.*