home *** CD-ROM | disk | FTP | other *** search
- PRODUCT : TURBO PASCAL NUMBER : 161
- VERSION : 2.0xx, 3.0xx
- OS : MSDOS
- DATE : March 13, 1986
-
- TITLE : MEMORY MAP INFORMATION
-
- 1. When TURBO.COM is executed, MS-DOS builds a program segment
- prefix in the lower 100H bytes of memory, and loads the code
- immediately above. MS-DOS then jumps to CS: 100H. When Turbo
- Pascal gains control, it sets the DS register to point at the
- first free paragraph after the code, and SS:SP to point at top of
- memory. The latter is achieved by loading Memtop-1000H into SS
- and 0FFFFH into SP. Memtop is the paragraph address of top of
- memory, and it is passed by MS-DOS at CS:02H in the program
- segment prefix.
-
- In systems with little RAM, Memtop-DS may be less than 1000H (64K
- bytes), and in that case SS is set to the same paragraph address
- as DS and SP is set to (Memtop-DS)?16. In the maps that follow
- we assume that Memtop-DS is greater than 1000H.
-
-
- When using the Editor, memory is mapped as follows:
-
- CS:0000 - CS:00FF MS-DOS PROGRAM SEGMENT PREFIX
- CS:0100 - CS:E0RC RUN-TIME LIBRARY CODE
- CS:E0RC - CS:E0CC MONITOR, EDITOR AND COMPILER CODE
- DS:0000 - DS:E0RW RUN-TIME LIBRARY DATA
- DS:E0RW - DS:E0CW MONITOR, EDITOR AND COMPILER DATA
- DS:E0CW - DS:EOEM ERROR MESSAGES (IF LOADED)
- DS:E0EM - DS:???? SOURCE TEXT
- SS:???? - SS:FFFF CPU STACK
-
-
- When the compiler is invoked to compile a program in memory, it
- creates a new code segment immediately above the source text.
- The PSP (Program Segment Prefix) and the run-time library are
- copied from Turbo Pascal's code segment. The reason Turbo Pascal
- creates a second copy of the run-time library is that it does not
- support intersegment references. All calls to run-time routines
- must originate from locations in the same code segment. During
- an in-memory compilation, memory is mapped as follows:
-
-
- CS:0000 - CS:00FF MS-DOS PROGRAM SEGMENT PREFIX
- CS:0100 - CS:E0RC RUN-TIME LIBRARY CODE
- CS:E0RC - CS:E0CC MONITOR, EDITOR AND COMPILER CODE
- DS:0000 - DS:E0RW RUN-TIME LIBRARY DATA
- DS:E0RW - DS:EOCW MONITOR, EDITOR AND COMPILER DATA
- DS:E0CW - DS:E0EM ERROR MESSAGES (IF LOADED)
- DS:O0EM - DS:EOST SOURCE TEXT
-
- CP:0000 - CP:00FF MS-DOS PROGRAM SEGMENT PREFIX (COPY)
- CP:0100 - CP:E0RC RUN-TIME LIBRARY CODE (COPY)
- CP:E0RC - CP:???? PROGRAM CODE
- SS:???? - SS:FC00 SYMBOL TABLE
- SS:???? - SS:FFFF CPU STACK
-
- To execute the finished program, Turbo Pascal simply does a far
- jump to offset 100H in the new program segment (CP). It will
- then look to the program as if it had been executed from MS-DOS.
-
- When a Turbo Pascal program is executed in memory or from MS-DOS,
- it maps memory as shown below:
-
- CS:0000 - CS:00FF MS-DOS PROGRAM SEGMENT PREFIX (COPY)
- CS:0100 - CS:E0RC RUN-TIME LIBRARY CODE (COPY)
- CS:E0RC - CS:E0PC PROGRAM CODE
- DS:0000 - DS:E0RW RUN-TIME LIBRARY DATA
- DS:E0RW - DS:E0PW PROGRAM DATA
- HS:0000 - ??????? HEAP (TOP ADDRESS IN HEAPPTR)
- SS:???? - SS:FFFF CPU STACK
-
- On entry, DS is set to point just above the code segment, and the
- heap pointer (HeapPtr) is set to point just above the data
- segment. SS:SP is set to point at top of memory, using the same
- technique as when Turbo Pascal itself is executed.
-
- When a program terminates, it either returns to MS-DOS (using
- system function 0) or it does a far jump back to Turbo Pascal,
- depending on a flag in the program code.
-
- Typed constants are stored in the code segment and, except for
- their base segment (CS versus DS), correspond to variables in all
- aspects. Untyped constants are never stored in the sense that
- they have a fixed address somewhere in memory. An untyped
- constant is only coded when used in an expression and is usually
- moved into a register or onto the stack, in this case.
-
- 2. There is no recursion stack in the 16-bit versions of Turbo
- Pascal. It is only in the 8-bit version that the CPU stack and
- the recursion stack are separated. The 16-bit version implements
- a true "stack frame" concept, meaning that all local variables
- are allocated on the CPU stack and addressed through the BP (Base
- Page) CPU register.
-
- 3. The CSEG, DSEG, and SSEG return the contents of the CS, DS,
- and SS Registers, respectively. However, contrary to the other
- segment registers, the value of the ES register is not fixed.
- Turbo Pascal will initialize it when it uses it. ES is used
- heavily by the run-time library routines and plays an active
- role in most 8086 string instructions (MOVS, STOS, CMPS, etc.).
- It is also used to access variables indirectly, such as variable
- parameters and pointers. You can use ES any way you like in your
- routines, but do not make any assumptions about its initial
- value.
-
- 4. The fields of the PSP are easily accessed by declaring them
- as absolute variables in the code segment. For instance:
-
- var CMDLine: String(127) absolute CSeg:$80H
-
- which declares a variable to access the command line passed by
- MS-DOS in the PSP.
-
- The chain and execute procedures store 0FF in the byte at CS:80H
- to indicate that the program was invoked from another program and
- not from MS-DOS. Otherwise, the PSP is not changed during a
- chain/execute operation. Turbo Pascal only accesses the PSP to
- find the address of top of memory and to write the chain/execute
- flag as described above.
-
- 5. There is no official way to catch run-time errors in the
- current versions of Turbo Pascal.
-
- 6. When a COM File is invoked from MS-DOS, all segment registers
- are set to point at the program segment prefix. This initial
- value is retained in the CS register during execution, and you
- can obtain it through the CSEG function.
-
-
-
- 7. Turbo Pascal initializes the divide-by-zero interrupt vector
- (Interrupt 0). When the U compiler option is activated with an
- {$U+} directive, Turbo Pascal initializes interrupt vector 3 to
- point at a Ctrl-C check routine. In both cases, MS-DOS system
- function 25 (set vector) is used to carry out the initialization.
-
-
- 8. There is no additional information available on the inner
- workings of the Turbo Pascal initialization routines (front end).
- However, most if not all of the tasks carried out by it are
- covered in the reference manual and the above answers.
-
-