Extended Memory

Extended memory is RAM storage at addresses above 1 megabyte (100000H) that can be accessed by an 80286 or 80386 processor running in protected mode. IBM PC/AT— and PS/2—compatible machines can (theoretically) have as much as 15 MB of extended memory installed, in addition to the usual 1 MB of conventional memory.

Protected-mode operating systems such as Microsoft XENIX or MS OS/2 can use extended memory for execution of programs. MS-DOS, on the other hand, runs in real mode on an 80286 or 80386, and programs running under its control cannot ordinarily execute from extended memory or even address that memory for storage of data. However, the ROM BIOS contains two routines that allow real-mode programs restricted access to extended memory:

ROM BIOS function Action

Int 15H Function 87H Move extended-memory block.

Int 15H Function 88H Get extended-memory size.

These routines can be used by electronic disks (RAMdisks) and by other programs that want to use extended memory for fast storage and retrieval of information that would otherwise have to be written to a slower physical disk drive. Section 3 of this book, "IBM ROM BIOS and Mouse Functions Reference," documents both of these functions.

You should use these ROM BIOS routines with caution. Data stored in extended memory is, of course, volatile; it is lost if the machine is turned off. The transfer of data to or from extended memory involves a switch from real mode to protected mode and back, which is a relatively slow process on 80286-based machines; in some cases it is only marginally faster than actually reading the data from a fixed disk. In addition, programs that use the ROM BIOS extended-memory functions are not compatible with the MS-DOS compatibility mode of MS OS/2.

Finally, a major deficit in these ROM BIOS functions is that they do not make any attempt to arbitrate between two or more programs or drivers that are using extended memory for temporary storage. For example, if an application program and an installed RAMdisk driver attempt to put data in the same area of extended memory, no error will be returned to either program, but the data of one or both may be destroyed.

Figure 11-9 shows an example of the code necessary to transfer data to and from extended memory.

bmdt db 30h dup (0) ; block move descriptor table

buff1 db 80h dup ('?') ; source buffer

buff2 db 80h dup (0) ; destination buffer

.

.

.

; copy 'buff1' to extended-

; memory address 100000h

mov dx,10h ; DX:AX = destination

mov ax,0 ; extended-memory address

mov bx,seg buff1 ; DS:BX = source conventional-

mov ds,bx ; memory address

mov bx,offset buff1

mov cx,80h ; CX = bytes to move

mov si,seg bmdt ; ES:SI = block move

mov es,si ; descriptor table

mov si,offset bmdt

call putblk ; request transfer

; fill buff2 from extended-

; memory address 100000h

mov dx,10h ; DX:AX = source extended-

mov ax,0 ; memory address

mov bx,seg buff2 ; DS:BX = destination

mov ds,bx ; conventional-memory address

mov bx,offset buff2

mov cx,80h ; CX = bytes to move

mov si,seg bmdt ; ES:SI = block move

mov es,si ; descriptor table

mov si,offset bmdt

call getblk ; request transfer

.

.

.

getblk proc near ; transfer block from extended

; memory to real memory

; call with

; DX:AX = source linear 32-bit

; extended-memory address

; DS:BX = segment and offset

; destination address

; CX = length in bytes

; ES:SI = block move descriptor

; table

; returns

; AH = 0 if transfer OK

mov es:[si+10h],cx ; store length into descriptors

mov es:[si+18h],cx

; store access rights bytes

mov byte ptr es:[si+15h],93h

mov byte ptr es:[si+1dh],93h

mov es:[si+12h],ax ; source extended-memory address

mov es:[si+14h],dl

; convert destination segment

; and offset to linear address

mov ax,ds ; segment * 16

mov dx,16

mul dx

add ax,bx ; + offset -> linear address

adc dx,0

mov es:[si+1ah],ax ; store destination address

mov es:[si+1ch],dl

shr cx,1 ; convert length to words

mov ah,87h ; int 15h function 87h = block move

int 15h ; transfer to ROM BIOS

ret ; back to caller

getblk endp

putblk proc near ; transfer block from real

; memory to extended memory

; call with

; DX:AX = dest linear 32-bit

; extended-memory address

; DS:BX = segment and offset

; source address

; CX = length in bytes

; ES:SI = block move descriptor

; table

; returns

; AH = 0 if transfer OK

mov es:[si+10h],cx ; store length into descriptors

mov es:[si+18h],cx

; store access rights bytes

mov byte ptr es:[si+15h],93h

mov byte ptr es:[si+1dh],93h

mov es:[si+1ah],ax ; store destination extended-

mov es:[si+1ch],dl ; memory address

; convert source segment and

; offset to linear address

mov ax,ds ; segment * 16

mov dx,16

mul dx

add ax,bx ; + offset -> linear address

adc dx,0

mov es:[si+12h],ax ; store source address

mov es:[si+14h],dl

shr cx,1 ; convert length to words

mov ah,87h ; int 15h function 87h = block move

int 15h ; transfer to ROM BIOS

ret ; back to caller

putblk endp

Figure 11-9. Moving blocks of data between conventional memory and extended memory, using the ROM BIOS extended-memory functions. For additional information on the format of the block move descriptor table, see the entry for Int 15H Function 87H in Section 3 of this book, "IBM ROM BIOS and Mouse Functions Reference." Note that you must specify the extended-memory address as a 32-bit linear address rather than as a segment and offset.