home *** CD-ROM | disk | FTP | other *** search
- ; Program - Allows you to access extended memory and still remain in real mode
- ; Release Date - 4/14/87 to the public domain
- ; Author - Garland Wong
- ; No Rights Reserved. You can modify this code all you like. Also, I am not liable for this
- ; code.
-
-
- EM_INT EQU 15H ;extended memory BIOS interrupt INT
- EM_BLKMOVE EQU 87H ;block move function
- PARA_SIZE EQU 16 ;number of bytes in one 8088 paragraph
-
- data segment word public 'DATA'
-
- ;-----------------------------------------------------------------------;
- ; Segment Descriptor (part of Global Descriptor Table) ;
- ;-----------------------------------------------------------------------;
- DESC STRUC ;data segment descriptor
- DESC_LMT DW 0 ;segment limit (length)
- DESC_BASEL DW 0 ;bits 15-0 of physical address
- DESC_BASEH DB 0 ;bits 23-16 of physical address
- DB 0 ;access rights byte
- DW 0 ;reserved
- DESC ENDS
-
- ;-----------------------------------------------------------------------;
- ; Global Descriptor Table (GDT), used for extended memory moves ;
- ;-----------------------------------------------------------------------;
- ;Access Rights Byte (93H) is
- ; P=1 (segment is mapped into physical memory)
- ; E=0 (data segment descriptor)
- ; D=0 (grow up segment, offsets must be <= limit)
- ; W=1 (data segment may be written into)
- ; DPL=0 (privilege level 0)
-
- even
- GDT LABEL BYTE ;begin global descriptor table
- DESC <> ;dummy descriptor
- DESC <> ;descriptor for GDT itself
- SRC DESC <,,,93H,> ;source descriptor
- TGT DESC <,,,93H,> ;target descriptor
- DESC <> ;BIOS CS descriptor
- DESC <> ;stack segment descriptor
- data ends
-
- _text segment byte public 'CODE' ;this is so C can call these routines
- assume cs:_text, ds:data
- public _ext_to_conv, _conv_to_ext, gdt, src, tgt
-
- ;-----------------------------------------------------------------------;
- ; Extended Memory I/O routine ;
- ;-----------------------------------------------------------------------;
-
- _ext_to_conv proc near
- ; called from C ext_to_conv(tgt_seg, tgt_off, src_hi, src_lo, count)
- ;int tgt_seg; /* segment of conventional buffer */
- ;int tgt_off; /* offset of conventional buffer */
- ;int src_hi; /* hi word of 24 bit address in extended memory (only lo 8 bits significant) */
- ;int src_lo; /* lo word of 24 bit address in extended memory */
- ;int count; /* number of bytes to move (max. of 64kb) */
- ;
- ;return code in ax
- ; ax = 0 successful
- ; ax = non-zero => error occured - consult AT tech reference Page 5-167
-
- push bp ;save bp for good form
- mov bp, sp ;access stack
- push ds
- push es
- mov ax, data
- mov ds, ax
-
- mov ax, [bp+4] ;segment conventional memory
- mov si, [bp+6] ;offset conventional memory
-
- ;Compute 24-bit address of caller's buffer in DX (hi) and AX (low)
- mov cl, 4 ;set count for bit shift
- push ax ;save the segment
- shr ah, cl ;we only want high nibble
- mov dh, ah ;save high nibble
- mov cx, 4 ;set count again
- pop ax ;restore segment
- shl ax, cl ;get rid of high nibble
- add ax, si ;add offset to calculate 24 bit address
- adc dh, 0 ;add carry to our high nibble
-
- mov tgt.desc_basel, ax ;low 16 bits of target address
- mov tgt.desc_baseh, dh ;high 8 bits of target address
-
- mov ax, [bp+8] ;get hi byte word of 24 bit source address
- mov bx, [bp+10] ;get lo word of 24 bit source address
- mov src.desc_basel, bx
- mov src.desc_baseh, al
-
- mov tgt.desc_lmt, 0ffffh ;store segment limit (byte count)
- mov src.desc_lmt, 0ffffh
-
- mov cx, [bp+12] ;number of bytes to move
- shr cx, 1 ;/2 = word count
- push ds
- pop es ;set es = ds
- cld ;go forward
- lea si, gdt ;ES:SI point to GDT
- mov ah, em_blkmove ;function is block move
- int em_int ;move an even number of words
- pop es
- pop ds
- pop bp ;restore C's base pointer
- ret ;return to C
- _ext_to_conv endp
-
- _conv_to_ext proc near
- ; called from C conv_to_ext(tgt_hi, tgt_lo, src_seg, src_off, count)
- ;int tgt_hi; /* hi word of 24 bit address in extended memory (only lo 8 bits significant) */
- ;int tgt_lo; /* lo word of 24 bit address in extended memory */
- ;int src_seg; /* segment of source buffer in conventional memory */
- ;int src_off; /* offset of source buffer in conventional memory */
- ;int count; /* number of bytes to move (max. of 64kb) */
- ;
- ;return code in ax
- ; ax = 0 successful
- ; ax = non-zero => error occured - consult AT tech reference Page 5-167
-
- push bp ;save bp for good form
- mov bp, sp ;access stack
- push ds
- push es
- mov ax, data
- mov ds, ax
-
- mov ax, [bp+8] ;segment conventional memory
- mov si, [bp+10] ;offset conventional memory
-
- ;Compute 24-bit address of caller's buffer in DX (hi) and AX (low)
- mov cl, 4 ;set count for bit shift
- push ax ;save the segment
- shr ah, cl ;we only want high nibble
- mov dh, ah ;save high nibble
- mov cx, 4 ;set count again
- pop ax ;restore segment
- shl ax, cl ;get rid of high nibble
- add ax, si ;add offset to calculate 24 bit address
- adc dh, 0 ;add carry to our high nibble
-
- mov src.desc_basel, ax ;low 16 bits of source address
- mov src.desc_baseh, dh ;high 8 bits of source address
-
- mov ax, [bp+4] ;get hi byte of 24 bit target address
- mov bx, [bp+6] ;get lo word of 24 bit target address
- mov tgt.desc_basel, bx
- mov tgt.desc_baseh, al
-
- mov tgt.desc_lmt, 0ffffh ;store segment limit (byte count)
- mov src.desc_lmt, 0ffffh
-
- mov cx, [bp+12] ;number of bytes to move
- shr cx, 1 ;/2 = word count
- push ds
- pop es ;set es = ds
- cld ;go forward
- mov si, offset gdt ;ES:SI point to GDT
- mov ah, em_blkmove ;function is block move
- int em_int ;move an even number of words
- pop es
- pop ds
- pop bp ;restore C's base pointer
- ret ;return to C
- _conv_to_ext endp
-
- _text ends
- end
-