How can I access himen.sys controlled memory

Started by untio, January 21, 2012, 07:06:15 PM

Previous topic - Next topic

untio

Hi to all,

First, thank to all you for reading this stuff.

I have been using assembly language within ms-dos a lot of times. Today I have searched for an example on using the himem.sys managed extended memory, but I found nothing.

Can someone write a short example on allocating, writing and freeing this kind of memory. I am referring to pure 16 bits ms-dos. I run it on a virtualbox virtual machine.

Thanks in advance.

clive

It could be a random act of randomness. Those happen a lot as well.

untio

Hi,

Thanks for your answer. The problem is that I have never worked neither with dpmi nor with extended memory.

And I do not know where to start. I would appreciate a tutorial or reference.

Thanks once more.

clive

You could start by Googling the specification

http://www.tenberry.com/dpmi/index.html
http://www.delorie.com/djgpp/doc/dpmi/
http://www.phatcode.net/res/262/files/dpmi10.pdf

Having digested the documentation, you might have some specific questions, this is very old and broad topic area. Without knowing specifically what you are trying to achieve, as an end goal, there might be better/easier/different ways of achieving that.

If you want to tinker with 32-bit code under DOS, or large/flat memory, you should look at the existing DOS extenders, many of which have source published for.
It could be a random act of randomness. Those happen a lot as well.

untio

Hi,

Finally I believe that I have found some documentation:

http://www.petesqbsite.com/sections/tutorials/zines/chronicles/1-xms.html

I'll try it tomorrow because now it is time to go out.

Thanks once more.

MichaelW

You can find at least most of the information you need in Ralf Brown's Interrupt list.

An HTML version is here:

http://www.ctyme.com/rbrown.htm

And the download version here:

http://www-2.cs.cmu.edu/~ralf/files.html

You start by calling Interrupt 2Fh Function 4300h to verify that the XMS driver is installed, then Function 4310h to get the driver entry point address. For information on the supported functions see the tables following the Function 4310h listing.

.model small, c
.386
.stack
.data
    fpXMS dd 0
    ok    db "ok$"
.code
.startup

    mov ax, 4300h
    int 2fh
    cmp al, 80h
    jne fini

    mov ax, 4310h
    int 2fh
    mov WORD PTR fpXMS, bx
    mov WORD PTR fpXMS+2, es

    ; Call the Get XMS version number function.
    xor ah, ah
    call fpXMS

    mov ah, 9
    mov dx, OFFSET ok
    int 21h

    mov ah, 0
    int 16h

  fini:
.exit
end

eschew obfuscation

untio

Hi,

Thanks to both of you for your answers. Finally I have got it. This is my code fully commented:

.MODEL SMALL

.386

.STACK 1024
MYS STRUC
   LEN DD ? ;NUMBERS OF BYTES TO MOVE. MUST BE EVEN
   SHAN DW ? ;SOURCE HANDLE
   SOFF DD ? ;OFFSET INTO SOURCE BLOCK
   DHAN DW ? ;DESTINATION HANDLE
   DOFF DD ? ;OFFSET INTO DESTINATION BLOCK
MYS ENDS     ;IF A HANLE IS ZERO THEN OFFSET IS
             ;A REAL MODE ADRESS SEGMENT:OFFSET


.DATA
  MES DB "Hello", "$"

.DATA?
  XMSROUTINE DD ?
  HMEM DW ?
  MESB DB 6 DUP(?)
  MY MYS ?


.CODE

ENTRADA:
  MOV AX, @DATA
  MOV DS, AX

  ;TEST IF XMS DRIVER IS INSTALLED.
  MOV AX, 4300H
  INT 2FH
  CMP AL, 80H
  JNE EXIT ;IF AL != 80H THE DRIVER IS NOT INSTALLED

  MOV AX, 4310H
  INT 2FH
  ;ADRESS OF XMS ROUTINE IS RETURNED IN ES:BX
  MOV WORD PTR [XMSROUTINE], BX
  MOV WORD PTR [XMSROUTINE + 2], ES

  MOV AH, 8     
  CALL [XMSROUTINE];RETURNS:
  CMP AX, 1        ;AX SIZE OF LARGEST MEMORY BLOCK IN KB
  JL EXIT          ;DX TOTAL EXTENDED MEMORY IN KB

 
  MOV AH, 9;ALLOCATE EXTENDED MEMORY
  MOV DX, 1;KB NEEDED
  CALL [XMSROUTINE]
  CMP AX, 1;IF SUCCESS: AX == 1
  JNE EXIT
  MOV HMEM, DX

  MOV EAX, 6  ;MOVE DATA FROM NORMAL MEMORY TO EXTENDED MEMORY
  MOV MY.LEN, EAX ;NUM BYTES TO MOVE
  MOV MY.SHAN, 0 ;IF SOURCE HANDLE == 0, SHAN IS AN ADDRESS SEGMENT:OFFSET
  MOV BX, OFFSET MES
  MOV WORD PTR [MY.SOFF], BX
  MOV BX, DS
  MOV WORD PTR [MY.SOFF + 2], BX
  MOV BX, HMEM ;DESTINATION HANDLE
  MOV MY.DHAN, BX
  MOV EAX, 0  ;OFFSET INSIDE DESTINATION MEMORY
  MOV MY.DOFF, EAX
  MOV SI, OFFSET MY ;OFFSET OF MY STRUCT
  MOV AH, 0BH
  CALL [XMSROUTINE]
  CMP AX, 1; IF SUCCESS: AX == 1
  JNE EXIT

  MOV EAX, 6    ;MOVE DATA FROM XMS MEMORY AND NORMAL MEMORY
  MOV MY.LEN, EAX  ;NUMBER OF BYTES
  MOV BX, HMEM     ;SOURCE HANDLE
  MOV MY.SHAN, BX
  MOV EAX, 0     ;DESTINATION OFSSET
  MOV MY.SOFF, EAX
  MOV MY.DHAN, 0 ;DESTINATION HANDLE.IF == 0 IT IS A ADDRESS SEGMENT:OFFSET
  MOV BX, OFFSET MESB
  MOV WORD PTR [MY.DOFF], BX
  MOV BX, DS
  MOV WORD PTR [MY.DOFF + 2], BX
  MOV SI, OFFSET MY  ;OFFSET OF MY STRUCT
  MOV AH, 0BH
  CALL [XMSROUTINE]
  CMP AX, 1
  JNE EXIT

  ;PRINT BYTES
  MOV AH, 9
  MOV DX, OFFSET MESB
  INT 21H

  ;RELEASE XMS MEMORY
  MOV AH, 0AH
  MOV BX, HMEM
  MOV DX, [BX]
  CALL [XMSROUTINE]

EXIT:
  MOV AX, 4C00H
  INT 21H
  RET
END ENTRADA


Cheers.