Content deleted Content added
Fixed link |
Matthiaspaul (talk | contribs) Added note on CP/M Zero page and long command lines |
||
Line 1:
The '''Program Segment Prefix''' (PSP) is a data structure used in [[DOS]] systems to store the state of a [[computer program|program]]. It resembles the [[Zero page (CP/M)|Zero Page]] in the [[CP/M]] operating system. The PSP has the following structure:
{| border="1" width="100%" class="wikitable"
Line 7 ⟶ 6:
! Contents
|-
|
| 2 bytes (code)
| [[CP/M]] exit (always contain INT
|-
|
| [[Word (data type)|word]] (2 bytes)
| Memory size in paragraphs
|-
|
| byte
| Reserved
|-
|
| 5 bytes (code)
| Far call to CP/M compatibility code within DOS
|-
|
| [[dword]] (4 bytes)
| Terminate address of previous program (old INT
|-
|
| dword
| Break address of previous program (old INT
|-
|
| dword
| Critical error address of previous program (old INT
|-
|
| word
| Caller's PSP segment (usually [[command.com]] - internal)
|-
|
| 20 bytes
| [[Job File Table]] (internal)
|-
|
| word
| [[Environment variable|Environment]] segment
|-
|
| dword
| SS:SP on entry to last INT
|-
|
| word
| Max open files (Internal - see below)
|-
|
| dword
| Handle-entries address (Internal - see below)
|-
|
| 24 bytes
| Reserved
|-
|
| 3 bytes (code)
| Far call to DOS (always contain INT
|-
|
| 9 bytes
| Reserved
|-
|
| 16 bytes
| Unopened Standard [[File control block|FCB]] 1
|-
|
| 20 bytes
| Unopened Standard FCB 2 (overwritten if FCB 1 is opened)
|-
|
| 1 byte
| Number of bytes on command-line
|-
|
| 127 bytes
| Command-line (terminated by a [[Carriage return|0Dh]])
Line 90 ⟶ 89:
The PSP is most often used to get the command line arguments of a DOS program, for example the command "foo.exe -a -f" executes foo.exe with the arguments '-a' and '-f'.
The segment address of the PSP is passed in the DS register when the program is executed. It can also be determined later by using [[interrupt]]
Alternatively, in [[.COM]] programs, one can address the PSP directly just by using the offsets listed above. 00h points to the beginning of the PSP, FFh points to the end, etc. For example, the following code displays the command line arguments:
<!-- This may serve as an example for illustration purposes, but it would be a bad idea to actually code it this way. It would be very easy to crash the system by just giving a command line longer than 126 bytes. -->
<pre><nowiki>
org 100h
Line 111:
int 21h
</nowiki></pre>
If the command line length is non-zero, programs should first try to retrieve the command line from the appendage of the environment, if the segment pointer to the environment is neither 0000h or FFFFh. This way, it is possible to pass longer command lines than 127 bytes to applications than via the fixed length command line buffer in the PSP. If this appendage is not available (for example under DOS prior to 3.2) or if it turns out to be of length zero, the command line can be retrieved from the PSP itself, but possibly truncated after 127 bytes. Indicated lengths beyond this should not be trusted on.
== See also ==
*[[Zero page (CP/M)|Zero Page]]
== References ==
|