home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / PROG / PASCAL / MISCTI10.ZIP / TI161.ASC < prev    next >
Encoding:
Text File  |  1988-04-18  |  6.4 KB  |  146 lines

  1. PRODUCT : TURBO PASCAL     NUMBER : 161
  2. VERSION : 2.0xx, 3.0xx
  3.      OS : MSDOS
  4.    DATE : March 13, 1986
  5.  
  6.   TITLE : MEMORY MAP INFORMATION
  7.  
  8. 1.   When TURBO.COM is executed,  MS-DOS builds a program segment
  9. prefix  in  the lower 100H bytes of memory,  and loads  the  code
  10. immediately above.   MS-DOS then jumps to CS:  100H.   When Turbo 
  11. Pascal  gains  control,  it sets the DS register to point at  the 
  12. first free paragraph after the code, and SS:SP to point at top of 
  13. memory.  The  latter is achieved by loading Memtop-1000H into  SS 
  14. and  0FFFFH into SP.  Memtop is the paragraph address of  top  of 
  15. memory,  and  it  is  passed by MS-DOS at CS:02H in  the  program 
  16. segment prefix.  
  17.  
  18. In systems with little RAM, Memtop-DS may be less than 1000H (64K 
  19. bytes),  and in that case SS is set to the same paragraph address 
  20. as  DS and SP is set to (Memtop-DS)?16.   In the maps that follow 
  21. we assume that Memtop-DS is greater than 1000H.
  22.  
  23.  
  24. When using the Editor, memory is mapped as follows:
  25.  
  26.    CS:0000 - CS:00FF   MS-DOS PROGRAM SEGMENT PREFIX
  27.    CS:0100 - CS:E0RC   RUN-TIME LIBRARY CODE
  28.    CS:E0RC - CS:E0CC   MONITOR, EDITOR AND COMPILER CODE
  29.    DS:0000 - DS:E0RW   RUN-TIME LIBRARY DATA
  30.    DS:E0RW - DS:E0CW   MONITOR, EDITOR AND COMPILER DATA
  31.    DS:E0CW - DS:EOEM   ERROR MESSAGES (IF LOADED) 
  32.    DS:E0EM - DS:????   SOURCE TEXT
  33.    SS:???? - SS:FFFF   CPU STACK
  34.  
  35.  
  36. When  the compiler is invoked to compile a program in memory,  it 
  37. creates  a  new code segment immediately above the  source  text.  
  38. The  PSP  (Program Segment Prefix) and the run-time  library  are 
  39. copied from Turbo Pascal's code segment.  The reason Turbo Pascal 
  40. creates a second copy of the run-time library is that it does not 
  41. support intersegment references.   All calls to run-time routines 
  42. must originate from locations in the same code  segment.   During 
  43. an in-memory compilation, memory is mapped as follows:
  44.  
  45.  
  46.    CS:0000 - CS:00FF   MS-DOS PROGRAM SEGMENT PREFIX
  47.    CS:0100 - CS:E0RC   RUN-TIME LIBRARY CODE
  48.    CS:E0RC - CS:E0CC   MONITOR, EDITOR AND COMPILER CODE
  49.    DS:0000 - DS:E0RW   RUN-TIME LIBRARY DATA
  50.    DS:E0RW - DS:EOCW   MONITOR, EDITOR AND COMPILER DATA
  51.    DS:E0CW - DS:E0EM   ERROR MESSAGES (IF LOADED)
  52.    DS:O0EM - DS:EOST   SOURCE TEXT
  53.  
  54.    CP:0000 - CP:00FF   MS-DOS PROGRAM SEGMENT PREFIX (COPY)
  55.    CP:0100 - CP:E0RC   RUN-TIME LIBRARY CODE (COPY)
  56.    CP:E0RC - CP:????   PROGRAM CODE
  57.    SS:???? - SS:FC00   SYMBOL TABLE
  58.    SS:???? - SS:FFFF   CPU STACK
  59.  
  60. To  execute the finished program,  Turbo Pascal simply does a far 
  61. jump  to offset 100H in the new program segment  (CP).   It  will 
  62. then look to the program as if it had been executed from MS-DOS.
  63.  
  64. When a Turbo Pascal program is executed in memory or from MS-DOS, 
  65. it maps memory as shown below:
  66.  
  67.    CS:0000 - CS:00FF   MS-DOS PROGRAM SEGMENT PREFIX (COPY)
  68.    CS:0100 - CS:E0RC   RUN-TIME LIBRARY CODE (COPY)
  69.    CS:E0RC - CS:E0PC   PROGRAM CODE
  70.    DS:0000 - DS:E0RW   RUN-TIME LIBRARY DATA
  71.    DS:E0RW - DS:E0PW   PROGRAM DATA
  72.    HS:0000 - ???????   HEAP (TOP ADDRESS IN HEAPPTR)
  73.    SS:???? - SS:FFFF   CPU STACK
  74.  
  75. On entry, DS is set to point just above the code segment, and the 
  76. heap  pointer  (HeapPtr)  is  set to point just  above  the  data 
  77. segment.   SS:SP is set to point at top of memory, using the same 
  78. technique as when Turbo Pascal itself is executed.
  79.  
  80. When  a  program terminates,  it either returns to MS-DOS  (using 
  81. system  function 0) or it does a far jump back to  Turbo  Pascal, 
  82. depending on a flag in the program code.
  83.  
  84. Typed  constants are stored in the code segment and,  except  for 
  85. their base segment (CS versus DS), correspond to variables in all 
  86. aspects.   Untyped  constants are never stored in the sense  that 
  87. they  have  a  fixed address somewhere  in  memory.   An  untyped 
  88. constant  is only coded when used in an expression and is usually 
  89. moved into a register or onto the stack, in this case. 
  90.  
  91. 2.   There  is no recursion stack in the 16-bit versions of Turbo 
  92. Pascal.   It is only in the 8-bit version that the CPU stack  and 
  93. the recursion stack are separated.  The 16-bit version implements 
  94. a  true "stack frame" concept,  meaning that all local  variables 
  95. are allocated on the CPU stack and addressed through the BP (Base 
  96. Page) CPU register.
  97.  
  98. 3.   The CSEG,  DSEG, and SSEG return the contents of the CS, DS, 
  99. and SS Registers,  respectively.  However,  contrary to the other 
  100. segment  registers,  the  value of the ES register is not  fixed. 
  101. Turbo  Pascal will initialize  it when it uses it.    ES is  used 
  102. heavily  by  the  run-time library routines and plays  an  active 
  103. role in most 8086 string instructions (MOVS,  STOS,  CMPS, etc.).  
  104. It is also used to access variables indirectly,  such as variable 
  105. parameters and pointers.  You can use ES any way you like in your 
  106. routines,  but  do  not make any assumptions  about  its  initial 
  107. value.
  108.  
  109. 4.   The  fields of the PSP are easily accessed by declaring them 
  110. as absolute variables in the code segment.  For instance:
  111.  
  112.      var CMDLine: String(127) absolute CSeg:$80H
  113.  
  114. which  declares a variable to access the command line  passed  by 
  115. MS-DOS in the PSP.
  116.  
  117. The chain and execute procedures store 0FF in the byte at  CS:80H 
  118. to indicate that the program was invoked from another program and 
  119. not  from MS-DOS.   Otherwise,  the PSP is not changed  during  a 
  120. chain/execute  operation.  Turbo Pascal only accesses the PSP  to 
  121. find the address of top of memory and to write the  chain/execute 
  122. flag as described above.
  123.  
  124. 5.   There  is  no official way to catch run-time errors  in  the 
  125. current versions of Turbo Pascal.  
  126.  
  127. 6.  When a COM File is invoked from MS-DOS, all segment registers 
  128. are  set to point at the program segment  prefix.   This  initial 
  129. value  is retained in the CS register during execution,  and  you 
  130. can obtain it through the CSEG function.
  131.  
  132.  
  133.  
  134. 7.   Turbo Pascal initializes the divide-by-zero interrupt vector 
  135. (Interrupt 0).   When the U compiler option is activated with  an 
  136. {$U+}  directive,  Turbo Pascal initializes interrupt vector 3 to 
  137. point at a Ctrl-C check routine.   In both cases,  MS-DOS  system 
  138. function 25 (set vector) is used to carry out the initialization.
  139.  
  140.  
  141. 8.   There  is no additional information available on  the  inner 
  142. workings of the Turbo Pascal initialization routines (front end).  
  143. However,  most  if  not  all of the tasks carried out by  it  are 
  144. covered in the reference manual and the above answers.
  145.  
  146.