home *** CD-ROM | disk | FTP | other *** search
/ Power Programming / powerprogramming1994.iso / progtool / info / dos3src.arc / DOS3SRC.DOC < prev    next >
Text File  |  1986-01-06  |  9KB  |  160 lines

  1.  
  2. This library contains scripts which can be used, in conjunction with the widely
  3. available public-domain disassembler 'ASMGEN.COM', produce fairly intelligible
  4. source for the PC-DOS v3.0 system files IBMBIO.COM, IBMDOS.COM, & COMMAND.COM.
  5. Tactfully, one might state that their use is intended to 'augment and clarify'
  6. the technical documentation provided by IBM and Microsoft.
  7.  
  8. The user is assumed to have access to and be familiar with v2.01 of ASMGEN; if
  9. the latter assumption holds, it may also follow that s/he is familiar with some
  10. of its limitations, as well.  Those limitations that are pertinent here 
  11. include :
  12.  
  13.     1) The destination operand of LES instructions is incorrectly
  14.     generated as a byte, vice word, register.  As per Intel CodeMacros,
  15.     the following equivalences hold :
  16.  
  17.                Byte               Word
  18.                ----               ----
  19.             AL            AX
  20.                    CL            CX
  21.                    DL            DX
  22.                    BL            BX
  23.                    AH            SP
  24.                    CH            BP
  25.                    DH            SI
  26.                    BH            DI
  27.  
  28.     Thus, read 'LES DI,[data]' for 'LES BH,[data]', etc.  The LES
  29.     instruction is an unfortunate exception to the general rule on
  30.     the 8086, where even opcodes take byte arguments.
  31.  
  32.     2) The arguments to inter-segment direct CALLs and JMPs are not
  33.     generated correctly by the disassembler.  I can't think of any
  34.     instance where either of these instructions occurs in any of the
  35.     DOS 3.0 system files; if you encounter any, you'll have to use
  36.     a debugger to provide the correct address.
  37.  
  38.     3) Most significantly, ASMGEN's ability to deal with segmentation
  39.     and relocation is somewhat limited:  immediate word data in a segment
  40.     other than the first in the file is generated inconsistently, although
  41.     the program will often generate the 'real' operand as a comment.  In
  42.     some cases, this manifests itself in generated output such as :
  43.  
  44. ...
  45. L1190    SEGMENT
  46.     ASSUME  ...
  47. ...
  48. L1234    CMP    AX, OFFSET L1190     ;0000
  49. ...
  50.       In other cases, the immediate operand is "clobbered" a bit more
  51.     thoroughly, i.e, made negative and large.  This limitation is 
  52.     encountered when disassembling IBMBIO and COMMAND, since both contain
  53.     large sections of code which is executed at an offset other than that
  54.     at which it is stored in the .COM file.  I found the behavior of the
  55.     suggested remedies (use of "d", "/l-", etc., in the .SEQ file) to
  56.     be inconsistent with the ASMGEN documentation and eventually abandoned
  57.     all attempts to deal with this problem; if you have any success with
  58.     it, I'd appreciate hearing of it.  In the meantime, view all immediate
  59.     'offsets' in listings of relocated code with sympathy and keep a hex
  60.     calculator handy.
  61.  
  62. Problem (3) can be circumvented by splitting COMMAND and IBMBIO into two parts,
  63. treating the relocated code as a large block of 'byte data' in the original,
  64. and using the .SEQ files as a guide to disassembling the 'new' file which
  65. contains the relocated code.   The relocated portion of IBMBIO (code which
  66. loads & interprets CONFIG.SYS) executes at offset 0000 within its segment;
  67. the 'transient portion of COMMAND.COM' executes at offset 0x0100.  This
  68. procedure will, of course, clarify the internal structure (intra-segment) of
  69. the relocated procedure but may obscure its interaction with the 'resident'
  70. segments of the programs.
  71.  
  72. The scripts provided are named BIO3.SEQ (for IBMBIO), DOS3.SEQ (for IBMDOS),
  73. and COMMAND3.SEQ (for COMMAND.COM).  I chose these names so that I could
  74. work with them on a DOS 2.x system, calling the executable files BIO3.ABS,
  75. DOS3.ABS, and COMMAND3.COM.  The disassembler cares only that the .SEQ file
  76. and the file to be disassembled have the same name and can be found on the
  77. same drive when it is invoked.   ATTRIB (or, for the brave, DEBUG) will have
  78. to be used to un-hide the first two files; remember to use caution and to use
  79. a backup DOS disk.
  80.  
  81. I claimed earlier that the output of all this was 'fairly intelligible'; I can
  82. substantiate this by noting that my own understanding of DOS' behavior has
  83. benefited from the exercise.  The work presented here is far from complete;
  84. hopefully, those interested in a greater level of detail can productively use
  85. this information as a starting point.
  86.  
  87.  
  88. Discoveries Big and Small, in no Particular Order :
  89. ----------- --- --- ------ -- -- ---------- ----- -
  90.  
  91. 1)  All of EXEC (int 21/4b) is now in low memory (in IBMDOS.)  This makes
  92. the task of writing an alternate shell a bit less gruesome than it has
  93. seemed on previous versions of PC-DOS, although many versions of MS-DOS
  94. have seen it as the responsibility of the operating system, and not of its
  95. command interpreter, to load and execute programs.  Perhaps TOPVIEW has a
  96. component which replaces COMMAND ?
  97.  
  98. If I read things right, IBMBIO 'EXECs' COMMAND (or whatever) 'by hand', i.e.,
  99. without going through function 4b.  Not only would this have made too much
  100. sense, but the initial invocation of COMMAND.COM must be made with an
  101. Environment address of 0; this is part of the means COMMAND uses to determine
  102. that it IS its initial invocation and that user requests to EXIT should be
  103. ignored.  One of the first things COMMAND does is to allocate an environment
  104. which contains a) a null PATH and b) COMSPEC pointing to itself.  A smarter
  105. shell could probably live without either of these, although it should probably
  106. allocate something which will pass EXEC's criteria of a 'valid environment.'
  107.  
  108. 2)  There is (and has been at least since PC-DOS 2.10/MS-DOS 2.11) something
  109. fishy about the 'CP/M-86 style' function calling mechanism (call psp:0005).
  110. If you've ever tried to use this mechanism to call old-style functions and
  111. found it a bit fishy yourself, read on :
  112.  
  113. There's an entry point in IBMDOS, just above the regular 'INT 21' entry, which,
  114. after verifying that CL contains a function # <= 0x24, pops a long return 
  115. address from the stack, pushes the flags, moves CL to AH, and falls into the
  116. INT 21 code near its beginning; when the IRET eventually occurs, it will cause
  117. a return to the caller's caller.  Early on in the initialization part of
  118. IBMDOS, it sets up a far JMP to this entry point at 0000:00C0, down where INT
  119. 30 and INT 31 would be vectored, were they not 'reserved for DOS.'
  120.  
  121. The problem is that, due to some unfortunate arithmetic, the code DOS puts at
  122. offset 0005 of the PSP effectively does a long call to 0000:00BE, which is
  123. where the segment portion of the INT 2F address should be stored.  If this word
  124. contains a 0, there will be a side effect of executing an 'ADD    [BX+SI],AL'
  125. before executing the long jump; depending, of course, on the contents of these
  126. registers, this may be less than desirable.  Worse yet, IBMDOS v3.0 initializes
  127. INT 2F to point to an IRET within itself, and this interrupt may be re-vectored
  128. if SHARE.EXE is invoked; thus, the chances of ever even reaching the long JMP 
  129. become increasingly remote.  Whenever a new PSP is created, the old one, with 
  130. this bogus CALL at 0005, is copied into it; one need find the point when the
  131. first PSP is created in order to find the source of this bug.
  132.  
  133. This is all kind of unfortunate; there are some excellent 8080-model CP/M-86
  134. programs (including an INTERACTIVE disassembler) which would be trivial to port
  135. to DOS if this calling mechanism worked (e.g., INT E0 -> PUSH CS, PUSH 5, 
  136. RET FAR.)
  137.  
  138. 3)  The functions of interrupts 2A and 2F are a bit more extensive than might
  139. have previously been indicated (see articles in PC Tech Journal [12/84, pp. 74-
  140. 75, 102-103].)   Both are initialized to point to IRETs;  SHARE.EXE steals 2F,
  141. and one must assume that the 'PC NETWORK PROGRAM' will steal 2A.   Calls to
  142. both functions are scattered throughout the code, but note the 'net_dummy_xxxx'
  143. routines in IBMDOS.  Note also that a table of the 'dummy' routines is main-
  144. tained, as if one could overwrite those addresses with NOPs and usher in 3.1.
  145. (I looked for such a routine, curious as to what might trigger it and what its
  146. effect might be.  I didn't find it, but that certainly doesn't mean that its
  147. not there.)
  148.  
  149. 4)  Enough !  If you're sick and twisted enough to have read this far, you are
  150. a mutant and will go far in computing, to paraphrase an old Apple reference
  151. manual.  Hopefully, the disassemblies produced by these scripts will enable
  152. you to understand DOS 3.0 ( & 2.x & 3.1) a bit better;  if you discover any
  153. features/bugs which you find interesting, please pass them on.
  154.  
  155. Documenting DOS adequately is a dirty job, but someone has to do it.  I hope
  156. that this will help to get things started.
  157.  
  158.                         Gary Byers
  159.                         CIS [74345,353]