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

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