home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 13 / 13.iso / p / p024 / 12.img / ADS3.LIB / MAPPHYS.ASM < prev    next >
Encoding:
Assembly Source File  |  1992-04-27  |  6.4 KB  |  166 lines

  1.         name    mapphys
  2. ; (assemble this with "386asm mapphys")
  3. ;**************************************************************************
  4. ;     (C) Copyright 1988-1992 by Autodesk, Inc.
  5. ;     This program is copyrighted by Autodesk, Inc. and is  licensed
  6. ;     to you under the following conditions.  You may not distribute
  7. ;     or  publish the source code of this program in any form.   You
  8. ;     may  incorporate this code in object form in derivative  works
  9. ;     provided  such  derivative  works  are  (i.) are  designed and 
  10. ;     intended  to  work  solely  with  Autodesk, Inc. products, and 
  11. ;     (ii.)  contain  Autodesk's  copyright  notice  "(C)  Copyright  
  12. ;     1988-1992 by Autodesk, Inc."
  13. ;     AUTODESK  PROVIDES THIS PROGRAM "AS IS" AND WITH  ALL  FAULTS.
  14. ;     AUTODESK  SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF  MER-
  15. ;     CHANTABILITY OR FITNESS FOR A PARTICULAR USE.  AUTODESK,  INC.
  16. ;     DOES  NOT  WARRANT THAT THE OPERATION OF THE PROGRAM  WILL  BE
  17. ;     UNINTERRUPTED OR ERROR FREE.
  18. ;**************************************************************************
  19. ;*                                                                        *
  20. ;*      Physical Memory Mapping module for use with MetaWare's High C     *
  21. ;*      Runtime Initialization Code for small model, protected mode 386.  *
  22. ;*                                                                        *
  23. ;**************************************************************************
  24.         include model   ; Memory model.
  25.  
  26.  
  27. ;Memory Layout:
  28. ;
  29. ; High memory   +---------------+
  30. ;               | END OF MEMORY | 
  31. ;               |---------------|
  32. ;               | top-of-heap   |
  33. ;               |   ...         |
  34. ;               | bottom-of-heap|
  35. ;               |---------------| 
  36. ;               | Physical mem- |
  37. ;               | ory mapped in |
  38. ;               | by 3rd party  |
  39. ;               |---------------|
  40. ;               | Physical mem- |  (This is not applicable for ADS.  This
  41. ;               | ory mapped in |   creates a common buffer for communication
  42. ;               | for ADI       |   between AutoCAD and protect mode ADI.)
  43. ;               |---------------|
  44. ;               |   stack       |
  45. ;               |   ...         |
  46. ;               | end-of-stack  |
  47. ;               |---------------|
  48. ;               |DATA   segments|
  49. ;               |CODE   segments|
  50. ; Low memory    +---------------+
  51. ;
  52. ; The memory layout above shows where physical memory is mapped into the
  53. ; linear address space of the 3rd party application.  A 3rd party can map
  54. ; in physical memory by installing a routine in map_phys_mem(), which is 
  55. ; called from within the MetaWare High C run-time initialization module
  56. ; INITL386.ASM. 
  57. ;
  58. ; The installed routine must map a physical base address that is on a page
  59. ; boundary (a page is four kilobytes) and the amount of memory mapped must
  60. ; be a multiple of four kilobytes.  The routine must return, in EAX, the
  61. ; number of pages mapped.  (See Function 250Ah, INT 21h, in the Phar Lap
  62. ; 386|DOS-Extender Reference Manual for more details.)
  63. ;
  64. ; One page of memory is mapped on top of the stack for protect mode ADI.
  65. ; This page is mapped by code inside INITL386.ASM and serves as the
  66. ; communication buffer between protect mode ADI and AutoCAD.
  67. ;
  68. ; There is limited support for this mechanism under Microsoft Windows
  69. ; and it requires that the PHARLAP.386 driver be installed (this was done
  70. ; for AutoCAD ADI driver support).  The 2509h call will succeed only for
  71. ; linear addresses that fall within the REALBREAK part of a segment.  The
  72. ; returned value is NOT a physical address, but rather an internal DOS-X
  73. ; "handle", and when passed in to the 250Ah call will succeed in mapping
  74. ; in the REALBREAK pages at the end of the segment specified in the 250Ah
  75. ; call.
  76.  
  77.         .386
  78.         .287
  79.  
  80. ifdef   ADS
  81. map_mem_addr    equ     ads_map_mem_addr
  82. map_phys_mem    equ     ads_map_phys_mem
  83. endif   ; ADS
  84.  
  85. TRUE    EQU     1
  86. FALSE   EQU     0
  87.  
  88. DO_SAMPLE_MAP   EQU     FALSE
  89.  
  90. dseg    segment dword 'DATA'
  91. IF      DO_SAMPLE_MAP
  92.         public  map_mem_addr
  93. map_mem_addr    dd      ?
  94. m_errmsg        db      'ERROR:  Unable to map physical memory to'
  95.                 db      ' end of segment.$'
  96. ENDIF
  97. dseg    ends
  98.  
  99. DGROUP  group dseg
  100.  
  101. ?init   segment dword 'CODE'
  102. CGROUP  group   ?init
  103.         assume cs:CGROUP
  104.         
  105. ;**************************************************************************
  106. ;*  map_phys_mem()                                                        *
  107. ;*                                                                        *
  108. ;*      Returns the number of physical memory pages mapped.               *
  109. ;**************************************************************************
  110.  
  111. map_phys_mem    proc    near
  112.         public  map_phys_mem
  113.         assume  ds:DGROUP
  114.  
  115. IF      DO_SAMPLE_MAP
  116.         push    ebx
  117.         push    es
  118.  
  119.         mov     eax,0
  120.         mov     ax,cs
  121.         and     ax,3                    ; mask off rpl bits
  122.         or      ax,34h                  ; Selector mapping in 1st Meg of mem
  123.         mov     ebx,eax
  124.         mov     ax, 2508h
  125.         int     21h                     ; Get Segment Linear Base Address
  126.  
  127.         mov     ebx, ecx                ; Linear base address of segment
  128.         add     ebx, 0A0000h            ; Add in desired offset within segment
  129.         mov     ax, 2509h
  130.         int     21h                     ; Convert Linear Addr to Physical Addr
  131.  
  132.         mov     ebx, ecx                ; Physical base addr of memory to map -
  133.                                         ;    must be a multiple of 4 kilobytes
  134.         push    ds
  135.         pop     es                      ; LDT Selector of segment to modify
  136.         mov     ecx, 16                 ; # of physical 4K memory pages to map
  137.         mov     ax, 250Ah
  138.         int     21h                     ; Map physical memory at end of segment
  139.         jc      m_err
  140.  
  141.         mov     map_mem_addr, eax       ; offset in segment of mapped memory
  142.         mov     eax, 16                 ; # of mapped pages
  143.         jmp     short m_ok
  144.  
  145. m_err:
  146.         lea     edx, m_errmsg
  147.         mov     ah, 09h
  148.         int     21h                     ; Output error message
  149.         mov     eax, 0
  150.  
  151. m_ok:
  152.         pop     es
  153.         pop     ebx
  154.         ret
  155. ELSE
  156.         mov     eax,0
  157.         ret
  158. ENDIF
  159.  
  160. map_phys_mem    endp
  161.  
  162. ?init   ends
  163.         end
  164.