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

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