News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

about "int 15h/ax=e820h"

Started by guesehsaio, April 17, 2005, 05:01:40 PM

Previous topic - Next topic

guesehsaio

INT15_E820      PROC    NEAR
      PUSH    ECX
      PUSH    EDX
      PUSH    DI
      MOV     EBX,0
E820_LP:
      MOV     EAX,0E820H
      MOV     ECX,20
      MOV     EDX,534D4150H
      MOV     DI,OFFSET E820_TAB
      INT     15H
      MOV     EAX,[DI]
      CMP     AX,0
      JNZ     E820_NEXT_FN
      CMP     EAX,03F00000H
      JC      E820_NEXT_FN
      SHR     EAX,10
      MOV     EBX,EAX
      JMP     E820
E820_NEXT_FN:
      INC     EBX
      CMP     EBX,6
      JC      E820_LP
      MOV     EBX,0FC00H
E820:       
      POP     DI
      POP     EDX
      POP     ECX
      RET
E820_TAB        DB      20 DUP(0)
INT15_E820      ENDP
;*******************************************
this sub-program have different result @ ASUS P4P800,and P4P800 -X ....
P4P800 can correctly show "total memory size"
but P4P800-x can't .always show"65535" .....my program have bug.....
somebody can help me?  P4P800 and  P4P8-00-x  BIOS 's manufacturer are the same.!

MichaelW

#1
Interrupt 15h, Function E820h, even if it is supported by the BIOS (recent systems only), will always return failure under Windows 2000/XP.

The function indicates success by returning 'SMAP' in EAX. The function also returns a continuation value in EBX. If on return EBX is zero, or the carry flag is set, the end of the map has been reached. Otherwise, pass the returned EBX value to the next function call.

To get the total memory size you must sum the lengths for each of the ranges. It might improve the clarity of your code if you used a structure variable for your buffer:

SMM_ADDRESS_RANGE_DESC STRUCT
  baseLo      dd 0
  baseHi      dd 0
  lengthLo    dd 0
  lengthHi    dd 0
  rangeType   dd 0
SMM_ADDRESS_RANGE_DESC ENDS

smmard SMM_ADDRESS_RANGE_DESC <>


You can probably safely ignore smmard.lengthHi.

You can get most of the necessary information from 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 can find some example code here (AFAIK you must be a registered member and you must be logged in):

http://www.old.masmforum.com/viewtopic.php?t=3388


eschew obfuscation

ninjarider

according to ralph browns site he only has the 1h - 4h values listed for the type. is that the most up to date. and if it returns a value higher than that do i just pay attention to those bytes.

MichaelW

I have doubts that it is the most up to date, but finding newer information might be difficult. Searching the net I find a lot of dmesg printouts, and there appears to be only four possibilities: usable, reserved, ACPI data, and ACPI NVS, which I assume correspond to those documented in the interrupt list.
eschew obfuscation

ninjarider


Tedd

#5
Everything you could need..

ACPI Spec., v3.0 (http://www.acpi.info/spec.htm)
QuoteACPI defines five address range types; AddressRangeMemory, AddressRangeACPI, AddressRangeNVS, AddressRangeUnusable, and AddressRangeReserved as described in the table below:

Address Range Types

ValueMnemonicDescription
1AddressRangeMemoryThis range is available RAM usable by the operating system.
2AddressRangeReservedThis range of addresses is in use or reserved by the system and must not be used by the operating system.
3AddressRangeACPIACPI Reclaim Memory. This range is available RAM usable by the OS after it reads the ACPI tables.
4AddressRangeNVSACPI NVS Memory. This range of addresses is in use or reserve by the system and must not be used by the operating system. This range is required to be saved and restored across an NVS sleep.
5AddressRangeUnusuableThis range of address contains memory in which errors have been detected. This range must not be used by the OSPM.
OtherUndefinedUndefined. Reserved for future use. OSPM must treat any range of this type as if the type returned was AddressRangeReserved.

The BIOS can use the AddressRangeReserved address range type to block out various addresses as not
suitable for use by a programmable device. Some of the reasons a BIOS would do this are:


  • The address range contains system ROM.
  • The address range contains RAM in use by the ROM.
  • The address range is in use by a memory-mapped system device.
  • The address range is, for whatever reason, unsuitable for a standard device to use as a device memory space.
  • The address range is within an NVRAM device where reads and writes to memory locations are no longer successful, that is, the device was worn out.

Note: OSPM will not save or restore memory reported as AddressRangeReserved or
AddressRangeUnusable when transitioning to or from the S4 sleeping state.


INT 15H, E820H - Query System Address Map
This interface is used in real mode only on IA-PC-based systems and provides a memory map for all of the
installed RAM, and of physical memory ranges reserved by the BIOS. The address map is returned through
successive invocations of this interface; each returning information on a single range of physical addresses.
Each range includes a type that indicates how the range of physical addresses is to be treated by the OSPM.

If the information returned from E820 in some way differs from INT-15 88 or INT-15 E801, the
information returned from E820 supersedes the information returned from INT-15 88 or INT-15 E801. This
replacement allows the BIOS to return any information that it requires from INT-15 88 or INT-15 E801 for
compatibility reasons. For compatibility reasons, if E820 returns any AddressRangeACPI or
AddressRangeNVS memory ranges below 16 MB, the INT-15 88 and INT-15 E801 functions must return
the top of memory below the AddressRangeACPI and AddressRangeNVS memory ranges.

The memory map conveyed by this interface is not required to reflect any changes in available physical
memory that have occurred after the BIOS has initially passed control to the operating system. For
example, if memory is added dynamically, this interface is not required to reflect the new system memory
configuration.

Input to the INT 15h E820h Call

EAXFunction CodeE820h
EBXContinuationContains the continuation value to get the next range of physical memory. This is the value returned by a previous call to this routine. If this is the first call, EBX must contain zero.
ES:DIBuffer PointerPointer to an Address Range Descriptor structure that the BIOS fills in.
ECXBuffer SizeThe length in bytes of the structure passed to the BIOS. The BIOS fills in the number of bytes of the structure indicated in the ECX register, maximum, or whatever amount of the structure the BIOS implements. The minimum size that must be supported by both the BIOS and the caller is 20 bytes. Future implementations might extend this structure.
EDXSignature'SMAP' Used by the BIOS to verify the caller is requesting the system map information to be returned in ES:DI.

Output from the INT 15h E820h Call

CFCarry FlagNon-Carry – Indicates No Error
EAXSignature'SMAP.' Signature to verify correct BIOS revision.
ES:DIBuffer PointerReturned Address Range Descriptor pointer. Same value as on input.
ECXBuffer SizeNumber of bytes returned by the BIOS in the address range descriptor. The minimum size structure returned by the BIOS is 20 bytes.
EBXContinuationContains the continuation value to get the next address range descriptor. The actual significance of the continuation value is up to the discretion of the BIOS. The caller must pass the continuation value unchanged as input to the next iteration of the E820 call in order to get the next Address Range Descriptor. A return value of zero means that this is the last descriptor.
Note: the BIOS can also indicate that the last descriptor has already been returned during previous iterations by returning the carry flag set. The caller will ignore any other information returned by the BIOS when the carry flag is set.

Address Range Descriptor Structure

Offset in BytesNameDescription
0BaseAddrLowLow 32 Bits of Base Address
4BaseAddrHighHigh 32 Bits of Base Address
8LengthLowLow 32 Bits of Length in Bytes
12LengthHighHigh 32 Bits of Length in Bytes
16TypeAddress type of this range
20Extended AttributesSee 'Extended Attributes' Table

The BaseAddrLow and BaseAddrHigh together are the 64-bit base address of this range. The base address
is the physical address of the start of the range being specified.

The LengthLow and LengthHigh together are the 64-bit length of this range. The length is the physical
contiguous length in bytes of a range being specified.

The Type field describes the usage of the described address range as defined in the 'Address Range Types' Table.


Extended Attributes for Address Range Descriptor Structure

BitMnemonicDescription
0AddressRangeEnabledIf clear, the OSPM ignores the Address Range Descriptor. This allows the BIOS to populate the E820 table with a static number of structures but only enable them as necessary
1AddressRangeNonVolatileIf set, the Address Range Descriptor represents non-volatile memory. Memory reported as non-volatile may require characterization to determine its suitability for use as conventional RAM.
2-31ReservedReserved for future use.

E820 Assumptions and Limitations

  • The BIOS returns address ranges describing baseboard memory.
  • The BIOS does not return a range description for the memory mapping of PCI devices, ISA Option ROMs, and ISA Plug and Play cards because the OS has mechanisms available to detect them.
  • The BIOS returns chip set-defined address holes that are not being used by devices as reserved.
  • Address ranges defined for baseboard memory-mapped I/O devices, such as APICs, are returned as reserved.
  • All occurrences of the system BIOS are mapped as reserved, including the areas below 1 MB, at 16 MB (if present), and at end of the 4-GB address space.
  • Standard PC address ranges are not reported. For example, video memory at A0000 to BFFFF physical addresses are not described by this function. The range from E0000 to EFFFF is specific to the baseboard and is reported as it applies to that baseboard.
  • All of lower memory is reported as normal memory. The OS must handle standard RAM locations that are reserved for specific uses, such as the interrupt vector table (0:0) and the BIOS data area (40:0).


Or, the short version: type 1 means available memory (free for you to use), all other values mean reserved. (If/when you know how to handle the other values - type 3, at least - you can use them, otherwise treat them as unavailable.)
No snowflake in an avalanche feels responsible.