Abstract:
A method for dynamically altering Read-Only Memory (ROM)-based programs utilizes Random-Access Memory (RAM) and standard processor linkages associated with subroutine or function calls. Each original ROM program includes a statement to call a ROM processing routine. If information passed to the processing routine by the original routine indicates a RAM-based replacement routine is to be executed for the original routine, the processing routine (i) restores the processor to its state immediately following the call to the processing routine, and (ii) branches directly to the replacement routine at a location provided by a RAM-based data structure.

Description:
FIELD OF THE INVENTION 
     This invention relates generally to a method for programming a digital computer and, more particularly, to a method of dynamically altering firmware programs during execution of these programs. 
     BACKGROUND OF THE INVENTION 
     A Read-Only Memory (ROM) is often used to store programs for computers, especially in microcomputer systems. The ROM is particularly useful since the programs are retained during power outages and may not be overwritten by programming errors. However, when one or more programs require change or updating, the conventional approach is to provide and then install a complete new ROM. The expense of such a change may be large, especially in a distributed processing system which incorporates remotely located computers, so errors generally have been corrected only when economically feasible or when they become deleterious to system operation. The present invention obviates these changes if the microcomputer system is configured with Random-Access Memory (RAM) and each ROM based program includes a test to determine if any ROM program is to be replaced by a RAM program. The following background discussion describes the standard subroutine or function linkages exploited by the present invention to effect such a test. 
     In certain high-level languages exemplified, for instance, by FORTRAN or C, the sequence of operations on a call to a subroutine or function from a calling routine is an essential part of the particular language. This is required since other processes, such as the loader or assembler associated with the system implementing the language, must interface with the language and its calling sequence. For example, because of this well-defined sequence of operations, a called subroutine need not be compiled at the same time as the calling routine. When the compiler processes a subroutine, one of its operations involves the allocation of storage for local variables. Typically each of these variables is stored in a memory area designated as a stack space or simply, stack, so space may be allocated by adjusting the stack pointer. Moreover, the contents of the stack upon entry to a subroutine are saved so that the stack may be restored to its original state upon exiting the called routine. 
     These programming properties, in combination with systems employing RAM, may be utilized to change or update ROM programs at system execution time. 
     SUMMARY OF THE INVENTION 
     The method in accordance with the present invention allows for dynamic alteration of ROM programs with the aid of Random-Access Memory (RAM) and through the use of the standard linkages associated with subroutine calls in the system processor. When each ROM-based routine is written, one program statement is a call to a ROM-located processing routine which searches a RAM-located data structure. If there exists a correspondence between information passed on the call to the processing routine and certain elements of the data structure, a RAM-based program is substituted for the ROM-based program. After adjusting the processor to the states just after the call to the ROM-based program, the processing routine effects a transfer to the replacement routine in RAM. The location of this replacement routine is also found in the data structure. 
     One feature of the present invention is the online, real-time substitution of one program for another. Moreover, this is accomplished without requiring memory boundary alignment which is typical of hardware related modifications to run-time software. 
     The organization and operation of this invention will be better understood from a consideration of the detailed description of the illustrative embodiment thereof, which follows, when taken in conjunction with the accompanying drawing. 
    
    
     BRIEF DESCRIPTION OF THE DRAWING 
     The sole FIGURE is a combined block diagram and flow diagram depicting the dynamic alteration method in accordance with the present invention. 
    
    
     DETAILED DESCRIPTION 
     With reference to the FIGURE, this combined block and flow diagram illustrates the general principles of the present invention. In particular, calling routine 100 comprises statements specifying the actual computing operations to be performed. In the C language, one example of calling routine 100 is the special routine or function called &#34;main&#34;, which typically invokes other functions to perform its overall task. 
     Embedded within routine 100 is a call to another routine, which is designated the original routine and is depicted by block 200. Original routine 200 is a ROM-based routine that is representative of any program which may be replaced at run time because of improvements to or errors in routine 200. Immediately after entry into original routine 200, a transfer to processing routine 300 is effected. This transfer occurs via a subroutine or function call, and a parameter, designated P, is passed as an argument on the call. The parameter is utilized by processing routine 300 to determine if this particular original routine is to be replaced. Typically, P represents the starting address of original routine 200. 
     Processing routine 300 is also a ROM-based routine implementing three basic steps. Upon entry into routine 300, a test is effected to determine if the parameter P is in a RAM-based data structure. This test step is depicted by decision block 310 in the FIGURE. The data structure contains elements representative of the original routines that are to be replaced. For instance, one type of element is the starting address of each original routine requiring substitution. In any case, if there exists a correspondence between P and certain elements of the data structure, branch 311 is followed. Otherwise, branch 312 is taken to effect a transfer back to statements immediately following the call to processing routine 300 from original routine 200. 
     If branch 311 is selected, the next step, depicted by block 320, is that of restoring the stack pointer and any other machine state registers to the state immediately following the call to original routine 200. In this manner, all traces of the call to routine 200 are removed so that it appears as if the replacement routine was called directly. Because original routine 200 is now transparent to system operation, there is no need to preserve information on the stack relating to the return address of original routine 200. 
     The final step, represented by transfer block 330 in the FIGURE, is a branch to replacement routine 400. Processing routine 300 does not initiate a call to accomplish this transfer, but rather jumps directly into replacement routine 400. This is accomplished by associating another set of elements in the data structure with replacement routine information. For instance, if P is an address and one part of the data structure may contain the starting address of an original routine 200, then another, corresponding part of the data structure may contain the starting address of the replacement routine 400. 
     Both the data structure and the replacement routines may be loaded at system initialization or they may be downloaded from a system controller during system operation. With this latter technique, replacement routines may be dynamically changed so that if RAM space is limited, the most important replacement routines may overwrite less important replacement routines at appropriate times. 
     The foregoing discussion described the present invention in a general way. The following discussion presents an example utilizing the C language. A simple original routine 200 is represented as follows: 
     
         ______________________________________        f(x)        int x;         {int i;         i=2*x*x;         return(i);         }______________________________________ 
    
     The above subroutine, called `f`, which computes twice the square of the value x, could be compiled and placed into ROM. However, to allow a change in this routine at some future time, only one additional statement is required: 
     
         ______________________________________       f(x)       int x;        {int i;        trap -door(f); - i=2*x*x;        return(i);        }______________________________________ 
    
     The call to the processing routine `trap --  door` includes a parameter which is the address of the subroutine `f`. In `trap --  door`, a check is made as to whether `f` is to be run as it was placed into ROM (trap door closed) or whether a RAM-based function is to be run (trap door open). If the ROM-based version of `f` is to be run, `trap --  door` simply returns to original routine `f`. Otherwise, an address in the RAM-based version of the function is found and a branch to that address occurs. 
     A simple data structure for implementing `trap --  door` is the NULL terminated linear list. The list is searched and if the address of `f` is found in the list, then a replacement routine is executed in place of `f`. The data structure may have the representation: 
     
         ______________________________________struct entry{    int *romf();    int *ramf(); }list [MAX -FUNCTS -TO BE -SWITCHED + 1]; /*the +1 is for a NULL terminator*/One version of `trap -door` becomes: trap -door(f) int *f(); {struct entry *this;  extern struct entry list[];  for(this=&amp;list[0];this-&gt;romf-=NULL;++this){  if(this-&gt;romf==f){   jump -to(this-&gt;ramf);  }  }  return; }______________________________________ 
    
     The function called `jump --  to`, for efficiency purposes, is written in machine or assembly language once the compiler implementation is known. This function computes the correct address to branch to in RAM. If the results of such a calculation are loaded into the `list` table initially, then the `jump --  to` function is simplified. Also, before the branch, `jump --  to` restores the stack and other state information to the state immediately after the call to `f`. This may be accomplished by storing the stack pointer of the desired state in memory and setting the stack pointer to the stored value prior to the jump to the replacement routine. 
     Finally, for those systems which expect to have a large number of ROM functions switched to RAM versions, some data structure other than a linear list with low-to-high list search may be preferable. For instance, a binary search may be one technique that may be deployed. 
     It is to be further understood that the methodology described herein is not limited to the specific forms disclosed by way of illustration, but may assume other embodiments limited only by the scope of the appended claims.