Segmentation: Difference between revisions

Jump to navigation Jump to search
m
no edit summary
[unchecked revision][unchecked revision]
No edit summary
mNo edit summary
Line 3:
In [[Real Mode]] you use a logical address in the form A:B to address memory. This is translated into a physical address using the equation:
 
Physical address = (A * 0x10) + B
 
The registers in pure real-mode are limited to 16 bits for addressing. 16 bits can represent any integer between 0 and 64k. This means that if we set A to be a fixed value and allow B to change we can address a 64k area of memory. This 64k area is called a segment.
 
A = A 64k segment B = Offset within the segment
 
The base address of a segment is the (A * 0x10) portion of the equation I showed. It should be obvious that segments can overlap.
Line 102:
==Notes Regarding C==
*Most C compilers assume a flat-memory model.
*In this model all the segments cover the full address space (Usually 0->4Gb on x86). In essence this means that we completely ignore the A part of our A:B logical address. The reason for this is that most processors don't actually have segmentation (Plus it's a hell of a lot easier for the compiler to optimiseoptimize).
*This leaves you with 2 descriptors per privilege level (Ring 0 and Ring 3 normally), one for code and one for data, which both describe precisely the same segment. The only difference being that the code descriptor is loaded into CS, and the data descriptor is used by all the other segment registers. The reason you need both a code and data descriptor is that the processor will not allow you to load CS with a data descriptor (This is to help with security when using a segmented memory model, and although useless in the flat-memory model it is still required because you can't turn off segmentation).
*In general if you want to use the segmentation mechanism, by having the different segment registers represent segments with different base addresses, you won't be able to use a modern C compiler, and may very well be restricted to just Assembly.
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.

Navigation menu