armOS  0.1.0
Minimal ARM Operating System for the Raspberry Pi - Documentation generated for Pi 4.
memory

Code for managing memory. More...

Files

file  mm.c
 Implementation of basic memory functions.
 
file  mm.h
 Definition of basic memory sizes and functions.
 

Macros

#define PAGE_SHIFT   12
 
#define TABLE_SHIFT   9
 
#define SECTION_SHIFT   (PAGE_SHIFT + TABLE_SHIFT)
 
#define PAGE_SIZE   (1 << PAGE_SHIFT)
 
#define SECTION_SIZE   (1 << SECTION_SHIFT)
 
#define LOW_MEMORY   (2 * SECTION_SIZE)
 
#define HIGH_MEMORY   MMIO_BASE
 
#define PAGING_MEMORY   (HIGH_MEMORY - LOW_MEMORY)
 
#define PAGING_PAGES   (PAGING_MEMORY / PAGE_SIZE)
 

Functions

uint64_t get_free_page ()
 
void free_page (uint64_t p)
 

Detailed Description

Code for managing memory.

Macro Definition Documentation

◆ HIGH_MEMORY

#define HIGH_MEMORY   MMIO_BASE

Start of Memory Mapped Registers.

See also
MMIO_BASE

◆ LOW_MEMORY

#define LOW_MEMORY   (2 * SECTION_SIZE)

4MB (First 4 MB of memory reserved for the kernel image and init task stack).

  • 2*2MB = 4MB

◆ PAGE_SHIFT

#define PAGE_SHIFT   12

Bits to shift to define Page size.

◆ PAGE_SIZE

#define PAGE_SIZE   (1 << PAGE_SHIFT)

PAGE_SIZE: 4KB

  • For kernel at address 0x0: Start of stack, 4MB available for kernel (except stack).
  • For kernel at address 0x8000: 4064KB available for kernel till 4MB.
  • For kernel at address 0x80000: 3584KB available for kernel till 4MB.
  • 2^12 = 4096 = 4KB

◆ PAGING_MEMORY

#define PAGING_MEMORY   (HIGH_MEMORY - LOW_MEMORY)

Available memory for paging

  • MMIO_BASE - 4MB

◆ PAGING_PAGES

#define PAGING_PAGES   (PAGING_MEMORY / PAGE_SIZE)

Available 4KB pages

  • (MMIO_BASE - 4MB) / 4KB

◆ SECTION_SHIFT

#define SECTION_SHIFT   (PAGE_SHIFT + TABLE_SHIFT)

Bits to shift to define Section size (= 21).

◆ SECTION_SIZE

#define SECTION_SIZE   (1 << SECTION_SHIFT)
  • 2^21 = 2048KB = 2MB

◆ TABLE_SHIFT

#define TABLE_SHIFT   9

Bits to shift to define Table size.

Function Documentation

◆ free_page()

void free_page ( uint64_t  p)

Function for deallocating memory pages.

Parameters
p64-bit address of page to be deallocated.

◆ get_free_page()

uint64_t get_free_page ( )

Function for allocating memory pages.

Returns
  • On success: Starting address (64-bit) of the allocated page.
  • On failure: 0