Execute in place

Execute in place

Discussion
Ask a question about 'Execute in place'
Start a new discussion about 'Execute in place'
Answer questions from other users
Full Discussion Forum
 
Encyclopedia
In computer science
Computer science
Computer science or computing science is the study of the theoretical foundations of information and computation and of practical techniques for their implementation and application in computer systems...

, execute in place (XIP) is a method of executing programs directly from long term storage rather than copying it into RAM. It is an extension of using shared memory
Shared memory
In computing, shared memory is memory that may be simultaneously accessed by multiple programs with an intent to provide communication among them or avoid redundant copies. Depending on context, programs may run on a single processor or on multiple separate processors...

 to reduce the total amount of memory required.

Its general effect is that the program text consumes no writable memory, saving it for dynamic data, and that all instances of the program are run from a single copy.

For this to work, several criteria have to be met:
  • The storage must provide a similar interface to the CPU
    Central processing unit
    The central processing unit is the portion of a computer system that carries out the instructions of a computer program, to perform the basic arithmetical, logical, and input/output operations of the system. The CPU plays a role somewhat analogous to the brain in the computer. The term has been in...

     as regular memory (or an adaptive layer must be present),
  • This interface must provide sufficiently fast read operations with a random access pattern,
  • The file system
    File system
    A file system is a means to organize data expected to be retained after a program terminates by providing procedures to store, retrieve and update data, as well as manage the available space on the device which contain it. A file system organizes data in an efficient manner and is tuned to the...

    , if one is used, needs to expose appropriate mapping functions,
  • The program must either be linked to be aware of the address the storage appears at in the system, or must be position-independent,
  • The program must not modify data within the loaded image.


The storage requirements are usually met by using NOR flash memory
Flash memory
Flash memory is a non-volatile computer storage chip that can be electrically erased and reprogrammed. It was developed from EEPROM and must be erased in fairly large blocks before these can be rewritten with new data...

, which can be addressed as individual words for read operations, although it is a bit slower than normal system RAM in most setups.

Typically, the first stage boot loader is an XIP program that is linked to run at the address at which the flash chip(s) are mapped at power-up and contains a minimal program to set up the system RAM (which depends on the components used on the individual boards and cannot be generalized enough so that the proper sequence could be embedded into the processor hardware) and then loads the second stage bootloader or the OS kernel into RAM.

During this initialization, no writable memory is available, so all computations have to be performed within the processor registers. For this reason, first stage boot loaders tend to be written in assembler language and only do the minimum to provide a normal execution environment for the next program.

For a kernel or bootloader, address space
Address space
In computing, an address space defines a range of discrete addresses, each of which may correspond to a network host, peripheral device, disk sector, a memory cell or other logical or physical entity.- Overview :...

 generally is assigned internally, so in order to use XIP for them, it is sufficient to instruct the linker to place unmodifiable and modifiable data in different address ranges and provide a mechanism for the modifiable data to be copied to writable memory before any code is run that assumes that data can be accessed normally. This can be done as part of the previous stage, or within a small code segment at the beginning of the program.

If address space is assigned externally, such as in an application program that is run on a system that does not provide virtual memory
Virtual memory
In computing, virtual memory is a memory management technique developed for multitasking kernels. This technique virtualizes a computer architecture's various forms of computer data storage , allowing a program to be designed as though there is only one kind of memory, "virtual" memory, which...

, the compiler needs to access all modifiable data by adding an offset to a pointer to a private copy of the data area. In this case, the external loader is responsible for setting up the instance specific memory areas.

XIP places requirements on file systems that are often difficult to meet. The entire file must be stored within consecutive bytes and may not be fragmented, while flash based file systems often aim to distribute data into sectors of the flash chip that have the least erase cycles and even out the wear
Wear leveling
Wear leveling is a technique for prolonging the service life of some kinds of erasable computer storage media, such as Flash memory used in solid-state drives and USB Flash drives...

 on the chip, prolonging its lifetime.

All these complications and the speed tradeoff mean that XIP is generally only used for first stage bootloaders or when memory is in extremely short supply.

A relatively new file system for Linux, called AXFS
AXFS
AXFS is a compressed read-only file system for Linux, initially developed at Intel, and now maintained at Numonyx. It was designed to utilize execute in place alongside compression aiming to reduce boot and program load times, while retaining a small memory footprint for embedded devices...

 (Advanced XIP File System), aims to overcome some of the shortcomings associated with XIP, especially in regard to the in-place execution of user-space applications. It makes for instance possible to split up an executable binary file into "XIP regions", thus avoiding the restriction of fragmentation that was mentioned above.

A NetBSD
NetBSD
NetBSD is a freely available open source version of the Berkeley Software Distribution Unix operating system. It was the second open source BSD descendant to be formally released, after 386BSD, and continues to be actively developed. The NetBSD project is primarily focused on high quality design,...

implementation is also under development.