NOVA
Stripped down NOVA kernel for the OSY course
Loading...
Searching...
No Matches
kalloc.h
1/*
2 * Very simple memory allocator
3 */
4
5#pragma once
6
7#include "types.h"
8#include "memory.h"
9
10class Kalloc
11{
12 private:
13 const mword begin;
14 mword end;
15
16 // Bitmap for 64 MB of memory
17 static const unsigned mempool_pages = 64*(1<<20)/PAGE_SIZE;
18 unsigned page_bitmap[mempool_pages/32];
19
20 bool is_page_allocated(unsigned idx);
21 void mark_page_allocated(unsigned idx, bool allocated);
22
23 public:
24
25 enum Fill
26 {
27 NOFILL = 0,
28 FILL_0,
29 FILL_1
30 };
31
32 static Kalloc allocator;
33
34 Kalloc (mword virt_begin, mword virt_end) : begin (virt_begin), end (virt_end) {}
35
36 void * alloc(unsigned size);
37
38 void * alloc_page (unsigned count, Fill fill = NOFILL);
39 void free_page (void *);
40
53 static void * phys2virt (mword);
54
56 static mword virt2phys (void *);
57};
static void * phys2virt(mword)
Returns the virtual address that can be used to access memory with physical address phys.
Definition kalloc.cc:92
static mword virt2phys(void *)
Return the physical address that is mapped from the virtual address virt (opposite of phys2virt).
Definition kalloc.cc:98
void free_page(void *)
Free a page previously allocated with Kalloc::alloc_page().
Definition kalloc.cc:82
void * alloc_page(unsigned count, Fill fill=NOFILL)
Allocate count virtually contiguous pages and optionally fill them with 0x00 or 0xFF.
Definition kalloc.cc:46