Archives
- October 2025
- September 2025
- August 2025
- July 2025
- June 2025
- May 2025
- April 2025
- March 2025
- February 2025
- January 2025
- December 2024
- November 2024
- October 2024
- September 2024
- August 2024
- July 2024
- June 2024
- May 2024
- April 2024
- March 2024
- February 2024
- January 2024
- October 2023
- September 2023
- August 2023
- July 2023
- June 2023
- May 2023
- April 2023
- March 2023
- January 2023
- December 2022
- November 2022
- October 2022
- September 2022
- July 2022
- June 2022
- May 2022
- April 2022
- March 2022
- February 2022
- January 2022
- December 2021
- November 2021
- October 2021
- September 2021
- August 2021
- July 2021
- June 2021
- May 2021
- April 2021
- March 2021
- February 2021
- January 2021
- December 2020
- November 2020
- October 2020
- September 2020
- August 2020
- July 2020
- June 2020
- May 2020
- April 2020
- March 2020
- February 2020
- January 2020
- December 2019
- November 2019
- October 2019
- September 2019
- August 2019
- July 2019
- June 2019
- May 2019
- April 2019
- March 2019
- February 2019
- January 2019
- December 2018
- November 2018
- October 2018
- August 2018
- July 2018
- June 2018
- May 2018
- April 2018
- March 2018
- February 2018
- January 2018
- December 2017
- November 2017
- October 2017
- August 2017
- July 2017
- June 2017
- May 2017
- April 2017
- March 2017
- February 2017
- January 2017
- December 2016
- November 2016
- October 2016
- September 2016
- August 2016
- July 2016
- June 2016
- May 2016
- April 2016
- March 2016
- February 2016
- January 2016
- December 2015
- November 2015
- October 2015
- September 2015
- August 2015
- July 2015
- June 2015
- May 2015
- April 2015
- March 2015
- February 2015
- January 2015
- December 2014
- November 2014
- October 2014
- September 2014
- August 2014
- July 2014
- June 2014
- May 2014
- April 2014
- March 2014
- February 2014
- January 2014
- December 2013
- November 2013
- October 2013
- September 2013
- August 2013
- July 2013
- June 2013
- May 2013
- April 2013
- March 2013
- February 2013
- January 2013
- December 2012
- November 2012
- October 2012
- September 2012
- August 2012
- July 2012
- June 2012
- May 2012
- April 2012
- March 2012
- February 2012
- January 2012
- December 2011
- November 2011
- October 2011
- September 2011
- August 2011
- July 2011
- June 2011
- May 2011
- April 2011
- March 2011
- January 2011
- November 2010
- October 2010
- August 2010
- July 2010
Another witness against WordStar
Previous posts examined the question why IBM implemented the A20 hardware in the PC/AT, causing endless headaches to future PC hardware and software developers. WordStar emerged as a possible culprit, but no one would quite point the finger at it.
The OS/2 Museum is now in possession of the original MS-DOS Encyclopedia (1986) which identifies WordStar in print. This is the same book that Larry Osterman claimed to have been subject to a publisher recall; either Microsoft Press didn’t do a very good job of pulling the book from the shelves or Larry Osterman’s recollection is inaccurate, but the book isn’t very difficult to find. (However, at about 8 pounds, or nearly 4 kilograms, it is quite difficult to carry around!)
On page 34, the MS-DOS Encyclopedia says: "For example, in CP/M-80, programmers would call address 5 in order to request a function. In MS-DOS, Interrupt 21 was the function call. But to support old programs, the first version of MS-DOS also allowed a program to request functions by calling address 5. Although this feature was not documented, a number of existing programs continued to use it when they were converted to MS-DOS. One of these programs was WordStar. Microsoft could not afford to make changes in the operating system that would make it impossible to run a program as popular as WordStar. So each new version had to continue supporting CALL 5, even though it was never documented."
It is worth pointing out that the Encyclopedia contradicts itself somewhat. On page 14, it talks about how one of the objectives of MS-DOS (or 86-DOS) was to support mechanical translation of CP/M-80 programs. Such programs naturally used the CALL 5 interface and of course DOS had to support that, officially documented or not. It is sufficiently different from the INT 21h interface that automatic translation would be likely to fail.
In the second edition of the MS-DOS Encyclopedia, CP/M compatibility and WordStar are mentioned, but without explicitly naming the CALL 5 interface. At any rate, if the early WordStar editions for the PC used the CALL 5 interface, they would have certainly (indirectly) required address wraparound. WordStar may well have been enough reason for IBM to worry about backwards compatibility in the PC/AT. Examining a copy of WordStar for the IBM PC from 1982-1983 would be the only way to tell with 100% certainty, but at this point it seems beyond reasonable doubt that WordStar did use the CALL 5 interface.
It should be noted that years later, when DOS 5.0 might run with the A20 line permanently enabled, the most common source of problems related to address wraparound was Microsoft’s EXEPACK utility (later built into Microsoft’s LINK), or rather executables processed with EXEPACK. The problem manifested itself with the infamous "Packed file corrupt" message. However, there is no evidence that EXEPACK was available before the release of the IBM PC/AT in August 1984; the first known EXEPACK version is from early 1985 (shipped with Microsoft C 3.0). On the other hand, WordStar most certainly predated the PC/AT and was quite popular at the time.
17 Responses to Another witness against WordStar
“It is sufficiently different from the INT 21h interface that automatic translation would be likely to fail.”
Yep, the problems with A20 makes the CP/M-86 solution of doing 8080 to 8086 translation then replace all CALL 5s with INT E0s look much better IMO.
If you are willing to ignore the possibility that a program might make indirect calls to offset 5, or that it uses the interrupt vector E0h for its own purposes.
“or that it uses the interrupt vector E0h for its own purposes.”
Given that the program’s just been translated from 8080 source, that’s just as unlikely as it using INT 30h for its own purposes and thereby breaking CALL 5.
That’s a good point, but let me rephrase that – “or that interrupt vector E0h might be used for some other purpose”. Interrupt 30h was reserved for DOS, interrupt E0h was in the “used by BASIC interpreter while BASIC is running” range and conceivably could used by something else as well. Not an issue for CP/M-86 per se, but an issue for any software running on the PC platform.
I wonder if there were any CP/M programs which patched the code at offset 5, diverting system calls to some custom handler. Although those would probably fail either way.
There were CP/M programs that hooked CALL 5 — for example, the Graphics System eXtension worked by attaching a loader to .COM files, and this loader would relocate itself to the top of memory, hook CALL 5, and load the appropriate graphics driver. But the moment you start doing things like that, mechanical translation isn’t going to cut it. Likewise with any program that tries to hook CALL 5 and go resident, or any program that assumes the word at 0001h is the address of a BIOS jumpblock, or any program which assumes system calls 7 / 8 / 12 have the same semantics in CP/M and DOS.
Really, translating CALL 5 to CALL 5 doesn’t get you much, if anything over translating it to MOV AH,CL ! INT 21h. It does make life easier for the author of the translation program, because it removes the requirement to parse all the symbols and work out which ones evaluate to 5.
If the translation program is written in 8-bit assembler and runs on some Z-80, that may well be an important consideration. Also, in a project like that, it’s a sound engineering practice to make only changes that are unavoidable… and replacing CALL 5 with some other means of invoking system calls was not.
The translation program is documented in the 86-DOS User manual (pages 47-49) at the Paterson Tech website. It is a simple general purpose 8080 to 8086 converter not a CP/M-80 to 86-DOS converter. Everything I have read indicates that SCP did not want to be an OS manufacturer so constraining the translator to only one OS would be less than helpful. I suspect that SCP anticpated that the converter would mostly be used for companies to get their own self-booting software including OSes quickly ported over to use the expensive SCP hardware.
I always thought that the CALL 5 interface in DOS and the little used DOS 2 stack frame interface at PSP 50h were clever ways of getting programmers to support DOS with minimal effort. Considering how only little of the CP/M-80 software got ported to CP/M-86, there might be something to making programmers lives easier.
A little late, I know, but …. I think you’re wrong. A call 5, let’s remember, is an *intra-segment* call which in most cases ends up in the PSP’s “int 21h / ret” combo. It has nothing to do with address wraparound, which occurs only at the very end of the 1st Mb.
Oh, it has everything to do with address wraparound. Because the code at offset 5 in the PSP is something like “CALL FEF0, F01D” (DOS 2.0) or “CALL F01D:FEEE” (PC DOS 2000).
But why did the code look like that, and why couldn’t IBM and Microsoft have changed DOS?
They could have changed DOS, but they couldn’t change CP/M. Remember, the PSP was meant to be compatible with CP/M (that is CP/M-80 of course, as the non-existence of CP/M-86 was the reason QDOS was written in the first place!). The short story is that there wasn’t enough space for a far call in the PSP. If you look for example here (see Figure 1 on page 6), you will see that the “syscall” jump is at offset 5 but the word at offset 6 gives the number of bytes available (because in CP/M-80, the jump target was right after the memory available to the program).
So you have one byte for a far jump opcode and the next word needs to indicate the number of bytes free in the segment, what do you do? If you’re Tim Paterson (and yes, he invented the mechanism), you take advantage of the address wraparound so that the offset (typically) points at the end of a 64K segment but the segment portion of the far jump is chosen such that the address wraps back around to the beginning of the address space where the DOS system call entry point lives. All this is necessary so that CP/M-80 programs (written in assembler) can be mechanically translated to run on 8086 + DOS.
It’s really a very clever idea on the 8086. Sadly falls apart on a 286 (but you can’t blame Tim Paterson for that). IBM enters the scene and chaos ensues.
Note that the oldest WordStar PC binaries are still missing to my knowledge, so I don’t think anyone has been able to undeniably confirm that WordStar for the IBM PC really used the CALL 5 interface. The newer WS binaries are different, but that’s not surprising. There is a non-zero chance that there were applications/utilities other than WordStar which used CALL 5.
Oh!
But what was in location 8,9,A e.t.c?
I don’t know that much about x86 assembly, but if there is some instruction that has a one byte op code and takes two bytes as operand(s) and doesen’t perform any function that could mess upp with the call to call 5, you could perhaps have had that instruction at byte 5, any two bytes you would want at byte 6 and 7, and have the actual jump at byte 8.
As far as I can see from here it seems like byte 8 and onwards is free to use:
http://www.gaby.de/cpm/manuals/archive/cpm22htm/ch6.htm#Section_6.9
If it were a 6502 system you could have used the BIT instruction which is meant to be used to test bits in any memory location, but the wanted effect is that it only affects the flags and “consumes”. I don’t know if this is possible on x86. (As the contents of location 6 and 7 should point to a specific location in memory you might be able to use an instruction where byte 6 or byte 6+7 is part of the opcode together with byte 5).
“Free to use” might just mean “users can write whatever they like in there”, although I don’t think that was a real concern. DOS 1.0 had termination address at offset 10 in the PSP I believe, so there wasn’t enough room left. But putting some “harmless” 3-byte instruction at offset 5 might have been a possibility, if the termination address were shifted. Perhaps.
The question is then: is there any such harmless instructions?
The problem with not being able to touch adress 10 might had been solveable in two ways. One is if it would be possible to use a two byte jump at adress 8 and 9 (is there any such jumps in x86?) and another would be to put a two byte store to memory instruction in those bytes (if there is any such instruction) and let the termination code check if a certain adress has been written to, i.e. detect call 5, or if not written to just run the exit code.
The more I read and discuss such topics the more I think I should learn x86 assembler π
(I always avoided x86 assembler back in the days because I got the impression that people who actually were writing some x86 assembler code didn’t really understand everything but just used some standard startup code that someone else had written e.t.c.. That was probably fine for just writing applications or more likely parts of applications, but for me who were more interested in system programming that weren’t good enough)
Pingback: The A20-Gate: It Wasn’t WordStar | OS/2 Museum
Looks like there are a few posts about the encyclopedia:
https://groups.google.com/d/msg/mod.computers.ibm-pc/yOYGTtpaNrg/49Gysx6dee4J
https://groups.google.com/d/msg/mod.computers.ibm-pc/W90mGMIxXUo/q9vIWzR1nasJ
I must have the recalled edition with flowcharts… it actually contains significantly more historical information than other sources. As a technical reference it’s less valuable.
This site uses Akismet to reduce spam. Learn how your comment data is processed.