[][src]Module sunrise_bootstrap::frame_alloc

A module implementing a physical memory manager that allocates and frees memory frames

We define a frame as the same size as a page, to make things easy for us. This module can only allocate and free whole frames.

It keeps tracks of the allocated frames by mean of a giant bitmap mapping every physical memory frame in the address space to a bit representing if it is free or not. This works because the address space in 32 bits is only 4GB, so ~1 million frames only

During init we initialize the bitmap by parsing the information that the bootloader gives us and marking some physical memory regions as reserved, either because of BIOS, MMIO or simply because our kernel is loaded in it

Structs

AllocatorBitmap

A big bitmap denoting for every frame if it is free or not

Frame

A pointer to a physical frame

FrameAllocator

A physical memory manger to allocate and free memory frames

Constants

FRAMES_BITMAP_SIZE

When testing we use a much smaller array.

FRAME_BASE_LOG
FRAME_BASE_MASK
FRAME_FREE
FRAME_OCCUPIED
FRAME_OFFSET_MASK
MEMORY_FRAME_SIZE

A memory frame is the same size as a page

Statics

FRAMES_BITMAP

A big bitmap denoting for every frame if it is free or not

Functions

addr_to_frame

Gets the frame number from a physical address

frame_to_addr

Gets the physical address from a frame number

round_to_page

Rounds an address to its page address

round_to_page_upper

Rounds an address to the next page address except if its offset in that page is 0