Palacios Public Git Repository

To checkout Palacios execute

  git clone http://v3vee.org/palacios/palacios.web/palacios.git
This will give you the master branch. You probably want the devel branch or one of the release branches. To switch to the devel branch, simply execute
  cd palacios
  git checkout --track -b devel origin/devel
The other branches are similar.


Release 1.0
[palacios.git] / misc / test_vm / include / geekos / mem.h
1 /*
2  * Physical memory allocation
3  * Copyright (c) 2001,2003,2004 David H. Hovemeyer <daveho@cs.umd.edu>
4  * Copyright (c) 2003, Jeffrey K. Hollingsworth <hollings@cs.umd.edu>
5  * $Revision: 1.1 $
6  * 
7  * This is free software.  You are permitted to use,
8  * redistribute, and modify it as specified in the file "COPYING".
9  */
10
11 #ifndef GEEKOS_MEM_H
12 #define GEEKOS_MEM_H
13
14 #include <geekos/ktypes.h>
15 #include <geekos/defs.h>
16 #include <geekos/list.h>
17 #include <geekos/paging.h>
18
19 struct Boot_Info;
20
21 /*
22  * Page flags
23  */
24 #define PAGE_AVAIL     0x0000    /* page is on the freelist */
25 #define PAGE_KERN      0x0001    /* page used by kernel code or data */
26 #define PAGE_HW        0x0002    /* page used by hardware (e.g., ISA hole) */
27 #define PAGE_ALLOCATED 0x0004    /* page is allocated */
28 #define PAGE_UNUSED    0x0008    /* page is unused */
29 #define PAGE_HEAP      0x0010    /* page is in kernel heap */
30 #define PAGE_PAGEABLE  0x0020    /* page can be paged out */
31 #define PAGE_LOCKED    0x0040    /* page is taken should not be freed */
32
33 /*
34  * PC memory map
35  */
36 #define ISA_HOLE_START 0x0A0000
37 #define ISA_HOLE_END   0x100000
38
39 /*
40  * We reserve the two pages just after the ISA hole for the initial
41  * kernel thread's context object and stack.
42  */
43 //#define HIGHMEM_START (ISA_HOLE_END + 8192)
44 #define HIGHMEM_START ISA_HOLE_END
45 /*
46  * Make the kernel heap this size
47  */
48 #define KERNEL_HEAP_SIZE (1024*1024)
49
50 struct Page;
51
52 /*
53  * List datatype for doubly-linked list of Pages.
54  */
55 DEFINE_LIST(Page_List, Page);
56
57 /*
58  * Each page of physical memory has one of these structures
59  * associated with it, to do allocation and bookkeeping.
60  */
61 struct Page {
62     unsigned flags;                      /* Flags indicating state of page */
63     DEFINE_LINK(Page_List, Page);        /* Link fields for Page_List */
64     int clock;
65     ulong_t vaddr;                       /* User virtual address where page is mapped */
66     pte_t *entry;                        /* Page table entry referring to the page */
67 };
68
69 IMPLEMENT_LIST(Page_List, Page);
70
71 void Init_Mem(struct Boot_Info* bootInfo);
72 void Init_BSS(void);
73 void* Alloc_Page(void);
74 void* Alloc_Pageable_Page(pte_t *entry, ulong_t vaddr);
75 void Free_Page(void* pageAddr);
76
77 /*
78  * Determine if given address is a multiple of the page size.
79  */
80 static __inline__ bool Is_Page_Multiple(ulong_t addr)
81 {
82     return addr == (addr & ~(PAGE_MASK));
83 }
84
85 /*
86  * Round given address up to a multiple of the page size
87  */
88 static __inline__ ulong_t Round_Up_To_Page(ulong_t addr)
89 {
90     if ((addr & PAGE_MASK) != 0) {
91         addr &= ~(PAGE_MASK);
92         addr += PAGE_SIZE;
93     }
94     return addr;
95 }
96
97 /*
98  * Round given address down to a multiple of the page size
99  */
100 static __inline__ ulong_t Round_Down_To_Page(ulong_t addr)
101 {
102     return addr & (~PAGE_MASK);
103 }
104
105 /*
106  * Get the index of the page in memory.
107  */
108 static __inline__ int Page_Index(ulong_t addr)
109 {
110     return (int) (addr >> PAGE_POWER);
111 }
112
113 /*
114  * Get the Page struct associated with given address.
115  */
116 static __inline__ struct Page *Get_Page(ulong_t addr)
117 {
118     extern struct Page* g_pageList;
119     return &g_pageList[Page_Index(addr)];
120 }
121
122 /*
123  * Get the physical address of the memory represented by given Page object.
124  */
125 static __inline__ ulong_t Get_Page_Address(struct Page *page)
126 {
127     extern struct Page* g_pageList;
128     ulong_t index = page - g_pageList;
129     return index << PAGE_POWER;
130 }
131
132 #endif  /* GEEKOS_MEM_H */