Design Methods for Embedded Storage Systems Based on Virtual Storage
2026-04-06 04:34:08··#1
1. Introduction Embedded systems consist of embedded hardware and embedded software embedded in the hardware platform. Traditional small-scale embedded systems often employ a foreground/background approach, typically used in simple applications with low real-time requirements. For complex applications, a more common practice is to equip the system with an embedded real-time operating system (RTOS). This not only provides good real-time performance and reduces software development workload but also improves overall system stability. Furthermore, to simplify user programs, the system usually provides necessary library functions for user calls. Compared to foreground/background systems, this type of real-time embedded system increases system storage space overhead. The Intel 8051 series and various compatible microcontrollers are widely used in various embedded fields due to their high cost-effectiveness, rich library functions, and long-term technological accumulation. Due to the limitations of traditional microcontroller address space, embedded applications often require storage space expansion. This paper draws on virtual memory technology from traditional computer system design, taking the 8051 microcontroller as an example, and proposes a method for expanding storage space using page grouping and virtual interface technology. This method has good compatibility with the Keil C compiler. 2. Storage System Organization 2.1 Virtual Storage System Virtual storage technology is often used in computer systems to expand the storage system capacity. Paged virtual memory is a commonly used organization method. In this method, the entire virtual address space and main memory space are divided into several pages of equal capacity. The address translation mechanism (usually a fast address translation table) establishes the mapping from virtual space to main memory space, from virtual pages to real pages. The paged memory organization relationship is shown in Figure 1. The virtual storage system uses a set of register files in the computer CPU as the page table base address register, as shown in Figure 1(b). It provides the user program address together with the page table. The paged virtual storage of actual computer systems is much more complex than this. It also needs to consider the external address translation when a miss occurs and the page replacement algorithm. However, in embedded systems, these can be simplified or even omitted. 2.2 Program Storage Area Expansion in Microcontroller Embedded Systems Inspired by the virtual storage system, we made some modifications to the above method to apply it to embedded systems. Since the system design uses an external program memory capacity of 256KB, while the address space of a typical microcontroller (such as the 8051 series) is 64KB, for simplicity, the 256KB virtual address is divided into four pages and mapped to the microcontroller's 64KB space, each page is 64KB. The address translation mechanism in the embedded system can be simplified: the microcontroller does not have a dedicated page table base address register; different pages can be specified using additional port lines (such as P1.0, P1.1, P1.2, etc.) as base addresses. Page table lookups can be implemented using a jump table. However, it is essential to ensure correct access to the jump table before and after page switching. Therefore, all 64KB pages need an identical code segment to store common resources such as jump tables and interrupt vectors. To improve memory utilization, the structure shown in Figure 2 can be used, where the common segment stores the jump table required for inter-segment calls. Before each segment calls another, it should jump to the common segment, perform a page switch, and then jump to the entry point of the called program. This achieves the translation from 18-bit virtual address to 16-bit main memory address. We can use P1.0, P1.1, and P1.2 as page base addresses to specify different pages. The corresponding jump table program structure is as follows: ADDR: CLR EA; Disable interrupts SETB/CLR P1.0; Switch pages SETB/CLR P1.1 SETB/CLR P1.2 SETB EA; Enable interrupts JMP REAL_ADDR; Jump. The operating system and other library functions provided to the user are stored in the common segment (the lower 32k of the 256k memory chip). The other segments are used to store the user program of the embedded system. The schematic diagram of the microcontroller and memory interface using the structure shown in Figure 2 is shown in Figure 3. The address lines A0 to A15 are connected in the same way as the ordinary memory expansion method. The above takes into account that the page should switch to the common code area when reset. The Keil C51 compiler is a very popular and efficient compiler in microcontroller development and application. It supports the above page grouping technology. 2.3 Expansion of Data Storage Area in Microcontroller Embedded Systems The introduction of an operating system into an embedded system requires an increase in data storage overhead. If necessary, paging technology can still be used to expand the data storage area capacity. With the introduction of an operating system, there are two methods for organizing the data area. A simpler method is to share a single data area between the operating system and user programs. The compiler compiles the entire program together without distinguishing between system and user programs. However, this makes the operating system opaque to the user, and a malicious user program could corrupt the system's data area, causing the entire system to crash. The corresponding method is to allocate separate data areas for the operating system and user programs, for example, allocating 64KB each of the 128KB data memory. Unfortunately, when the operating system and user programs are compiled together, the compiler automatically assigns them different addresses. Even though the memory is physically separate, the data areas of the operating system and user programs cannot reuse addresses, resulting in a significant waste of address space. Furthermore, for traditional microcontrollers, the Keil C compiler only supports a maximum of 64KB of data area. Fortunately, this contradiction can be resolved by using a virtual interface. To address this, programs in the common code segment are compiled separately, and during linking and object code location, a fixed starting address is assigned to each function in the operating system and common library functions within the range of 0x0000 to 0x7FFFH. Since user programs may call these functions, a pseudo-function of the same type and name needs to be written for each function. Each pseudo-function contains only one jump instruction to the real function (entry address known). All these functions are stored in a header file called the virtual interface. The virtual interface file is compiled together with the user program, completing the interface between the user program and the operating system after two compilations. Obviously, this method occupies only a very small amount of code space in the user area, without wasting any user data area, while also achieving address reuse. The special correspondence between the common code segment and the operating system's data area can be easily specified through the P2 port line. As can be seen from the microcontroller's external program area access timing (Figure 5), instructions or instruction operands begin to appear on the data bus A0~A7 after the rising edge of PSEN. At this time, the address line A15 indicates whether the current access is to the common code segment (corresponding to the high 64k of the data area) or another program segment (corresponding to the low 64k of the data area). Therefore, the address line A15 is latched at the rising edge of PSEN, which can be used to select different data memory spaces. 3 Performance Analysis of the Storage System This paper implements the expansion of large-capacity memory in an embedded system based on the concept of a virtual memory system. It is easy to see that the system's scalability is limited by the port lines. Since constructing the structure shown in Figure 2 on the same chip requires an additional port line, using the entire P1 port for the 8051 series can expand the system's virtual program space to 8MB. The maximum capacity of the data storage area expansion is also related to the number of blocks the program is divided into during compilation, reaching a maximum of 16MB, which is sufficient for microcontroller embedded systems. Calling functions on different pages requires additional software switching cycles; frequent page switching degrades system performance. Therefore, functions should be carefully selected during compilation, allocating related functions to the same page whenever possible. Data storage area switching is implemented in hardware, and page switching does not degrade system performance. Since the operating system and user program data areas are independent, the entire 64KB space is available to the user, increasing the transparency of the operating system. 4. Conclusion Due to their specialized and unique nature, embedded systems differ from traditional computer system design methods in both hardware and software design. However, it is still essential to draw upon mature design methods from traditional computer system architectures when designing embedded systems, adapting them to specific needs. When designing the embedded platform, the author drew on the concept of traditional computer virtual storage to expand the storage system, and applied it in a real project, proving that this method is very effective.