root/arch/i386/mm/init.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. __bad_pagetable
  2. __bad_page
  3. __zero_page
  4. show_mem
  5. paging_init
  6. mem_init
  7. si_meminfo

   1 /*
   2  *  linux/arch/i386/mm/init.c
   3  *
   4  *  Copyright (C) 1995  Linus Torvalds
   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 
  22 extern void scsi_mem_init(unsigned long);
  23 extern void sound_mem_init(void);
  24 extern void die_if_kernel(char *,struct pt_regs *,long);
  25 extern void show_net_buffers(void);
  26 
  27 /*
  28  * BAD_PAGE is the page that is used for page faults when linux
  29  * is out-of-memory. Older versions of linux just did a
  30  * do_exit(), but using this instead means there is less risk
  31  * for a process dying in kernel mode, possibly leaving a inode
  32  * unused etc..
  33  *
  34  * BAD_PAGETABLE is the accompanying page-table: it is initialized
  35  * to point to BAD_PAGE entries.
  36  *
  37  * ZERO_PAGE is a special page that is used for zero-initialized
  38  * data and COW.
  39  */
  40 pte_t * __bad_pagetable(void)
     /* [previous][next][first][last][top][bottom][index][help] */
  41 {
  42         extern char empty_bad_page_table[PAGE_SIZE];
  43 
  44         __asm__ __volatile__("cld ; rep ; stosl":
  45                 :"a" (pte_val(BAD_PAGE)),
  46                  "D" ((long) empty_bad_page_table),
  47                  "c" (PTRS_PER_PAGE)
  48                 :"di","cx");
  49         return (pte_t *) empty_bad_page_table;
  50 }
  51 
  52 pte_t __bad_page(void)
     /* [previous][next][first][last][top][bottom][index][help] */
  53 {
  54         extern char empty_bad_page[PAGE_SIZE];
  55 
  56         __asm__ __volatile__("cld ; rep ; stosl":
  57                 :"a" (0),
  58                  "D" ((long) empty_bad_page),
  59                  "c" (PTRS_PER_PAGE)
  60                 :"di","cx");
  61         return pte_mkdirty(mk_pte((unsigned long) empty_bad_page, PAGE_SHARED));
  62 }
  63 
  64 unsigned long __zero_page(void)
     /* [previous][next][first][last][top][bottom][index][help] */
  65 {
  66         extern char empty_zero_page[PAGE_SIZE];
  67 
  68         __asm__ __volatile__("cld ; rep ; stosl":
  69                 :"a" (0),
  70                  "D" ((long) empty_zero_page),
  71                  "c" (PTRS_PER_PAGE)
  72                 :"di","cx");
  73         return (unsigned long) empty_zero_page;
  74 }
  75 
  76 void show_mem(void)
     /* [previous][next][first][last][top][bottom][index][help] */
  77 {
  78         int i,free = 0,total = 0,reserved = 0;
  79         int shared = 0;
  80 
  81         printk("Mem-info:\n");
  82         show_free_areas();
  83         printk("Free swap:       %6dkB\n",nr_swap_pages<<(PAGE_SHIFT-10));
  84         i = high_memory >> PAGE_SHIFT;
  85         while (i-- > 0) {
  86                 total++;
  87                 if (mem_map[i] & MAP_PAGE_RESERVED)
  88                         reserved++;
  89                 else if (!mem_map[i])
  90                         free++;
  91                 else
  92                         shared += mem_map[i]-1;
  93         }
  94         printk("%d pages of RAM\n",total);
  95         printk("%d free pages\n",free);
  96         printk("%d reserved pages\n",reserved);
  97         printk("%d pages shared\n",shared);
  98         show_buffers();
  99 #ifdef CONFIG_NET
 100         show_net_buffers();
 101 #endif
 102 }
 103 
 104 extern unsigned long free_area_init(unsigned long, unsigned long);
 105 
 106 /*
 107  * paging_init() sets up the page tables - note that the first 4MB are
 108  * already mapped by head.S.
 109  *
 110  * This routines also unmaps the page at virtual kernel address 0, so
 111  * that we can trap those pesky NULL-reference errors in the kernel.
 112  */
 113 unsigned long paging_init(unsigned long start_mem, unsigned long end_mem)
     /* [previous][next][first][last][top][bottom][index][help] */
 114 {
 115         pgd_t * pg_dir;
 116         pte_t * pg_table;
 117         unsigned long tmp;
 118         unsigned long address;
 119 
 120 /*
 121  * Physical page 0 is special; it's not touched by Linux since BIOS
 122  * and SMM (for laptops with [34]86/SL chips) may need it.  It is read
 123  * and write protected to detect null pointer references in the
 124  * kernel.
 125  */
 126 #if 0
 127         memset((void *) 0, 0, PAGE_SIZE);
 128 #endif
 129         start_mem = PAGE_ALIGN(start_mem);
 130         address = 0;
 131         pg_dir = swapper_pg_dir;
 132         while (address < end_mem) {
 133                 /* map the memory at virtual addr 0xC0000000 */
 134                 if (pgd_none(pg_dir[768])) {
 135                         pgd_set(pg_dir+768, (pte_t *) start_mem);
 136                         start_mem += PAGE_SIZE;
 137                 }
 138                 pg_table = (pte_t *) pgd_page(pg_dir[768]);
 139 
 140                 /* also map it tempoarily at 0x0000000 for init */
 141                 pgd_set(pg_dir+768, pg_table);
 142                 pgd_set(pg_dir, pg_table);
 143                 pg_dir++;
 144                 for (tmp = 0 ; tmp < PTRS_PER_PAGE ; tmp++,pg_table++) {
 145                         if (address < end_mem)
 146                                 *pg_table = mk_pte(address, PAGE_SHARED);
 147                         else
 148                                 pte_clear(pg_table);
 149                         address += PAGE_SIZE;
 150                 }
 151         }
 152         invalidate();
 153         return free_area_init(start_mem, end_mem);
 154 }
 155 
 156 void mem_init(unsigned long start_mem, unsigned long end_mem)
     /* [previous][next][first][last][top][bottom][index][help] */
 157 {
 158         unsigned long start_low_mem = PAGE_SIZE;
 159         int codepages = 0;
 160         int reservedpages = 0;
 161         int datapages = 0;
 162         unsigned long tmp;
 163         extern int etext;
 164 
 165         end_mem &= PAGE_MASK;
 166         high_memory = end_mem;
 167 
 168         /* mark usable pages in the mem_map[] */
 169         start_low_mem = PAGE_ALIGN(start_low_mem);
 170         start_mem = PAGE_ALIGN(start_mem);
 171 
 172         /*
 173          * IBM messed up *AGAIN* in their thinkpad: 0xA0000 -> 0x9F000.
 174          * They seem to have done something stupid with the floppy
 175          * controller as well..
 176          */
 177         while (start_low_mem < 0x9f000) {
 178                 mem_map[MAP_NR(start_low_mem)] = 0;
 179                 start_low_mem += PAGE_SIZE;
 180         }
 181 
 182         while (start_mem < high_memory) {
 183                 mem_map[MAP_NR(start_mem)] = 0;
 184                 start_mem += PAGE_SIZE;
 185         }
 186 #ifdef CONFIG_SCSI
 187         scsi_mem_init(high_memory);
 188 #endif
 189 #ifdef CONFIG_SOUND
 190         sound_mem_init();
 191 #endif
 192         for (tmp = 0 ; tmp < high_memory ; tmp += PAGE_SIZE) {
 193                 if (mem_map[MAP_NR(tmp)]) {
 194                         if (tmp >= 0xA0000 && tmp < 0x100000)
 195                                 reservedpages++;
 196                         else if (tmp < (unsigned long) &etext)
 197                                 codepages++;
 198                         else
 199                                 datapages++;
 200                         continue;
 201                 }
 202                 mem_map[MAP_NR(tmp)] = 1;
 203                 free_page(tmp);
 204         }
 205         tmp = nr_free_pages << PAGE_SHIFT;
 206         printk("Memory: %luk/%luk available (%dk kernel code, %dk reserved, %dk data)\n",
 207                 tmp >> 10,
 208                 high_memory >> 10,
 209                 codepages << (PAGE_SHIFT-10),
 210                 reservedpages << (PAGE_SHIFT-10),
 211                 datapages << (PAGE_SHIFT-10));
 212 /* test if the WP bit is honoured in supervisor mode */
 213         wp_works_ok = -1;
 214         pg0[0] = pte_val(mk_pte(0, PAGE_READONLY));
 215         invalidate();
 216         __asm__ __volatile__("movb 0,%%al ; movb %%al,0": : :"ax", "memory");
 217         pg0[0] = 0;
 218         invalidate();
 219         if (wp_works_ok < 0)
 220                 wp_works_ok = 0;
 221 #ifdef CONFIG_TEST_VERIFY_AREA
 222         wp_works_ok = 0;
 223 #endif
 224         return;
 225 }
 226 
 227 void si_meminfo(struct sysinfo *val)
     /* [previous][next][first][last][top][bottom][index][help] */
 228 {
 229         int i;
 230 
 231         i = high_memory >> PAGE_SHIFT;
 232         val->totalram = 0;
 233         val->sharedram = 0;
 234         val->freeram = nr_free_pages << PAGE_SHIFT;
 235         val->bufferram = buffermem;
 236         while (i-- > 0)  {
 237                 if (mem_map[i] & MAP_PAGE_RESERVED)
 238                         continue;
 239                 val->totalram++;
 240                 if (!mem_map[i])
 241                         continue;
 242                 val->sharedram += mem_map[i]-1;
 243         }
 244         val->totalram <<= PAGE_SHIFT;
 245         val->sharedram <<= PAGE_SHIFT;
 246         return;
 247 }

/* [previous][next][first][last][top][bottom][index][help] */