OurOS 0.1
Operating System built by McGill Students
 
Loading...
Searching...
No Matches
frame.c File Reference
#include <stdbool.h>
#include <stddef.h>
#include <string.h>
#include "mm/kalloc.h"
#include "kernel/limine_responses.h"
#include "kernel/panic.h"
#include "mm/frame.h"

Data Structures

struct  frame
 Metadata for a physical frame. More...
 

Functions

static bool limine_entry_type_maybe_usable (uint64_t type)
 Check if a Limine memmap entry type is either usable (now) or reclaimable.
 
size_t pfn_to_phys (size_t pfn)
 Converts a PFN to a physical address.
 
struct frame * alloc_frame (const char *identifier)
 Allocates a frame and returns a pointer to it. The allocated frame will be zeroed out.
 
void free_frame (struct frame *frame)
 Frees a frame.
 
size_t frame_to_pfn (struct frame *frame)
 Returns the PFN of a frame.
 
static void memmap_count_init (const struct limine_memmap_response *memmap_response)
 Counting the number of usable frames in the Limine memory map response to initialize memmap_count
 
static void find_memmap_base (const struct limine_memmap_response *memmap_response)
 Finds a suitable place in memory to place our own memmap, and initializes memmap, memmap_start_phys, and memmap_end_phys.
 
void memmap_init (const struct limine_memmap_response *memmap_response)
 Initializes the array of memmap entries and the free frame linked list based on the Limine memory map response.
 
void frame_init ()
 Initializes the frame allocator and memory map.
 

Variables

static struct frame * memmap
 Array of physical frame metadata, indexed by PFN.
 
static size_t memmap_count
 Number of frames in memmap.
 
static size_t memmap_start_phys = 0
 Physical address start of memmap, inclusive. Page aligned.
 
static size_t memmap_end_phys = 0
 Physical address end of memmap, exclusive. Page aligned.
 
static struct frame * free_frame_list
 Pointer to the head of the free frame linked list.
 
static const char *const limine_memmap_entry_type_to_string []
 String representations of Limine memmap entry types for debugging purposes.
 

Function Documentation

◆ alloc_frame()

struct frame * alloc_frame ( const char *  identifier)

Allocates a frame and returns a pointer to it. The allocated frame will be zeroed out.

Parameters
identifierA string identifier for the frame (for debugging purposes).
Returns
A pointer to the allocated frame.

◆ find_memmap_base()

static void find_memmap_base ( const struct limine_memmap_response *  memmap_response)
static

Finds a suitable place in memory to place our own memmap, and initializes memmap, memmap_start_phys, and memmap_end_phys.

◆ frame_init()

void frame_init ( )

Initializes the frame allocator and memory map.

◆ frame_to_pfn()

size_t frame_to_pfn ( struct frame *  frame)

Returns the PFN of a frame.

Parameters
frameA pointer to the frame.
Returns
The PFN of the frame.

◆ free_frame()

void free_frame ( struct frame *  frame)

Frees a frame.

Parameters
frameA pointer to the frame to free.
Note
The frame will only be truly freed if its reference count drops to 0.

◆ limine_entry_type_maybe_usable()

static bool limine_entry_type_maybe_usable ( uint64_t  type)
static

Check if a Limine memmap entry type is either usable (now) or reclaimable.

Parameters
typeThe Limine memmap entry type to check.
Returns
true if the entry type is maybe usable, false otherwise.

◆ memmap_count_init()

static void memmap_count_init ( const struct limine_memmap_response *  memmap_response)
static

Counting the number of usable frames in the Limine memory map response to initialize memmap_count

◆ memmap_init()

void memmap_init ( const struct limine_memmap_response *  memmap_response)

Initializes the array of memmap entries and the free frame linked list based on the Limine memory map response.

◆ pfn_to_phys()

size_t pfn_to_phys ( size_t  pfn)

Converts a PFN to a physical address.

Parameters
pfnThe PFN to convert.
Returns
The physical address.

Variable Documentation

◆ free_frame_list

struct frame* free_frame_list
static

Pointer to the head of the free frame linked list.

◆ limine_memmap_entry_type_to_string

const char* const limine_memmap_entry_type_to_string[]
static
Initial value:
= {
[LIMINE_MEMMAP_USABLE] = "usable",
[LIMINE_MEMMAP_RESERVED] = "reserved",
[LIMINE_MEMMAP_ACPI_RECLAIMABLE] = "acpi reclaimable",
[LIMINE_MEMMAP_ACPI_NVS] = "acpi nvs",
[LIMINE_MEMMAP_BAD_MEMORY] = "bad memory",
[LIMINE_MEMMAP_BOOTLOADER_RECLAIMABLE] = "bootloader reclaimable",
[LIMINE_MEMMAP_EXECUTABLE_AND_MODULES] = "executable and modules",
[LIMINE_MEMMAP_FRAMEBUFFER] = "framebuffer",
[LIMINE_MEMMAP_ACPI_TABLES] = "acpi tables",
}
#define LIMINE_MEMMAP_RESERVED
Definition limine.h:341
#define LIMINE_MEMMAP_ACPI_NVS
Definition limine.h:343
#define LIMINE_MEMMAP_ACPI_TABLES
Definition limine.h:348
#define LIMINE_MEMMAP_FRAMEBUFFER
Definition limine.h:347
#define LIMINE_MEMMAP_ACPI_RECLAIMABLE
Definition limine.h:342
#define LIMINE_MEMMAP_USABLE
Definition limine.h:340
#define LIMINE_MEMMAP_BOOTLOADER_RECLAIMABLE
Definition limine.h:345
#define LIMINE_MEMMAP_EXECUTABLE_AND_MODULES
Definition limine.h:346
#define LIMINE_MEMMAP_BAD_MEMORY
Definition limine.h:344

String representations of Limine memmap entry types for debugging purposes.

◆ memmap

struct frame* memmap
static

Array of physical frame metadata, indexed by PFN.

◆ memmap_count

size_t memmap_count
static

Number of frames in memmap.

◆ memmap_end_phys

size_t memmap_end_phys = 0
static

Physical address end of memmap, exclusive. Page aligned.

◆ memmap_start_phys

size_t memmap_start_phys = 0
static

Physical address start of memmap, inclusive. Page aligned.