IBNOS
physmem.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014, Michael Müller
3  * Copyright (c) 2014, Sebastian Lackner
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright notice, this
10  * list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright notice,
12  * this list of conditions and the following disclaimer in the documentation
13  * and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
19  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25  *
26  */
27 
28 #ifndef _H_PHYSMEM_
29 #define _H_PHYSMEM_
30 
35 #define PAGE_SIZE 0x1000
36 #define PAGE_MASK 0xFFF
37 #define PAGE_BITS 12
38 #define PAGE_COUNT 0x100000
39 
40 #ifdef __KERNEL__
41 
42  #include <stdint.h>
43  #include <stdbool.h>
44 
45  #include <util/util.h>
46  #include <multiboot/multiboot.h>
47 
48  #define PHYSMEM_FREE 0
49  #define PHYSMEM_RESERVED 1
50 
51  void physMemInit(multiboot_info_t* bootInfo);
52 
53  uint32_t physMemRAMSize();
54  uint32_t physMemUsableMemory();
55 
56  void physMemProtectBootEntry(uint32_t addr, uint32_t length);
57 
59  void physMemReserveMemory(uint32_t addr, uint32_t length);
60  void physMemFreeMemory(uint32_t addr, uint32_t length);
61  void physMemSetMemoryBits(uint32_t startIndex, uint32_t length, bool reserved);
62 
63  uint32_t physMemAllocPage(bool lowmem);
64  uint32_t physMemReleasePage(uint32_t index);
65 
66  uint32_t physMemAddRefPage(uint32_t index);
67  uint32_t physMemMarkUnpageable(uint32_t index);
68  bool physMemIsLastRef(uint32_t index);
69 
70  void physMemPageOut(UNUSED uint32_t length);
71  uint32_t physMemPageIn(UNUSED uint32_t hdd_index);
72 
73  void physMemDumpMemInfo();
74 
75 #endif
76 
79 #endif
void physMemFreeMemory(uint32_t addr, uint32_t length)
Marks all pages fully contained within the memory range as free.
Definition: physmem.c:299
uint32_t physMemReleasePage(uint32_t index)
Releases a page of physical memory.
Definition: physmem.c:426
uint32_t physMemMarkUnpageable(uint32_t index)
Marks a physical page as unpageable.
Definition: physmem.c:486
#define UNUSED
Definition: util.h:39
uint32_t physMemPageIn(UNUSED uint32_t hdd_index)
Pages in some data from the hard drive.
Definition: physmem.c:535
void physMemProtectBootEntry(uint32_t addr, uint32_t length)
Marks all pages within a memory range as reserved and adds them to the boot map.
Definition: physmem.c:259
bool physMemIsLastRef(uint32_t index)
Checks if a physical page is only referenced exactly one time.
Definition: physmem.c:510
void physMemReserveMemory(uint32_t addr, uint32_t length)
Marks all pages within a memory range as reserved.
Definition: physmem.c:280
uint32_t physMemAddRefPage(uint32_t index)
Increment the refcounter of a physical page.
Definition: physmem.c:460
void physMemSetMemoryBits(uint32_t startIndex, uint32_t length, bool reserved)
Marks a specific range of pages as reserved or free.
Definition: physmem.c:319
void physMemInit(multiboot_info_t *bootInfo)
Initializes the physical memory management.
Definition: physmem.c:116
uint32_t physMemRAMSize()
Query RAM size.
Definition: physmem.c:219
void physMemDumpMemInfo()
Dumps information about the physical memory usage.
Definition: physmem.c:544
uint32_t physMemAllocPage(bool lowmem)
Allocates a page of physical memory.
Definition: physmem.c:383
void physMemClearMemoryBits(bool reserved)
Marks the full memory range as reserved or free.
Definition: physmem.c:244
void physMemPageOut(UNUSED uint32_t length)
Pages out some memory to the hard drive.
Definition: physmem.c:521
uint32_t physMemUsableMemory()
Query usable RAM size.
Definition: physmem.c:232
uint8_t reserved
Definition: gdt.h:134