Mail Archives: djgpp/1997/07/31/01:03:04
Nate Eldredge wrote:
>
>
> Does anyone know why the decision was made to have CS and DS refer to the
> same region of memory, the program's entire address space? IMHO, CS should
> be `text' only, and DS and SS should be `DGROUP' (or whatever it's called)
> only. This would keep problems of this sort from occuring, since you can't
> write to the CS segment.
Yes--but. There is no way to guarantee that the selectors (or segments,
in real mode) found in the segment registers do not refer to the same
region of memory. Certainly, I could set my segments to point to
regions which overlap. Indeed, this is often done in real mode to save
address space-- if, for example, your program uses small amounts of near
variables. In MS systax assembler, real mode:
.dgroup
.data
(your variables less than 64k)
.stack 4096 ; your stack
.text
lea dx, .dgroup ; get the dgroup into ds
push dx
pop ds
lea dx, .heap ; get the heap into es
push dx
pop es
( your code etc)
.heap
Where .heap starts after the end of .text. In this case, since .dgroup
is small, you could generate addresses ds:dx that actually point into
.text. This would usually have undesirable effects, but not
necessarily. For example, Windoze 3.x has a section of code that
determines whether or not you're using genuine MS-DOS or a clone. In
the beta versions, it would complain and exit. In the release versions,
it does nothing. This code is obfuscated and xor encoded. In order to
execute, it must be read into .text, then xor'd with its key string,
then executed. It is convenient to have both es and cs point to the
same region of RAM, in this case, so that x86 string operators can be
used.
This is documented in "Undocumented DOS"
--
Charles Krug, Jr.
- Raw text -