UbixOS
2.0
vmm_allocpagetable.c
Go to the documentation of this file.
1
#include <
vmm/vmm.h
>
2
#include <
vmm/paging.h
>
3
#include <
ubixos/spinlock.h
>
4
#include <
string.h
>
5
6
7
int
vmm_allocPageTable
(
uint32_t
pdI,
pidType
pid) {
8
uint32_t
*pageDirectory =
PD_BASE_ADDR
;
9
uint32_t
*pageTable = 0x0;
10
11
if
((pdI >=
PD_ENTRIES
) || ((pageDirectory[pdI] &
PAGE_PRESENT
) ==
PAGE_PRESENT
))
12
return
(-1);
13
14
15
/* Lock The Page Directory So We Dont Collide With Another Thread */
16
//spinLock(&pdSpinLock);
17
18
/* Map Page Table Page Into Page Directory */
19
if
((pdI >=
PD_INDEX
(
VMM_USER_START
)) && (pdI <=
PD_INDEX
(
VMM_USER_END
)))
20
pageDirectory[pdI] = (
uint32_t
)
vmm_findFreePage
(pid) |
PAGE_DEFAULT
;
21
else
22
pageDirectory[pdI] = (
uint32_t
)
vmm_findFreePage
(pid) |
KERNEL_PAGE_DEFAULT
;
23
24
/* Map Page Table To Virtual Space So We Can Easily Manipulate It */
25
pageTable = (
uint32_t
*) (
PT_BASE_ADDR
+ (
PD_INDEX
(
PT_BASE_ADDR
) *
PAGE_SIZE
));
26
27
if
((pageTable[pdI] &
PAGE_PRESENT
) ==
PAGE_PRESENT
)
28
kpanic
(
"How did this happen"
);
29
30
pageTable[pdI] = pageDirectory[pdI];
31
32
/* Reload Page Directory */
33
asm
(
34
"movl %cr3,%eax\n"
35
"movl %eax,%cr3\n"
36
);
37
38
/* Clean The Page */
39
pageTable = (
uint32_t
*) (
PT_BASE_ADDR
+ (pdI *
PAGE_SIZE
));
40
bzero
(pageTable,
PAGE_SIZE
);
41
42
//spinUnlock(&pdSpinLock);
43
44
return
(0x0);
45
46
}
spinlock.h
vmm_allocPageTable
int vmm_allocPageTable(uint32_t pdI, pidType pid)
Definition:
vmm_allocpagetable.c:7
string.h
vmm.h
kpanic
void kpanic(const char *fmt,...)
print panic message and halt system
Definition:
kpanic.c:41
bzero
#define bzero(buf, size)
Definition:
gpt.h:37
vmm_findFreePage
uint32_t vmm_findFreePage(pidType pid)
Definition:
vmm_memory.c:221
PD_INDEX
#define PD_INDEX(v_addr)
Definition:
paging.h:40
PAGE_DEFAULT
#define PAGE_DEFAULT
Definition:
paging.h:68
paging.h
PD_BASE_ADDR
#define PD_BASE_ADDR
Definition:
paging.h:45
uint32_t
__uint32_t uint32_t
Definition:
types.h:46
pidType
int pidType
Definition:
types.h:75
VMM_USER_START
#define VMM_USER_START
Definition:
vmm.h:58
PD_ENTRIES
#define PD_ENTRIES
Definition:
paging.h:48
PAGE_SIZE
#define PAGE_SIZE
Definition:
paging.h:37
KERNEL_PAGE_DEFAULT
#define KERNEL_PAGE_DEFAULT
Definition:
paging.h:69
VMM_USER_END
#define VMM_USER_END
Definition:
vmm.h:59
PT_BASE_ADDR
#define PT_BASE_ADDR
Definition:
paging.h:46
PAGE_PRESENT
#define PAGE_PRESENT
Definition:
paging.h:55
vmm
vmm_allocpagetable.c
Generated by
1.8.16