Content deleted Content added
Guy Harris (talk | contribs) →x86 architecture: Many OSes started using paging with IA-32, before x86-64. Copyedit a bit. (Still needs an explanation of 1) 32-bit OSes using the segment registers for some purposes, such as making writable regions of the address space non-executable and *vice versa*, and providing thread-specific data and 2) what the stub segmentation in x86-64 does and how it's used (e.g., for thread-specific data). |
reworded descriptions. joined semi-split paragraphs. sorted. |
||
Line 1:
{{Short description|The division of computer's primary memory into separately relocatable segments or sections}}
{{
{{
'''Memory segmentation''' is an [[operating system]] [[memory management (operating systems)|memory management]] technique of
Segments usually correspond to natural divisions of a program such as individual routines or data tables<ref name="holt1961"/> so segmentation is generally more visible to the programmer than [[paging]] alone.<ref name="englander"/> Segments may be created for program [[module (programming)|module]]s, or for classes of memory usage such as [[code segment]]s and [[data segment]]s.<ref name="glaser1965"/> Certain segments may be shared between programs.<ref name="holt1961"/><ref name="englander"/>
Segmentation was originally invented as a method by which [[system software]] could isolate software [[
==Hardware implementation==
In a system using segmentation, computer memory addresses consist of a segment id and an offset within the segment.<ref name="glaser1965"/> A hardware [[memory management unit]] (MMU) is responsible for translating the segment and offset into a [[physical
▲A hardware [[memory management unit]] (MMU) is responsible for translating the segment and offset into a [[physical address]], and for performing checks to make sure the translation can be done and that the reference to that segment and offset is permitted.
Each segment has a length and set of permissions (for example, ''read'', ''write'', ''execute'') associated with it.<ref name="glaser1965"/> A [[process (computing)|process]] is only allowed to make a reference into a segment if the type of reference is allowed by the permissions, and if the offset within the segment is within the range specified by the length of the segment. Otherwise, a [[hardware exception]] such as a [[segmentation fault]] is raised.
Segments may also be used to implement [[virtual memory]]. In this case each segment has an associated flag indicating whether it is present in main memory or not. If a segment is accessed that is not present in main memory, an exception is raised, and the [[operating system]] will read the segment into memory from secondary storage.▼
▲In this case each segment has an associated flag indicating whether it is present in main memory or not. If a segment is accessed that is not present in main memory, an exception is raised, and the [[operating system]] will read the segment into memory from secondary storage.
Segmentation is one method of implementing [[memory protection]].<ref name="ostep-1">{{cite book |title=Operating Systems: Three Easy Pieces |chapter=Segmentation |chapter-url=http://pages.cs.wisc.edu/~remzi/OSTEP/vm-segmentation.pdf |publisher=
Segmentation has been implemented several ways on various hardware, with or without paging. Intel [[x86 memory segmentation]] does not fit either model and is discussed separately below, and also in greater detail in a separate article.
Line 26 ⟶ 22:
Associated with each segment is information that indicates where the segment is located in memory— the ''segment base''. When a program references a memory ___location, the offset is added to the segment base to generate a physical memory address.
An implementation of virtual memory on a system using segmentation without paging requires that entire segments be swapped back and forth between main memory and secondary storage.
===Segmentation with paging===
Instead of a memory ___location, the segment information includes the address of a [[page table]] for the segment.
When a program references a memory ___location the offset is translated to a memory address using the page table.
An implementation of [[virtual memory]] on a system using segmentation with paging usually only moves individual pages back and forth between main memory and secondary storage, similar to a paged non-segmented system. Pages of the segment can be located anywhere in main memory and need not be contiguous. This usually results in a reduced amount of input/output between primary and secondary storage and reduced memory fragmentation.
==History==
The [[Burroughs Corporation]] [[Burroughs large systems|B5000]] computer was one of the first to implement segmentation, and "perhaps the first commercial computer to provide virtual memory"<ref>{{cite web |last=Mayer |first=Alastair J. W. |title=The Architecture of the Burroughs B5000 - 20 Years Later and Still Ahead of the Times? |url=http://www.smecc.org/The%20Architecture%20%20of%20the%20Burroughs%20B-5000.htm |access-date=2012-03-15}}</ref> based on segmentation.
The [[GE-600 series|GE-645]] computer, a modification of the GE-635 with segmentation and paging support added, was designed in 1964 to support [[Multics]].
The [[Intel iAPX 432]],<ref>{{cite book |publisher=Intel Corporation |title=Introduction to the IAPX 432 Architecture |date=1981 |pages=78 |url=http://bitsavers.org/components/intel/iAPX_432/171821-001_Introduction_to_the_iAPX_432_Architecture_Aug81.pdf}}</ref> begun in 1975, attempted to implement a true segmented architecture with memory protection on a microprocessor.
The 960MX version of the [[Intel i960]] processors supported load and store instructions with the source or destination being an "access descriptor" for an object, and an offset into the object, with the access descriptor being in a 32-bit register and with the offset computed from a base offset in the next register and from an additional offset and, optionally, an index register specified in the instruction.
[[Prime Computer|Prime]], [[Stratus Technologies|Stratus]], [[Apollo Computer|Apollo]], [[IBM System/38]], and [[IBM AS/400]] (including [[IBM i]]) computers use memory segmentation.
==Examples==
===S/370 architecture===
In the [[IBM System/370]] models{{efn|Models 115, 125, 135, 138, 145, 148, 155 II, 158, 165 II, and 168}} with virtual storage<ref name="S370">{{cite
| section = Dynamic Address Translation▼
| section-url = http://www.bitsavers.org/pdf/ibm/370/princOps/GA22-7000-4_370_Principles_Of_Operation_Sep75.pdf#page=57▼
▲ | pages = 57–68
| url = http://www.bitsavers.org/pdf/ibm/370/princOps/GA22-7000-4_370_Principles_Of_Operation_Sep75.pdf▼
▲
▲ | work = Systems
▲
▲ | publisher = IBM
</ref><ref name="S370-10">{{cite
</ref> (DAT) and 24-bit addresses, [[control register]] 0 specifies a segment size of either 64 KiB or 1 MiB and a page size of either 2 KiB or 4 KiB; control register 1 contains a Segment Table Designator (STD), which specifies the length and real address of the segment table. Each segment table entry contains a page table ___location, a page table length and an invalid bit. IBM later expanded the address size to 31 bits and added two bits to the segment table entries:
;Segment-
:Segment is read-only
;Common-
:The segment is shared between address spaces; this bit is set to optimize TLB use
Each of IBM's DAT implementations includes a translation cache, which IBM called a Translation Lookaside Buffer (TLB). While Principles of Operation discusses the TLB in general terms, the details are not part of the architecture and vary from model to model.
Starting with the [[IBM 303X|3031, 3032, and 3033]] processor complexes, IBM offered a feature called ''Dual-address Space''<ref name="S370-10"/>{{rp|at=Dual-Address-Space Control|pp=5-13-5-17}}{{rp|at=DAS Authorization Mechanisms|pp=5-17-5-20}}{{rp|at=PC-Number Translation|pp=5-21-5-24}}<ref name="S370-XA">{{cite
| section = Address spaces▼
| section-url = http://bitsavers.org/pdf/ibm/370/princOps/SA22-7085-1_370-XA_Principles_of_Operation_Jan87.pdf#page=40▼
▲ | pages = 3-13-3-14
▲
▲ | publisher = IBM
</ref> (DAS), which allows a program to switch between the translation tables for two address spaces, referred to as ''primary address space'' (CR1) and ''secondary address space'' (CR7), and to move data between the address spaces subject to protection key. DAS supports a translation table to convert a 16-bit address space number (ASN) to an STD, with privileged instructions to load the STD into CR1 (primary) or CR7 (secondary).
Line 95 ⟶ 92:
Early [[x86]] processors, beginning with the [[Intel 8086]], provide crude memory segmentation and no [[memory protection]]. (Every byte of every segment is always available to any program.) The 16-bit segment registers allow for 65,536 segments; each segment begins at a fixed offset equal to 16 times the segment number; the segment starting address granularity is 16 bytes. Each segment grants read-write access to 64 KiB (65,536 bytes) of address space (this limit is set by the 16-bit PC and SP registers; the processor does no bounds checking). Offset+address exceeding 0xFFFFF wraps around to 0x00000. Each 64 KiB segment overlaps the next 4,095 segments; each physical address can be denoted by 4,096 segment–offset pairs. This scheme can address only 1 MiB (1024 KiB) of physical memory (and memory-mapped i/o). (Optional [[expanded memory]] hardware can add bank-switched memory under software control.) Intel retroactively named the sole operating mode of these x86 CPU models "[[real mode]]".
The [[Intel 80286]] and later processors add "286 [[protected mode]]", which
The
The [[x86-64]] architecture does not support segmentation in "[[long mode]]" (64-bit mode).<ref name=":1">{{cite book |title=AMD64 Technology AMD64 Architecture Programmer's Manual Volume 2: System Programming |publisher=Advanced Micro Devices |volume=2 |date=2018 |url=https://www.amd.com/system/files/TechDocs/24594.pdf}}</ref> In [[X86-64]] architecture, memory segmentation is considered legacy, and most x86-64-based modern system software does not use it
==
* [[BSS Segment]]▼
* [[Data segment]]▼
* [[Flat memory model]]▼
* [[Memory management (operating systems)]]
* [[Segmentation fault]]▼
* [[Virtual address space]]
* [[Virtual memory]]
▲* [[Data segment]]
▲* [[BSS Segment]]
* [[x86 memory segmentation]]
▲* [[Segmentation fault]]
▲* [[Flat memory model]]
==
{{
==
{{
<ref name="holt1961">{{cite journal
|title=Program Organization and Record Keeping for Dynamic Storage Allocation
Line 131 ⟶ 128:
<ref name="glaser1965">{{cite conference
|title=System Design of a Computer for Time Sharing Applications
|url=https://multicians.org/fjcc2.html▼
|first1=Edward L.▼
|last1=Glaser
▲|first1=Edward L.
|first2=John F.
|last2=Couleur▼
|first3=G. A.
▲|last2=Couleur
|last3=Oliver
|date=1965
|conference=1965 Fall Joint Computer Conference
▲|url=https://multicians.org/fjcc2.html}}
</ref>
<ref name="englander">{{cite book
Line 150 ⟶ 147:
==External links==
*IA-32 Intel Architecture Software Developer’s Manual Volume 3A: System Programming Guide. http://www.intel.com/products/processor/manuals/index.htm.
*Operating Systems: Internals and Design Principles by William Stallings. Publisher:
{{Memory management
{{
[[Category:Memory management]]
|