MonkOS  v0.1
A simple 64-bit operating system (x86_64)
pmap.h
Go to the documentation of this file.
1 //============================================================================
2 /// @file pmap.h
3 /// @brief Physical memory map describing usable and reserved regions
4 /// of physical memory.
5 /// @details Most of the map is derived from data provided by the system
6 /// BIOS at boot time.
7 //
8 // Copyright 2016 Brett Vickers.
9 // Use of this source code is governed by a BSD-style license that can
10 // be found in the MonkOS LICENSE file.
11 //============================================================================
12 
13 #pragma once
14 
15 #include <core.h>
16 
17 //----------------------------------------------------------------------------
18 // @enum pmemtype
19 /// @brief The types of physical memory.
20 //----------------------------------------------------------------------------
22 {
23  PMEMTYPE_USABLE = 1, ///< Reported usable by the BIOS.
24  PMEMTYPE_RESERVED = 2, ///< Reported (or inferred) to be reserved.
25  PMEMTYPE_ACPI = 3, ///< Used for ACPI tables or code.
26  PMEMTYPE_ACPI_NVS = 4, ///< Used for ACPI non-volatile storage.
27  PMEMTYPE_BAD = 5, ///< Reported as bad memory.
28  PMEMTYPE_UNCACHED = 6, ///< Marked as uncacheable, usually for I/O.
29  PMEMTYPE_UNMAPPED = 7, ///< Marked as "do not map".
30 };
31 
32 //----------------------------------------------------------------------------
33 // @struct pmapregion_t
34 /// @brief A memregion represents and describes a contiguous region of
35 /// physical memory.
36 //----------------------------------------------------------------------------
37 struct pmapregion
38 {
39  uint64_t addr; ///< base address
40  uint64_t size; ///< size of memory region
41  int32_t type; ///< Memory type (see memtype enum)
42  uint32_t flags; ///< flags (currently unused)
43 };
44 typedef struct pmapregion pmapregion_t;
45 
46 //----------------------------------------------------------------------------
47 // @struct pmap_t
48 /// @brief A memory map describing available and reserved regions of
49 /// physical memory.
50 /// @details There are no gaps in a memory map.
51 //----------------------------------------------------------------------------
52 struct pmap
53 {
54  uint64_t count; ///< Memory regions in the memory map
55  uint64_t last_usable; ///< End of last usable region
56  pmapregion_t region[1]; ///< An array of 'count' memory regions
57 };
58 typedef struct pmap pmap_t;
59 
60 //----------------------------------------------------------------------------
61 // @function pmap_init
62 /// @brief Initialize the physical memory map using data installed by the
63 /// BIOS during boot loading.
64 //----------------------------------------------------------------------------
65 void
66 pmap_init();
67 
68 //----------------------------------------------------------------------------
69 // @function pmap_add
70 /// @brief Add a region of memory to the physical memory map.
71 /// @param[in] addr The starting address of the region.
72 /// @param[in] size The size of the region.
73 /// @param[in] type The type of memory to add.
74 //----------------------------------------------------------------------------
75 void
76 pmap_add(uint64_t addr, uint64_t size, enum pmemtype type);
77 
78 //----------------------------------------------------------------------------
79 // @function pmap
80 /// @brief Return a pointer to the current physical memory map.
81 /// @returns A pointer to the physical memory map.
82 //----------------------------------------------------------------------------
83 const pmap_t *
84 pmap();
int32_t type
Memory type (see memtype enum)
Definition: pmap.h:41
const pmap_t * pmap()
Return a pointer to the current physical memory map.
Definition: pmap.c:316
void pmap_init()
Initialize the physical memory map using data installed by the BIOS during boot loading.
Definition: pmap.c:292
Core include file.
uint64_t count
Memory regions in the memory map.
Definition: pmap.h:54
pmemtype
The types of physical memory.
Definition: pmap.h:21
Marked as uncacheable, usually for I/O.
Definition: pmap.h:28
Reported usable by the BIOS.
Definition: pmap.h:23
Used for ACPI tables or code.
Definition: pmap.h:25
uint64_t addr
base address
Definition: pmap.h:39
A memory map describing available and reserved regions of physical memory.
Definition: pmap.h:52
uint64_t last_usable
End of last usable region.
Definition: pmap.h:55
Reported as bad memory.
Definition: pmap.h:27
Reported (or inferred) to be reserved.
Definition: pmap.h:24
void pmap_add(uint64_t addr, uint64_t size, enum pmemtype type)
Add a region of memory to the physical memory map.
Definition: pmap.c:322
Marked as "do not map".
Definition: pmap.h:29
uint64_t size
size of memory region
Definition: pmap.h:40
A memregion represents and describes a contiguous region of physical memory.
Definition: pmap.h:37
uint32_t flags
flags (currently unused)
Definition: pmap.h:42
Used for ACPI non-volatile storage.
Definition: pmap.h:26