'What is the Program Segment Prefix (PSP)?
What exactly is Program Segment Prefix (PSP)?
I searched in Google but couldn't find any clean and straight answers to help me completely understand it. What does it do and what is the use of it?
Solution 1:[1]
When you want to run a program in DOS, its command processor command.com reserves a block from remaining free memory and fills a 256 bytes long structure called PSP in the beginning of this block. Image of the executable program is loaded from disk to memory right behind the PSP. Segment address of PSP is loaded into segment registers DS and ES and the program is launched.
If it is a COM program, CS=DS=ES=SS and instruction pointer IP is set right after the PSP, i.e. IP=256.
When the program is MZ executable, CS:IP and SS:SP are set from their corresponding fields in MZ header.
Program Segment Prefix is useful for the program in many ways:
- The launched program can inspect command-line arguments located at
offset 80hin PSP.
- Segment address of block of strings with environment
variables can be found at PSP:2Ch.
- Program may hook and change
the default system reaction to Ctrl-Break at PSP:0Ehor reaction to critical error atPSP:12h.
- At PSP:16hit can get PSP address of its parent process to find out whether it was launched fromcommand.comor spawned from other executable program.
- And last
but not least the return instruction INT 20hatPSP:0can be used in COM program to terminate itself by a single instructionRET.
More detailed description of PSP can be found in Wikipedia.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source | 
|---|---|
| Solution 1 | Sep Roland | 
