Bank switching

From Wikipedia, the free encyclopedia
  (Redirected from Bank switch)
Jump to: navigation, search

Bank switching is a technique to increase the amount of usable memory beyond the amount directly addressable by the processor.[1] It can be used to configure a system differently at different times; for example, a ROM required to start a system from diskette could be switched out when no longer needed. In video game systems, bank switching allowed larger games to be developed for play on existing consoles.

Bank switching originated in minicomputer systems.[2] Many modern microcontrollers and microprocessors use bank switching to manage random-access memory, non-volatile memory, input-output devices and system management registers in small embedded systems. The technique was common in 8-bit microcomputer systems. Bank-switching may also be used to work around limitations in address bus width, where some hardware constraint prevents straightforward addition of more address lines. Some control-oriented microprocessors use a bank-switching technique to access internal I/O and control registers, which limits the number of register address bits that must be used in every instruction.

Unlike memory management by paging, data is not exchanged with a mass storage device like disk memory. Data remains in quiescent storage in a memory area that is not currently accessible to the processor, (although it may be accessible to the video display, DMA controller, or other subsystems of the computer).

Technique[edit]

Bank switching can be considered as a way of extending the address bus of a processor with some external register. For example, a processor with a 16-bit external address bus can only address 216 = 65536 memory locations. If an external latch was added to the system, it could be used to control which of two sets of memory devices, each with 65536 addresses, could be accessed. The processor could change which set is in current use by setting or clearing the latch bit.

The latch can be set or cleared by the processor in several ways; a particular memory address may be decoded and used to control the latch, or, in processors with separately-decoded I/O addresses, an output address may be decoded. Several bank-switching control bits could be gathered into a register, approximately doubling the available memory spaces with each additional bit in the register.

Because the external bank-selecting latch (or register) is not directly connected with the program counter of the processor, it does not automatically change state when the program counter overflows; this cannot be detected by the external latch since the program counter is an internal register of the processor. The extra memory is not seamlessly available to programs. Internal registers of the processor remain at their original length, so the processor cannot directly span all of bank-switched memory by, for example, incrementing an internal register.[3] Instead the processor must explicitly do a bank-switching operation to access large memory objects. There are other limitations. Generally a bank-switching system will have one block of program memory that is common to all banks; no matter which bank is currently active, for part of the address space only one set of memory locations will be used. This area would be used to hold code that manages the transitions between banks, and also to process interrupts.

Unlike a virtual memory scheme, bank-switching must be explicitly managed by the running program or operating system; the processor hardware cannot automatically detect that data not currently mapped into the active bank is required. The application program must keep track of which memory bank holds a required piece of data, and then call the bank-switching routine to make that bank active. [4] However, bank-switching can access data much faster than, for example, retrieving the data from disk.

A hypothetical memory map of bank-switched memory for a processor that can only address 64 kB. This scheme shows 200 kB of memory, of which only 64 kb can be accessed at any time by the processor. The operating system must manage the bank-switching operation to ensure that program execution can continue when part of memory is not accessible to the processor.

Microcomputer use[edit]

Processors with 16-bit addressing (Z80, 6502, 6809, etc.) commonly used in early video game consoles and home computers can directly address only 64 KB. Systems with more memory had to divide the address space into a number of blocks that could be dynamically mapped into parts of a larger address space. Blocks of various sizes were switched in and out via bank select registers or similar mechanisms. Some blocks typically were always enabled. Some caution was required in order not to corrupt the handling of subroutine calls, interrupts, the machine stack, and so on. While the contents of memory temporarily switched out from the CPU was inaccessible to the processor, it could be used by other hardware, such as video display, DMA, I/O devices, etc. The last version of CP/M released in 1982 supported bank switching to allow use of more than the 64K of memory that the 8080 or Z80 processor could address. [5]

Bank switching allowed extra memory and functions to be added to a computer design without the expense and incompatibility of switching to a processor with a wider address bus. For example, the C64 used bank switching to allow for a full 64KB of RAM and still provide for ROM and memory-mapped I/O as well. The Atari 130XE could allow its two processors (the 6502 and the ANTIC) to access separate RAM banks, allowing programmers on both machines to make large playfields and other graphic objects without using up the memory visible to the CPU.

The Sojourner rover uses a 80C85 with external bank switching hardware that extends the normal 64KByte address range to allow it to access more than 512KByte of RAM, 16KByte at a time. [6] Another prototype of a Mars rover used a 80C51 with external memory bank switching hardware to access 256KByte of SRAM.[7]

The IBM PC[edit]

Expanded memory in the IBM PC

In 1985 the companies Lotus and Intel introduced Expanded Memory Specification (EMS) 3.0 for use in IBM PC compatible computers running MS-DOS. Microsoft joined for versions 3.2 in 1986 and 4.0 in 1987 and the specification became known as Lotus-Intel-Microsoft EMS or LIM EMS.[8][9][4] It is a form of bank switching technique that allows more than the 640 KB of RAM defined by the original IBM PC architecture, by letting it appear piecewise in a 64 KB "window" located in the Upper Memory Area.[10] The 64 KB is divided into four 16 KB "pages" which can each be independently switched. Some computer games made use of this, and though EMS is obsolete, the feature is nowadays emulated by later Microsoft Windows operating systems to provide backwards compatibility with those programs.

The later eXtended Memory Specification (XMS), also now obsolete, is a standard for, in principle, simulating bank switching for memory above 1 MB (called "extended memory"), which is not directly addressable in the Real Mode of x86 processors in which MS-DOS runs. XMS allows extended memory to be copied anywhere in conventional memory, so the boundaries of the "banks" are not fixed, but in every other way it works like the bank switching of EMS, from the perspective of a program that uses it. Later versions of MS-DOS (starting circa version 5.0) included the EMM386 driver, which simulates EMS memory using XMS, allowing programs to use extended memory even if they were written for EMS. Microsoft Windows emulates XMS also, for those programs that require it.

Video game consoles[edit]

Bank switching was also utilized in some video game consoles. [11] The Atari 2600, for instance, could only address 4 KB of ROM, so later 2600 game cartridges contained their own bank switching hardware in order to permit the use of more ROM and thus allow for more sophisticated games (via more program code and, equally important, larger amounts of game data such as graphics and different game stages).[12] The Nintendo Entertainment System contained a modified 6502 but its cartridges sometimes contained a megabit or more of ROM, addressed via bank switching called a Multi-Memory Controller. Game Boy cartridges used a chip called MBC (Memory Bank Controller), which not only offered ROM bank switching, but also cartridge SRAM bank switching, and even access to such peripherals as infrared links or rumble motors. Bank switching was still being used on later game systems. Several Sega Mega Drive cartridges were over 4MB in size and required the use of this technique[citation needed] (4MB being the maximum address size). The GP2X handheld from Gamepark Holdings uses bank switching in order to control the start address (or memory offset) for the second processor.

Alternative and successor techniques[edit]

Bank switching was later supplanted by segmentation in many 16-bit systems, which in turn gave way to paging memory management units. In embedded systems, however, bank switching is still often used, for its simplicity, low cost, and often better adaptation to those contexts than to general purpose computing.

Video processing[edit]

In some types of computer video displays, the related technique of double buffering may be used to improve video performance. In this case, while the processor is updating the contents of one set of physical memory locations, the video generation hardware is accessing and displaying the contents of a second set. When the processor has completed its update, it can signal to the video display hardware to swap active banks, so that the transition visible on screen is free of artifacts or distortion. In this case, the processor may have access to all the memory at once, but the video display hardware is bank-switched between parts of the video memory. If the two (or more) banks of video memory contain slightly different images, rapidly cycling (page-flipping) between them can create animation or other visual effects that the processor might otherwise be too slow to carry out directly.

See also[edit]

Computers using bank switching[edit]

External links[edit]

References[edit]

  1. ^ D. Aspinall (ed), The Microprocessor and its application: an advanced course, CUP Archive, 1978, ISBN 0-521-22241-9 pp.47-50
  2. ^ C. Gordon Bell, Allen Newell Computer structures: readings and examples,Mc Graw Hill, 1971 page 156
  3. ^ Steve Heath, Embedded systems design Newnes, 2003 ISBN 0-7506-5546-1 page 242
  4. ^ a b Scott Mueller Upgrading and Repairing PCs, Second Edition, Que Books, 1992, ISBN 0-88022-856-3 pages 699-700
  5. ^ Paul Freiberger, Digital Research offers CP/M upgrade, Info World October 25, 1982 page 1
  6. ^ Jake Matijevic, et al. "Mars Pathfinder Frequently Asked Questions: Sojourner Rover". 1997.
  7. ^ E. Tunstel, R. Welch, B. Wilcox. "Embedded control of a miniature science rover for planetary exploration". doi:10.1.1.52.8645. 1998.
  8. ^ New 1-2-3 Gets 4 Megabytes of Memory, Lotus, Intel Break PC-DOS Memory Barrier, InfoWorld, Apr 29, 1985
  9. ^ EMS Update Gives DOS Improved Multitasking, InfoWorld, Aug 17, 1987
  10. ^ Paul W. Ross (ed.), The Handbook of Software for Engineers and Scientists CRC Press, 1995 ISBN 0-8493-2530-7 page 26
  11. ^ Brian Sinofsky in Charles W. Carey, American inventors, entrepreneurs & business visionaries , Infobase Publishing, 2002 ISBN 0-8160-4559-3, pages 322-324
  12. ^ Joe Grand, Ryan Russell, Kevin D. Mitnick ,Hardware hacking: have fun while voiding your warranty, Syngress, 2004 ISBN 1-932266-83-6, page 229