UbixOS
2.0
unmappage.c
Go to the documentation of this file.
1
/*-
2
* Copyright (c) 2002-2018 The UbixOS Project.
3
* All rights reserved.
4
*
5
* This was developed by Christopher W. Olsen for the UbixOS Project.
6
*
7
* Redistribution and use in source and binary forms, with or without modification, are permitted
8
* provided that the following conditions are met:
9
*
10
* 1) Redistributions of source code must retain the above copyright notice, this list of
11
* conditions, the following disclaimer and the list of authors.
12
* 2) Redistributions in binary form must reproduce the above copyright notice, this list of
13
* conditions, the following disclaimer and the list of authors in the documentation and/or
14
* other materials provided with the distribution.
15
* 3) Neither the name of the UbixOS Project nor the names of its contributors may be used to
16
* endorse or promote products derived from this software without specific prior written
17
* permission.
18
*
19
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
20
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
21
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
22
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
24
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
26
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
*/
28
29
#include <
vmm/vmm.h
>
30
31
/************************************************************************
32
33
Function: void vmm_unmapPage(uInt32 pageAddr,int flags);
34
Description: This Function Will Unmap A Page From The Kernel VM Space
35
The Flags Variable Decides If Its To Free The Page Or Not
36
A Flag Of 0 Will Free It And A Flag Of 1 Will Keep It
37
Notes:
38
39
07/30/02 - I Have Decided That This Should Free The Physical Page There
40
Is No Reason To Keep It Marked As Not Available
41
42
07/30/02 - Ok A Found A Reason To Keep It Marked As Available I Admit
43
Even I Am Not Perfect Ok The Case Where You Wouldn't Want To
44
Free It Would Be On Something Like Where I Allocated A Page
45
To Create A New Virtual Space So Now It Has A Flag
46
47
************************************************************************/
48
void
vmm_unmapPage
(
uint32_t
pageAddr,
unmapFlags_t
flags) {
49
int
pageDirectoryIndex = 0, pageTableIndex = 0;
50
uint32_t
*pageTable = 0x0;
51
uint32_t
*pageDirectory = 0x0;
52
53
pageDirectory =
PD_BASE_ADDR
;
54
55
/* Get The Index To The Page Directory */
56
pageDirectoryIndex = (pageAddr >> 22);
57
58
if
((pageDirectory[pageDirectoryIndex] &
PAGE_PRESENT
) !=
PAGE_PRESENT
)
59
return
;
60
61
//Calculate The Page Table Index
62
pageTableIndex = ((pageAddr >> 12) & 0x3FF);
63
64
/* Set pageTable To The Virtual Address Of Table */
65
pageTable = (
uint32_t
*) (
PT_BASE_ADDR
+ (0x1000 * pageDirectoryIndex));
66
67
/* Free The Physical Page If Flags Is 0 */
68
if
(flags == 0)
69
freePage
((
uint32_t
) (pageTable[pageTableIndex] & 0xFFFFF000));
70
71
/* Unmap The Page */
72
pageTable[pageTableIndex] = 0x0;
73
74
/* Rehash The Page Directory */
75
asm
volatile
(
76
"movl %cr3,%eax\n"
77
"movl %eax,%cr3\n"
78
);
79
80
/* Return */
81
return
;
82
}
83
84
/************************************************************************
85
86
Function: void vmm_unmapPages(uInt32 pageAddr,int flags);
87
Description: This Function Will Unmap A Page From The Kernel VM Space
88
The Flags Variable Decides If Its To Free The Page Or Not
89
A Flag Of 0 Will Free It And A Flag Of 1 Will Keep It
90
Notes:
91
92
07/30/02 - I Have Decided That This Should Free The Physical Page There
93
Is No Reason To Keep It Marked As Not Available
94
95
07/30/02 - Ok A Found A Reason To Keep It Marked As Available I Admit
96
Even I Am Not Perfect Ok The Case Where You Wouldn't Want To
97
Free It Would Be On Something Like Where I Allocated A Page
98
To Create A New Virtual Space So Now It Has A Flag
99
100
************************************************************************/
101
void
vmm_unmapPages
(
void
*ptr,
uint32_t
size,
unmapFlags_t
flags) {
102
uInt32
baseAddr = (
uInt32
) ptr & 0xFFFFF000;
103
uInt32
dI = 0x0, tI = 0x0;
104
uInt32
y = 0x0;
105
uInt32
*pageTable = 0x0;
106
107
dI = (baseAddr / (1024 * 4096));
108
tI = ((baseAddr - (dI * (1024 * 4096))) / 4096);
109
pageTable = (
uInt32
*) (
PT_BASE_ADDR
+ (4096 * dI));
110
for
(y = tI; y < (tI + ((size + 4095) / 4096)); y++) {
111
pageTable[y] = 0x0;
112
}
113
return
;
114
}
vmm_unmapPages
void vmm_unmapPages(void *ptr, uint32_t size, unmapFlags_t flags)
Definition:
unmappage.c:99
uInt32
unsigned long int uInt32
Definition:
objgfx30.h:49
freePage
int freePage(uint32_t pageAddr)
Definition:
vmm_memory.c:262
vmm.h
vmm_unmapPage
void vmm_unmapPage(uint32_t pageAddr, unmapFlags_t flags)
Definition:
unmappage.c:47
unmapFlags_t
unmapFlags_t
Definition:
vmm.h:110
PD_BASE_ADDR
#define PD_BASE_ADDR
Definition:
paging.h:45
uint32_t
__uint32_t uint32_t
Definition:
types.h:46
PT_BASE_ADDR
#define PT_BASE_ADDR
Definition:
paging.h:46
PAGE_PRESENT
#define PAGE_PRESENT
Definition:
paging.h:55
vmm
unmappage.c
Generated by
1.8.16