root / lab4 / .minix-src / include / lcom / liblm.h @ 13
History | View | Annotate | Download (2.07 KB)
1 |
#pragma once
|
---|---|
2 |
|
3 |
/** @defgroup liblm liblm
|
4 |
* @{
|
5 |
*
|
6 |
* Functions related to low memory (first 1 MB of physical memory), required for BIOS
|
7 |
*/
|
8 |
|
9 |
#include <stdbool.h> |
10 |
|
11 |
#include <minix/syslib.h> |
12 |
|
13 |
#define PB2BASE(x) (((x) >> 4) & 0x0F000) // phys_bytes to segment base |
14 |
#define PB2OFF(x) ((x) & (0x0FFFF)) // phys_bytes to segment offset |
15 |
|
16 |
/** @name Memory Map Struct*/
|
17 |
/**@{
|
18 |
*
|
19 |
* Struct that keeps info regarding the mapping of physical memory to virtual memory
|
20 |
*/
|
21 |
typedef struct { |
22 |
phys_bytes phys; /**< @brief physical address */
|
23 |
void *virt; /**< @brief virtual address */ |
24 |
size_t size; /**< @brief size of mapped memory region */
|
25 |
} mmap_t; |
26 |
|
27 |
/** @} end of Memory Map Struct */
|
28 |
|
29 |
/**
|
30 |
* @brief Initializes the low memory area, the region up to the 1 MByte physical address, by mapping it on the process' physical memory address
|
31 |
*
|
32 |
* @param enable_logging set whether log messages should be printed or not
|
33 |
*
|
34 |
* @return virtual address on which the first 1 MB was mapped, NULL upon failure
|
35 |
*/
|
36 |
void *lm_init(bool enable_logging); |
37 |
|
38 |
/**
|
39 |
* @brief Allocates a memory block in low memory area with the specified size
|
40 |
*
|
41 |
* Allocates a memory block in the region up to the 1 MByte physical address with the input size,
|
42 |
* and initializes the input mmap_t struct with the mapping information.
|
43 |
*
|
44 |
* @param size size of the memory block to allocate
|
45 |
* @param map pointer to mmap_t data structure, which represents the memory map
|
46 |
* @return the virtual address of the memory block on success, NULL otherwise
|
47 |
*/
|
48 |
void *lm_alloc(size_t size, mmap_t *map);
|
49 |
|
50 |
/**
|
51 |
* @brief Frees a memory block in the low memory area, previously allocated using lm_alloc()
|
52 |
*
|
53 |
* Frees a memory block in the region up to the 1 MByte physical address, previously
|
54 |
* allocated using lm_alloc(). Takes as input the address of the mmap_t structure that
|
55 |
* was passed to lm_alloc(), and that must have not been modified since.
|
56 |
*
|
57 |
* @param map pointer to mmap_t data structure of the block being freed
|
58 |
* @return a boolean indicating whether memory deallocation succeeded
|
59 |
*/
|
60 |
bool lm_free(const mmap_t *map); |
61 |
|
62 |
/** @} end of liblm */
|