Skip to content

Pagination

Sukant Pal edited this page Mar 1, 2018 · 12 revisions

Memory Pagination

Silcos kernel uses the memory protection and organization technique known as paging. In this technique, each virtual address is mapped to a physical address in blocks known as pages. These pages can be of various sizes - 4KB and 2MB (IA32, PAE). The blocks in physical memory are known as page-frames and in virtual memory they are called only pages.

Kernel Memory

Silcos has a "build" time map of the locations of various permanent data structures in kernel memory. This map is declared through sets of macros in Memory/KMemorySpace.h. On changing the values in this file & re-building the kernel, the data structures will be mapped to different offsets in kernel memory. The data structures include -

  1. Platform Information

  2. ACPI Tables & Objects

  3. CPU Status Table

  4. Dynamically-allocable Memory

Platform Information

This is not being used currently and is reserved. It is intended for use to store architectural information - x2APIC enabled, TSC enabled, etc.

ACPI Tables & Objects

This memory is intended for use by the kernel's ACPI subsystem. Later it will be shared by drivers (when the kernel finishes). It is used for mapping ACPI tables in non-cacheable memory currently.

CPU Status Table

This region of memory is intended for storing the struct Processor and related data structures which are usually accessed only by the owner-CPU. Each CPU gets a 32-KB block in kernel-memory which can be accessed by the GetProcessorById and GetIRQTableById macros included in HardwareAbstraction/Processor.h.

Dynamically-allocable Memory

This memory is used for allocating objects & module-segments (plus some other minute purposes). The size of dynamic-memory is decided during boot depending on the amount of physical memory available. The KMemoryManager was built to manage this portion of kernel-memory.

Kernel Paging

The kernel provides a platform-independent interface that allows software to map ranges of virtual addresses to physical addresses or exclusively allocated page-frames. This is done without the help of any MemoryContext object after it has been switched to using switchSpace() because of the recursive-mapping nature of the kernel-pager. The pager is implemented in the KernelHost's Arch folder and is completely platform-dependent.

class Pager
{
public:
	static void switchSpace(MemoryContext *cxt);

	static void dispose(VirtAddr vadr);

	static void disposeAll(VirtAddr base, VirtAddr limit);

	static void map(VirtAddr vadr, PhysAddr padr,
			unsigned allocFlags, PageAttributes attr);
	static void mapAll(VirtAddr base, PhysAddr pbase, unsigned size,
			unsigned allocFlags, PageAttributes attr);
	static void useAllSmall(VirtAddr base, VirtAddr limit,
			unsigned allocFlags, PageAttributes attr);
	static void useAllHuge(VirtAddr base, VirtAddr limit,
			unsigned allocFlags, PageAttributes attr);
	static void use(VirtAddr base, unsigned allocFlags,
			PageAttributes attr);
	static void useAll(VirtAddr base, VirtAddr limit,
			unsigned allocFlags, PageAttributes attr);
private:
	Pager();
};
Clone this wiki locally