A dynamic loading method of an embedded operating system based on a LoongArch processor
By using C language to write and generate ELF format files on the LoongArch processor, and combining global symbol tables and the tag binary search method to achieve dynamic loading of the embedded operating system, the problem of dynamic loading under the embedded operating system is solved, and the dynamic loading function of the domestic LoongArch processor is realized.
Patent Information
- Application Number
- CN202511361045.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-09-23
- Publication Date
- 2026-11-03
- Estimated Expiration
- 2045-09-23
AI Technical Summary
Existing technologies cannot effectively solve the dynamic loading problem of LoongArch processors under embedded operating systems, especially the problem of duplicate anonymous symbol names, and are not applicable to domestic LoongArch processors.
The application is dynamically loaded using C or C++. A compiler based on the LoongArch architecture is used for partial linking to generate an ELF file, obtains the global and local symbol tables, and uses a binary search method to relocate symbols and redirect instruction code offset addresses to achieve dynamic loading.
The system implements dynamic loading functionality under an embedded operating system, which reduces development difficulty, decreases system coupling, facilitates modular and standardized development, and supports dynamic loading of the domestic LoongArch processor.
Smart Images

Figure CN121387379B_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of embedded technology, specifically relating to a method for dynamically loading an embedded operating system based on a LoongArch processor. Background Technology
[0002] In the field of computer science and technology, "dynamic loading" refers to the process of loading programs and data from external storage or the network into memory as needed during system operation. In general-purpose desktop operating systems such as Windows and Linux, dynamic loading is primarily achieved by compiling and generating "dynamic link library files," which are then loaded dynamically through internal system calls of the desktop operating system.
[0003] An embedded operating system is a type of operating system designed for dedicated systems to manage customized hardware and software resources. Compared to general-purpose operating systems, it has the advantages of consuming fewer resources and being customizable and tailorable, but it also has the disadvantage of having relatively limited functionality.
[0004] LoongArch is a Reduced Instruction Set Computing (RISC) style instruction set architecture, independently designed and developed by Loongson Technology Co., Ltd., and officially released in 2020.
[0005] The national invention patent "Method, Apparatus, Terminal and Storage Medium for Determining Dynamically Loaded Files" (Publication No. CN113064601B) discloses a method for determining whether a target file is a dynamically loaded file by using the characteristic values of the target file and confirming it by using a signature file. This method can achieve the effect of monitoring the dynamic files downloaded by the target application at the operating system level, which is conducive to improving the security protection level of the operating system itself and ensuring the security of the target application running on the operating system.
[0006] The national invention patent "A method and apparatus for loading code" (publication number CN118626166A) discloses a dynamic code loading method used in Internet of Things (IoT) devices. By setting a fixed-size intermediate memory space, it solves the problem of large RAM resource consumption during dynamic loading in IoT devices.
[0007] The national invention patent "A method for dynamically loading algorithms without an operating system based on an ARM processor" (publication number CN114816581B) discloses a method for dynamically loading algorithms on an ARM processor. By setting a fixed loading address, it solves the problem of dynamically loading code in an environment without an operating system.
[0008] The national invention patent "A Method and Apparatus for Supporting Binary Formats of RISC-V Multi-Instruction Set Combinations" discloses a method and apparatus for supporting binary formats of RISC-V multi-instruction set combinations. It uses a rich instruction set format packaging tool to package executable files compiled from different instruction set combinations into a single rich instruction set format file package. This method effectively avoids the application-dependent runtime environment incompatibility problems caused by different extended instruction set combinations.
[0009] Chinese patent "CN113064601B Method, Apparatus, Terminal and Storage Medium for Determining Dynamically Loaded Files" is applicable to general desktop operating systems, and its main objective is to improve the security protection level of the operating system itself. It cannot be applied to solving the problem of dynamic loading under embedded operating systems.
[0010] The method described in Chinese patent "CN118626166A A method and apparatus for loading code" proposes a way to solve the problem of dynamic loading in devices with limited memory resources, such as the Internet of Things, by setting a fixed-size memory segment for transfer. However, this method cannot handle the problem of "anonymous symbol name duplication" generated under the LoongArch architecture.
[0011] The Chinese patent "CN114816581B A Dynamic Loading Method for Algorithms Without an Operating System Based on ARM Processors" mainly solves the problem of dynamic loading in an environment without an operating system. However, it is only applicable to ARM processors and does not solve the problem of dynamic loading under an embedded operating system. The method used is also not applicable to the domestic Loongarch processor.
[0012] Chinese patent "CN117827317A A method and apparatus for supporting binary formats for RISC-V multi-instruction set combinations" is mainly aimed at the RISC-V instruction set and is primarily dedicated to processing binary format files. This method is not applicable to processors based on the LoongArch architecture. Summary of the Invention
[0013] (a) Technical problems to be solved
[0014] The technical problem to be solved by this invention is how to provide a dynamic loading method for an embedded operating system based on the LoongArch processor, so as to solve the problem of dynamic loading under an embedded operating system.
[0015] (II) Technical Solution
[0016] To address the aforementioned technical problems, this invention proposes a method for dynamically loading an embedded operating system based on the LoongArch processor. This method includes the following steps:
[0017] S1. Write dynamically loaded applications: Use C or C++ to write applications that need to be dynamically loaded. Use the extern keyword to declare parts that need to use the internal calls of the embedded operating system.
[0018] S2. Compile dynamically loaded applications: Use a compiler based on the LoongArch architecture, add compilation options to perform only partial linking and not link the standard library interface, and generate a file that conforms to the ELF format, which will be referred to as "dynamically loaded .ELF file" below;
[0019] S3. Obtain the global symbol table: The global symbol table is a list of function interfaces that the embedded operating system exposes to applications. It is arranged in binary format using C language inline assembly syntax.
[0020] S4. Deploy the dynamically loaded .ELF file to the file system of the embedded operating system;
[0021] S5. Open dynamically loaded .ELF files as files;
[0022] S6. Obtain the local symbol table required for dynamically loading .EFL files;
[0023] S7. Relocate the local symbol table: Use the "marking binary search" method to find the symbols in the "dynamically loaded .ELF" file that need address redirection. Symbols that need to be called by the operating system are searched in the global symbol table, and symbols implemented inside the "dynamically loaded .ELF" file are searched in the local symbol table. When the "dynamically loaded .ELF" file is actually loaded into memory, the actual physical address of each location can be determined. At this time, it is necessary to relocate the addresses of the locations in the local symbol table that call global symbols and use global calls by searching for symbols.
[0024] S8, Instruction Code Offset Address Redirection: Each relocated symbol corresponds to an instruction code, which is the actual operation instruction executed by the CPU. Based on the relocated symbol table and according to the instruction code rules of the LoongArch architecture, each symbol is mapped to the correct instruction code. At the same time, the offset address of these instruction codes that need to be relocated is redirected, and finally the instruction code is written back.
[0025] S9. Execute the "Dynamically Load .ELF" file as needed.
[0026] (III) Beneficial Effects
[0027] This invention proposes a dynamic loading method for embedded operating systems based on the LoongArch processor. Under the embedded operating system, the "dynamic loading" function can be directly implemented using existing C language syntax, eliminating the need to develop new functions based on the embedded operating system. This reduces development difficulty and effectively lowers the coupling of the embedded system, promoting the modular and standardized development of embedded systems. The method supports dynamic loading for processors based on the domestic LoongArch architecture under the embedded operating system. Attached Figure Description
[0028] Figure 1 Screenshot from the LoongArch architecture reference manual;
[0029] Figure 2 Screenshot from the LoongArch architecture reference manual;
[0030] Figure 3 This is a schematic representation of the relocation local symbols of the present invention;
[0031] Figure 4 This is the main flowchart of the technical solution of the present invention. Detailed Implementation
[0032] To make the objectives, contents, and advantages of the present invention clearer, the specific embodiments of the present invention will be described in further detail below with reference to the accompanying drawings and examples.
[0033] The purpose of this invention is to propose a dynamic loading method that is usable in an embedded operating system environment and applicable to the domestic LoongArch processor.
[0034] This invention provides a method for dynamically loading an embedded operating system based on a LoongArch processor, the method comprising the following steps:
[0035] S1. Write dynamically loaded applications: Use C or C++ to write applications that need to be dynamically loaded. Use the extern keyword to declare parts that need to use the internal calls of the embedded operating system.
[0036] S2. Compile dynamically loaded applications: Use a compiler based on the LoongArch architecture, add compilation options to perform only partial linking and not link the standard library interface, and generate a file that conforms to the ELF format, which will be referred to as "dynamically loaded .ELF file" below;
[0037] S3. Obtain the global symbol table: The global symbol table is a list of function interfaces that the embedded operating system exposes to applications. It is arranged in binary format using C language inline assembly syntax.
[0038] S4. Deploy the dynamically loaded .ELF file to the file system of the embedded operating system;
[0039] S5. Open dynamically loaded .ELF files as files;
[0040] S6. Obtain the local symbol table required for dynamically loading .EFL files;
[0041] S7. Relocate the local symbol table: Use the "marking binary search" method to find the symbols in the "dynamically loaded .ELF" file that need address redirection. Symbols that need to be called by the operating system are searched in the global symbol table, and symbols implemented inside the "dynamically loaded .ELF" file are searched in the local symbol table. When the "dynamically loaded .ELF" file is actually loaded into memory, the actual physical address of each location can be determined. At this time, it is necessary to relocate the addresses of the locations in the local symbol table that call global symbols and use global calls by searching for symbols.
[0042] S8, Instruction Code Offset Address Redirection: Each relocated symbol corresponds to an instruction code, which is the actual operation instruction executed by the CPU. Based on the relocated symbol table and according to the instruction code rules of the LoongArch architecture, each symbol is mapped to the correct instruction code. At the same time, the offset address of these instruction codes that need to be relocated is redirected, and finally the instruction code is written back.
[0043] S9. Execute the "Dynamically Load .ELF" file as needed.
[0044] Example 1:
[0045] Figure 4 This is the main flowchart of the technical solution of this invention. For example... Figure 4 As shown, the embedded operating system dynamic loading method proposed in this invention includes the following steps:
[0046] S1. Write dynamically loaded applications: Use C or C++ to write applications that need to be dynamically loaded. Use the extern keyword to declare parts that need to use internal calls of the embedded operating system.
[0047] S2. Compile dynamically loaded applications: Use the compiler based on the LoongArch architecture released by Loongson Corporation, add the compilation option "-qnolinkcmds-nostdlib-r" to only perform partial linking and not link the standard library interface, and generate a file that conforms to the ELF format, which will be referred to as "dynamically loaded .ELF file" below.
[0048] S3. Obtain the global symbol table: The global symbol table is a list of function interfaces that the embedded operating system exposes to applications. It is arranged in binary format using C language inline assembly syntax, with the format "symbol name 0x00 symbol address".
[0049] S4. Deploy the dynamically loaded .ELF file to the file system of the embedded operating system: Deploy the compiled dynamically loaded .ELF file to storage components such as hard disk, Flash, memory, and ROM through network transmission methods such as FTP and SSH, or by directly reading and writing external storage hardware.
[0050] S5. Open dynamically loaded .ELF files as files: Use the embedded operating system's file system interface to open dynamically loaded .ELF files as files.
[0051] S6. Obtain the local symbol table required for dynamically loaded .EFL files: If the embedded system hardware memory capacity is greater than or equal to twice that of the dynamically loaded .ELF file, then the entire dynamically loaded .ELF file is read into memory, and then the local symbol table is formed by traversing the dynamically loaded .ELF file. Otherwise, the dynamically loaded .ELF file is read into memory in segments and the local symbol table is formed in segments. In particular, when an "anonymous global symbol" is read, a sequence number is added to the symbol. The local symbol table records local symbol information through the data structure shown below.
[0052]
[0053] S7. Relocate Local Symbol Table: Use the "marking binary search" method to find symbols in the "dynamically loaded .ELF" file that require address redirection. Symbols that need to be called by the operating system are searched in the global symbol table, while symbols implemented internally within the "dynamically loaded .ELF" file are searched in the local symbol table. Figure 3 As shown, when the "dynamically loaded .ELF" file is actually loaded into memory, the actual physical address of each location can be determined. At this time, it is necessary to relocate the addresses of the locations that call global symbols and use global calls in the local symbol table by searching for symbols.
[0054] S8. Instruction Code Offset Address Redirection: Each relocated symbol corresponds to an instruction code, which is the actual operation instruction executed by the CPU. Based on the relocated symbol table and according to the instruction code rules of the LoongArch architecture, each symbol is mapped to the correct instruction code. Simultaneously, offset address redirection is performed on these instruction codes that require address redirection. Finally, the instruction code is written back, as shown below. Figure 1 , Figure 2As shown, the LoongArch architecture provides a series of instruction codes, and the corresponding instruction code offset can be obtained by calculating according to the instruction code format.
[0055] S9. Execute the "Dynamically Load .ELF" file as needed: After the above steps, the "Dynamically Load .ELF" file has completed the redirection of all symbols and the offset address redirection of the instruction code. At this time, the pre-defined functions of the "Dynamically Load .EFL" file can be executed through the agreed interface.
[0056] Key points of this invention:
[0057] By leveraging the C language's inline assembly syntax, implementation is simple and it can be used normally even under conditions where the functions and resources of the embedded operating system are limited.
[0058] By using the "labeled binary search method", the problem of "duplicate anonymous global symbols" under the LoongArch architecture processor is solved while ensuring the speed of global symbol lookup.
[0059] Parsing instruction code based on the LoongArch architecture enables dynamic loading on LoongArch-based processors.
[0060] Effects of the invention:
[0061] Under an embedded operating system, the "dynamic loading" function can be implemented directly using existing C language syntax, eliminating the need to develop new functions based on the embedded operating system. This reduces development difficulty and effectively lowers the coupling of the embedded system, promoting its modular and standardized development. Furthermore, the embedded operating system supports dynamic loading for processors based on the domestic LoongArch architecture.
[0062] The above description is only a preferred embodiment of the present invention. It should be noted that for those skilled in the art, several improvements and modifications can be made without departing from the technical principles of the present invention, and these improvements and modifications should also be considered within the scope of protection of the present invention.
Claims
1. A method for dynamically loading an embedded operating system based on a LoongArch processor, characterized in that, The method includes the following steps: S1. Write dynamically loaded applications: Use C or C++ to write applications that need to be dynamically loaded. Use the extern keyword to declare parts that need to use the internal calls of the embedded operating system. S2. Compile dynamically loaded applications: Use a compiler based on the LoongArch architecture, add compilation options to perform only partial linking and not link the standard library interface, and generate files that conform to the ELF format, which will be referred to as "dynamically loaded .ELF files" below; S3. Obtain the global symbol table: The global symbol table is a list of function interfaces that the embedded operating system exposes to applications. It is arranged in binary format using C language inline assembly syntax. S4. Deploy the dynamically loaded .ELF file to the file system of the embedded operating system; S5. Open dynamically loaded .ELF files as files; S6. Obtain the local symbol table required for dynamically loading .EFL files; S7. Relocate the local symbol table: Use the "marking binary search" method to find the symbols in the "dynamically loaded .ELF" file that need address redirection. Symbols that need to be called by the operating system are searched in the global symbol table, and symbols implemented inside the "dynamically loaded .ELF" file are searched in the local symbol table. When the "dynamically loaded .ELF" file is actually loaded into memory, the actual physical address of each location can be determined. At this time, it is necessary to relocate the addresses of the locations in the local symbol table that call global symbols and use global calls by searching for symbols. S8, Instruction Code Offset Address Redirection: Each relocated symbol corresponds to an instruction code, which is the actual operation instruction executed by the CPU. Based on the relocated symbol table and according to the instruction code rules of the LoongArch architecture, each symbol is mapped to the correct instruction code. At the same time, the offset address of these instruction codes that need to be relocated is redirected, and finally the instruction code is written back. S9. Execute the "Dynamically Load .ELF" file as needed; in, S6 includes: if the embedded system hardware memory capacity is greater than or equal to twice the dynamically loaded .ELF file, then the entire dynamically loaded .ELF file is read into memory, and then the dynamically loaded .ELF file is traversed to form a local symbol table; otherwise, the dynamically loaded .ELF file is read into memory in segments and a local symbol table is formed in segments. When an "anonymous global symbol" is read, a sequence number is added to the symbol. The local symbol table records local symbol information through a data structure.
2. The embedded operating system dynamic loading method based on the LoongArch processor as described in claim 1, characterized in that, In S2, the compilation option is "-qnolinkcmds -nostdlib -r".
3. The embedded operating system dynamic loading method based on the LoongArch processor as described in claim 1, characterized in that, In S3, the specified format is "symbol name 0x00 symbol address".
4. The embedded operating system dynamic loading method based on the LoongArch processor as described in claim 1, characterized in that, The S4 includes: deploying the compiled dynamically loaded .ELF file to hard disk, Flash, memory, and ROM storage components via FTP or SSH network transmission.
5. The method for dynamically loading an embedded operating system based on a LoongArch processor as described in claim 1, characterized in that, The S4 includes: deploying the compiled dynamically loaded .ELF file to hard disk, Flash, memory, and ROM storage components by directly reading and writing external storage hardware.
6. The embedded operating system dynamic loading method based on the LoongArch processor as described in claim 1, characterized in that, The S5 includes: using the file system interface of the embedded operating system to open and load the dynamically loaded .ELF file as a file.
7. The method for dynamically loading an embedded operating system based on a LoongArch processor as described in claim 1, characterized in that, The data structure includes: previous node information, next node information, doubly linked list node, local symbol name string, local symbol internal offset address, local symbol corresponding instruction code, and local symbol sequence number.
8. The embedded operating system dynamic loading method based on the LoongArch processor as described in claim 1, characterized in that, In S8, the LoongArch architecture provides a series of instruction codes, and the corresponding instruction code offset can be obtained by calculating according to the instruction code format.
9. The method for dynamically loading an embedded operating system based on a LoongArch processor as described in claim 1, characterized in that, S9 includes: After the above steps, the "dynamically loaded .ELF" file has completed the redirection of all symbols and the redirection of the instruction code offset address. At this time, the predetermined function of the "dynamically loaded .EFL" file is executed through the agreed interface.
Citation Information
Patent Citations
Method, device, terminal and storage medium for determining dynamically loaded files
CN113064601B
A method for dynamically loading algorithms without an operating system based on an ARM processor
CN114816581B
Code loading method and device
CN118626166A
RISC-V multi-instruction-set combination-oriented binary format support method and device
CN117827317A
Method for running application program, and computing device and storage medium
WO2022247106A1
