Jump to content

Zero page

From Wikipedia, the free encyclopedia

This is an old revision of this page, as edited by 92.249.211.155 (talk) at 05:24, 9 September 2019 (Try to tidy up the explanation of why zero page is protection against null pointer dereferencin). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

The zero page is the series of memory addresses at the very beginning of a computer's address space; that is, the page whose starting address is zero. The size of a "page" depends on the context, and the significance of zero-page memory versus higher addressed memory is highly dependent on machine architecture. For example, the Motorola 6800 and MOS Technology 6502 processor families treat the first 256 bytes of memory specially,[1] whereas many other processors do not.

The actual size of the zero page in bytes is determined by the microprocessor design and in older designs, is often equal to the largest value that can be referenced by the processor's indexing registers. For example, the aforementioned 8-bit processors have 8-bit index registers and a page size of 256 bytes. Therefore, their zero page extends from address 0 to address 255.

In early computers, including the PDP-8, the zero page had a special fast addressing mode, which facilitated its use for temporary storage of data and compensated for the relative shortage of CPU registers. The PDP-8 had only one register, so zero page addressing was essential.

Unlike more modern hardware, in the 1970s computer RAM was as fast or faster than the CPU. Thus it made sense to have few registers and use the main memory as an extended pool of extra registers. Since each memory location within the zero page of a 16-bit address bus computer may be addressed by a single byte, it was faster, in 8-bit data bus machines, to access such a location rather than a non-zero page location.

For example, the MOS Technology 6502 has only one general purpose register (the accumulator). As a result, it used the zero page extensively. Many instructions are coded differently for zero page and non-zero page addresses:

 LDA $00            ; zero page
 LDA $0000          ; non-zero page

The above two instructions both accomplish the same thing: they load the value of memory location $00 into the .A register (accumulator). However, the first instruction is only two bytes long and requires three clock cycles to complete. The second instruction is three bytes in length and requires four clock cycles to execute. This difference in execution time could become significant in repetitive code.

Zero page addressing now has mostly historical significance, since the developments in integrated circuit technology have made adding more registers to a CPU less expensive and CPU operations much faster than RAM accesses. Some computer architectures still reserve the beginning of address space for other purposes, though; for instance, Intel x86 systems reserve the first 512 words of address space for the interrupt table if they run in real mode. A similar technique of using the zero page for hardware related vectors was employed in the ARM architecture, leading in some badly written programs to the infamous "ofla" behaviour, which is when a program tries to read information from an unintended memory area, and winds up mistaking executable code for data or vice versa. This is especially a problem if the zero page area is used to store system jump vectors and the firmware is tricked into storing data there.[2]

Contrary to the zero page's original preferential use, some modern operating systems such as FreeBSD, Linux and Microsoft Windows[3] actually make the zero page inaccessible to trap uses of null pointers. Such a pointer does not point to a valid object, and typically is represented as the memory address "0", in zero page. Since code reaching through (dereferencing) a pointer will assume that it points to a valid object, any attempt to dereference a null pointer is a runtime bug.

CP/M

In 8-bit CP/M, the zero page is used for communication between the running program and the operating system.

See also

References

  1. ^ Sjödin, Tomas; Jonsson, Johan (2006). Student Papers in Computer Architecture (PDF). Umeå, Sweden. p. 29. Retrieved 21 August 2019.{{cite book}}: CS1 maint: location missing publisher (link)
  2. ^ "ARM 'security hole' is ofla cousin". drobe.co.uk. 2007-04-24. Retrieved 2008-10-22.
  3. ^ "Managing Virtual Memory". microsoft.com. 2014-12-05. Retrieved 2014-12-05.

Further reading