home *** CD-ROM | disk | FTP | other *** search
- .287
- .386
- name zcmaphys
- ; (assemble this with "386asm zcmaphys")
- ;**************************************************************************
- ; (C) Copyright 1988-1992 by Autodesk, Inc.
- ;
- ; This program is copyrighted by Autodesk, Inc. and is licensed
- ; to you under the following conditions. You may not distribute
- ; or publish the source code of this program in any form. You
- ; may incorporate this code in object form in derivative works
- ; provided such derivative works are (i.) are designed and
- ; intended to work solely with Autodesk, Inc. products, and
- ; (ii.) contain Autodesk's copyright notice "(C) Copyright
- ; 1988-1992 by Autodesk, Inc."
- ;
- ; AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
- ; AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF MER-
- ; CHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC.
- ; DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
- ; UNINTERRUPTED OR ERROR FREE.
- ;**************************************************************************
- ;* *
- ;* Zortech C++ 2.1 Runtime Initialization Physical Memory Mapping *
- ;* Module for small model, protected mode 386. *
- ;* *
- ;**************************************************************************
-
-
- ;Memory Layout:
- ;
- ; High memory +---------------+
- ; | END OF MEMORY |
- ; |---------------|
- ; | top-of-heap |
- ; | ... |
- ; | bottom-of-heap|
- ; |---------------|
- ; | Physical mem- |
- ; | ory mapped in |
- ; | by 3rd party |
- ; |---------------|
- ; | Physical mem- | (This is not applicable for ADS. This
- ; | ory mapped in | creates a common buffer for communication
- ; | for ADI | between AutoCAD and protect mode ADI.)
- ; |---------------|
- ; | stack |
- ; | ... |
- ; | end-of-stack |
- ; |---------------|
- ; |DATA segments|
- ; |CODE segments|
- ; Low memory +---------------+
- ;
- ; The memory layout above shows where physical memory is mapped into the
- ; linear address space of the 3rd party application. A 3rd party can map
- ; in physical memory by installing a routine in map_phys_mem(), which is
- ; called from within the Zortech C++ run-time initialization module.
- ;
- ; The installed routine must map a physical base address that is on a page
- ; boundary (a page is four kilobytes) and the amount of memory mapped must
- ; be a multiple of four kilobytes. The routine must return, in EAX, the
- ; number of pages mapped. (See Function 250Ah, INT 21h, in the Phar Lap
- ; 386|DOS-Extender Reference Manual for more details.)
- ;
- ; One page of memory is mapped on top of the stack for protect mode ADI.
- ; This page is mapped by code inside the runtime initializer and serves
- ; as the communication buffer between protect mode ADI and AutoCAD.
- ;
- ; There is limited support for this mechanism under Microsoft Windows
- ; and it requires that the PHARLAP.386 driver be installed (this was done
- ; for AutoCAD ADI driver support). The 2509h call will succeed only for
- ; linear addresses that fall within the REALBREAK part of a segment. The
- ; returned value is NOT a physical address, but rather an internal DOS-X
- ; "handle", and when passed in to the 250Ah call will succeed in mapping
- ; in the REALBREAK pages at the end of the segment specified in the 250Ah
- ; call.
-
- ifdef ADS
- map_mem_addr equ ads_map_mem_addr
- map_phys_mem equ ads_map_phys_mem
- endif ; ADS
-
- TRUE EQU 1
- FALSE EQU 0
-
- DO_SAMPLE_MAP EQU FALSE
-
-
- DGROUP group CONST, _DATA, _BSS
- CONST segment public word use32 'DATA'
- CONST ends
- _BSS segment public word use32 'BSS'
- _BSS ends
-
- _DATA segment public word use32 'DATA'
- IF DO_SAMPLE_MAP
- public map_mem_addr
- map_mem_addr dd ?
- m_errmsg db 'ERROR: Unable to map physical memory to'
- db ' end of segment.$'
- ENDIF
- _DATA ends
-
-
- _TEXT segment public byte use32 'CODE'
- assume cs:_TEXT,ds:DGROUP
-
- ;**************************************************************************
- ;* map_phys_mem() *
- ;* *
- ;* Returns the number of physical memory pages mapped. *
- ;**************************************************************************
-
- public map_phys_mem
- map_phys_mem proc near
-
- IF DO_SAMPLE_MAP
- push ebx
- push es
-
- mov eax,0
- mov ax,cs
- and ax,3 ; mask off rpl bits
- or ax,34h ; Selector mapping in 1st Meg of mem
- mov ebx,eax
- mov ax, 2508h
- int 21h ; Get Segment Linear Base Address
-
- mov ebx, ecx ; Linear base address of segment
- add ebx, 0A0000h ; Add in desired offset within segment
- mov ax, 2509h
- int 21h ; Convert Linear Addr to Physical Addr
-
- mov ebx, ecx ; Physical base addr of memory to map -
- ; must be a multiple of 4 kilobytes
- push ds
- pop es ; LDT Selector of segment to modify
- mov ecx, 16 ; # of physical 4K memory pages to map
- mov ax, 250Ah
- int 21h ; Map physical memory at end of segment
- jc m_err
-
- mov map_mem_addr, eax ; offset in segment of mapped memory
- mov eax, 16 ; # of mapped pages
- jmp short m_ok
-
- m_err:
- lea edx, m_errmsg
- mov ah, 09h
- int 21h ; Output error message
- mov eax, 0
-
- m_ok:
- pop es
- pop ebx
- ret
- ELSE
- mov eax,0
- ret
- ENDIF
-
- map_phys_mem endp
-
- _TEXT ends
- end
-