home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c221 / 1.ddi / MWHC.001 / A < prev    next >
Encoding:
Text File  |  1992-12-09  |  6.5 KB  |  231 lines

  1. small_m = 1
  2. mach386 = 1
  3. GOC = 1
  4. include model
  5.     .386p
  6.     page    66,132
  7.     title    _67INIT - Point WTLSEG segment to ABACUS Physical Address
  8.     name    _67INIT
  9.     public    _67INIT, _mwWTLBASE
  10.  
  11. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  12. ; 67INIT -
  13. ;   This routine modifies the Physical Page tables so that references
  14. ;   into the WTLSEG segment will be translated into offsets from the
  15. ;   ABACUS physical address C0000000h.  It was written to facilitate mapped
  16. ;   addressing under the Pharlap Protected mode environment.
  17. ;
  18. ;  Returns: eax = 0   If mapping completed normally.
  19. ;           eax = -1  If FS selector does not point to the ABACUS.
  20. ;
  21. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  22.  
  23. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  24. ; Pharlap segment descriptors.
  25. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  26. THE_PSP    equ    24h            ; Pharlap PSP segment descriptor
  27. GDT_SEG equ     38h                     ; Maps the GDT
  28. LDT_SEG equ     30h                     ; Maps the LDT
  29. THE_LDT equ     28h                     ; The actual LDT descriptor
  30. MEM_SEG equ     40h                     ; Maps all of physical memory
  31.  
  32. SEGSTR    struc                ; Structure of segment table entry.
  33. limlow    dw    ?
  34. baselow    dw    ?
  35. basemid    db    ?
  36. segtype    db    ?
  37. limhi    db    ?
  38. basehi    db    ?
  39. SEGSTR    ends
  40.  
  41. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  42. ; The base of the ABACUS address space is defined by WTLBASE below.  If linked
  43. ; as the first object module, WTLBASE should be at offset 0 from the DS
  44. ; selector.  If WTLBASE is at 0, references to the ABACUS are directed to the
  45. ; very first 64K of the data segment.  If the public symbol WTLBASE is used
  46. ; for all ABACUS instructions it is possible to locate the ABACUS base
  47. ; address on any 64K boundry within the program.  However, it then becomes
  48. ; necessary to define WTLBASE as an external symbol in all object modules
  49. ; that reference the ABACUS.
  50. ;
  51. ; The trick is to map the actual physical address of the ABACUS, C0000000h,
  52. ; to the page table for the logical address WTLBASE.  Ideally, the OS 
  53. ; will be able to make this association through a system call.  The FS
  54. ; selector should remain unchanged for backwards compatibility.
  55. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  56. WTLSEG    segment    page4k rw use32 public 'DATA'
  57. _mwWTLBASE    db    10000h dup (1)        ;Weitek address space.
  58. WTLSEG    ends
  59.  
  60. _DATA    segment use32 para public 'DATA'
  61.  
  62.     align    4
  63. CONFIG  label    dword
  64. flag1    dd    ?
  65. flag2    dd    ?
  66. flag3    dd    ?
  67. major   dd      ?        ; pharlap major version
  68. minor   dd      ?        ; pharlap minor version
  69. letter  dd      ?        ; letter following minor version
  70.     org    CONFIG+512
  71.  
  72. swapfile db    256 DUP (?)
  73.  
  74. _DATA    ends
  75.  
  76. DGROUP    group    WTLSEG,_DATA
  77.     assume    ds:DGROUP
  78.  
  79. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  80. ;CODESEG    segment use32 para public 'code'
  81. CODESEG    segment
  82.     assume    CS:CODESEG
  83. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  84. _67INIT    proc    near
  85.     push    ebp
  86.     mov    ebp, esp
  87.     push    edi
  88.     push    esi
  89.     push    ebx
  90.     push    edx
  91.     push     gs
  92.     push     es
  93.  
  94. ; See if the ABACUS is even present.
  95.     mov    ax, ds
  96.     mov    bx, fs
  97.     cmp    ax, bx
  98.     jz    enderr
  99.  
  100.  
  101. ; Find Pharlap version.  Note that this only works for
  102. ; Pharlap versions >= 2.2d.  
  103.     lea    ebx,CONFIG
  104.     lea    ecx,swapfile
  105.     mov    eax,2526h
  106.     int    21h
  107.     cmp    major,3
  108.     jge    ph30
  109.  
  110. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  111. ;;      for pharlap version >=2.2d and < 3.0      ;;
  112. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  113.  
  114. ; Set up to address the LDT and Physical Memory
  115.     push MEM_SEG        ;gs <- Physical memory address selector
  116.     pop gs 
  117.     push LDT_SEG        ;es <- LDT selector 
  118.     pop es
  119.  
  120. ; Load the Base Linear address of DS
  121.     mov    dx, ds
  122.     and    edx, 0FFF8h        ;edx <- DS Selector index.
  123.     mov    al, es:[edx].basehi
  124.     shl    eax, 8
  125.     mov    al, es:[edx].basemid
  126.     shl    eax, 16
  127.     mov    ax, es:[edx].baselow
  128.     mov    edi, offset _mwWTLBASE    ;Add the ABACUS segment offset.
  129.     add    edi, eax        ;edi <- DS Linear address
  130.    
  131. ; Load the Base Linear address of ABACUS
  132.     mov    bx, fs        
  133.     and    ebx, 0FFF8h        ;ebx <- ABACUS (FS) Selector index.
  134.     mov    al, es:[ebx].basehi
  135.     shl    eax, 8
  136.     mov    al, es:[ebx].basemid
  137.     shl    eax, 16
  138.     mov    ax, es:[ebx].baselow
  139.     mov    esi, eax        ;esi <- ABACUS Linear address
  140.      
  141. ; eax <- Physical Page Directory-Directory from CR3.
  142.     mov     eax, cr3        ;Load eax with CR3
  143.     and    eax, 0FFFFF000h        ;  -clear off reserved portion.
  144.     mov     ecx, esi
  145.     shr     ecx, 22
  146.     mov     ebx, gs:[eax+ecx*4]     ;ebx <- ABACUS Page Directory address
  147.     and     ebx, 0FFFFF000h         ;  -clear off attribute bytes
  148.     and     esi, 003FFFFFh            ;
  149.     shr     esi, 10               ;esi <- ABACUS Page Table Index
  150.     add    esi, ebx        ;esi <- Address of first ABACUS PTE
  151.  
  152.     mov     ecx, edi
  153.     shr     ecx, 22
  154.     mov     edx, gs:[eax+ecx*4]    ;edx <- DS Page Directory address
  155.     and     edx, 0FFFFF000h         ;  -clear off attribute bytes.
  156.     and     edi, 003FFFFFh        
  157.     shr     edi, 10            ;edi <- DS Page Table Index
  158.         add    edi, edx        ;edi <- Address of first DS PTE
  159.  
  160.  
  161. ;ebx = ABACUS Page Directory address
  162. ;edx = DS Page Directory address
  163. ;esi = ABACUS Linear Page
  164. ;edi = DS Linear Page
  165.     mov     ecx, 16            ;Do 16 page table entries.
  166. bloop:
  167.     mov     eax, gs:[esi]
  168. ; make it  cachable
  169. ;     and      eax, 0ffffffefh
  170. ; make it non  cachable
  171.         or      eax, 00000010h
  172.     mov    gs:[edi],eax
  173.     add    esi, 4
  174.     add    edi, 4
  175.     loop    bloop
  176.     jmp    endok
  177.  
  178. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  179. ;;      for pharlap version >=3.0     ;;
  180. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  181.  
  182. PHYS_DEV_ADDR    EQU    0C0000000H ; address of Weitek chip
  183. DEV_ADDR_SPAN    EQU    10000H       ; 64K address span of chip
  184.  
  185. ph30:
  186. ; Memory address expected in ES:ECX for DOSX calls
  187.     push    ds
  188.     pop    es
  189.     lea    ecx, _mwWTLBASE
  190.  
  191. ; Ensure pages are unmapped, free them if they are.
  192.     mov    bl, 1          ; address type
  193.     mov    edx, DEV_ADDR_SPAN
  194.     mov    bh, 0          ; Create Unmapped Pages (sub-function 0)
  195.     mov    eax, 252bh        ; DOSX Page management Call
  196.     int    21h
  197.     jc    short enderr        ; CF true if error
  198.  
  199. ; Map the Weitek to WTLBASE
  200.     mov    bl, 1          ; address type
  201.     mov    edx, DEV_ADDR_SPAN
  202.     mov    bh, 2          ; Create Physical Device Pages (sub-function 2)
  203.     mov    edi, PHYS_DEV_ADDR; Page aligned chip physical address
  204.     mov    eax, 252bh        ; DOSX Page management Call
  205.     int    21h
  206.     jc    short enderr        ; CF true if error
  207.     jmp    short endok
  208.  
  209. enderr:
  210.     mov    eax, -1          ; error exit
  211.     jmp     short endprog
  212. endok:
  213.     mov    eax, 0          ; successful exit
  214. endprog:
  215.     pop    es
  216.     pop    gs
  217.     pop    edx
  218.     pop    ebx
  219.     pop    esi
  220.     pop    edi
  221.     pop    ebp
  222.     ret
  223.  
  224. _67INIT    endp
  225. CODESEG    ends
  226.  
  227.  
  228. addinit    _67INIT
  229.  
  230.     end
  231.