AMC-OS Loader Memory management

From AMC-OS Developers
Jump to navigation Jump to search

Memory used during AMC-OS Loader execution

AMC-OS Loader uses only the first megabyte of memory :

00000-003FF Real-mode interrupt table
00400-00500 BIOS static data
00501-005FF Free (unused)
00600-007FF Master boot record
00800-[__A] Kernel static data (initialized by boot loader)
[__A]-[__B] AMC-OS Loader code
[__B]-[__C] AMC-OS Loader picture
[__C]-077FF Free for allocation
077FF-07BFF AMC-OS Loader stack
07C00-07DFF Boot loader code (VBR or MBR for floppy disk)
07E00-07FFF Free (unused)
08000-9[_D] Free for allocation
9[_D]-09FFF Extended BIOS data area (EBDA - optional)

Memory management

Initialization

During memory initialization process (AMCOSLDR_InitFirstMegabyte), AMC-OS Loader :

  • looks for EBDA using interrupt 12H and value stored in 0040:000E to get highest pointer in memory [_D]
  • calculates the values of [__C] to get lowest pointer in memory
  • creates a linked list of available blocks of memory (AMCOSLDR_Malloc_Entry)
  • initializes two blocks of available memory (marked Free for allocation in previous table)

Allocation of 512 bytes or more

Three main functions are available to AMC-OS Loader for memory allocation. They wait for the requested size in segment size (16-bytes unit), and returns a segment of memory aligned on 512 bytes boundaries to facilitate disk operations.

  • AMCOSLDR_DefinitiveAlloc : Used to allocate memory that shall stay at this place at the end of the process (used by kernel afterwards). Memory will be taken from bottom of free memory.
  • AMCOSLDR_TempAlloc : Used to allocate memory that will be freed at the end of AMC-OS Loader. Memory will be taken from top of free memory.
  • AMCOSLDR_VolatileAlloc : Used to allocate memory for immediate use (valid only until a new call to any memory function is made). Memory will be taken from top of free memory. It typically do the same as AMCOSLDR_TempAlloc but do not consider the memory to be really used, so only the two other functions maintain the linked list of available blocks of memory.

Temporary allocations are reclaimed by kernel later during INIT_MemoryUsableIn1stMeg.

Allocation of less than 512 bytes, "Small allocation"

For definitive allocation of less than 512 bytes, an other function is available. It also waits for the requested size in segment size (16-bytes unit), and returns a 16-byte aligned memory segment.

  • AMCOSLDR_DefinitiveSmallAlloc : Used to allocate memory that shall stay at this place at the end of the process (used by kernel afterwards). Memory will be taken from bottom of free memory. Small allocation is maintained with a linked list of structures { free_size_in_segment ; ptr_next_segment } stored directly in free memory, and starting by pointer stored in AMCOSLDR_SmallAllocSegPtr.

After AMC-OS Loader has finished, kernel reclaims the available memory later during INIT_MemorySmallocInit.