home *** CD-ROM | disk | FTP | other *** search
/ PC Underground / UNDERGROUND.ISO / memory / flat / rmemasm.asm < prev    next >
Encoding:
Assembly Source File  |  1995-07-28  |  5.0 KB  |  131 lines

  1. ;*************************************************************************
  2. ;***                   ABACUS' "PC UNDERGROUND"                        ***
  3. ;***                  ================================                 ***
  4. ;***                                                                   ***
  5. ;***                  Unit for using the Flat Model                    ***
  6. ;***                                                                   ***
  7. ;*** The unit makes routines available with which the entire memory    ***
  8. ;*** of can be accessed in Real mode.                                  ***
  9. ;*** Memory managers such as EMM386 or QEMM CANNOT be installed.       ***
  10. ;*** HIMEM.SYS is required !                                           ***
  11. ;***                                                                   ***
  12. ;*** Author          : Boris Bertelsons  (InspirE)                     ***
  13. ;*** Filename        : RMEM.PAS                                        ***
  14. ;*** Last Update     : 04/28/94                                        ***
  15. ;*** Version         : 1.0                                             ***
  16. ;*** Compiler        : Turbo Pascal 6.0 and above                      ***
  17. ;*************************************************************************
  18.  
  19. .386P
  20. .model tpascal
  21.  
  22. .data
  23. extrn GDT_Off         : byte
  24. extrn GDT             : byte
  25.  
  26. .code
  27. extrn xms_enable_a20  : far
  28.  
  29. public mem_read
  30. public mem_Write
  31. public Enable_4Giga
  32. public Multitasker_active
  33.  
  34.  
  35. ;*************************************************************************
  36. ;***                                                                   ***
  37. ;***   Checks whether a multitasker like QEMM or EMM386 is active      ***
  38. ;***                                                                   ***
  39. ;*************************************************************************
  40. Multitasker_active proc pascal
  41.    mov eax,cr0
  42.    and ax,1
  43.    ret
  44. Multitasker_active endp
  45.  
  46. ;*************************************************************************
  47. ;***                                                                   ***
  48. ;***      Copies a block from RMEM to RAM                              ***
  49. ;***                                                                   ***
  50. ;*************************************************************************
  51. mem_read proc pascal sourcep:dword,destinationofs : word,destinationseg : word,length1:word
  52.          call xms_Enable_A20
  53.          mov  ax,destinationseg           ; RAM-addy to ES:SI
  54.          mov  es,ax
  55.          mov  di,destinationofs
  56.          xor  ax,ax                ; RMEM source address to GS:EAX
  57.          mov  gs,ax
  58.          mov  eax,sourcep
  59.          mov  cx,length1
  60. lloop:   mov  bl,byte ptr gs:[eax] ; copy bytes
  61.          mov  es:[di],bl
  62.          inc  eax
  63.          inc  di
  64.          loop lloop
  65.          ret
  66. mem_read endp
  67.  
  68.  
  69. ;*************************************************************************
  70. ;***                                                                   ***
  71. ;***       Copies a block from RAM to RMEM                             ***
  72. ;***                                                                   ***
  73. ;*************************************************************************
  74.  
  75. mem_Write proc pascal sourcep:dword, destinationofs:word, destinationseg:word, length1:word
  76.          call xms_Enable_A20
  77.          mov  ax,destinationseg           ; RAM-addy to ES:SI
  78.          mov  es,ax
  79.          mov  di,destinationofs
  80.          xor  ax,ax                ; RMEM source address to GS:EAX
  81.          mov  gs,ax
  82.          mov  eax,sourcep
  83.          mov  cx,length1
  84. nloop:
  85.          mov  bl,es:[di]           ; copy bytes
  86.          mov  byte ptr gs:[eax],bl
  87.          inc  eax
  88.          inc  di
  89.          loop nloop
  90.          ret
  91. mem_Write endp
  92.  
  93. ;*************************************************************************
  94. ;***                                                                   ***
  95. ;***            Switches the processor to Flat - Model                 ***
  96. ;***                                                                   ***
  97. ;*************************************************************************
  98. Enable_4Giga proc pascal
  99.     mov GDT_Off[0],16
  100.     mov eax,seg GDT
  101.     shl eax,4
  102.     mov bx,offset GDT
  103.     movzx ebx,bx
  104.     add eax,ebx
  105.     mov dword ptr GDT_Off[2],eax
  106.     lgdt pword ptr GDT_Off         ; load GDT
  107.  
  108.     mov bx,08h                     ;  bx points to 1st entry of GDT
  109.     push ds
  110.     cli                            ; disable interrupts
  111.     mov eax,cr0                    ; switch to Protected mode
  112.     or eax,1
  113.     mov cr0,eax
  114.     jmp To_Protectedmode       ; clear execution pipe
  115.     To_Protectedmode:
  116.     mov gs,bx                      ; adapt segments to 4 gigabytes
  117.     mov fs,bx
  118.     mov es,bx
  119.     mov ds,bx
  120.     and al,0FEh                    ; switch back to Real mode, without 
  121.     mov cr0,eax                    ; resetting the processor
  122.     jmp To_Realmode            ; clear execution pipe
  123.     To_Realmode:
  124.     sti                            ; enable interrupts again
  125.     pop ds
  126.   ret
  127. Enable_4Giga endp
  128.  
  129. END
  130.  
  131.