DOS UNBOUND: USES OF

exist but seem not to, the word virtual re- TWO VERSIONS OF THE DOS WRITE FUNCTION fers to things that seem to exist but don't. The 386 provides a V86 mode that Table 4:DOS extenders alter the normal DOS protocol; the source buffer can creates the illusicn of an 8086 machine hold 4 gigabytes of data. located in an arb:trary place in the 386 address space. The 386's segmentation Real -mode MS-DOS Int 21h function 40h and paging provide hardware assistance Write file or device for virtual memory; this allows it to pre- BX = handle tend that it has more memory than is CX = number of bytes to write physically present. DS:DX = segment:offset of buffer While V86 mode is generally used by 32 -bit protected -mode DOS extender multitaskers such as Desqview and Win- Int 21h function 40h dows or memory managers such as 386 - Write file or device Max or QEMM, Ergo's OS/386 makes a BX = handle ECX = number of bytes to write novel use of V86 mode. It uses it as a DS:EDX = segment:offset of buffer quick -and -dirty way to provide simple DOS applications (normally limited to something less than 640K bytes) with several hundred kilobytes more memory. without a program's knowledge andality. the DOS API includes the follow- Ergo's up program, which runs .EXP without any source code changes, almosting: absolute memory locations, port ad- files, can also run real -mode .EXE files. all genuine programs that use VM re-dresses, undocumented DOS calls and As table1 shows, when up runs underquire some recoding to get decent perfor- data structures, handlers, DOS OS/386 in this configuration, the real - mance. For example, if a program allo- exter sions (e.g., the mouse or NetBIOS), mode MEM program now allocatescates 13 MB of memory (of which only 3 and even the vagaries of itself 617K bytes. MBis physical memory), and if the pro-(e.g., a segment ID corresponds to its ab- OS/386 also provides a utility calledgram frequently loops over, say, 4 MB at solute physical address divided by 16). giveameg. When this utility runs onany one time, the program will thrash Such code may represent less than 5 per- simple programs like MEM, it can pro- horribly. To be usable, the program cent of all code in a real DOS applica- vide up to1 MB of memory in V86 tion. Some of it may have been written to mode. (This only works on the 386.) Be- get around the 640K -byte or 64K -byte cause the resulting program isn't really DOS barriers, so you can simply ditch it running at the memory location that it when you work in 32 -bit protected mode. thinks it's running at, this technique Something But what about graphics code, interrupt won't work if yoJ need to address abso- handlers, and telecommunications or lute memory locations such as B8000h or that at first seems like networking code? How can you make 400h. But and other stdio text such low-level code work in 32 -bit pro- processors may find that the few hundred a free lunch tected mode? extra kilobytes can be quite handy. This Most of the work in porting to pro- technique just takes a real -mode execut- is virtual memory. tected mode will be confined to small able and runs it; n a funny way. To take portions of your code. The best way to full advantage cf the 386, though, you proceed with such a port is to get all your have to switch to a 32 -bit . modules to compile and link for 32 -bit Something that at first seems like a protected mode and then try to run the free lunch is virtual memory. Both Phar would need to be tweaked until its "lo-thing. The chances are good that the pro- Lap and Ergo crovide VM options forcality of reference" fell within 3 MB. gram will, in some way, break one of the their 32 -bit DOS extenders. From table 1 rules of protected mode. Because of you can see that, on the same machine Protection Violations these rules, protected mode is sometimes with 4 MB of memory, and with the So far, I haven't described anything re- regarded as an unfair and stern task mas- same source code (and, in fact, the same sembling the sort of work you might ex-ter, forcing you to change all your pro- MEM.EXP), the tiny program can allo- pect when porting code to a new environ- gramming habits in exchange for extra cate 13 MB of memory when it runsment. Unlike OS/2, for example, whichmegabytes of memory. In fact, you under VM. The 13 -MB limit was merelypresents an entirely new world view,should look on protected mode as a the amount of free disk space I had. DOS extenders try to preserve as much offriend that will help you incrementally For Ergo OS/386, using VM requiresyour old source code as possible. Their port your program. Because of protec- installing the os386vm TSR instead ofrelationship to MS-DOS is somewhat like tion, it's fairly difficult to crash the ma- os386. By default, this uses "only" 8that of early DOS to CP/M. The use ofchir.e. Instead, you just run your pro- MB of VM (i.e.. disk space), but you can INT 21h is, of course, the prime exam-gram until it violates protection, fix the reconfigure it. The 3861VMM option tople: 32 -bit protected -mode operationsproblem, and then let the program run 's 386 DOS -Extender is a pro- have been made to look like plain -vanilla until it hits the next protection violation. tected -mode executable, VMMDRV DOS operations. The CPU itself, running in protected .EXP, which you can bind into your exe- But for most commercial DOS appli-mode, will find most of your problems cutable or, during development, run oncations, the MS-DOS application pro- for you. the DOS command line: run386 -vmgramming interface does not consist en- What does a protection violation look vmmdrv. exp mein. tirely of INT 21h calls, or even of BIOS like? For an example, look at TICKS, the While this shows that you can use VM calls such as INT 10h or INT 13h. In re- continued

BYTE IBM Special Edition Fall 1990 255