home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PROGRAMS / UTILS / MEMORIA / EXTMOVE.ZIP / EXMOVE.ASM < prev    next >
Encoding:
Assembly Source File  |  1987-04-14  |  8.2 KB  |  172 lines

  1. ; Program - Allows you to access extended memory and still remain in real mode
  2. ; Release Date - 4/14/87 to the public domain
  3. ; Author - Garland Wong
  4. ; No Rights Reserved. You can modify this code all you like. Also, I am not liable for this
  5. ; code.
  6.  
  7.  
  8. EM_INT     EQU        15H                 ;extended memory BIOS interrupt INT
  9. EM_BLKMOVE EQU        87H                 ;block move function
  10. PARA_SIZE  EQU        16                  ;number of bytes in one 8088 paragraph
  11.  
  12. data   segment word     public  'DATA'
  13.  
  14. ;-----------------------------------------------------------------------;
  15. ;        Segment Descriptor (part of Global Descriptor Table)                 ;
  16. ;-----------------------------------------------------------------------;
  17. DESC        STRUC                         ;data segment descriptor
  18.    DESC_LMT   DW        0                 ;segment limit (length)
  19.    DESC_BASEL DW        0                 ;bits 15-0 of physical address
  20.    DESC_BASEH DB        0                 ;bits 23-16 of physical address
  21.               DB        0                 ;access rights byte
  22.               DW        0                 ;reserved
  23. DESC        ENDS
  24.  
  25. ;-----------------------------------------------------------------------;
  26. ;        Global Descriptor Table (GDT), used for extended memory moves        ;
  27. ;-----------------------------------------------------------------------;
  28. ;Access Rights Byte (93H) is
  29. ;        P=1        (segment is mapped into physical memory)
  30. ;        E=0        (data segment descriptor)
  31. ;        D=0        (grow up segment, offsets must be <= limit)
  32. ;        W=1        (data segment may be written into)
  33. ;        DPL=0        (privilege level 0)
  34.  
  35. even
  36. GDT        LABEL        BYTE               ;begin global descriptor table
  37.             DESC        <>                 ;dummy descriptor
  38.             DESC        <>                 ;descriptor for GDT itself
  39.  SRC        DESC        <,,,93H,>          ;source descriptor
  40.  TGT        DESC        <,,,93H,>          ;target descriptor
  41.             DESC        <>                 ;BIOS CS descriptor
  42.             DESC        <>                 ;stack segment descriptor
  43. data   ends
  44.  
  45. _text   segment byte    public  'CODE'     ;this is so C can call these routines
  46.         assume  cs:_text, ds:data
  47.         public  _ext_to_conv, _conv_to_ext, gdt, src, tgt
  48.  
  49. ;-----------------------------------------------------------------------;
  50. ;        Extended Memory I/O routine                                            ;
  51. ;-----------------------------------------------------------------------;
  52.  
  53. _ext_to_conv     proc    near
  54. ; called from C ext_to_conv(tgt_seg, tgt_off, src_hi, src_lo, count)
  55. ;int     tgt_seg;   /* segment of conventional buffer */
  56. ;int     tgt_off;   /* offset of conventional buffer */
  57. ;int     src_hi;   /* hi word of 24 bit address in extended memory (only lo 8 bits significant) */
  58. ;int     src_lo;   /* lo word of 24 bit address in extended memory */
  59. ;int     count;   /* number of bytes to move (max. of 64kb) */
  60. ;
  61. ;return code in ax
  62. ;       ax = 0 successful
  63. ;       ax = non-zero => error occured - consult AT tech reference Page 5-167
  64.  
  65.         push    bp                              ;save bp for good form
  66.     mov    bp, sp                          ;access stack
  67.         push    ds
  68.         push    es
  69.         mov     ax, data
  70.         mov     ds, ax
  71.  
  72.     mov    ax, [bp+4]            ;segment conventional memory
  73.     mov    si, [bp+6]            ;offset conventional memory
  74.  
  75. ;Compute 24-bit address of caller's buffer in DX (hi) and AX (low)
  76.         mov     cl, 4                           ;set count for bit shift
  77.         push    ax                              ;save the segment
  78.         shr     ah, cl                          ;we only want high nibble
  79.         mov     dh, ah                          ;save high nibble
  80.         mov     cx, 4                           ;set count again
  81.         pop     ax                              ;restore segment
  82.         shl     ax, cl                          ;get rid of high nibble
  83.         add     ax, si                          ;add offset to calculate 24 bit address
  84.         adc     dh, 0                           ;add carry to our high nibble
  85.  
  86.         mov     tgt.desc_basel, ax              ;low 16 bits of target address
  87.         mov     tgt.desc_baseh, dh              ;high 8 bits of target address
  88.  
  89.         mov     ax, [bp+8]                      ;get hi byte word of 24 bit source address
  90.         mov     bx, [bp+10]                     ;get lo word of 24 bit source address
  91.         mov     src.desc_basel, bx
  92.         mov     src.desc_baseh, al
  93.  
  94.         mov     tgt.desc_lmt, 0ffffh            ;store segment limit (byte count)
  95.         mov     src.desc_lmt, 0ffffh
  96.  
  97.         mov     cx, [bp+12]                     ;number of bytes to move
  98.         shr     cx, 1                           ;/2 = word count
  99.         push    ds
  100.         pop     es                              ;set es = ds
  101.         cld                                     ;go forward
  102.         lea     si, gdt                         ;ES:SI point to GDT
  103.         mov     ah, em_blkmove                  ;function is block move
  104.         int     em_int                          ;move an even number of words
  105.         pop     es
  106.         pop     ds
  107.         pop     bp                              ;restore C's base pointer
  108.         ret                                     ;return to C
  109. _ext_to_conv     endp
  110.  
  111. _conv_to_ext     proc    near
  112. ; called from C conv_to_ext(tgt_hi, tgt_lo, src_seg, src_off, count)
  113. ;int     tgt_hi;   /* hi word of 24 bit address in extended memory (only lo 8 bits significant) */
  114. ;int     tgt_lo;   /* lo word of 24 bit address in extended memory */
  115. ;int     src_seg;   /* segment of source buffer in conventional memory */
  116. ;int     src_off;   /* offset of source buffer in conventional memory */
  117. ;int     count;   /* number of bytes to move (max. of 64kb) */
  118. ;
  119. ;return code in ax
  120. ;       ax = 0 successful
  121. ;       ax = non-zero => error occured - consult AT tech reference Page 5-167
  122.  
  123.         push    bp                              ;save bp for good form
  124.     mov    bp, sp                          ;access stack
  125.         push    ds
  126.         push    es
  127.         mov     ax, data
  128.         mov     ds, ax
  129.  
  130.     mov    ax, [bp+8]            ;segment conventional memory
  131.     mov    si, [bp+10]            ;offset conventional memory
  132.  
  133. ;Compute 24-bit address of caller's buffer in DX (hi) and AX (low)
  134.         mov     cl, 4                           ;set count for bit shift
  135.         push    ax                              ;save the segment
  136.         shr     ah, cl                          ;we only want high nibble
  137.         mov     dh, ah                          ;save high nibble
  138.         mov     cx, 4                           ;set count again
  139.         pop     ax                              ;restore segment
  140.         shl     ax, cl                          ;get rid of high nibble
  141.         add     ax, si                          ;add offset to calculate 24 bit address
  142.         adc     dh, 0                           ;add carry to our high nibble
  143.  
  144.         mov     src.desc_basel, ax              ;low 16 bits of source address
  145.         mov     src.desc_baseh, dh              ;high 8 bits of source address
  146.  
  147.         mov     ax, [bp+4]                      ;get hi byte of 24 bit target address
  148.         mov     bx, [bp+6]                      ;get lo word of 24 bit target address
  149.         mov     tgt.desc_basel, bx
  150.         mov     tgt.desc_baseh, al
  151.  
  152.         mov     tgt.desc_lmt, 0ffffh            ;store segment limit (byte count)
  153.         mov     src.desc_lmt, 0ffffh
  154.  
  155.         mov     cx, [bp+12]                     ;number of bytes to move
  156.         shr     cx, 1                           ;/2 = word count
  157.         push    ds
  158.         pop     es                              ;set es = ds
  159.         cld                                     ;go forward
  160.         mov     si, offset gdt                  ;ES:SI point to GDT
  161.         mov     ah, em_blkmove                  ;function is block move
  162.         int     em_int                          ;move an even number of words
  163.         pop     es
  164.         pop     ds
  165.         pop     bp                              ;restore C's base pointer
  166.         ret                                     ;return to C
  167. _conv_to_ext     endp
  168.  
  169. _text   ends
  170.     end
  171.  
  172.