- #1
RedX
- 970
- 3
I thought a segment table had 4 segments and looked something like this:
[tex]
\begin{array}{ccc}
\mbox{Seg ID# } &\mbox{Base }& \mbox{Limit} \\
\mbox{0 (code) } &0\mbox{x}4000& 0\mbox{x}0800 \\
\mbox{1 (data) } &0\mbox{x}4800& 0\mbox{x}1400 \\
\mbox{2 (shared) } &0\mbox{x}\mbox{F}000 & 0\mbox{x}1000\\
\mbox{3 (stack) } &0\mbox{x}0000 &0\mbox{x}3000 \\
\end{array}
[/tex]
But on an actual CPU, there is a register for each of these segments, so it seems like the table above is useless. Is each segment register 32 bits, with the 1st 16 bits containing the base address, and the 2nd 16 bits containing the limit? So when the CPU swaps out your program for another one (called a context switch), it swaps out all the segment registers with new ones that contain the different base address and limits for the new program?
I guess another way to put is this: do the segment registers contain a pointer to the memory address containing the information about the base and limit, or contain the actual information about the base and limit inside it? I heard that the segmentation table is in the processor itself, and not the memory, so that when you switch programs, you have to switch out the entire table, instead of a single pointer to the memory address of a table. But I'm not sure this is right.
I tried understanding Intel's specification for the segment registers, but I don't quite understand them. Their segment register is 16 bits, not 32 bits. 13 of the bits are an index to a segment entry, and the rest are flag bits. Does this mean that, say for the code segment register, there are 2^13=8 K entries?
So really the table should look like this:
[tex]
\begin{array}{ccc}
\mbox{Code Seg ID# } &\mbox{Base }& \mbox{Limit} \\
\mbox{0} &0\mbox{x}4000& 0\mbox{x}0800 \\
\mbox{.} &0\mbox{x}4800& 0\mbox{x}1400 \\
\mbox{.} &0\mbox{x}6200& 0\mbox{x}1000\\
\mbox{.} &0\mbox{x}7200 &0\mbox{x}1000 \\
2^{13}-1 &... &... \\
\end{array}
[/tex]
and there is also a similar 2^13 entry table for the data segment, the stack segment, and the shared segment? Why would you need 2^13 segments for just the code, 2^13 segments for the data, 2^13 segments for any segment register that exists? I thought a single program only needed 1 segment for code, 1 segment for data, etc, like the 1st table I have?
For each of the 2^13 entries there seems to be two 32-bit numbers that describe each entry ( http://www.cs.cmu.edu/~410/doc/segments/segments.html ), and one of them has 16 bits for the base and 16 bits for the segment limit. The other one I have no idea what it is. But how does the processor, just from looking at the 2^13 bit number in the register, know to look at these two particular 32-bit numbers stored somewhere? Doesn't the processor need the address for those 32-bit numbers? But how does it get a 32-bit address from just the 2^13 bit number?
[tex]
\begin{array}{ccc}
\mbox{Seg ID# } &\mbox{Base }& \mbox{Limit} \\
\mbox{0 (code) } &0\mbox{x}4000& 0\mbox{x}0800 \\
\mbox{1 (data) } &0\mbox{x}4800& 0\mbox{x}1400 \\
\mbox{2 (shared) } &0\mbox{x}\mbox{F}000 & 0\mbox{x}1000\\
\mbox{3 (stack) } &0\mbox{x}0000 &0\mbox{x}3000 \\
\end{array}
[/tex]
But on an actual CPU, there is a register for each of these segments, so it seems like the table above is useless. Is each segment register 32 bits, with the 1st 16 bits containing the base address, and the 2nd 16 bits containing the limit? So when the CPU swaps out your program for another one (called a context switch), it swaps out all the segment registers with new ones that contain the different base address and limits for the new program?
I guess another way to put is this: do the segment registers contain a pointer to the memory address containing the information about the base and limit, or contain the actual information about the base and limit inside it? I heard that the segmentation table is in the processor itself, and not the memory, so that when you switch programs, you have to switch out the entire table, instead of a single pointer to the memory address of a table. But I'm not sure this is right.
I tried understanding Intel's specification for the segment registers, but I don't quite understand them. Their segment register is 16 bits, not 32 bits. 13 of the bits are an index to a segment entry, and the rest are flag bits. Does this mean that, say for the code segment register, there are 2^13=8 K entries?
So really the table should look like this:
[tex]
\begin{array}{ccc}
\mbox{Code Seg ID# } &\mbox{Base }& \mbox{Limit} \\
\mbox{0} &0\mbox{x}4000& 0\mbox{x}0800 \\
\mbox{.} &0\mbox{x}4800& 0\mbox{x}1400 \\
\mbox{.} &0\mbox{x}6200& 0\mbox{x}1000\\
\mbox{.} &0\mbox{x}7200 &0\mbox{x}1000 \\
2^{13}-1 &... &... \\
\end{array}
[/tex]
and there is also a similar 2^13 entry table for the data segment, the stack segment, and the shared segment? Why would you need 2^13 segments for just the code, 2^13 segments for the data, 2^13 segments for any segment register that exists? I thought a single program only needed 1 segment for code, 1 segment for data, etc, like the 1st table I have?
For each of the 2^13 entries there seems to be two 32-bit numbers that describe each entry ( http://www.cs.cmu.edu/~410/doc/segments/segments.html ), and one of them has 16 bits for the base and 16 bits for the segment limit. The other one I have no idea what it is. But how does the processor, just from looking at the 2^13 bit number in the register, know to look at these two particular 32-bit numbers stored somewhere? Doesn't the processor need the address for those 32-bit numbers? But how does it get a 32-bit address from just the 2^13 bit number?