UbixOS
2.0
getfreepage.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
#include <
ubixos/kpanic.h
>
31
#include <
ubixos/spinlock.h
>
32
33
static
struct
spinLock
vmmGFPlock =
SPIN_LOCK_INITIALIZER
;
34
35
/************************************************************************
36
37
Function: void *vmm_getFreePage(pidType pid);
38
39
Description: Returns A Free Page Mapped To The VM Space
40
41
Notes:
42
43
07/30/02 - This Returns A Free Page In The Top 1GB For The Kernel
44
45
************************************************************************/
46
void
*
vmm_getFreePage
(
pidType
pid) {
47
uInt16
x = 0x0, y = 0x0;
48
uInt32
*pageTableSrc = 0x0;
49
50
spinLock
(&vmmGFPlock);
51
52
/* Lets Search For A Free Page */
53
for
(x =
PD_INDEX
(
VMM_KERN_START
); x <=
PD_INDEX
(
VMM_KERN_END
); x++) {
54
55
/* Set Page Table Address */
56
pageTableSrc = (
uInt32
*) (
PT_BASE_ADDR
+ (0x1000 * x));
57
58
for
(y = 0x0; y < 1024; y++) {
59
60
/* Loop Through The Page Table Find An UnAllocated Page */
61
if
((
uInt32
) pageTableSrc[y] == (
uInt32
) 0x0) {
62
63
/* Map A Physical Page To The Virtual Page */
64
if
((
vmm_remapPage
(
vmm_findFreePage
(pid), ((x * 0x400000) + (y * 0x1000)),
KERNEL_PAGE_DEFAULT
, pid, 0)) == 0x0)
65
kpanic
(
"vmmRemapPage: vmm_getFreePage\n"
);
66
67
/* Clear This Page So No Garbage Is There */
68
vmm_clearVirtualPage
((
uInt32
) ((x * 0x400000) + (y * 0x1000)));
69
70
/* Return The Address Of The Newly Allocate Page */
71
spinUnlock
(&vmmGFPlock);
72
return
((
void
*) ((x * 0x400000) + (y * 0x1000)));
73
}
74
}
75
}
76
77
/* If No Free Page Was Found Return NULL */
78
spinUnlock
(&vmmGFPlock);
79
80
return
(0x0);
81
}
spinlock.h
uInt32
unsigned long int uInt32
Definition:
objgfx30.h:49
uInt16
unsigned short int uInt16
Definition:
objgfx30.h:48
vmm_getFreePage
void * vmm_getFreePage(pidType pid)
Definition:
getfreepage.c:45
spinUnlock
void spinUnlock(spinLock_t *lock)
Definition:
spinlock.c:36
vmm.h
SPIN_LOCK_INITIALIZER
#define SPIN_LOCK_INITIALIZER
Definition:
spinlock.h:36
kpanic
void kpanic(const char *fmt,...)
print panic message and halt system
Definition:
kpanic.c:41
VMM_KERN_START
#define VMM_KERN_START
Definition:
vmm.h:64
spinLock
void spinLock(spinLock_t *lock)
Definition:
spinlock.c:55
kpanic.h
vmm_findFreePage
uint32_t vmm_findFreePage(pidType pid)
Definition:
vmm_memory.c:221
PD_INDEX
#define PD_INDEX(v_addr)
Definition:
paging.h:40
vmm_remapPage
int vmm_remapPage(uint32_t, uint32_t, uint16_t, pidType, int haveLock)
Definition:
paging.c:199
vmm_clearVirtualPage
int vmm_clearVirtualPage(uint32_t pageAddr)
Definition:
paging.c:356
pidType
int pidType
Definition:
types.h:75
spinLock
Definition:
spinlock.h:41
KERNEL_PAGE_DEFAULT
#define KERNEL_PAGE_DEFAULT
Definition:
paging.h:69
VMM_KERN_END
#define VMM_KERN_END
Definition:
vmm.h:65
PT_BASE_ADDR
#define PT_BASE_ADDR
Definition:
paging.h:46
vmm
getfreepage.c
Generated by
1.8.16