Memory initialization

From AMC-OS Developers
Jump to navigation Jump to search

During AMC-OS Loader

To get size and map of memory, AMC-OS Loader now relies mainly on BIOS instead of probing, which was the preferred way in AMC-OS <2.10.

AMC-OS Loader proceed this way :

  • Try INT 15H, function E820 to get memory map.
  • Try INT 15H, function E801 to get size of memory below 16MB and above 16MB
  • Try INT 15H, function 88 to get effective size of extended memory
  • Get configured size of extended memory in CMOS

Depending on functions supported by BIOS, map will be more or less precise, and memory might be lost if ISA Hole in the 15-16M area is configured.

After AMC-OS Loader execution, the first megabyte of memory is divided like this :

00000-003FF Real-mode interrupt table (for V86)
00400-00500 BIOS static data (for V86)
00501-007FF Partially allocated memory by AMCOSLDR_DefinitiveAlloc
00800-[__A] Kernel static data
[__A]-077FF Partially allocated memory by AMCOSLDR_DefinitiveAlloc
077FF-07BFF AMC-OS Loader stack (no longer used- reclaimable)
07C00-07DFF Boot loader code (no longer used - reclaimable)
07E00-07FFF Free (unused - reclaimable)
08000-9[_D] Partially allocated memory by AMCOSLDR_DefinitiveAlloc, including Kernel
9[_D]-9FFFF Extended BIOS data area (EBDA - optional)

All reclaimable memory is added to the SMALLOC structures of AMC-OS Loader, than will be analyzed by Kernel.

End of 1st megabyte, segment-like, [_D] or A000H is stored in MEMORY_BaseMaxSegment.

Kernel start

Process of memory initialization by Kernel is the following :

  • Initialization of 1st MB of memory : AMC-OS uses information discovered by the loader to build initial memory structures.
  • A20 gate unlocking to access memory above 1MB
  • Initialization of all physical memory

Initialization of first megabyte

Kernel starts by calling INIT_MemoryUsableIn1stMeg(). The function determines the first address of free memory in the first megabyte, just after kernel relocation code and below EBDA. It checks that it matches with AMC-OS Loader MALLOC structure, as its last allocatable block should start just after kernel relocation code.

The function fills :

  • MEMORY_FreePageAddrIn1stMeg
  • MEMORY_FreePagesIn1stMeg

which allow the call to INIT_AllocatePagesBelow() for allocation of contiguous pages of memory during initialization.

It also calls INIT_MemorySmallocInit, which rebuilds AMC-OS Loader SMALLOC structures with 32-byte direct offsets to have a quick function for small memory allocation during memory initialization : INIT_MemoryDefinitiveAlloc() .

At this point, all unused memory by AMC-OS Loader is reclaimed by kernel, and 1st megabyte of memory is fully analyzed.

A20 Gate

Kernel unlocks A20 gate by calling INIT_A20Gate.

A20 gate was controlled by keyboard controller on AT+. To allow compatibility with 8086/8088, the A20 address line was forced to 0 on AT computers, blocking access to memory above 1MB. A20 gate must be enabled to allow A20 address line to be used normally.

Physical memory initialization

Physical memory is initialized by calling INIT_GlobalMemory.

Memory map

The function first builds a map of physical memory :

  • If available, it relies first on type-1 (available) entries of E820 BIOS records. In current release, memory above 4GB is ignored.
  • If available, it relies on E801 BIOS call results to determine a block of memory below 16MB and a block of memory above 16MB.
  • In other cases, kernel do a manual probing of available memory, using function INIT_MemoryCheckSegment.