<s>
Memory	B-General_Concept
segmentation	I-General_Concept
is	O
an	O
operating	B-General_Concept
system	I-General_Concept
memory	B-General_Concept
management	I-General_Concept
technique	O
of	O
dividing	O
a	O
computer	O
's	O
primary	O
memory	O
into	O
segments	O
or	O
sections	O
.	O
</s>
<s>
In	O
a	O
computer	B-General_Concept
system	I-General_Concept
using	O
segmentation	B-General_Concept
,	O
a	O
reference	O
to	O
a	O
memory	O
location	O
includes	O
a	O
value	O
that	O
identifies	O
a	O
segment	O
and	O
an	O
offset	B-General_Concept
(	O
memory	O
location	O
)	O
within	O
that	O
segment	O
.	O
</s>
<s>
Segments	O
or	O
sections	O
are	O
also	O
used	O
in	O
object	B-Application
files	I-Application
of	O
compiled	O
programs	O
when	O
they	O
are	O
linked	B-Application
together	O
into	O
a	O
program	B-Application
image	I-Application
and	O
when	O
the	O
image	O
is	O
loaded	B-Operating_System
into	O
memory	O
.	O
</s>
<s>
Segments	O
usually	O
correspond	O
to	O
natural	O
divisions	O
of	O
a	O
program	O
such	O
as	O
individual	O
routines	O
or	O
data	O
tables	O
so	O
segmentation	B-General_Concept
is	O
generally	O
more	O
visible	O
to	O
the	O
programmer	O
than	O
paging	B-Architecture
alone	O
.	O
</s>
<s>
Segments	O
may	O
be	O
created	O
for	O
program	O
modules	B-Architecture
,	O
or	O
for	O
classes	O
of	O
memory	O
usage	O
such	O
as	O
code	B-General_Concept
segments	I-General_Concept
and	O
data	B-General_Concept
segments	I-General_Concept
.	O
</s>
<s>
Segmentation	B-General_Concept
was	O
originally	O
invented	O
as	O
a	O
method	O
by	O
which	O
system	B-Application
software	I-Application
could	O
isolate	O
software	O
processes	B-Operating_System
(	O
tasks	B-General_Concept
)	O
and	O
data	O
they	O
are	O
using	O
.	O
</s>
<s>
It	O
was	O
intended	O
to	O
increase	O
reliability	O
of	O
the	O
systems	O
running	O
multiple	O
processes	B-Operating_System
simultaneously	O
.	O
</s>
<s>
In	O
a	O
system	O
using	O
segmentation	B-General_Concept
,	O
computer	O
memory	O
addresses	O
consist	O
of	O
a	O
segment	O
id	O
and	O
an	O
offset	B-General_Concept
within	O
the	O
segment	O
.	O
</s>
<s>
A	O
hardware	O
memory	B-General_Concept
management	I-General_Concept
unit	I-General_Concept
(	O
MMU	B-General_Concept
)	O
is	O
responsible	O
for	O
translating	O
the	O
segment	O
and	O
offset	B-General_Concept
into	O
a	O
physical	B-General_Concept
address	I-General_Concept
,	O
and	O
for	O
performing	O
checks	O
to	O
make	O
sure	O
the	O
translation	O
can	O
be	O
done	O
and	O
that	O
the	O
reference	O
to	O
that	O
segment	O
and	O
offset	B-General_Concept
is	O
permitted	O
.	O
</s>
<s>
A	O
process	B-Operating_System
is	O
only	O
allowed	O
to	O
make	O
a	O
reference	O
into	O
a	O
segment	O
if	O
the	O
type	O
of	O
reference	O
is	O
allowed	O
by	O
the	O
permissions	O
,	O
and	O
if	O
the	O
offset	B-General_Concept
within	O
the	O
segment	O
is	O
within	O
the	O
range	O
specified	O
by	O
the	O
length	O
of	O
the	O
segment	O
.	O
</s>
<s>
Otherwise	O
,	O
a	O
hardware	B-General_Concept
exception	I-General_Concept
such	O
as	O
a	O
segmentation	B-Error_Name
fault	I-Error_Name
is	O
raised	O
.	O
</s>
<s>
Segments	O
may	O
also	O
be	O
used	O
to	O
implement	O
virtual	B-Architecture
memory	I-Architecture
.	O
</s>
<s>
If	O
a	O
segment	O
is	O
accessed	O
that	O
is	O
not	O
present	O
in	O
main	O
memory	O
,	O
an	O
exception	O
is	O
raised	O
,	O
and	O
the	O
operating	B-General_Concept
system	I-General_Concept
will	O
read	O
the	O
segment	O
into	O
memory	O
from	O
secondary	O
storage	O
.	O
</s>
<s>
Segmentation	B-General_Concept
is	O
one	O
method	O
of	O
implementing	O
memory	B-General_Concept
protection	I-General_Concept
.	O
</s>
<s>
Paging	B-Architecture
is	O
another	O
,	O
and	O
they	O
can	O
be	O
combined	O
.	O
</s>
<s>
The	O
size	O
of	O
a	O
memory	B-General_Concept
segment	I-General_Concept
is	O
generally	O
not	O
fixed	O
and	O
may	O
be	O
as	O
small	O
as	O
a	O
single	O
byte	B-Application
.	O
</s>
<s>
Segmentation	B-General_Concept
has	O
been	O
implemented	O
several	O
ways	O
on	O
various	O
hardware	O
,	O
with	O
or	O
without	O
paging	B-Architecture
.	O
</s>
<s>
Intel	B-Operating_System
x86	I-Operating_System
memory	B-General_Concept
segmentation	I-General_Concept
does	O
not	O
fit	O
either	O
model	O
and	O
is	O
discussed	O
separately	O
below	O
,	O
and	O
also	O
in	O
greater	O
detail	O
in	O
a	O
separate	O
article	O
.	O
</s>
<s>
When	O
a	O
program	O
references	O
a	O
memory	O
location	O
,	O
the	O
offset	B-General_Concept
is	O
added	O
to	O
the	O
segment	O
base	O
to	O
generate	O
a	O
physical	O
memory	O
address	O
.	O
</s>
<s>
An	O
implementation	O
of	O
virtual	B-Architecture
memory	I-Architecture
on	O
a	O
system	O
using	O
segmentation	B-General_Concept
without	O
paging	B-Architecture
requires	O
that	O
entire	O
segments	O
be	O
swapped	O
back	O
and	O
forth	O
between	O
main	O
memory	O
and	O
secondary	O
storage	O
.	O
</s>
<s>
When	O
a	O
segment	O
is	O
swapped	O
in	O
,	O
the	O
operating	B-General_Concept
system	I-General_Concept
has	O
to	O
allocate	O
enough	O
contiguous	O
free	O
memory	O
to	O
hold	O
the	O
entire	O
segment	O
.	O
</s>
<s>
Often	O
memory	B-Architecture
fragmentation	I-Architecture
results	O
if	O
there	O
is	O
not	O
enough	O
contiguous	O
memory	O
even	O
though	O
there	O
may	O
be	O
enough	O
in	O
total	O
.	O
</s>
<s>
Instead	O
of	O
a	O
memory	O
location	O
,	O
the	O
segment	O
information	O
includes	O
the	O
address	O
of	O
a	O
page	B-General_Concept
table	I-General_Concept
for	O
the	O
segment	O
.	O
</s>
<s>
When	O
a	O
program	O
references	O
a	O
memory	O
location	O
the	O
offset	B-General_Concept
is	O
translated	O
to	O
a	O
memory	O
address	O
using	O
the	O
page	B-General_Concept
table	I-General_Concept
.	O
</s>
<s>
A	O
segment	O
can	O
be	O
extended	O
by	O
allocating	O
another	O
memory	B-General_Concept
page	I-General_Concept
and	O
adding	O
it	O
to	O
the	O
segment	O
's	O
page	B-General_Concept
table	I-General_Concept
.	O
</s>
<s>
An	O
implementation	O
of	O
virtual	B-Architecture
memory	I-Architecture
on	O
a	O
system	O
using	O
segmentation	B-General_Concept
with	O
paging	B-Architecture
usually	O
only	O
moves	O
individual	O
pages	O
back	O
and	O
forth	O
between	O
main	O
memory	O
and	O
secondary	O
storage	O
,	O
similar	O
to	O
a	O
paged	O
non-segmented	O
system	O
.	O
</s>
<s>
This	O
usually	O
results	O
in	O
a	O
reduced	O
amount	O
of	O
input/output	O
between	O
primary	O
and	O
secondary	O
storage	O
and	O
reduced	O
memory	B-Architecture
fragmentation	I-Architecture
.	O
</s>
<s>
The	O
Burroughs	O
Corporation	O
B5000	B-Device
computer	O
was	O
one	O
of	O
the	O
first	O
to	O
implement	O
segmentation	B-General_Concept
,	O
and	O
"	O
perhaps	O
the	O
first	O
commercial	O
computer	O
to	O
provide	O
virtual	B-Architecture
memory	I-Architecture
"	O
based	O
on	O
segmentation	B-General_Concept
.	O
</s>
<s>
The	O
later	O
B6500	O
computer	O
also	O
implemented	O
segmentation	B-General_Concept
;	O
a	O
version	O
of	O
its	O
architecture	O
is	O
still	O
in	O
use	O
today	O
on	O
the	O
Unisys	O
ClearPath	O
Libra	O
servers	O
.	O
</s>
<s>
The	O
GE-645	B-Device
computer	O
,	O
a	O
modification	O
of	O
the	O
GE-635	B-Device
with	O
segmentation	B-General_Concept
and	O
paging	B-Architecture
support	O
added	O
,	O
was	O
designed	O
in	O
1964	O
to	O
support	O
Multics	B-Application
.	O
</s>
<s>
The	O
Intel	B-Device
iAPX	I-Device
432	I-Device
,	O
begun	O
in	O
1975	O
,	O
attempted	O
to	O
implement	O
a	O
true	O
segmented	O
architecture	O
with	O
memory	B-General_Concept
protection	I-General_Concept
on	O
a	O
microprocessor	O
.	O
</s>
<s>
The	O
960MX	O
version	O
of	O
the	O
Intel	B-General_Concept
i960	I-General_Concept
processors	O
supported	O
load	O
and	O
store	O
instructions	O
with	O
the	O
source	O
or	O
destination	O
being	O
an	O
"	O
access	O
descriptor	O
"	O
for	O
an	O
object	O
,	O
and	O
an	O
offset	B-General_Concept
into	O
the	O
object	O
,	O
with	O
the	O
access	O
descriptor	O
being	O
in	O
a	O
32-bit	O
register	O
and	O
with	O
the	O
offset	B-General_Concept
computed	O
from	O
a	O
base	O
offset	B-General_Concept
in	O
the	O
next	O
register	O
and	O
from	O
an	O
additional	O
offset	B-General_Concept
and	O
,	O
optionally	O
,	O
an	O
index	O
register	O
specified	O
in	O
the	O
instruction	O
.	O
</s>
<s>
An	O
access	O
descriptor	O
contains	O
permission	O
bits	O
and	O
a	O
26-bit	O
object	O
index	O
;	O
the	O
object	O
index	O
is	O
an	O
index	O
into	O
a	O
table	O
of	O
object	O
descriptors	O
,	O
giving	O
an	O
object	O
type	O
,	O
an	O
object	O
length	O
,	O
and	O
a	O
physical	B-General_Concept
address	I-General_Concept
for	O
the	O
object	O
's	O
data	O
,	O
a	O
page	B-General_Concept
table	I-General_Concept
for	O
the	O
object	O
,	O
or	O
the	O
top-level	O
page	B-General_Concept
table	I-General_Concept
for	O
a	O
two-level	O
page	B-General_Concept
table	I-General_Concept
for	O
the	O
object	O
,	O
depending	O
on	O
the	O
object	O
type	O
.	O
</s>
<s>
Prime	O
,	O
Stratus	B-General_Concept
,	O
Apollo	O
,	O
IBM	B-Device
System/38	I-Device
,	O
and	O
IBM	B-Device
AS/400	I-Device
(	O
including	O
IBM	B-Application
i	I-Application
)	O
computers	O
use	O
memory	B-General_Concept
segmentation	I-General_Concept
.	O
</s>
<s>
In	O
the	O
IBM	B-Device
System/370	I-Device
models	O
with	O
virtual	B-Architecture
storage	I-Architecture
(	O
DAT	O
)	O
and	O
24-bit	O
addresses	O
,	O
control	B-Operating_System
register	I-Operating_System
0	O
specifies	O
a	O
segment	O
size	O
of	O
either	O
64	O
KiB	O
or	O
1	O
MiB	O
and	O
a	O
page	B-General_Concept
size	I-General_Concept
of	O
either	O
2	O
KiB	O
or	O
4	O
KiB	O
;	O
control	B-Operating_System
register	I-Operating_System
1	O
contains	O
a	O
Segment	O
Table	O
Designator	O
(	O
STD	O
)	O
,	O
which	O
specifies	O
the	O
length	O
and	O
real	B-General_Concept
address	I-General_Concept
of	O
the	O
segment	O
table	O
.	O
</s>
<s>
Each	O
segment	O
table	O
entry	O
contains	O
a	O
page	B-General_Concept
table	I-General_Concept
location	O
,	O
a	O
page	B-General_Concept
table	I-General_Concept
length	O
and	O
an	O
invalid	O
bit	O
.	O
</s>
<s>
Starting	O
with	O
the	O
3031	B-Device
,	I-Device
3032	I-Device
,	I-Device
and	I-Device
3033	I-Device
processor	O
complexes	O
,	O
IBM	O
offered	O
a	O
feature	O
called	O
Dual-address	O
Space	O
(	O
DAS	O
)	O
,	O
which	O
allows	O
a	O
program	O
to	O
switch	O
between	O
the	O
translation	O
tables	O
for	O
two	O
address	O
spaces	O
,	O
referred	O
to	O
as	O
primary	O
address	O
space	O
(	O
CR1	O
)	O
and	O
secondary	O
address	O
space	O
(	O
CR7	O
)	O
,	O
and	O
to	O
move	O
data	O
between	O
the	O
address	O
spaces	O
subject	O
to	O
protection	O
key	O
.	O
</s>
<s>
Early	O
x86	B-Operating_System
processors	O
,	O
beginning	O
with	O
the	O
Intel	B-General_Concept
8086	I-General_Concept
,	O
provide	O
crude	O
memory	B-General_Concept
segmentation	I-General_Concept
and	O
no	O
memory	B-General_Concept
protection	I-General_Concept
.	O
</s>
<s>
(	O
Every	O
byte	B-Application
of	O
every	O
segment	O
is	O
always	O
available	O
to	O
any	O
program	O
.	O
)	O
</s>
<s>
The	O
16-bit	O
segment	B-Device
registers	I-Device
allow	O
for	O
65,536	O
segments	O
;	O
each	O
segment	O
begins	O
at	O
a	O
fixed	O
offset	B-General_Concept
equal	O
to	O
16	O
times	O
the	O
segment	O
number	O
;	O
the	O
segment	O
starting	O
address	O
granularity	O
is	O
16	O
bytes	B-Application
.	O
</s>
<s>
Each	O
segment	O
grants	O
read-write	O
access	O
to	O
64KiB	O
(	O
65,536	O
bytes	B-Application
)	O
of	O
address	O
space	O
(	O
this	O
limit	O
is	O
set	O
by	O
the	O
16-bit	O
PC	O
and	O
SP	O
registers	O
;	O
the	O
processor	O
does	O
no	O
bounds	O
checking	O
)	O
.	O
</s>
<s>
Offset+address	O
exceeding	O
0xFFFFF	O
wraps	O
around	O
to	O
0x00000	O
.	O
</s>
<s>
Each	O
64KiB	O
segment	O
overlaps	O
the	O
next	O
4,095	O
segments	O
;	O
each	O
physical	B-General_Concept
address	I-General_Concept
can	O
be	O
denoted	O
by	O
4,096	O
segment	O
–	O
offset	B-General_Concept
pairs	O
.	O
</s>
<s>
(	O
Optional	O
expanded	B-Device
memory	I-Device
hardware	O
can	O
add	O
bank-switched	O
memory	O
under	O
software	O
control	O
.	O
)	O
</s>
<s>
Intel	O
retroactively	O
named	O
the	O
sole	O
operating	O
mode	O
of	O
these	O
x86	B-Operating_System
CPU	O
models	O
"	O
real	B-Application
mode	I-Application
"	O
.	O
</s>
<s>
The	O
Intel	B-General_Concept
80286	I-General_Concept
and	O
later	O
processors	O
add	O
"	O
286	B-Application
protected	I-Application
mode	I-Application
"	O
,	O
which	O
retains	O
16-bit	O
addressing	O
,	O
and	O
adds	O
segmentation	B-General_Concept
(	O
without	O
paging	B-Architecture
)	O
and	O
per-segment	O
memory	B-General_Concept
protection	I-General_Concept
.	O
</s>
<s>
For	O
backward	O
compatibility	O
,	O
all	O
x86	B-Operating_System
CPUs	O
start	O
up	O
in	O
"	O
real	B-Application
mode	I-Application
"	O
,	O
with	O
the	O
same	O
fixed	O
overlapping	O
64KiB	O
segments	O
,	O
no	O
memory	B-General_Concept
protection	I-General_Concept
,	O
only	O
1MiB	O
physical	B-General_Concept
address	I-General_Concept
space	O
,	O
and	O
some	O
subtle	O
differences	O
(	O
high	B-Device
memory	I-Device
area	I-Device
,	O
unreal	B-Device
mode	I-Device
)	O
.	O
</s>
<s>
In	O
order	O
to	O
use	O
its	O
full	O
24-bit	O
(	O
16MiB	O
)	O
physical	B-General_Concept
address	I-General_Concept
space	O
and	O
advanced	O
MMU	B-General_Concept
features	O
,	O
an	O
80286	B-General_Concept
or	O
later	O
processor	O
must	O
be	O
switched	O
into	O
"	O
protected	B-Application
mode	I-Application
"	O
by	O
software	O
,	O
usually	O
the	O
operating	B-General_Concept
system	I-General_Concept
or	O
a	O
DOS	B-Device
extender	I-Device
.	O
</s>
<s>
If	O
a	O
program	O
does	O
not	O
use	O
the	O
segment	B-Device
registers	I-Device
,	O
or	O
only	O
puts	O
values	O
into	O
them	O
that	O
it	O
receives	O
from	O
the	O
operating	B-General_Concept
system	I-General_Concept
,	O
then	O
identical	O
code	O
can	O
run	O
in	O
real	B-Application
mode	I-Application
or	O
protected	B-Application
mode	I-Application
,	O
but	O
most	O
real-mode	B-Application
software	O
computes	O
new	O
values	O
for	O
the	O
segment	B-Device
registers	I-Device
,	O
breaking	O
this	O
compatibility	O
.	O
</s>
<s>
The	O
Intel	B-General_Concept
i386	I-General_Concept
and	O
later	O
processors	O
add	O
"	O
386	B-General_Concept
protected	B-Application
mode	I-Application
"	O
,	O
which	O
uses	O
32-bit	O
addressing	O
,	O
retains	O
segmentation	B-General_Concept
,	O
and	O
adds	O
memory	B-Architecture
paging	I-Architecture
.	O
</s>
<s>
In	O
these	O
processors	O
,	O
the	O
segment	O
table	O
,	O
rather	O
than	O
pointing	O
to	O
a	O
page	B-General_Concept
table	I-General_Concept
for	O
the	O
segment	O
,	O
contains	O
the	O
segment	O
address	O
in	O
linear	O
memory	O
.	O
</s>
<s>
When	O
paging	B-Architecture
is	O
enabled	O
,	O
addresses	O
in	O
linear	O
memory	O
are	O
then	O
mapped	O
to	O
physical	O
addresses	O
using	O
a	O
separate	O
page	B-General_Concept
table	I-General_Concept
.	O
</s>
<s>
Most	O
operating	B-General_Concept
systems	I-General_Concept
did	O
not	O
use	O
the	O
segmentation	B-General_Concept
capability	O
,	O
despite	O
possible	O
advantages	O
(	O
4	O
x	O
4GiB	O
logical	O
address	O
space	O
instead	O
of	O
only	O
4	O
GiB	O
)	O
,	O
opting	O
to	O
keep	O
the	O
base	O
address	O
in	O
all	O
segment	B-Device
registers	I-Device
equal	O
to	O
0	O
at	O
all	O
times	O
and	O
provide	O
per-page	O
memory	O
protection	O
and	O
swapping	O
using	O
only	O
paging	B-Architecture
.	O
</s>
<s>
Some	O
use	O
the	O
CS	O
register	O
to	O
provide	O
executable	B-Application
space	O
protection	O
on	O
processors	O
lacking	O
the	O
NX	B-General_Concept
bit	I-General_Concept
or	O
use	O
the	O
FS	O
or	O
GS	O
registers	O
to	O
access	O
thread-local	O
storage	O
.	O
</s>
<s>
The	O
x86-64	B-Device
architecture	O
does	O
not	O
support	O
segmentation	B-General_Concept
in	O
"	O
long	B-Application
mode	I-Application
"	O
(	O
64-bit	O
mode	O
)	O
.	O
</s>
<s>
Four	O
of	O
the	O
segment	B-Device
registers	I-Device
:	O
CS	O
,	O
SS	O
,	O
DS	O
,	O
and	O
ES	O
are	O
forced	O
to	O
0	O
,	O
and	O
the	O
limit	O
to	O
264	O
.	O
</s>
<s>
The	O
segment	B-Device
registers	I-Device
FS	B-Device
and	I-Device
GS	I-Device
can	O
still	O
have	O
a	O
nonzero	O
base	O
address	O
.	O
</s>
<s>
This	O
allows	O
operating	B-General_Concept
systems	I-General_Concept
to	O
use	O
these	O
segments	O
for	O
special	O
purposes	O
such	O
as	O
thread-local	O
storage	O
.	O
</s>
