Memory segmentation

Segmentation refers to the memory management in an operating system, the subdivision of the memory address space used in individual segments. The purpose of the subdivision is usually the implementation of protection mechanisms or virtual memory management. Depending on the operating system and underlying hardware a segment various attributes can be assigned. Thus, program, data and stack segments can for example be defined. The memory management then provides, among other things, that from the program segment only commands but no data is read, or that data in the data segment can not be interpreted as commands. Often, it is also possible to assign privilege levels segments, so you can access the corresponding segments of programs only certain privileged levels. You can protect by other programs such as operating system data and commands from access. Often, the type of access may (for example, read only, write only, no access) to be restricted. Some systems also allow privilege level -dependent types of access restriction.

Memory addressing with segmentation

A segment is defined by two values:

Is segmented into a rule, the physical address space directly, or virtual linear address space that maps to the physical address space. The segmentation is a so-called logical address space is formed. Logical addresses are divided into a segment selector and an offset. The segment selector determined directly or indirectly, on a segment management table, the addressed segment and thus the segment start address and length. The offset is relative to the segment start, the location within this segment to.

If a logical address is the linear address determines the segment base properties, length, type, read and write permissions, etc. are initially determined by the segment selector. It is then checked based on the determined segment properties, whether the memory access is allowed. Furthermore, the offset is compared to the segment length to ensure that the access is within the segment limits. Fails any of these checks, error handling (interrupt, exception, etc.) is initiated. The offset is added to the segment base address and provides the linear address. If the linear address space is not the physical, the linear address is converted by a subsequent page management ( eng. "paging unit" ) to a physical address.

These address conversions typically taken in modern computers of memory management units, which are integrated in many modern processors.

Examples

Intel's x86 processors in real mode

During 8086 and newer x86ern in real mode segment base address is calculated directly from the segment selector of the logical address. All segments have a fixed length of 64 KiB. A logical address is usually written in real mode programs as follows: segment: offset, where segment and offset 16 -bit numbers and are usually specified in hexadecimal, for example: 2F10: 87A1.

This logical address is as follows translated into a physical:

Physically address = segment selector logic · 16 offset logically

In the example results for the physical address:

0x2F10 · 16 0x87A1 = 0x2F10 · 0x10 0x87A1 0x87A1 = 0x2F100 = 0x378A1

With this addressing can extend the physical address width of 20 bits, since the 16 -bit segment address to a 20 -bit number by multiplying by 16, to which the offset is not added. These 20 bits can be addressed on a 16 -bit processor, at least up to 1 MiB RAM. In fact, under certain circumstances by the carry in the addition even 21 -bit numbers arise in the address calculation, so it can be addressed by slightly more than 1 MiB memory. For more information, please refer to the article High Memory Area and A20 gate.

Intel's x86 processors in protected mode

From Intel's 80286 processor, the so-called Protected Mode has been introduced. Here, segments between one byte and 64K ( from 80386 up to 4 gigabytes ) in length and begin at arbitrary byte positions in the linear address space. Each segment is referred to by a special data structure, segment descriptor is described. In addition to the segment base address and the segment length a segment descriptor also contains information on segment attributes such as segment type, privilege level, and read and write permissions. Segment descriptors are read from lying in the memory descriptor. These tables are built and managed by the operating system. The segment selector to a logical address indicates the descriptor table and the index of a segment descriptor in the table. Then the data necessary for address calculation data are read from the selected segment descriptor.

History

The segmentation was formerly a particularly important opportunity to address more memory than the existing address lines or the size ( number of bits ) of processor registers was alone possible. Also to outsource entire processes and to retain memory segmentation was used. But with more powerful processors, it was through the paging to segmentation with page addressing ( segmentation with paging ) expanded, which allowed a more fine-grained and flexible management of the memory. Common operating systems make use of the mechanisms of segmenting in 64- bit mode no more extensive use and instead use extensively paging. Only the operating system kernel is privileged by a higher privilege data and code segment of the other programs separately ( "Protected Flat Model ").

  • Memory management
  • Computer Architecture
721275
de