This source file includes following definitions.
- __bad_pagetable
- __bad_page
- show_mem
- paging_init
- mem_init
- si_meminfo
1
2
3
4
5
6
7 #include <linux/config.h>
8 #include <linux/signal.h>
9 #include <linux/sched.h>
10 #include <linux/head.h>
11 #include <linux/kernel.h>
12 #include <linux/errno.h>
13 #include <linux/string.h>
14 #include <linux/types.h>
15 #include <linux/ptrace.h>
16 #include <linux/mman.h>
17 #include <linux/mm.h>
18
19 #include <asm/system.h>
20 #include <asm/segment.h>
21 #include <asm/pgtable.h>
22
23 extern void scsi_mem_init(unsigned long);
24 extern void sound_mem_init(void);
25 extern void die_if_kernel(char *,struct pt_regs *,long);
26 extern void show_net_buffers(void);
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41 pte_t * __bad_pagetable(void)
42 {
43 extern char empty_bad_page_table[PAGE_SIZE];
44
45 __asm__ __volatile__("cld ; rep ; stosl":
46 :"a" (pte_val(BAD_PAGE)),
47 "D" ((long) empty_bad_page_table),
48 "c" (PAGE_SIZE/4)
49 :"di","cx");
50 return (pte_t *) empty_bad_page_table;
51 }
52
53 pte_t __bad_page(void)
54 {
55 extern char empty_bad_page[PAGE_SIZE];
56
57 __asm__ __volatile__("cld ; rep ; stosl":
58 :"a" (0),
59 "D" ((long) empty_bad_page),
60 "c" (PAGE_SIZE/4)
61 :"di","cx");
62 return pte_mkdirty(mk_pte((unsigned long) empty_bad_page, PAGE_SHARED));
63 }
64
65 void show_mem(void)
66 {
67 int i,free = 0,total = 0,reserved = 0;
68 int shared = 0;
69
70 printk("Mem-info:\n");
71 show_free_areas();
72 printk("Free swap: %6dkB\n",nr_swap_pages<<(PAGE_SHIFT-10));
73 i = high_memory >> PAGE_SHIFT;
74 while (i-- > 0) {
75 total++;
76 if (mem_map[i].reserved)
77 reserved++;
78 else if (!mem_map[i].count)
79 free++;
80 else
81 shared += mem_map[i].count-1;
82 }
83 printk("%d pages of RAM\n",total);
84 printk("%d free pages\n",free);
85 printk("%d reserved pages\n",reserved);
86 printk("%d pages shared\n",shared);
87 show_buffers();
88 #ifdef CONFIG_NET
89 show_net_buffers();
90 #endif
91 }
92
93 extern unsigned long free_area_init(unsigned long, unsigned long);
94
95
96
97
98
99
100
101
102 unsigned long paging_init(unsigned long start_mem, unsigned long end_mem)
103 {
104 pgd_t * pg_dir;
105 pte_t * pg_table;
106 unsigned long tmp;
107 unsigned long address;
108
109
110
111
112
113
114
115 #if 0
116 memset((void *) 0, 0, PAGE_SIZE);
117 #endif
118 #ifdef CONFIG_TEST_VERIFY_AREA
119 wp_works_ok = 0;
120 #endif
121 start_mem = PAGE_ALIGN(start_mem);
122 address = 0;
123 pg_dir = swapper_pg_dir;
124 while (address < end_mem) {
125 #ifdef CONFIG_PENTIUM_MM
126 if (address <= end_mem + 4*1024*1024 &&
127 (x86_capability & 8)) {
128 #ifdef GAS_KNOWS_CR4
129 __asm__("movl %%cr4,%%eax\n\t"
130 "orl $16,%%eax\n\t"
131 "movl %%eax,%%cr4"
132 : : :"ax");
133 #else
134 __asm__(".byte 0x0f,0x20,0xe0\n\t"
135 "orl $16,%%eax\n\t"
136 ".byte 0x0f,0x22,0xe0"
137 : : :"ax");
138 #endif
139 wp_works_ok = 1;
140 pgd_val(pg_dir[0]) = _PAGE_TABLE | _PAGE_4M | address;
141 pgd_val(pg_dir[768]) = _PAGE_TABLE | _PAGE_4M | address;
142 pg_dir++;
143 address += 4*1024*1024;
144 continue;
145 }
146 #endif
147
148 pg_table = (pte_t *) (PAGE_MASK & pgd_val(pg_dir[768]));
149 if (!pg_table) {
150 pg_table = (pte_t *) start_mem;
151 start_mem += PAGE_SIZE;
152 }
153
154
155 pgd_val(pg_dir[0]) = _PAGE_TABLE | (unsigned long) pg_table;
156 pgd_val(pg_dir[768]) = _PAGE_TABLE | (unsigned long) pg_table;
157 pg_dir++;
158 for (tmp = 0 ; tmp < PTRS_PER_PTE ; tmp++,pg_table++) {
159 if (address < end_mem)
160 set_pte(pg_table, mk_pte(address, PAGE_SHARED));
161 else
162 pte_clear(pg_table);
163 address += PAGE_SIZE;
164 }
165 }
166 invalidate();
167 return free_area_init(start_mem, end_mem);
168 }
169
170 void mem_init(unsigned long start_mem, unsigned long end_mem)
171 {
172 unsigned long start_low_mem = PAGE_SIZE;
173 int codepages = 0;
174 int reservedpages = 0;
175 int datapages = 0;
176 unsigned long tmp;
177 extern int _etext;
178
179 end_mem &= PAGE_MASK;
180 high_memory = end_mem;
181
182
183 memset(empty_zero_page, 0, PAGE_SIZE);
184
185
186 start_low_mem = PAGE_ALIGN(start_low_mem);
187 start_mem = PAGE_ALIGN(start_mem);
188
189
190
191
192
193
194 while (start_low_mem < 0x9f000) {
195 mem_map[MAP_NR(start_low_mem)].reserved = 0;
196 start_low_mem += PAGE_SIZE;
197 }
198
199 while (start_mem < high_memory) {
200 mem_map[MAP_NR(start_mem)].reserved = 0;
201 start_mem += PAGE_SIZE;
202 }
203 #ifdef CONFIG_SCSI
204 scsi_mem_init(high_memory);
205 #endif
206 #ifdef CONFIG_SOUND
207 sound_mem_init();
208 #endif
209 for (tmp = 0 ; tmp < high_memory ; tmp += PAGE_SIZE) {
210 if (mem_map[MAP_NR(tmp)].reserved) {
211 if (tmp >= 0xA0000 && tmp < 0x100000)
212 reservedpages++;
213 else if (tmp < (unsigned long) &_etext)
214 codepages++;
215 else
216 datapages++;
217 continue;
218 }
219 mem_map[MAP_NR(tmp)].count = 1;
220 free_page(tmp);
221 }
222 tmp = nr_free_pages << PAGE_SHIFT;
223 printk("Memory: %luk/%luk available (%dk kernel code, %dk reserved, %dk data)\n",
224 tmp >> 10,
225 high_memory >> 10,
226 codepages << (PAGE_SHIFT-10),
227 reservedpages << (PAGE_SHIFT-10),
228 datapages << (PAGE_SHIFT-10));
229
230 if (wp_works_ok < 0) {
231 pg0[0] = pte_val(mk_pte(0, PAGE_READONLY));
232 invalidate();
233 __asm__ __volatile__("movb 0,%%al ; movb %%al,0": : :"ax", "memory");
234 pg0[0] = 0;
235 invalidate();
236 if (wp_works_ok < 0)
237 wp_works_ok = 0;
238 }
239 return;
240 }
241
242 void si_meminfo(struct sysinfo *val)
243 {
244 int i;
245
246 i = high_memory >> PAGE_SHIFT;
247 val->totalram = 0;
248 val->sharedram = 0;
249 val->freeram = nr_free_pages << PAGE_SHIFT;
250 val->bufferram = buffermem;
251 while (i-- > 0) {
252 if (mem_map[i].reserved)
253 continue;
254 val->totalram++;
255 if (!mem_map[i].count)
256 continue;
257 val->sharedram += mem_map[i].count-1;
258 }
259 val->totalram <<= PAGE_SHIFT;
260 val->sharedram <<= PAGE_SHIFT;
261 return;
262 }