1. Field of the Invention
This invention relates generally to the execution of software programs and, more particularly to the procedure for calling a subroutine for use by a software program.
2. Background of the Invention
As chip architectures evolve, newer architectures might add new machine resources or even make more efficient usage of a certain subset of existing machine resources. Since the resource might not have existed at the time of the original design or might not have been a primary focus area during the original design of the original “calling convention” the best possible usage of such resources might not be represented. This problem is particularly pertinent in the case where existing resources are more efficiently being used by newer evolutions of the original architectures. Identifying a mechanism to make better usage efficiently of such machine resources by defining an updated calling convention without breaking the original “calling convention” is the problem addressed by this invention.
The primary existing solution to this problem today is to define a brand new calling convention for a newer architecture. However, such a definition breaks the existing calling convention and so software code compiled for earlier architectures is incompatible with the code compiled for the newer architecture.
Referring to
The activity of saving the state of a processing unit resource typically includes saving the contents of a register to memory. Then, after completion of the sub-routine and the return to the software program, the values in the register are restored by transferring the contents saved in memory to the appropriate register. Note that each software program must include code for the saving the resources. Thus each program has a certain amount of duplicated code.
Another solution to this problem has been to save and restore resources “contaminated” during the function call in the body of the calling function itself. But this method is not generally “efficient” in terms of the size of the body of the calling function.
A need has therefore been felt for apparatus and an associated method having the feature of providing an in improved technique for the calling of a sub-routine by a software program. It would be another feature of the apparatus and associated method to provide a calling technique that permits backward compatibility with calling techniques for previous architectures. It would be a further feature of the apparatus and associated method to reduce the code length of the calling requirements of a plurality of software programs. It would be a still further feature of the apparatus and associated method to provide an intermediate sub-routine which incorporates the calling convention compatible for a plurality of software programs.
Our solution proposes that we save/restore/transform required machine resources in a single, shared, central location.
The foregoing and other features are accomplished, according the present invention, by calling a sub-routine by means of an intermediate sub routine, herein after referred to as a stub sub-routine. The stub sub-routine includes all of the calling conventions with respect to resource availability. By using a stub sub-routine, a plurality of software programs that require the sub-routine can be provided with the sub-routine without the need to provide the code in each program. Furthermore, the stub sub-routine can maintain a backward-compatibility with previous program versions.
Other features and advantages of present invention will be more clearly understood upon reading of the following description and the accompanying drawings and the claims.
Referring to
The present invention involves generating a central, shared piece of code (i.e., the stub sub-routine) where certain activity can be performed before actually transferring to the desired lower level function or the sub-routine. The called stub sub-routine receives as input the address of the lower level function and the address to which the process must return after the execution of the sub-routine.
The call stub then implements mechanisms to save the existing state of certain machine resources before jumping to the lower level function, restore the saved state after completion of the lower level function, and shifting the contents of some resources around.
All of the foregoing activity is performed such that a pre-defined, legacy “convention” can be honored when we enter the called function. In other words, the use of the stub sub-routine permits the calling of the sub-routine to be backward compatible.
The calling function then provides the input required by the central, shared call stub sub-routine and jumps to the call stub instead of the lower level function. The calling function is also aware of the fact that it is calling the stub sub-routine so can now follow the more efficient and appropriate calling convention for the duration of its execution.
A function or software program calling a sub-routine to perform a certain task very often has a specific convention/contract about usage of machine resources by the lower level function. Things defined by the convention include, but are not limited to, some of the following:
preservation of convention in certain machine resources, and
passage of expected input to the lower level function.
In the foregoing discussion, the generic term resources has been used. As will be clear to those skilled in the art, the term resources most frequently refers to registers. As the architecture of a processing unit changes, the registers can be relabeled and/or the characteristics, such as register length can be changed. The present invention permits these changes to be accommodated in the stub sub-routine and not in the calling program.
While the invention has been described with respect to the embodiments set forth above, the invention is not necessarily limited to these embodiments. Accordingly, other embodiments, variations, and improvements not described herein are not necessarily excluded from the scope of the invention, the scope of the invention being defined by the following claims.
This application claims the benefit of Provisional Application Serial No. 60/699,988, entitled “Function Calling Convention Customization Optimized for Code Size”, filed on Jul. 15, 2005.
Number | Date | Country | |
---|---|---|---|
60699988 | Jul 2005 | US |