Content deleted Content added
Matthiaspaul (talk | contribs) →See also: +emtries |
m Fixed broken links |
||
(21 intermediate revisions by 9 users not shown) | |||
Line 1:
{{Short description|
{{Use dmy dates|date=May 2019|cs1-dates=y}}
{{Use list-defined references|date=December 2021}}
{{TOC right}}
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"
! Offset
! Size
! Contents
|-
| 00h–01h
| 2 bytes (code)
| [[CP/M-80]]-like<!-- not CP/M-86! --> exit (always contains [[DOS_API#Interrupt_vectors_used_by_DOS|INT 20h]])<ref name="Taylor_1982_Translators"/><ref name="Paul_2002_COM"/>
|-
| 02h–03h
| [[Word (data type)|word]] (2 bytes)
| Segment of the first byte beyond the memory allocated to the program
Line 20 ⟶ 22:
| Reserved
|-
| 05h–09h
| 5 bytes (code)
| [[CALL 5 (PSP)|
|-
| 0Ah–0Dh
| [[dword]] (4 bytes)
| Terminate address of previous program (old [[DOS_API#Interrupt_vectors_used_by_DOS|INT 22h]])
|-
| 0Eh–11h
| dword
| Break address of previous program (old [[DOS_API#Interrupt_vectors_used_by_DOS|INT 23h]])
|-
| 12h–15h
| dword
| Critical error address of previous program (old [[DOS_API#Interrupt_vectors_used_by_DOS|INT 24h]])
|-
| 16h–17h
| word
| Parent's PSP segment (usually [[COMMAND.COM]] - internal)
|-
| 18h–2Bh
| 20 bytes
| [[Job File Table]] (JFT) (internal)
|-
| 2Ch–2Dh
| word
| [[Environment variable|Environment]] segment
|-
| 2Eh–31h
| dword
| SS:SP on entry to last [[INT 21h]] call (internal)
|-
| 32h–33h
| word
| JFT size (internal)
|-
| 34h–37h
| dword
| Pointer to JFT (internal)
|-
| 38h–3Bh
| dword
| Pointer to previous PSP (only used by SHARE in DOS 3.3 and later)
|-
| 3Ch–3Fh
| 4 bytes
| Reserved
|-
| 40h–41h
| word
| DOS version to return (DOS
|-
| 42h–4Fh
| 14 bytes
| Reserved
|-
| 50h–52h
| 3 bytes (code)
|
|-
| 53h–54h
| 2 bytes
| Reserved
|-
| 55h–5Bh
| 7 bytes
| Reserved (can be used to make first FCB into an extended FCB)
|-
| 5Ch–6Bh
| 16 bytes
| Unopened Standard [[File control block|FCB]] 1
|-
| 6Ch–7Fh
| 20 bytes
| Unopened Standard FCB 2 (overwritten if FCB 1 is opened)
Line 100 ⟶ 102:
| Number of bytes on command-line
|-
| 81h–FFh
| 127 bytes
| Command-line tail (terminated by a [[Carriage return|0Dh]])<ref name="Paul_1997_MSDOS"/><ref name="Paul_1997_4DOSTIP"/>
|}
The PSP is most often used to get the [[argc|command line arguments]] of a DOS program; for example, the command "FOO.EXE /A /F" executes FOO.EXE with the arguments '/A' and '/F'.
If the PSP entry for the command line length is non-zero and the pointer to the environment segment is neither 0000h nor FFFFh<!-- 0000h indicating "no environment" and "FFFF" reserved -->, programs should first try to retrieve the command line from the [[environment variable]] [[%CMDLINE%]] before extracting it from the PSP. This way, it is possible to pass command lines longer than 126 characters to applications.
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 Int 21h function 51h or Int 21h function 62h. Either function will return the PSP address in register BX.<ref name="R1"/>
Alternatively, in [[.COM]] programs loaded at offset <
For example, the following code displays the command line arguments:
<
org 100h ; .COM - not using ds
Line 132 ⟶ 136:
mov ax,4C00h ; subfunction 4C
int 21h
</syntaxhighlight>
In DOS 1.x, it was necessary for the CS (Code Segment) register to contain the same segment as the PSP at program termination, thus standard programming practice involved saving the DS register
<
; save
push ds
Line 152 ⟶ 156:
retf
</syntaxhighlight>
If the executable was a .COM file, this procedure was unnecessary and the program could be terminated merely with a direct INT 20h instruction or else calling INT 21h
<
jmp start
Line 167 ⟶ 171:
int 20h
</syntaxhighlight>
In DOS 2.x and higher, program termination was accomplished instead with INT 21h
== See also ==
* [[Zero page (CP/M)]]
* [[CALL 5 (DOS)]]
* [[Stack frame]] (Unix)<ref name="Schulman_1994_Undocumented-DOS"/>
* [[Process directory]]<!-- with possibilities --> (Multics)<ref name="Schulman_1994_Undocumented-DOS"/>
* [[Process identifier]] (PID)<ref name="Schulman_1994_Undocumented-DOS"/>
* [[this (computer programming)]]
* [[Self-reference]]
Line 183 ⟶ 187:
{{reflist|refs=
<ref name="R1">{{cite web |url=http://www.htl-steyr.ac.at/~morg/pcinfo/hardware/interrupts/inte8fjk.htm |title=INT 21h,62h - Get PSP address (DOS 3.x) |url-status=dead |archive-url=https://web.archive.org/web/20120207062050/http://www.htl-steyr.ac.at/~morg/pcinfo/hardware/interrupts/inte8fjk.htm |archive-date=2012-02-07}}</ref>
<ref name="Taylor_1982_Translators">{{cite magazine |title=Upward migration - Part 1: Translators - Using translation programs to move CP/M-86 programs to CP/M and MS-DOS<!-- this is the actual but faulty title --> |trans-title=<!-- this is how it should have been titled -->Using translation programs to move CP/M programs to CP/M-86 and MS-DOS |author-first1=Roger |author-last1=Taylor |author-first2=Phil |author-last2=Lemmons |date=June 1982 |magazine=[[BYTE]] |issn=0360-5280 |id={{CODEN|BYTEDJ}} |volume=7 |number=6 |publisher=[[BYTE Publications Inc.]] |pages=321–322, 324, 326, 328, 330, 332, 334, 336, 338, 340, 342, 344 [342, 344] |url=https://tech-insider.org/personal-computers/research/acrobat/8206-b.pdf |access-date=2020-01-15 |url-status=live |archive-url=https://web.archive.org/web/20200116024623/https://tech-insider.org/personal-computers/research/acrobat/8206-b.pdf |archive-date=2020-01-16 |quote=[…] Gaining Access to [[CP/M-86]] […] Gaining access to CP/M-86 requires placing the function code in the CL register, placing the byte parameter in the DL register or placing the word parameter in the DX register, placing the data segment in the DS register (the data segment is usually not changed for a
<ref name="Schulman_1994_Undocumented-DOS">{{cite book |author-first1=Andrew |author-last1=Schulman |author-first2=Ralf D. |author-last2=Brown |author-link2=Ralf D. Brown |author-first3=David |author-last3=Maxey |author-first4=Raymond J. |author-last4=Michels |author-first5=Jim |author-last5=Kyle |title=Undocumented DOS: A programmer's guide to reserved MS-DOS functions and data structures - expanded to include MS-DOS 6, Novell DOS and Windows 3.1 |publisher=[[Addison Wesley]] |edition=2 |date=1994 |orig-year=November 1993<!-- first printing --> |isbn=0-201-63287-X |___location=Reading, Massachusetts, USA |url-access=registration |url=https://archive.org/details/undocumenteddosp00andr_0}} (xviii+856+vi pages, 3.5"-floppy) Errata: [https://web.archive.org/web/20190417215556/http://www.cs.cmu.edu/afs/cs/user/ralf/pub/books/UndocumentedDOS/errata.ud2][https://web.archive.org/web/20190417212906/https://www.pcjs.org/pubs/pc/programming/Undocumented_DOS/#errata-2nd-edition]</ref>
<ref name="Necasek_2011_CALL5">{{cite web |title=Who needs the address wraparound, anyway? |date=2011-09-13 |author-first=Michal |author-last=Necasek |work=OS/2 Museum |url=http://www.os2museum.com/wp/who-needs-the-address-wraparound-anyway/ |access-date=2020-02-19 |url-status=live |archive-url=https://web.archive.org/web/20200219004644/http://www.os2museum.com/wp/who-needs-the-address-wraparound-anyway/ |archive-date=2020-02-19 |quote=[…] [[86-DOS]], and hence [[PC DOS]]/[[MS-DOS]], used a clever trick. The byte at offset 5 of the PSP contained a far call opcode (9Ah); the word at offset 6 of the PSP contained the appropriate value to indicate program segment size, and also the offset part of the far call. The word at offset 8, which served as the segment part of the far call, was crafted such that when combined with the offset, it would wrap around (a well understood feature of the [[8086]] CPU) and point to address 0:C0h, which contains interrupt vector 30h. […] the [[CALL 5 (DOS)|CALL 5]] interface works even in DOS emulation under Windows NT and OS/2, and those systems most certainly cannot run with the [[A20 line]] disabled. How does that work then? […] Rather than chopping off address bits, the system mirrors the five bytes at 0:C0h at 1000C0h. The same technique had been in fact used in DOS 5 and above running with [[DOS (CONFIG.SYS directive)|DOS=HIGH]]. In that case, DOS makes sure that linear address 1000C0h contains the appropriate far call. […]}}</ref>
<ref name="Paul_1997_MSDOS">{{cite book |title=MSDOSTIPs — Tips für den Umgang mit MS-DOS 5.0-7 |work=MPDOSTIP |author-first=Matthias R. |author-last=Paul |date=1997-07-01 |orig-year=1994-01-01 |language=de |url=http://www.antonis.de/dos/dos-tuts/mpdostip/html/msdostip.htm |access-date=2013-10-25 |url-status=live |archive-url=https://web.archive.org/web/20170822214030/http://www.antonis.de/dos/dos-tuts/mpdostip/html/msdostip.htm |archive-date=2017-08-22}} (NB. MSDOSTIP.TXT is part of MPDOSTIP.ZIP, maintained up to 2001 and distributed on many sites at the time. The provided link points to a HTML-converted older version of the MSDOSTIP.TXT file.) [https://web.archive.org/web/20190601152204/https://www.sac.sk/download/text/mpdostip.zip<!-- A yet older version 155 from 1997-05-13 of the 1997-07-15 distribution archive. -->]</ref>
<ref name="Paul_1997_4DOSTIP">{{cite web |title=Hinweise zu JPSofts 4DOS 5.5b/c, 5.51, 5.52a und NDOS |work=MPDOSTIP |author-first=Matthias R. |author-last=Paul |date=1997-05-01 |orig-year=1995-03-01 |language=de |url=http://www.antonis.de/dos/dos-tuts/mpdostip/html/4dostip.htm |access-date=2015-05-08 |url-status=live |archive-url=https://web.archive.org/web/20161104211143/http://www.antonis.de/dos/dos-tuts/mpdostip/html/4dostip.htm |archive-date=2016-11-04}} (NB. The provided link points to a HTML-converted version of the <code>4DOS5TIP.TXT</code> file, which is part of the <code>MPDOSTIP.ZIP</code><!-- still named TIPS_MP.ZIP between 1991 and 1996-11 --> collection.) [https://web.archive.org/web/20190601152204/https://www.sac.sk/download/text/mpdostip.zip<!-- A yet older version 155 from 1997-05-13 of the 1997-07-15 distribution archive. -->]</ref>
<ref name="Paul_2002_COM">{{cite newsgroup |title=Re: Run a COM file |author-first=Matthias R. |author-last=Paul |date=2002-10-07 |orig-date=2000 |newsgroup=alt.msdos.programmer |url=https://groups.google.com/d/msg/alt.msdos.programmer/d7blJjY0H5M/Qu3VeTOIGVcJ |access-date=2017-09-03 |url-status=live |archive-url=https://archive.today/20170903230312/https://groups.google.com/forum/%23!msg/alt.msdos.programmer/d7blJjY0H5M/Qu3VeTOIGVcJ |archive-date=2017-09-03}} [https://groups.google.com/d/msg/alt.lang.asm/PNOd9zfYow0/vXbab16j4XwJ] (NB. Has details on DOS COM program calling conventions.)</ref>
}}
==Further reading==
* {{cite
* {{cite web |title=Format of Program Segment Prefix (PSP) |date=2000 |work=[[INTER61]] |url=http://www.delorie.com/djgpp/doc/rbinter/it/78/13.html |access-date=2019-12-19 |url-status=live |archive-url=https://web.archive.org/web/20200217223939/http://www.delorie.com/djgpp/doc/rbinter/it/78/13.html |archive-date=2020-02-17}}
* {{cite book |title=DOS 5 für Programmierer: Die endgültige Referenz |language=de |chapter=Kapitel 5: EXEC im Detail - Program Segment Prefix (PSP) |author-first=Arne |author-last=Schäpers |date=1991 |edition=1 |publisher=[[Addison Wesley (Deutschland) GmbH]] |isbn=3-89319-350-2 |pages=148–151, 971–972}} (1123+v pages, foldout, 5.25"-floppy)
==External links==
|