CN100555222C - Method and address relocation device that the application program relocatable loads - Google Patents

Method and address relocation device that the application program relocatable loads Download PDF

Info

Publication number
CN100555222C
CN100555222C CNB2007100802553A CN200710080255A CN100555222C CN 100555222 C CN100555222 C CN 100555222C CN B2007100802553 A CNB2007100802553 A CN B2007100802553A CN 200710080255 A CN200710080255 A CN 200710080255A CN 100555222 C CN100555222 C CN 100555222C
Authority
CN
China
Prior art keywords
application
code offset
register
application program
operating system
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Expired - Fee Related
Application number
CNB2007100802553A
Other languages
Chinese (zh)
Other versions
CN101246427A (en
Inventor
陈立勤
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
BEIJING SUNPLUS-EHUE TECHNOLOGY CO., LTD.
Sunplus Technology Co Ltd
Original Assignee
BEIJING BEIYANG ELECTRONIC TECHNOLOGY Co Ltd
Sunplus Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by BEIJING BEIYANG ELECTRONIC TECHNOLOGY Co Ltd, Sunplus Technology Co Ltd filed Critical BEIJING BEIYANG ELECTRONIC TECHNOLOGY Co Ltd
Priority to CNB2007100802553A priority Critical patent/CN100555222C/en
Publication of CN101246427A publication Critical patent/CN101246427A/en
Application granted granted Critical
Publication of CN100555222C publication Critical patent/CN100555222C/en
Expired - Fee Related legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Landscapes

  • Stored Programmes (AREA)

Abstract

The invention discloses the method and apparatus that a kind of application program relocatable loads, this method comprises: the internal memory start address and the code offset of operating system are saved in scratch pad storer one; Invokes application; According to the Memory Allocation situation is the application assigned free memory; Create process control block (PCB), preserve start address, code offset and the application length of free memory; With the copying codes of application program to free memory.Under the trigger condition of process switching, application program internal memory start address and code offset that process control block (PCB) is preserved are set to scratch pad storer two; When kernel mode switches to user's attitude, the content of scratch pad storer two is set to the application register group; With the virtual address and the addition of application program internal memory start address of application program, the code offset that the deducts application program internal memory physical address of program that is applied.Use the present invention to make application program and operating system operate in self independently memory headroom separately, protection operating system.

Description

Method and address relocation device that the application program relocatable loads
Technical field
The present invention relates to the application program loading technique, be specifically related to method and corresponding address relocation device that a kind of application program relocatable loads.
Background technology
Operating system needed loading application programs before starting application program, just prepare running environment in advance for application program, was included as the preceding memory environment of preparing of application program operation.
In existing embedded OS, the mode of loading application programs mainly contains two kinds:
First kind is not have hardware memory manage-ment unit (MMU, Memory ManagementUnit) or do not using under the mode of hardware MMU, and embedded OS is loading application programs in the following manner:
Embedded OS and all predefined The Application of Thread compilings link together.Operating system is carried out from self starting each application program when operation as required.So in this case, operating system and application program unification operate in same memory address space, the collapse of application program will cause the paralysis of total system.And all application programs must be set in advance and finish, and compile with operating system, thereby can not dynamically increase new application program in the existing system that is moving.
Embedded OS is loaded into application program the fixed address of internal memory.Because operating system can cannot pre-determine for the address space of all application assigned when operation, so cause operating system to be merely able to specify the loading space of one section specific memory address space as application program, and headspace is the maximum application program of operation enough, and once is merely able to move an application program.
Embedded OS dynamic load application program arrives memory address space arbitrarily.But, because the operation address space of application program is determined when compiling, so, must carry out the address reorientation according to the symbolic information application programs of application program in order to be loaded into memory address space operation arbitrarily with compiling the application program of finishing.This just requires application program to carry all symbolic information and address relocation information in the compilation phase, the operation conditions that operating system just can be when loading, and dynamic assigning memory is resolved symbolic information and the address relocation information that application program carries and is loaded.But the application program that has symbolic information and address relocation information is will be at least bigger more than 10 times than the length of the application file of no symbolic information and address relocation information, thereby increased the code size of application program, increase the time of operating system when loading application programs, finally influenced the travelling speed of operating system.
Second kind, under the mode of using hardware MMU, embedded OS can be realized perfect application program loading scheme.Each application program all has oneself independently address space, so application program can not endanger the operation of operating system when collapse.But during with this operating modes for performing application program, operating system need be preserved its operation page table of comparisons for each application program.For example, in the typical x86 system, just need to distribute the space 3 * 4k of at least three pages to do the page table space, comprise an one-level page table and two secondary page tables in case start application program, and along with the operation of application program, operating system can constantly be application assigned page tables at different levels.And in some system, each page table may be made up of two pages, uses so need do page table for the address space of new application assigned 2 * 3 * 4k.Because the complicacy of hardware MMU, the management of page table is also quite complicated in the management of operating system, need cost operating system a large amount of working time the maintain pages table of comparisons integrality and consistance, thereby make to the slowed down speed of operating system of the management of page table.In the exigent embedded system of some real-times is used, with the Embedded Application effect of directly influence reality.
In common Reduced Instruction Set Computer (RISC, Reduced Instruction Set Computer) architecture, the access mode of internal memory replaces stage mode by page mode.Complex instruction set computer (CISC) such as x86 (CISC at classics, Complex Instruction Set Computer) CPU (central processing unit) (CPU of architecture, Central Processing Unit) in, have tangible section notion, the setting of the section of knowing in advance, when compiling application program or initialization application program, need carry out assignment to segment register, it is complicated that this process that makes becomes.Code that produces in the code implementation and data address all need to produce the actual physical address jointly with these segment registers, make code segment can only move on to another section from a section in physical memory, rather than flexible movement.
Summary of the invention
In view of this, the invention provides the method that a kind of application program reorientation loads, simplified the dynamic load of application program, the application program that is compiled in same address can be moved on operating system simultaneously simultaneously.
The invention provides the address relocation device that a kind of support application program relocatable loads, simplified the dynamic load of application program, the application program that is compiled in same address can be moved on operating system simultaneously simultaneously.
For achieving the above object, the technical scheme of the embodiment of the invention is achieved in that
The method that a kind of application program relocatable loads comprises:
The internal memory start address and the code offset of operating system are saved in the scratch pad storer one;
Invokes application is inquired about the code offset and the application length of this application program;
According to the Memory Allocation situation is the free memory of this application assigned length more than or equal to described application length;
For this application program is created process control block (PCB), start address, code offset and the application length of preserving described free memory;
This application code is copied to described free memory;
Under the trigger condition of process switching, the application program internal memory start address and the code offset of preserving in the process control block (PCB) is set in the scratch pad storer two;
When kernel mode switches to user's attitude executive utility, the content that is kept in the scratch pad storer two is set in the application register group; With the virtual address and the addition of application program internal memory start address of application program, the code offset that the deducts application program internal memory physical address of program that is applied;
When user's attitude switches to the instruction of kernel mode executive operating system, the content that is kept in the scratch pad storer one is set in the application register group; With the internal memory start address addition of the virtual address and the operating system of operating system, the code offset that deducts operating system obtains the internal memory physical address of operating system.
After the internal memory physical address of the described program that is applied, this method further comprises: judge the address realm of the application program operation whether described physical address obtains in start address, code offset and application length according to described free memory, if would continue execution command; Otherwise carry out the Interrupt Process of crossing the border.
A kind of address relocation device comprises central processing unit CPU nuclear, address adder, application base register and code offset register,
Described CPU nuclear is used for virtual address is outputed to address adder;
Described application base register is used for preserving and uses plot, and described application plot is the start address of the free memory of application assigned for the distribution condition according to internal memory; Described application plot is sent and remains on the bus that links to each other with described address adder;
Described code offset register is used to preserve code offset; Described code offset is sent and remains on the bus that links to each other with described address adder;
Described address adder, the CPU that is used for receiving are authorized the application plot addition that the virtual address sent and described application base register send, and deduct the code offset that described code offset register sends again, obtain the physical address of internal memory;
This device further comprises scratch pad storer one and scratch pad storer two,
Described scratch pad storer one is used in system initialization, preserves the application plot and the code offset of operating system; When by user's attitude when kernel mode switches, authorize at CPU under the control of the trigger pip of sending, the operating system of preserving is used plot and code offset sends to described application base register and code offset register respectively;
Described scratch pad storer two is used in process switching, application plot and code offset in the process control block (PCB) of preservation application program; When switching to user's attitude by kernel mode, authorize at CPU under the control of the trigger pip of sending, the application program application plot and the code offset of preserving sent to described application base register and code offset register respectively;
Described application base register is further used for receiving and preserving the operating system application plot that described scratch pad storer one sends; Or the application program that receives and preserve two transmissions of scratch pad storer is used plot;
Described code offset register is further used for receiving and preserve the code offset of the operating system that described scratch pad storer one sends; Or the code offset of the application program of reception and two transmissions of preservation scratch pad storer;
Described CPU nuclear is further used for sending trigger pip to scratch pad storer one and scratch pad storer two.
This device further comprises the application length register, is used to preserve the application length of application program; This application length is sent to CPU nuclear;
Described application base register, the application plot that is further used for the application program that will preserve sends to CPU nuclear;
Described code offset register, the code offset that is further used for the application program that will preserve sends to CPU nuclear;
Described address adder, the physical address that is further used for the application program that will obtain sends to CPU nuclear;
Described CPU nuclear is further used for according to the application plot, code offset and the application length that receive, the address realm of the program run that is applied; Judge the described physical address that receives whether within the address realm of described application program operation, if, executive utility then; Otherwise, carry out the Interrupt Process of crossing the border.
Described application base register and described code offset register are a register, are used for preserving the poor of application plot and code offset; This application plot is sent and is saved on the bus that links to each other with described address adder with the difference of code offset;
Described address adder is further used for receiving the poor of application plot that described register sends and code offset, and the difference and the CPU of this application plot and code offset authorized the virtual address addition of sending, and obtains the internal memory physical address.
Described scratch pad storer one comprises operating system application base register and operating system code offset register; Described scratch pad storer two comprises application program application base register and application code offset register,
Described operating system is used base register, be used to preserve the application plot of operating system, when switching to kernel mode by the family attitude, authorize at CPU under the control of the trigger pip of sending, the application plot of described operating system is sent to described application base register;
Described operating system code offset register, be used to preserve the code offset of operating system, when switching to kernel mode by the family attitude, authorize at CPU under the control of the trigger pip of sending, the code offset of described operating system is sent to described code offset register;
Described application program is used base register, be used to preserve the application plot of application program, when switching to user's attitude by kernel mode, authorize at CPU under the control of the trigger pip of sending, the application plot of described application program is sent to described application plot deposit;
Described application code offset register, be used to preserve the code offset of application program, when switching to user's attitude by kernel mode, authorize at CPU under the control of the trigger pip of sending, the code offset of described application program is sent to described code offset register;
Described application base register is further used for receiving the application plot that described operating system is used the operating system of base register transmission; Or receive described application program and use plot and deposit the application plot of the application program of transmission;
Described code offset register is further used for receiving the operating system code skew that described operating system code offset register sends; Or receive the code offset of the application program that described application code offset register sends;
Described CPU nuclear is further used for using base register, operating system code offset register, application program application base register and application code offset register to operating system and sends trigger pip.
Described scratch pad storer comprises the memory headroom of register one and storage operating system application plot and code offset; Described scratch pad storer two comprises the memory headroom of register two and application storing application plot and code offset,
Described register one is used to preserve the pointer that the sensing storage operating system is used the memory address of plot and code offset;
Described register two is used to preserve the pointer that the sensing application storing is used the memory address of plot and code offset;
Described CPU nuclear, be further used for when switching to kernel mode by the family attitude, call application plot and the code offset that is kept at the operating system in the pointer indication memory address by the pointer in the register one, be saved in described application base register and code offset register respectively; When switching to user's attitude by kernel mode, call application plot and the code offset that is kept at the application program in the pointer indication memory address by the pointer in the register two, be saved in described application base register and code offset register respectively.
It is described that to be used to preserve the memory headroom of using plot and code offset be the memory headroom that has only kernel mode to visit.
Compared with prior art, the address relocation device that method that the application program relocatable that the embodiment of the invention provided loads and support application program relocatable load has following effect:
First, add and subtract mutually by the start address that application program is compiled the code offset address, application program virtual address and the detected free memory of current operation system that obtain, internal memory physical address when the program that is applied is carried out, thereby can realize the dynamic load of application program very easily according to actual memory operating position loading application programs; And make operating system not need the maintain pages table of comparisons, do not need to resolve symbolic information and address relocation information in the application program, thereby simplified the dynamic load of application program, improved the travelling speed of operating system.
Second; is the loading storage allocation address space of application program by operating system according to the distribution condition of current internal memory; operating system can be the memory address space outside the application assigned self-operating address space; thereby make application program and operating system operate in self independently memory headroom separately, realize the protection of operating system.
The 3rd, because operating system can be neatly be the address space of application assigned loading, so all application programs can be compiled in same start address, have simplified the compilation process of application program; And a plurality of application programs can be moved simultaneously.
The 4th, be that application program loads the storage allocation space by operating system, therefore, operating system only need revise use plot just can completion code in the reorientation of physical space, make that application program can be mobile flexibly in whole physical memory.
Simultaneously, hardware spending and operating system maintenance costs are very little in the design proposal of the present invention, especially are fit to be applied in the embedded system.
Description of drawings
The method flow diagram that Fig. 1 loads for application program relocatable of the present invention;
Fig. 2 is the compiling situation synoptic diagram of the current Memory Allocation situation of the present invention and application A and application program B;
Fig. 3 is the load condition synoptic diagram of current Memory Allocation situation of the present invention and application A;
Fig. 4 is the load condition synoptic diagram of current Memory Allocation situation of the present invention and application program B;
Fig. 5 is the method flow diagram of application A of the present invention and application program B switching;
Fig. 6 is the address relocation device structural representation that the embodiment of the invention one support application program relocatable loads;
Fig. 7 is operating system of the present invention and application program ruuning situation synoptic diagram;
Fig. 8 is the address relocation device structural representation that the embodiment of the invention two support application program relocatables load;
Fig. 9 is the address relocation device structural representation that the embodiment of the invention three support application program relocatables load.
Embodiment
The present invention is described in detail below in conjunction with drawings and the specific embodiments.
The method that application program relocatable of the present invention loads provides a kind of memory access pattern of CPU.Under this pattern, all application programs and compiler do not need to know the existence of using base register.Compiler only need be compiled in application program identical address space, operating system when loading application programs according to current Memory Allocation situation, be the application assigned free memory, promptly, the content of using base register adjusted according to the distribution condition of current internal memory; The application plot addition that internal memory physical address during executive utility then is application assigned by the virtual address and the operating system of application program operation, the code offset of determining when deducting the application program compiling again obtains, that is to say executive mode, can make the compiling address of application program and executive address obtain unified by modify instruction.Therefore, all application programs can be compiled in same start address, as long as by the distribution condition of operating system according to internal memory, the loading space of assigns applications gets final product.Like this, when having simplified the application program compiling, since be the memory headroom of application assigned by operating system according to internal memory operating position dynamic assignment, operating system can be loaded into application code the different addresses of physical memory when each the startup, thereby has realized the dynamic load of application code section in physical memory; Operating system can also be finished the reorientation of application code at physical memory by the application plot that is revised as application assigned, realizes that the integral body of application code in physical memory moves; Operating system can also be loaded into different application programs different physical memories by the start address for the different free memory of different application assigned, makes a plurality of application programs to move simultaneously.
Figure 1 shows that the method flow diagram that application program relocatable of the present invention loads, as shown in Figure 1, this method may further comprise the steps:
Step 100: invokes application.
Step 101: the code offset (offset) and the application length (len) of inquiring about this application program.
Step 102: for this application assigned start address is application plot (base), length is the free memory of len.
Step 103: set up process control block (PCB) for application program, be used to preserve application corresponding plot, code offset and application length.
Step 104: with application copy to from using the free memory that plot begins.
This method further comprises step 105: switching under the trigger condition of program process direct or being set in the application corresponding registers group by the scratch pad indirect memory with start address, code offset and the application length of preserving in the process control block (PCB); When the instruction of application program is carried out, with the virtual address of application program and the start address addition in the application register group, the code offset that the deducts application program again internal memory physical address of program that is applied.
This method can also comprise, in the executive utility process, judge the actual memory physical address that obtains according to the application program virtual address, whether in the internal memory range of physical addresses that obtains according to application code skew and application length, if, then continue execution command; If do not exist, then definite this application program is crossed the border, and carries out the Interrupt Process of crossing the border according to method of the prior art, to realize the protection to operating system and other application program.
Below with the example that is loaded as of application A and application program B the method for support application program dynamic load of the present invention is elaborated.
Fig. 2 is the compiling situation synoptic diagram of the current Memory Allocation situation of the present invention and application A and application program B, as shown in Figure 2, the start address after the application A compiling, promptly code offset is 0x0,3000, application length is 0x1,0000; The skew of application program B compiled code is 0x0,3000, and application length is 0x2,0000; In the current physical memory, operating system is distributed from 0x0000, and 0000 to 0x000D, 0000 internal memory, current can be application assigned in save as from 0x000D the idle physical memory in 0000 to 0x0100,0000.
Fig. 3 is the load condition synoptic diagram of current Memory Allocation situation of the present invention and application A, as shown in Figure 3, operating system is according to the distribution condition of current internal memory, detect at physical memory 0x0010,0000 place exists idle, and the length of its free area is greater than the application length of application A, so operating system is loaded into application A from 0x0010, the idle physical memory of 0000 beginning, and for the A allocated length is 0x1,0000 memory address space is promptly at internal memory 0x0010,0000 to 0x0011, the code of 0000 space loading application programs A; And create the process control block (PCB) of application A, except that other essential progress informations, also to preserve the application plot 0x0010 of application A, 0000, code offset 0x0,3000 and application length 0x1,0000.
After finishing the loading of application A, when the operating system under being operated in kernel mode is changed to the application process A that is operated under user's attitude:
Receiving under the trigger condition of process switching that the start address of preserving in the process control block (PCB) with application A, code offset and application length are saved in the relevant hardware register;
Operating system when the instruction of application program is carried out with the virtual address that produces, the instruction address and the executory data access of the application program instructions address that comprise application program, with the start address addition in the hardware register, the code offset that the deducts application program again internal memory physical address of program that is applied;
In the application A operational process, the actual memory physical address that virtual address when judgement moves according to application A calculates, the physical address 0x0010 that calculates in code offset and application length whether according to application A, 0000 to 0x0011, in 0000 the scope, be the instruction that then continues executive utility A; Otherwise definite application A is crossed the border, and carries out the interrupt routine that crosses the border according to method of the prior art, to realize the protection to operating system and other application program.
Suppose that operating system needs loading application programs B in the A that runs application at this moment, and switch to application program B operation, then the situation of loading application programs B as shown in Figure 4.Fig. 4 is the load condition synoptic diagram of current Memory Allocation situation of the present invention and application program B, operating system is according to current Memory Allocation situation, detect at physical memory 0x0018,0000 place exists idle, and free area length is greater than the application length of application program B, so operating system is loaded into application program B from 0x0018, the physical memory of 0000 beginning, and be that application program B allocated length is 0x2,0000 internal memory, promptly at internal memory 0x0018,0000 arrives 0x001A, the code of 0000 space loading application programs B; And the process control block (PCB) of establishment application program B, except that other essential progress informations, the application plot that also will preserve application program B is 0x0018,0000, and code offset is 0x0,3000, application length is 0x2,0000.
After application program B loaded and finishes, operating system switched to application program B operation by application A, and the method flow of switching may further comprise the steps as shown in Figure 5:
Step 500: operating system is saved in the scene of application A in the process control block (PCB) of application A.
In this step, the scene of application A comprises the content of system context, each general-purpose register and control register etc.
Step 501: operating system is recovered the scene of application program B from the process control block (PCB) of application program B.
Step 502: operating system will be used plot, code offset and application length and return in the relevant hardware register from the process control block (PCB) of application program B.
Below with three embodiment the address relocation device that support application program relocatable of the present invention loads is elaborated.
Embodiment one:
In the following time of other pattern except that memory access pattern provided by the invention, the address relocation device that the support application program relocatable loads is elaborated present embodiment to operating system.
Fig. 6 is the address relocation device structural representation that the embodiment of the invention one support application program relocatable loads, and as shown in Figure 6, this device comprises CPU nuclear, address adder and application register group.
Wherein, CPU nuclear is used for the virtual address of application program is outputed to address adder.
Instruction address or data access address when this virtual address is the application program execution.
The application register group comprises uses base register and code offset register, use base register and be used to preserve CPU when operation, the detected start address that can be used for the free memory of loading application programs, promptly use plot, should use plot and output to address adder, and remain on bus that address adder links to each other on; The code offset register is used to preserve the start address that application program is determined when compiling, promptly code offset outputs to address adder with this code offset, and remain on bus that address adder links to each other on.
Address adder, the CPU that is used for receiving authorizes the virtual address of the application program of sending and uses the application plot addition of base register output, subtract each other with the code offset of the code offset register transmission that receives again, the internal memory physical address of the program that is applied, and output to the outside.
This moment, the process of execution in step 105 comprised: when switching to program process, will be set to respectively for the code offset of the start address of the free memory of application assigned and application program and use in base register and the code offset register; Then when application program instructions is carried out, by totalizer with application program virtual address and the content addition of using base register, again with the code offset register in content subtract each other the internal memory physical address of the program that is applied.
The device of present embodiment can also increase the application length register in the application register group, be used to preserve the application length that application program is determined when compiling; This application length is outputed to CPU nuclear;
At this moment, use the content that base register and code offset register be further used for self preserving and be input to CPU nuclear; The physical address that address adder is further used for drawing is input to CPU nuclear;
CPU nuclear is further used for receiving the code offset of the application length of application length register output, the application plot of using base register output, the output of code offset register and the physical address of address adder input, calculate the internal memory range of physical addresses of application program operation according to application length, application plot and code offset, and judge that physical address that address adder obtains is whether in this scope, if, executive utility then, otherwise carry out the Interrupt Process of crossing the border according to method of the prior art.
Because the code offset of determining when operating system is the application plot of application assigned and application program compiling when loading application programs, behind application program launching, do not need to revise again, therefore, can be combined into a register with using base register and code offset register in the practical application, be used for preserving the poor of application plot and code offset.
Close when being made as a register when using base register and code offset register, the process of execution in step 105 comprises: will be set in this register for the difference of the code offset of the application plot of the free memory of application assigned and application program; Then, by totalizer with the virtual address of application program and the content addition in this register, the internal memory physical address of the program that is applied.
Above-described application register group can be selected any hardware register that the content of himself preserving can be remained on the bus that is input to address adder, for example segment base register among the CPU for use.
Memory access pattern provided by the invention also can adopt the method for external protocol processor to realize, to make things convenient for the reduction of hardware capability.
In addition, in order to protect operating system, prevent the destruction of application program to operating system, in embodiments of the present invention, application program operates in user's attitude of CPU, and operating system then operates under the kernel mode of CPU.When executive utility, system need constantly switch between kernel mode and user's attitude.As shown in Figure 7, switch by instruction between user's attitude and the kernel mode, instruction comprises system call, interruption, exception and link order.User's attitude realizes by interruption, exception and system call to the switching of kernel mode; Kernel mode is realized by link order to the switching of user's attitude.
The application plot of operating system kernel attitude can be fixed, also can when os starting, set, so the device that present embodiment provides can also comprise the memory access mode register, be used to preserve the memory access pattern that operating system adopts, after when starting, setting up corresponding registers by operating system, the memory access pattern of preserving is sent to CPU nuclear.As shown in table 1, can utilize 00 to identify internal memory consecutive access pattern, identify memory access pattern of the present invention with 01, with 10 sign paging access modes.
Figure C20071008025500181
The spendable memory access pattern of table 1CPU
The memory access pattern that CPU nuclear uses according to the decision of the content in memory access mode register operating system.
When operating system was not used memory access pattern provided by the invention, when application program produced interruption, exception or system call, CPU switched to kernel mode operation system.The operation of operating system only need get final product according to the mode of prior art.
Because operating system of the present invention and application program operate in oneself independently address space, therefore adopt method provided by the invention to make the internal memory of application program outside cannot access oneself section space, thereby realized protection the operating system space.
When operating system is used memory access pattern provided by the invention, the address size information temporary storages such as application plot, code offset and application length that operating system and application program need be used are in a certain scratch pad storer, for example in memory headroom or the hardware register, so that when user's attitude and kernel mode switch, address size information can be composed in the application register group that its content can be remained to when the execution command on the address bus.At this moment, the address relocation device that loads of the support application program relocatable of the present invention scratch pad storer one that also comprises the application plot that is used to preserve operating system and code offset be used to preserve the application plot of application program and the scratch pad storer two of code offset.Below be elaborated with embodiment two and three pairs of address relocation devices provided by the invention of embodiment.
Embodiment two:
Under memory access pattern provided by the invention, the device that the support application program relocatable loads is elaborated present embodiment to operating system.Scratch pad storer in the present embodiment is the scratch pad register.
Fig. 8 is the address relocation device structural representation that the embodiment of the invention two support application program relocatables load, and as shown in Figure 8, this device comprises scratch pad registers group one, scratch pad registers group two, application register group, CPU nuclear and address adder.The device that present embodiment provides has increased scratch pad register one and scratch pad register two on the basis of the device that embodiment one provides.
Wherein, scratch pad registers group one comprises operating system application base register and operating system code offset register, be used in system initialization, preserve the application plot and the code offset of operating system respectively, when by user's attitude when kernel mode switches, authorize at CPU under the control of the trigger pip of sending, the operating system application plot and the operating system code skew of preserving separately sent in the corresponding register of application register group.
Scratch pad registers group two comprises application program application base register and application code offset register, be used for when switching to the program process of certain loading, be kept at the application plot and the code offset of preserving in the process control block (PCB) of this application program respectively; When by kernel mode when user's attitude is switched, authorize at CPU under the control of the trigger pip of sending, the application program of preserving is separately used plot and application code skew sends in the corresponding register in the application register group.
The application register group comprises uses base register and code offset register, be respectively applied for the application plot and the code offset of preserving current operating system of moving or application program, and application plot and the code offset that will preserve separately send to address adder, and remain on bus that address adder links to each other on.
CPU nuclear is used for the virtual address of application program and the virtual address of operating system are sent to address adder; And to scratch pad registers group one and scratch pad registers group two transmission trigger pips.
Address adder is used for CPU is authorized application program or the virtual address of operating system and the application plot addition of sending that the application base register sends, subtract each other the internal memory physical address the when program that is applied or operating system are carried out with the code offset of code offset register transmission then.
The process of present embodiment execution in step 105 comprises:
Under the trigger condition of process switching, promptly at kernel mode when user's attitude is switched, the content in the process control block (PCB) of application program is set in the corresponding registers of scratch pad registers group two;
Before invokes application, in advance application plot, the code offset of operating system is kept in the corresponding registers of scratch pad registers group one;
When kernel mode switched to user's attitude executive utility, CPU nuclear triggered scratch pad registers group two with the content of himself preserving, and comprised that the content replication of using in base register and the code offset register is in the corresponding register of application register group; Totalizer is CPU virtual address of authorizing the application program of sending and the application plot addition of using in the base register, again with the code offset register in code offset subtract each other after, the internal memory physical address when being applied program run;
When interrupt, when exception or system call, system need switch to the instruction of kernel mode executive operating system from user's attitude, the process that switch this moment comprises:
CPU examines and triggers scratch pad registers group one with the content of himself preserving, and comprises that the operating system code that the operating system of using in the base register is used in plot and the code offset register is offset, and copies in the corresponding register in the application register group;
When executive operating system is instructed under kernel mode, totalizer is authorized CPU virtual address of sending and the application plot addition of using in the base register, again with the code offset register in code offset subtract each other, obtain give an order internal memory physical address when carrying out of kernel mode;
When the operation link order, system need switch to user's attitude executive utility by kernel mode.
After the internal memory physics of the program of being applied, also comprise the address realm of the application program the operation whether physical address of judging this application program obtains in application plot, code offset and application length according to application program, if would continue execution command; Otherwise carry out the Interrupt Process of crossing the border.
Embodiment three:
In the present embodiment, operating system is under memory access mode provided by the invention, the application plot and the code offset of operating system and application program are saved in the memory headroom, and the pointer of memory address that will point to the above information of storage stores in the register.Scratch pad storer one in the present embodiment is for being used to preserve the operating system memory headroom of using plot and code offset and the register one of preserving pointer; Scratch pad storer two is for being used to preserve the application program memory headroom of using plot and code offset and the register two of preserving pointer.
Fig. 9 is the address relocation device structural representation that the embodiment of the invention three support application program relocatables load, and as shown in Figure 9, this device comprises register one, register two, internal memory, application register group, CPU nuclear and address adder.
Wherein register one is used to preserve the pointer of the memory address of the application plot that points to storage operating system and code offset.
Register two is used to preserve the pointer of the memory address of the application plot that points to application storing and code offset.
The application register group comprises uses base register and code offset register, uses base register and is used to preserve the application plot of operating system or application program, and will use plot and output to address adder; The code offset register is used to preserve the code offset of operating system or application program, and code offset is outputed to address adder.
CPU nuclear is used for the virtual address of operating system or application program is outputed to address adder; When user's attitude switches to kernel mode, be invoked at the application plot and the code offset of the operating system in the memory address of pointer indication by the pointer in the register one, be saved in described application base register and code offset register respectively; When switching to user's attitude by kernel mode, call application plot and the code offset that is kept at the application program in the pointer indication memory address by the pointer in the register two, be saved in respectively in the application base register and code offset register of application register group.
Address adder is used for CPU is authorized virtual address of sending and the application plot addition of using the base register transmission, and subtracts each other the internal memory physical address when obtaining the execution of operating system or application program with the code offset that the code offset register sends.
The process of present embodiment execution in step 105 comprises:
Address information in the program process controll block is copied in the internal memory, the pointer that points to the memory address of preserving the application program address information is saved in the register two;
In system initialization, in advance application plot, the code offset of operating system copied in the internal memory, the pointer that points to the memory address of preserving the operating system address information is saved in the register one;
When switching to user's attitude executive utility from kernel mode, CPU nuclear calls the address information of the application program that is stored in the correspondence memory address by being stored in pointer in the register two, and address information is copied in the corresponding registers in the application register group; Totalizer is CPU virtual address of authorizing the application program of sending and the application plot addition of using in the base register, again with the code offset register in code offset subtract each other after, the internal memory physical address when being applied program run;
When interrupt, when exception or system call, system need switch to kernel mode from user's attitude, the method flow of switching comprises:
CPU nuclear calls the address information of the operating system that is stored in the internal memory appropriate address by the pointer that is stored in the register one, and this address information is copied in the corresponding registers of application register group;
When executive operating system is instructed under kernel mode, totalizer is authorized CPU virtual address of sending and the application plot addition of using in the base register, again with the code offset register in code offset subtract each other, obtain give an order internal memory physical address when carrying out of kernel mode;
When the operation link order, system need be switched under user's attitude by kernel mode and continue executive utility.
Present embodiment is described to be used to preserve the application plot of operating system and application program and the memory headroom of memory headroom for only visiting at kernel mode of code offset.
The embodiment of the invention two and embodiment three described all need preserve in the scratch pad register or memory address space of using plot and code offset, can also increase application length register or the memory address space of preserving application length, examine the detection that is used to cross the border for CPU.
By the above as can be seen, the method and the address relocation device of application program relocatable loading provided by the present invention have the following advantages:
First, operating system can be according to the actual allocated situation dynamic load application program of internal memory, the compiling and the dynamic load process of application program have been simplified, make operating system not need the maintain pages table of comparisons and parsing symbolic information table and address relocation information, thereby in the time of in being applied to embedded system, significantly improved the travelling speed of embedded system.
The second, application program and operating system operate in oneself independently memory headroom separately, realize the protection of operating system.
The 3rd, all application programs can be compiled in same start address, are loaded into different physical memory positions by operating system, do not need the support of hardware MMU.Simplified the compiling of application program; And can move a plurality of application programs simultaneously.
The 4th, can be with code whole moving in physical memory of application program, operating system only need be revised the application plot just can finish the reorientation of application code in physical space.
The above is preferred embodiment of the present invention only, is not to be used to limit protection scope of the present invention.Within the spirit and principles in the present invention all, any modification of being done, be equal to replacement, improvement etc., all should be included within protection scope of the present invention.

Claims (8)

1, a kind of method of application program relocatable loading is characterized in that this method comprises:
The internal memory start address and the code offset of operating system are saved in the scratch pad storer one;
Invokes application is inquired about the code offset and the application length of this application program;
According to the Memory Allocation situation is the free memory of this application assigned length more than or equal to described application length;
For this application program is created process control block (PCB), start address, code offset and the application length of preserving described free memory;
This application code is copied to described free memory;
Under the trigger condition of process switching, the application program internal memory start address and the code offset of preserving in the process control block (PCB) is set in the scratch pad storer two;
When kernel mode switches to user's attitude executive utility, the content that is kept in the scratch pad storer two is set in the application register group; With the virtual address and the addition of application program internal memory start address of application program, the code offset that the deducts application program internal memory physical address of program that is applied;
When user's attitude switches to the instruction of kernel mode executive operating system, the content that is kept in the scratch pad storer one is set in the application register group; With the internal memory start address addition of the virtual address and the operating system of operating system, the code offset that deducts operating system obtains the internal memory physical address of operating system.
2, the method for claim 1 is characterized in that, after the internal memory physical address of the described program that is applied, this method further comprises:
Judge the address realm of the application program operation whether described physical address obtains in start address, code offset and application length according to described free memory, if would continue execution command; Otherwise carry out the Interrupt Process of crossing the border.
3, a kind of address relocation device is characterized in that, this device comprises central processing unit CPU nuclear, address adder, application base register and code offset register,
Described CPU nuclear is used for virtual address is outputed to address adder;
Described application base register is used for preserving and uses plot, and described application plot is the start address of the free memory of application assigned for the distribution condition according to internal memory; Described application plot is sent and remains on the bus that links to each other with described address adder;
Described code offset register is used to preserve code offset; Described code offset is sent and remains on the bus that links to each other with described address adder;
Described address adder, the CPU that is used for receiving are authorized the application plot addition that the virtual address sent and described application base register send, and deduct the code offset that described code offset register sends again, obtain the physical address of internal memory;
This device further comprises scratch pad storer one and scratch pad storer two,
Described scratch pad storer one is used in system initialization, preserves the application plot and the code offset of operating system; When by user's attitude when kernel mode switches, authorize at CPU under the control of the trigger pip of sending, the operating system of preserving is used plot and code offset sends to described application base register and code offset register respectively;
Described scratch pad storer two is used in process switching, application plot and code offset in the process control block (PCB) of preservation application program; When switching to user's attitude by kernel mode, authorize at CPU under the control of the trigger pip of sending, the application program application plot and the code offset of preserving sent to described application base register and code offset register respectively;
Described application base register is further used for receiving and preserving the operating system application plot that described scratch pad storer one sends; Or the application program that receives and preserve two transmissions of scratch pad storer is used plot;
Described code offset register is further used for receiving and preserve the code offset of the operating system that described scratch pad storer one sends; Or the code offset of the application program of reception and two transmissions of preservation scratch pad storer;
Described CPU nuclear is further used for sending trigger pip to scratch pad storer one and scratch pad storer two.
4, device as claimed in claim 3 is characterized in that, this device further comprises the application length register, is used to preserve the application length of application program; This application length is sent to CPU nuclear;
Described application base register, the application plot that is further used for the application program that will preserve sends to CPU nuclear;
Described code offset register, the code offset that is further used for the application program that will preserve sends to CPU nuclear;
Described address adder, the physical address that is further used for the application program that will obtain sends to CPU nuclear;
Described CPU nuclear is further used for according to the application plot, code offset and the application length that receive, the address realm of the program run that is applied; Judge that the described physical address that receives is whether within the address realm of described application program operation, if continue execution command; Otherwise, carry out the Interrupt Process of crossing the border.
5, device as claimed in claim 3 is characterized in that, described application base register and described code offset register are a register, is used for preserving the poor of application plot and code offset; This application plot is sent and remains on the bus that links to each other with described address adder with the difference of code offset;
Described address adder is further used for receiving the poor of application plot that described register sends and code offset, and the difference and the CPU of this application plot and code offset authorized the virtual address addition of sending, and obtains the internal memory physical address.
6, device as claimed in claim 3 is characterized in that, described temporary storage one comprises operating system application base register and operating system code offset register; Described scratch pad storer two comprises application program application base register and application code offset register,
Described operating system is used base register, be used to preserve the application plot of operating system, when switching to kernel mode by the family attitude, authorize at CPU under the control of the trigger pip of sending, the application plot of described operating system is sent to described application base register;
Described operating system code offset register, be used to preserve the code offset of operating system, when switching to kernel mode by user's attitude, authorize at CPU under the control of the trigger pip of sending, the code offset of described operating system is sent to described code offset register;
Described application program is used base register, be used to preserve the application plot of application program, when switching to user's attitude by kernel mode, authorize at CPU under the control of the trigger pip of sending, the application plot of described application program is sent to described application base register;
Described application code offset register, be used to preserve the code offset of application program, when switching to user's attitude by kernel mode, authorize at CPU under the control of the trigger pip of sending, the code offset of described application program is sent to described code offset register;
Described application base register is further used for receiving the application plot that described operating system is used the operating system of base register transmission; Or receive described application program and use plot and deposit the application plot of the application program of transmission;
Described code offset register is further used for receiving the operating system code skew that described operating system code offset register sends; Or receive the code offset of the application program that described application code offset register sends;
Described CPU nuclear is further used for using base register, operating system code offset register, application program application base register and application code offset register to operating system and sends trigger pip.
7, device as claimed in claim 3 is characterized in that, described scratch pad storer one comprises the memory headroom of register one and storage operating system application plot and code offset; Described scratch pad storer two comprises the memory headroom of register two and application storing application plot and code offset,
Described register one is used to preserve the pointer that the sensing storage operating system is used the memory address of plot and code offset;
Described register two is used to preserve the pointer that the sensing application storing is used the memory address of plot and code offset;
Described CPU nuclear, be further used for when switching to kernel mode by the family attitude, call application plot and the code offset that is kept at the operating system in the pointer indication memory address by the pointer in the register one, be saved in described application base register and code offset register respectively; When switching to user's attitude by kernel mode, call application plot and the code offset that is kept at the application program in the pointer indication memory address by the pointer in the register two, be saved in described application base register and code offset register respectively.
8, device as claimed in claim 7 is characterized in that, described to be used to preserve the memory headroom of using plot and code offset be the memory headroom that has only kernel mode to visit.
CNB2007100802553A 2007-02-15 2007-02-15 Method and address relocation device that the application program relocatable loads Expired - Fee Related CN100555222C (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CNB2007100802553A CN100555222C (en) 2007-02-15 2007-02-15 Method and address relocation device that the application program relocatable loads

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CNB2007100802553A CN100555222C (en) 2007-02-15 2007-02-15 Method and address relocation device that the application program relocatable loads

Publications (2)

Publication Number Publication Date
CN101246427A CN101246427A (en) 2008-08-20
CN100555222C true CN100555222C (en) 2009-10-28

Family

ID=39946897

Family Applications (1)

Application Number Title Priority Date Filing Date
CNB2007100802553A Expired - Fee Related CN100555222C (en) 2007-02-15 2007-02-15 Method and address relocation device that the application program relocatable loads

Country Status (1)

Country Link
CN (1) CN100555222C (en)

Families Citing this family (16)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101907994A (en) * 2009-06-08 2010-12-08 鸿富锦精密工业(深圳)有限公司 Method for loading display card BIOS
CN101706725B (en) * 2009-11-20 2014-03-19 中兴通讯股份有限公司 Method and system for loading and debugging relocatable program
CN102541579A (en) * 2010-12-17 2012-07-04 沈阳新邮通信设备有限公司 Method for dynamically loading application program of embedded system
CN102226894A (en) * 2011-05-23 2011-10-26 中兴通讯股份有限公司 Mobile device memory management method and device
CN102819439B (en) * 2011-06-10 2017-09-29 中兴通讯股份有限公司 A kind of dynamic loading method and device of the multi-standard application program based on reorientation
CN102331940A (en) * 2011-06-24 2012-01-25 浙大网新科技股份有限公司 Method and system for loading applications on Android mobile phones
CN102707966B (en) * 2012-04-12 2014-09-03 腾讯科技(深圳)有限公司 Method and device for acceleratively starting operating system, and method, device and terminal for generating prefetched information
CN104281537B (en) * 2013-07-05 2017-09-08 阿里巴巴集团控股有限公司 A kind of internal memory clone method and device
CN104572752A (en) * 2013-10-24 2015-04-29 中兴通讯股份有限公司 Method and device for finding positioning method by application program
CN105426223B (en) * 2015-12-25 2019-01-04 百度在线网络技术(北京)有限公司 Using loading method and device
CN106528254A (en) * 2016-12-16 2017-03-22 中南大学 APP rapid loading method
CN109710544B (en) * 2017-10-26 2021-02-09 华为技术有限公司 Memory access method, computer system and processing device
CN108874468B (en) * 2018-06-20 2021-03-26 深圳市腾讯网络信息技术有限公司 Application program loading method and device, computer equipment and storage medium
CN111240765B (en) * 2020-01-15 2023-02-03 深圳英飞拓智能技术有限公司 LINUX compression application program loading method
CN113111012B (en) * 2021-04-14 2023-07-25 景德镇市明泰精工瓷业有限公司 Application data locator generation method and application data locating method
CN114781322B (en) * 2022-04-24 2023-04-25 苏州睿芯集成电路科技有限公司 Memory state recovery method for MMU-free environment in CPU chip simulation acceleration

Non-Patent Citations (2)

* Cited by examiner, † Cited by third party
Title
操作系统--内核与设计原理(第四版). William Stallings,91-92,94-100,226-238,电子工业出版社. 2001
操作系统——内核与设计原理(第四版). William Stallings,91-92,94-100,226-238,电子工业出版社. 2001 *

Also Published As

Publication number Publication date
CN101246427A (en) 2008-08-20

Similar Documents

Publication Publication Date Title
CN100555222C (en) Method and address relocation device that the application program relocatable loads
US10310991B2 (en) Timely address space randomization
JP3801643B2 (en) Instruction folding processing for arithmetic machines using stacks
KR0132696B1 (en) Memory management method
KR20130050156A (en) Apparatus for translating virtual address space
US7506096B1 (en) Memory segment emulation model for virtual machine
JPWO2003025743A1 (en) Processor system with Java accelerator
US11474956B2 (en) Memory protection unit using memory protection table stored in memory system
CN113688062B (en) Method for storing data and related product
JP2020518910A (en) Device and method for managing the use of features
EP3649550A1 (en) An apparatus and method for controlling execution of instructions
Suchy et al. CARAT: A case for virtual memory through compiler-and runtime-based address translation
US20210311997A1 (en) Binary search procedure for control table stored in memory system
CN111580798A (en) Dynamic link library implementation method, system, computer equipment and storage medium
KR20120070326A (en) A apparatus and a method for virtualizing memory
EP1421475B1 (en) Frameworks for generation of java macro instructions for instantiating java objects
EP3274824B1 (en) Efficient address translation
CN115004158A (en) Apparatus, method and computer program for executing processor instructions in an extended set on a multi-core processor
KR100884926B1 (en) Method for utilizing legacy shared libraries on VM-less embedded systems
US11269788B2 (en) Managing memory in an electronic device
TWI835856B (en) Apparatus, method, computer program, and computer-readable storage medium for range checking instruction
Du Protecting Applications on Real-time Embedded Systems from Control-flow Hijacking with Kage
Liedtke A short note a small virtually-addressed control blocks
Kerstan et al. Configurable Hybridkernel for Embedded Real-Time Systems
Hwang et al. Translated Block Optimization of Dynamic Binary Translator for Embedded System Virtualization

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
C14 Grant of patent or utility model
GR01 Patent grant
ASS Succession or assignment of patent right

Owner name: BEIJING SUNPLUS EHUI TECHNOLOGY CO., LTD.

Free format text: FORMER OWNER: BEIJING BEIYANG ELECTRONIC TECHNOLOGY CO., LTD.

Effective date: 20140227

TR01 Transfer of patent right
TR01 Transfer of patent right

Effective date of registration: 20140227

Address after: Science and Industry Park, Taiwan, Hsinchu, China, No. 19

Patentee after: Lingyang Science and Technology Co., Ltd.

Patentee after: BEIJING SUNPLUS-EHUE TECHNOLOGY CO., LTD.

Address before: Science and Industry Park, Taiwan, Hsinchu, China, No. 19

Patentee before: Lingyang Science and Technology Co., Ltd.

Patentee before: Beijing Beiyang Electronic Technology Co., Ltd.

CF01 Termination of patent right due to non-payment of annual fee
CF01 Termination of patent right due to non-payment of annual fee

Granted publication date: 20091028

Termination date: 20170215