A.5 Memory Handling

A.5.1 AllocMem()

Usage

void *AllocMem(unsigned int Size);

Purpose

Allocates Size bytes of memory by extending DS.

Inputs

Size, the amount of memory (in bytes) to allocate.

Outputs

Returns starting offset of allocated memory, or -1 on error.

Notes

This function works by extending the limit of the DS selector by Size bytes and returning the old limit.

There is no FreeMem() function; all allocated memory is freed upon program exit.

A.5.2 AllocSelector()

Usage

unsigned short AllocSelector(unsigned int Size);

Purpose

Allocates a memory block of Size bytes in a new selector.

Inputs

Size, the amount of memory to allocate.

Outputs

Returns new selector for the memory block, or -1 on error.

Notes

Can only allocate a maximum of MAXMEMHANDLES memory blocks.

A.5.3 FreeSelector()

Usage

void FreeSelector(unsigned short Selector);

Purpose

Frees a memory block allocated by AllocSelector().

Inputs

Selector, the selector of the memory block to free.

Outputs

None

Notes

No error checking on Selector value.

A.5.4 LockArea()

Usage

bool LockArea(short Selector, unsigned int Offset, unsigned int Length);

Purpose

Locks an area of memory so it is safe for an interrupt handler to access.

Inputs

Selector, selector of the area to lock (e.g. DS).

Offset, offset from start of segment of the beginning of the area to lock.

Length, length of the area to lock.

Outputs

Returns 1 on error, 0 on success.

A.5.5 GetPhysicalMapping()

Usage

bool GetPhysicalMapping(unsigned int *LinearAddress, short *Selector, unsigned int PhysicalAddress, unsigned int Size);

Purpose

Maps a physical memory region into linear (program) memory space.

Inputs

PhysicalAddress, the starting address of the physical memory region to map.

Size, size of the region, in bytes.

Outputs

LinearAddress, the linear address of the mapped region.

Selector, a selector that can be used to access the region.

Returns 1 on error, 0 on success.

Notes

Some outputs are passed as parameters; pass the address of a variable, and after a successful call, the variable will be filled with the output information.

A.5.6 FreePhysicalMapping()

Usage

void FreePhysicalMapping(unsigned int *LinearAddress, short *Selector);

Purpose

Frees the resources allocated by GetPhysicalMapping().

Inputs

LinearAddress, the linear address of the mapping to free.

Selector, the selector used to point to mapped memory block.

Outputs

LinearAddress and Selector cleared to 0.

Notes

This function takes the addresses of LinearAddress and Selector, not their contents.