Controling privilege level in protected mode programs ?
Quote:
>How do you control the use of privilege level, programming protected mode programs with Borland Pascal ?
>The problem is, that the program is made for an embedded applikation (not a PC) and the
>in circuit emulator used for debugging, does not support privilege levels different from 0.
When you run TDUMP.EXE on a protected mode application you get a dump
with a.o. the logical segment table entries as:
Segment Table offset: 0E7Eh
Segment Number: 01h
Segment Type: CODE Alloc Size : 3FC9h
Sector Offset: 000Fh File length: 3FC9h
80286 DPL Bits: 3 Discard Priority: 00
Attributes: Moveable Relocations Discardable
The system loader in Windows or DPMI server, as part of the operating
system, looks at the DPL bits and allocates the selector/descriptor
entries for the segments based on a.o. this information.
The generic descriptor entry looks like:
TDescriptor = record
LimitL,
BaseL: word;
BaseM,
AccessRights: byte; {no=0 and yes=1
segment type:
data/stack code both
bit 7 segment present in memory
bit 5+6 descriptor privilege level
bit 4 always 1 always 1 descriptor type
bit 3 always 0 always 1 segment type
bit 2 expand down conforming
bit 1 writable readable
bit 0 accessed}
LimitH_Flags, { >=80386, must be 0 on 80286
bit 7 granularity of Limit: 1 byte (=0) or 4K (=1),
if page granular:
- then top 8 bits are evaluated only and
. limit=00000h gives valid offsets of 0-FFFh
- CPU will interpret as 32 bit segment
bit 6 default segment size 16 (=0) or 32 (=1) bits
bit 5 available to programmers
bit 0/4 LimitHigh}
BaseH: byte; { >=80386 only, must be 0 on 80286}
end;
Bits 5 and 6 in the AccessRights reflect the descriptor privilege
level (which you want to be zero).
The assumption is that your (embedded) operating system works the same
and for its loader to load your program at CPU privilege level 0, you
will have to fiddle the DPL-bits in the segment table of your
application.
P.S. The loader in Windows 3.x has been tricked to load NE-executables
always at level 3.