Product Family: DACS, SCORE
Target CPU: 80x86
Language: Ada
Host: Any
The 32-bit variants of DACS-80x86 (80386, 80486, and Pentium) are available in two different versions each supporting one of the two different memory models: Protected Mode and Flat Mode. A better term would have been Segmented Mode and Flat Mode, since both actually operate the target CPU in the Protected Mode.
SCORE for 80x86/Pentium exclusively supports the Flat Mode.
All Intel 80386 (and higher) microprocessors share the same strategy for memory access.
Once the CPU is in the Protected Mode, all memory accesses are composed of:
Segment Selector
and
Offset within the segment
They are normally written as <selector>:<offset>
The CPU's Protected Mode offers 4 Gbyte of address space, but there are several ways of achieving this (Segmented versus Flat model). However, let us first take a look at the components of the address composition.
Segment Selector
The Segment Selector is an index into either the Global Descriptor Table (GDT) or (one of the potentially several) Local Descriptor Tables (LDT). The size of the selector is 16 bits. However, when pushed it occupies 32 bits on the stack.
The descriptor tables consist of segment descriptors defining the attributes of each memory segment including:
Base address
Segment limit
Type of segment
Privilege level
Read/Write, Read/Only, Execute attribute
31
23
15
7
0
Base
31..24
G
B
0
A
Lim
19..16
P
DPL
1
0
A
Base 23..16
Segment base
15..0
Segment limit
15..0
Segment Descriptor
Offset
When calculating the physical address of a selector and offset pair, the 32 bit offset is added to the base address obtained from the selector's descriptor.
All memory accesses have default segment selectors, unless specifically overridden.
Protection
The 32-bit 80x86 processors offer a wide range of implicit protection. Whenever memory is accessed, be it instruction fetch, data read or data write, the attributes of the used segment are checked against the instruction. The error conditions are many, and the reader is referred to Intel's 80386 Programmer's Reference Manual for details.
Whenever an error is detected, the CPU will raise software interrupt #13, the Protection Fault.
Even though these checks are performed implicitly, they do take time. In particularly loading segment registers with selector values is expensive.
Segmented Memory Model
This model is supported by the DACS-80x86 compilers in Protected Mode. There are separate segments for:
Ada code
Global Ada data
RTS code
RTS data
Stack
Heaps
Collections
The benefit is that applications have higher system integrity in that it is impossible to:
Write in the code space
Execute data
Address memory beyond a segment's limit
These benefits implicitly also catch attempts to use invalid addresses.
The segmented model requires that
Calls from Ada to RTS are FAR calls
All addresses are 16+32 bits
Segment registers are often loaded for memory accesses
It should be noted that DACS-80x86 does not utilize the protection mechanism associated with using several privilege levels. In DACS-80x86, all code and data is at the most privileged level (zero).
Flat Memory Model
This model is supported by DACS-80x86 in the Flat Mode and SCORE for 80x86/Pentium. In this model, an address is still composed of a Segment Selector and an offset.
However, the idea of the Flat Model is that all segment selector registers are set-up initially to descriptors that point to the full 4 Gbyte address space.
By relying on the default segment selector registers for all operations, these registers need never be loaded - and this is what otherwise is expensive.
Furthermore, addresses can be expressed in pure 32-bit form, since the default segment selector will be used.
All calls are NEAR
All addresses are 32 bits
Segment registers never reloaded
Segment overrides never used
So not only does the code execute faster (15-20%), but it is also more compact.
The segments are not 4 Gbytes long however, just sufficiently long to hold the application. This means that a memory access to an address which is beyond the application will be caught with a protection fault.
In Flat Mode, DDC-I's target linker will automatically create one segment for 'flat' access to all code, and one segment for 'flat' access to all data. These are the two segments in use while executing in the Flat Mode.
Segmented vs Flat
The Segmented model offers higher system integrity at the cost of performance, and this model should be preferred for safety critical applications.
Code in the Flat model will typically execute 15-20% faster compared to the Segmented model, so if performance is of the highest priority, and safety of a lesser priority, then we recommend the Flat Mode.
It should also be noted that for Pentium the benefit of the dual instruction pipes (U and V) is limited in the Segmented model because, every segment override will flush the pipes.
Customer Quote:
"Thank you for the excellent support during our evaluation phase... I need to make special mention of Michael, the support and comments he made really put me on the track of finding solutions very fast."