Methods, computer systems, and computer readable media for changing module pointer values upon switches between different modes of memory addressing

Methods, computer systems, and computer readable media maintain address values of a module stored in computer memory by changing the module pointer values upon switches between physical memory addressing and virtual memory addressing. Upon a function call to the module, the pointer values of the module are changed to correspond to the current mode of memory addressing. Thus, upon changing the pointer values to the current mode, the locations of the module can be properly accessed during execution of the module in the computer system.

TECHNICAL FIELD

The present invention is related to the execution of modules stored in computer memory. More particularly, the present invention is related to the adaptation of pointer values stored in the module upon a switch between different modes of memory addressing of the computer.

BACKGROUND

Computers have executable program modules stored in memory that may be executed by a processor of the computer. To properly execute the module, the processor must be able to properly locate information stored within the module when the module itself is stored in the memory of the computer system. The module provides pointer values that may be accessed by the processor to then find locations of information within the module being executed.

The computer system accesses memory according to a particular memory addressing mode. Various memory addressing modes may be used. For example, for multiple processor systems, one processor has its own address space while another processor has a different set of address space such that the address of a memory location is processor specific. Thus, the particular memory addressing mode depends upon the particular processor that owns the memory location.

Other examples of memory addressing schemes include a virtual mode of memory addressing and a physical mode of memory addressing. The physical mode of memory addressing utilizes the physical address of memory of the computer system without any remapping of the physical address space. The virtual mode of memory addressing applies a remapping scheme of the physical address space. This remapping scheme for virtual mode addressing allows for various desirable characteristics, such as to allow a virtual memory address to remain the same while the underlying physical addresses being used may change over time and/or to cause multiple memory devices to appear as a single address space or to cause a single memory device to appear as multiple address spaces.

However, because there is a remapping scheme being applied, the virtual memory mode pointer value for a location of particular data is different than the actual underlying physical pointer value where the data is stored. Thus, when the processor accesses memory in the virtual memory addressing mode, the actual location that is accessed is based on the remapping scheme. When the processor accesses memory in the physical mode, there is no remapping scheme involved.

Regardless of the particular example of where multiple memory addressing modes are in use, the memory location pointers of a module that a processor references to access information must be representative of the proper memory addressing mode or the processor will attempt to access a non-existent memory location.

As an example of having incorrect pointer values in the module, if the processor is currently in a first memory addressing mode but the pointer values of the module are representative of a second memory addressing mode, then the processor will read the second memory addressing mode pointer values of the module and apply them to the address space of the first memory addressing mode without a remapping scheme being applied. These second memory addressing mode pointers will direct the processor to an invalid location in memory and will result in a system failure.

The processor may be switched between a first mode of memory addressing and a second mode memory of addressing for various reasons. For example, when the operating system is controlling the memory accesses, the processor will likely be using virtual mode addressing discussed above. However, the hardware system may require a switch to the physical addressing mode, also discussed above. For instance, various hardware errors may require that the processor switch to the physical mode of addressing. However, the module in memory has pointer values representative of the virtual mode address space such that this module cannot be successfully executed once the switch to the physical mode of addressing has occurred.

SUMMARY

Embodiments of the present invention address these issues and others by providing methods, computer systems, and computer readable media that provide for adapting the pointer values of the module to be representative of the current mode of memory addressing. Thus, when the mode of memory addressing switches from one mode to the other, the pointer values of the module are changed to reflect the address space for the mode that is being employed after the switch has occurred.

One embodiment is a method of providing maintenance for pointer values in a module in computer memory during switches between a previous mode of memory addressing and a current mode of memory addressing. The method involves, after a switch from the previous mode of memory addressing to the current mode of memory addressing, receiving a function call to the module in memory. Upon receiving the function call to the module in memory, beginning execution of the module to convert the pointer values of the module from pointer values corresponding to the previous memory addressing mode to pointer values corresponding to the current memory addressing mode.

Another embodiment is a computer system for providing maintenance for pointer values in a module in memory of the computer system during switches between a previous mode of memory addressing and current mode of memory addressing. The computer system includes a memory containing the module and a processor configured to begin execution of the module at a known point of entry. The processor, upon receiving a function call to the module in memory, then begins execution of the module starting at the point of entry to convert the pointer values of the module from values corresponding to the previous memory addressing mode to values corresponding to the current memory addressing mode.

Another embodiment is a computer readable medium containing instructions of a module that when executed by a computer perform various steps to provide maintenance for pointer values in the module once it is stored in computer memory during switches between a previous mode of memory addressing and a current mode of memory addressing. The steps involve receiving a function call to the module in memory and then beginning execution of the module to convert the pointer values of the module from values corresponding to the previous memory addressing mode to values corresponding to the current memory addressing mode.

Another embodiment is a method of providing maintenance for pointer values in a module in computer memory during switches between a first mode of memory addressing and a second mode of memory addressing. The method involves receiving a first function call to the module in memory and upon receiving the function call to the module in memory, converting the pointer values of the module from pointer values corresponding to the first mode of memory addressing to pointer values corresponding to the second mode of memory addressing. After having received the first function call and having converted the pointer values, a second function call to the module in memory is received, and upon receiving the second function call to the module in memory, the pointer values of the module are converted from pointer values corresponding to the second mode of memory addressing to pointer values corresponding to the first mode of memory addressing.

DETAILED DESCRIPTION

Embodiments of the present invention allow for execution of a module in memory both before and after a switch from one memory addressing mode to another. The pointer values of the module that are used to access the information of the module are adapted to the current memory address mode when there is a function call to the module. Accordingly, the module in memory may be accessed both before and after a switch in the mode of memory addressing without causing a system failure that would otherwise result from accessing a non-existent, or otherwise incorrect location in memory.

FIG. 1shows a typical computer system100that provides an operational environment for embodiments of the present invention. The computer architecture shown inFIG. 1illustrates a conventional personal computer, including a central processing unit102(“CPU”), a system memory104, including a random access memory106(“RAM”) and a read-only memory (“ROM”)108, and a system bus118that couples the memory to the CPU102. A BIOS containing the basic routines that help to transfer information between elements within the computer, such as during startup, is stored in the ROM108. The personal computer100further includes a mass storage device110for storing an operating system112and application programs114. The mass storage device110is connected to the CPU102through a mass storage controller (not shown) connected to the bus118. The personal computer100may also include an input/output controller116for receiving and processing input from a number of devices, including a keyboard or mouse (not shown). Similarly, an input/output controller116may provide output to a display screen, a printer, or other type of output device.

The mass storage device110and its associated computer-readable media, provide non-volatile storage for the personal computer100. Although the description of computer-readable media contained herein refers to a mass storage device, such as a hard disk or CD-ROM drive, it should be appreciated by those skilled in the art that computer-readable media can be any available media that can be accessed by the personal computer100. By way of example, and not limitation, computer-readable media may comprise computer storage media and communication media.

Computer storage media include volatile and non-volatile, removable and non-removable media implemented in any method or technology for storage of information such as computer-readable instructions, data structures, program modules or other data. Computer storage media include, but is not limited to, RAM, ROM, EPROM, EEPROM, flash memory or other solid state memory technology, CD-ROM, DVD, or other optical storage, magnetic cassettes, magnetic tape, magnetic disk storage or other magnetic storage devices, or any other medium which can be used to store the desired information and which can be accessed by the computer.

FIG. 2shows the two components of the system memory, the ROM device108and the RAM device106. The ROM device108includes a ROM image202that includes main BIOS code206, a ROM image header204, and various data modules208,210. Upon the computer starting to boot up, the BIOS code206being executed from the ROM device108by the processor102directs the processor102to make a complete copy of the ROM image202in RAM106. The RAM image106of the ROM108includes a BIOS code copy, a BIOS header copy, and a copy of the various data modules. Once the ROM image is copied to RAM106, the processor102continues to execute the remaining portions of the BIOS code copy and utilize the BIOS header copy and various data modules208,210from RAM for increased speed of access.

During the copy to RAM, a portable executable (“PE”) loader of the BIOS code206performs the copy. During the copying operation, the PE loader performs pointer value modification for the modules being copied because the pointer values in modules of the ROM image are only assumed pointer values made by the linker during compilation of the ROM image that are based on an assumed starting value for each of the modules. This starting value has an actual value once the module is in RAM, so the PE loader writes in the actual physical address starting value and then recalculates the proper pointer values based on the actual starting value and writes the new pointer values into the module. For a PE ROM image module, the starting value is located at offset28in the Optional header while it is stored in the Optional header at offset24for PE32+ ROM image modules. In a standard PE file, the Optional header can be found by finding the PE signature whose offset is specified at offset60from the beginning of the file module. The Optional PE header is located just after a File header that is located just after the PE signature.

As one example of a switch from a previous mode to a current mode, after the modules are copied to RAM and the proper physical address space pointer values are written into the modules, the computer system may transition to a virtual address space mode once the operating system loads. The operating system then notifies the BIOS core code206about the switch to virtual mode, and the BIOS core code206then converts the physical mode pointers to virtual mode pointers. At this point, the conventional ability to change the pointers ends such that upon a switch back to the physical mode, the module cannot be successfully called because there is no conventional mechanism to switch the pointers back to physical address mode pointers. However, embodiments of the present invention provide for logic within the modules to allow for subsequent conversion of pointer values due to subsequent changes from one mode of addressing to the next. Accordingly, such subsequent conversion of pointer values allows the modules to be successfully called after subsequent switches from one mode of memory addressing to another.

While various modules are transferred from ROM108and are unpacked when being stored in RAM106, for purposes of illustrationFIG. 2shows an example of one module212being placed in RAM106. The data module212has various portions that form a linked list in that pointer values stored in the module point to various locations of information within the module. In this example, the module212contains a main header portion214that contains a header signature portion216(e.g. MZ signature) and various offsets including a PE offset218indicating the location of the PE signature discussed above. The module212also includes a reallocation table222that maintains a set of offsets to the pointer values that point to the various locations of information including local variables and functions within the module212.

The module212also includes program data224, a program stack226, as well as the program code230. The program code230begins at a program entry point228. This program entry point location is identified by a pointer stored by the BIOS core code206once copied to RAM106, and this pointer is stored for both physical mode address space and virtual mode address space. The logic of the present invention may be located at the program point of entry228, prior to the remainder of the program code230such that once a function call to the module212occurs, the logic of the present invention is executed prior to the remainder of the program code to ensure that the pointer values of the module correspond to the current mode of memory addressing.

FIG. 3illustrates the logical operations that are performed by an embodiment of the present invention to detect a change in the mode of memory addressing so that the pointer values of the module may be changed accordingly. The logical operations begin at function operation302where the module in RAM receives a function call which directs the BIOS core to reference the program point of entry for the module whose address the BIOS core has stored upon the module being initially loaded in RAM. The BIOS core checks to determine the current mode of memory addressing prior to accessing the module so that the proper pointer mode will be used to find the program point of entry. The bit to check is dependent upon the processor in use. For example, with the Itanium® processor family by Intel®, the bit is located at offset17of the status register. Once at the program point of entry, execution of the program begins at program operation304. The beginning of execution of the program results in the remaining operations ofFIG. 3occurring.

Through execution of the program of the module, the pointer to the program point of entry of the module is decremented at decrement operation306by a set amount that is also dependent upon the particular processor to move from one boundary to a previous one. For example, the set amount to decrement is 8 bits for the Itanium® family of processors. Decrementing the pointer allows for searching of the main header for the module. Upon decrementing the pointer by the set amount, the module information at that location is read to determine if the main header is located at that position at read operation308. Query operation310detects whether the main header has been found. Several pieces of information may be sought when reading from the module to find the main header, including the MZ signature, the PE signature, the machine type, and the image type.

If the main header has not been found for the module, then operational flow returns to decrement operation306where the pointer is again decremented to continue searching for the main header of the module. If the main header has been found, then operational flow proceeds to change operation312where the pointer values are changed to correspond to the current mode of memory addressing. One example of logical operations as represented by change operation312for changing the pointer values is shown inFIG. 4, while an alternative set of location operations as represented by changer operation312for changing the pointer values is shown inFIG. 5.

The logical operations ofFIG. 3assume that the current mode of memory addressing has changed from the mode being used on any previous attempt to access the module. Thus, these logical operations may be preformed upon each attempt to access the module, and then the operations ofFIG. 4orFIG. 5will be implemented each time as well to convert the pointer values. If the mode has not changed since the previous access to the module, then there is no reason to convert the pointer values. One of ordinary skill will appreciate that rather than these logical operations ofFIG. 3making the assumption which may result in needless application of the conversion process, a value indicative of the previous mode may be stored at a known location and may be referred to each time there is an attempt to access the module. The previous mode may then be compared to the current mode that has been detected as noted above, and then the logical operations ofFIG. 3may proceed to decrement operation306only when the previous mode and the current mode differ. If they are the same, then there is no need to proceed with the logical operations ofFIG. 3as there is no need to convert the pointer values that are already in the proper mode.

The logical operations ofFIG. 4begin at address operation402where the starting address of the module for the current mode of memory addressing is obtained upon reaching the signature of the main header, through the operations ofFIG. 3, which lies at the new starting address. At address operation404, the starting address of the module for the previous mode of memory addressing (i.e., the mode last used when accessing module) is obtained by accessing it from the Optional header which is located within the module as discussed above. Upon finding both the new start address and the old start address, the difference between these two addresses is computed at computation operation406.

Once the difference between the old start address for the previous mode of memory addressing and the new start address for the current mode of memory addressing is known, it can be applied to the pointer values referenced by the reallocation table. The difference is applied to a pointer value referenced by the reallocation table to find the new pointer value at table operation408. The application of the difference value to the pointer value involves bit manipulations, adding the difference, and reverse bit manipulations. This process of applying the difference that has been found is well-known in the art, and is described in section 6.6 of the Microsoft® Portable Executable and Common Object File Format Specification, ver. 6.0, February 1999, by Microsoft Corporation. Upon finding the new pointer value, it is stored in place of the old pointer value referenced by the table at store operation410. Query operation412then detects whether there is another pointer value that is referenced by the table to change.

If there are additional pointer values in the table, operational flow proceeds to pointer operation414where the next pointer referenced by the table is obtained. Operational flow then returns to table operation408where the difference is again applied to the old pointer value to find the new pointer value. Once query operation412detects that there are no other pointer values referenced by the reallocation table, operational flow proceeds to store operation416where the current starting address of the module for the current mode of memory addressing is stored in the Optional header in place of the old starting address. Thus, the next time the memory addressing mode changes, this value for the starting address will be in place to allow the pointer values referenced by the reallocation table to be changed once again to correspond to the new mode of memory addressing. While it has been described that the new starting address value is stored after all pointer values have been changed, it will be appreciated that the new starting address value can be stored in the Optional header in place of the old starting value at any time after address operation404.

The logical operations of the alternative shown inFIG. 5begin at address operation502where the old starting address is found as described above, by starting from the signature of the main header to proceed to the Optional header where the old starting address is stored. Upon accessing the old starting value, a pointer value is obtained from the offset specified in the reallocation table at pointer operation504. A difference value is computed between the old starting value and the pointer value at computation operation506.

After finding the difference between the old starting value and the pointer value, this difference is then applied to the new starting value at pointer operation508to find the new pointer value to replace the pointer value that was used to find the difference value. The new starting value is known from the logical operations ofFIG. 3finding the start of the module by searching for the main header signature. The new pointer value is then stored at the location referenced by the reallocation table in place of the old pointer value at store operation510. Query operation512then detects whether there are additional pointer values in the table to be changed.

If there are additional pointer values referenced by the table to be changed, operational flow proceeds to pointer operation514where the next pointer referenced by the table is obtained. Operational flow then returns to computation operation506where the difference is again determined between the old pointer value just obtained and the old start value. Once query operation512detects that there are no other pointer values referenced by the reallocation table, operational flow proceeds to store operation516where the current starting address of the module for the current mode of memory addressing is stored in the Optional header in place of the old starting address to allow the pointer values referenced by the reallocation table to be changed once again should there be another change in the mode of memory addressing. Again, while it has been described that the new starting address value is stored after all pointer values have been changed, it will be appreciated that the new starting address value can be stored in the Optional header in place of the old starting value at any time after address operation502so long as the old starting value is maintained in some accessible location while the pointer values are being changed.

The logical operations ofFIGS. 4 and 5also assume that the current mode of memory addressing has changed from the mode used on any previous attempt to access the module. As noted above, this may be an accurate assumption as there may have been a check to determine whether the mode has changed before the logical operations ofFIG. 4or5are invoked. However, where the logical operations ofFIG. 3assume that the mode has changed rather than making such a determination, then the logical operations ofFIG. 4or5will be invoked upon every access of the module. One of ordinary skill will appreciate that rather than these logical operations ofFIG. 4or5being invoked to complete the conversion of pointer values, these logical operations may be modified so that if a difference of zero is detected at computation operation406or506, then the logical operations may terminate as the pointer value is already in the proper mode.