Nuttx operating system (13): memory layout

This article explains the memory layout of the Nuttx system when using PMP under the RISC-V architecture.

memory layout

The NuttX system has three compilation modes, which are divided into Flat compilation mode with unified addressing, Protected compilation mode with PMP address protection, and Kernel mode that supports virtual addresses.

There is no distinction between privileged programs and non-privileged programs in Flat mode, and both application programs and kernel programs run in M-Mode mode. In M-Mode mode, the processor can access the entire address space, that is, the application can access the kernel code at will, which will easily cause the system to crash and cannot guarantee the stability of the system;

Both Protected and Kernel modes provide PMP memory protection function, which can make untrusted code run only in U-Mode mode, restricting the processor access rights so that it can only access the specified memory range, which can ensure the stability of the system to the greatest extent. . Among them, Kernel mode implements memory protection and virtual address function, but Kernel mode requires the support of hardware MMU and has hardware limitations; in comparison, Protected compilation mode has address protection function and does not require hardware MMU support, which is suitable for most embedded systems. equipment.

Physical memory is usually divided into Flash (ROM, data is saved when power fails) for storing firmware and RAM for program running (data is lost when power fails). In Protected compilation mode, user space and kernel space have different access rights, so the entire physical memory address space can be divided into 4 areas, namely UROM for storing user images, KROM for kernel images, user running memory URAM and kernel Running memory KRAM, NuttX physical memory division is as shown below:

NuttX memory layout

The four memory areas in Figure 6-2 will be introduced in detail below:

  • EXCEPT
  • The KROM area stores the kernel image, including kernel startup code and modules trimmed by make menuconfig;
  • The KROM area is protected by PMP memory and has read permission. Direct access by user programs is prohibited (U-Mode). Applications need to fall into M-Mode mode through system calls for indirect access;
  • nightmares
  • The UROM area stores application images, including NSH (NuttX Shell) and embedded applications;
  • The UROM area does not require PMP memory protection and has read permission. In principle, it is dedicated to U-Mode, but it can still be accessed in M-Mode;
  • HUG
  • The KRAM area serves as the NuttX kernel running main memory;
  • The KRAM area is protected by PMP memory and has read, write and execution permissions. User programs are prohibited from using it, that is, it is exclusively used in M-Mode and inaccessible in U-Mode.
  • LORD
  • The URAM area serves as the application running main memory;
  • The URAM area does not require PMP memory protection and has read, write and execution permissions. In principle, it is dedicated to U-Mode, but it can still be accessed in M-Mode;

 

Guess you like

Origin blog.csdn.net/u012294613/article/details/132163057