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. show_mem
  4. paging_init
  5. mem_init
  6. 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 #include <linux/smp.h>
  19 
  20 #include <asm/system.h>
  21 #include <asm/segment.h>
  22 #include <asm/pgtable.h>
  23 
  24 extern void scsi_mem_init(unsigned long);
  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 void show_mem(void)
     /* [previous][next][first][last][top][bottom][index][help] */
  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  * paging_init() sets up the page tables - note that the first 4MB are
  97  * already mapped by head.S.
  98  *
  99  * This routines also unmaps the page at virtual kernel address 0, so
 100  * that we can trap those pesky NULL-reference errors in the kernel.
 101  */
 102 unsigned long paging_init(unsigned long start_mem, unsigned long end_mem)
     /* [previous][next][first][last][top][bottom][index][help] */
 103 {
 104         pgd_t * pg_dir;
 105         pte_t * pg_table;
 106         unsigned long tmp;
 107         unsigned long address;
 108 
 109 /*
 110  * Physical page 0 is special; it's not touched by Linux since BIOS
 111  * and SMM (for laptops with [34]86/SL chips) may need it.  It is read
 112  * and write protected to detect null pointer references in the
 113  * kernel.
 114  * It may also hold the MP configuration table when we are booting SMP.
 115  */
 116 #if 0
 117         memset((void *) 0, 0, PAGE_SIZE);
 118 #endif
 119 #ifdef CONFIG_SMP
 120         smp_scan_config(0x0,0x400);     /* Scan the bottom 1K for a signature */
 121         /*
 122          *      FIXME: Linux assumes you have 640K of base ram.. this continues
 123          *      the error...
 124          */
 125         smp_scan_config(639*0x400,0x400);       /* Scan the top 1K of base RAM */
 126         smp_scan_config(0xF0000,0x10000);       /* Scan the 64K of bios */
 127         /*
 128          *      If it is an SMP machine we should know now, unless the configuration
 129          *      is in an EISA/MCA bus machine with an extended bios data area. I don't
 130          *      have such a machine so someone else can fill in the check of the EBDA
 131          *      here.
 132          */
 133 /*      smp_alloc_memory(8192); */
 134 #endif
 135 #ifdef CONFIG_TEST_VERIFY_AREA
 136         wp_works_ok = 0;
 137 #endif
 138         start_mem = PAGE_ALIGN(start_mem);
 139         address = 0;
 140         pg_dir = swapper_pg_dir;
 141         while (address < end_mem) {
 142 #ifdef CONFIG_PENTIUM_MM
 143 #ifndef CONFIG_SMP
 144                 if (address <= end_mem + 4*1024*1024 &&
 145                     (x86_capability & 8)) {
 146 #ifdef GAS_KNOWS_CR4
 147                         __asm__("movl %%cr4,%%eax\n\t"
 148                                 "orl $16,%%eax\n\t"
 149                                 "movl %%eax,%%cr4"
 150                                 : : :"ax");
 151 #else
 152                         __asm__(".byte 0x0f,0x20,0xe0\n\t"
 153                                 "orl $16,%%eax\n\t"
 154                                 ".byte 0x0f,0x22,0xe0"
 155                                 : : :"ax");
 156 #endif
 157                         wp_works_ok = 1;
 158                         pgd_val(pg_dir[0]) = _PAGE_TABLE | _PAGE_4M | address;
 159                         pgd_val(pg_dir[768]) = _PAGE_TABLE | _PAGE_4M | address;
 160                         pg_dir++;
 161                         address += 4*1024*1024;
 162                         continue;
 163                 }
 164 #endif
 165 #endif
 166                 /* map the memory at virtual addr 0xC0000000 */
 167                 pg_table = (pte_t *) (PAGE_MASK & pgd_val(pg_dir[768]));
 168                 if (!pg_table) {
 169                         pg_table = (pte_t *) start_mem;
 170                         start_mem += PAGE_SIZE;
 171                 }
 172 
 173                 /* also map it temporarily at 0x0000000 for init */
 174                 pgd_val(pg_dir[0])   = _PAGE_TABLE | (unsigned long) pg_table;
 175                 pgd_val(pg_dir[768]) = _PAGE_TABLE | (unsigned long) pg_table;
 176                 pg_dir++;
 177                 for (tmp = 0 ; tmp < PTRS_PER_PTE ; tmp++,pg_table++) {
 178                         if (address < end_mem)
 179                                 set_pte(pg_table, mk_pte(address, PAGE_SHARED));
 180                         else
 181                                 pte_clear(pg_table);
 182                         address += PAGE_SIZE;
 183                 }
 184         }
 185         invalidate();
 186         return free_area_init(start_mem, end_mem);
 187 }
 188 
 189 void mem_init(unsigned long start_mem, unsigned long end_mem)
     /* [previous][next][first][last][top][bottom][index][help] */
 190 {
 191         unsigned long start_low_mem = PAGE_SIZE;
 192         int codepages = 0;
 193         int reservedpages = 0;
 194         int datapages = 0;
 195         unsigned long tmp;
 196         extern int _etext;
 197 
 198         end_mem &= PAGE_MASK;
 199         high_memory = end_mem;
 200 
 201         /* clear the zero-page */
 202         memset(empty_zero_page, 0, PAGE_SIZE);
 203 
 204         /* mark usable pages in the mem_map[] */
 205         start_low_mem = PAGE_ALIGN(start_low_mem);
 206 
 207 #ifdef CONFIG_SMP
 208         /*
 209          * But first pinch a few for the stack/trampoline stuff
 210          */
 211         start_low_mem += PAGE_SIZE;                             /* 32bit startup code */
 212         start_low_mem = smp_alloc_memory(start_low_mem);        /* AP processor stacks */
 213 #endif
 214         start_mem = PAGE_ALIGN(start_mem);
 215 
 216         /*
 217          * IBM messed up *AGAIN* in their thinkpad: 0xA0000 -> 0x9F000.
 218          * They seem to have done something stupid with the floppy
 219          * controller as well..
 220          */
 221         while (start_low_mem < 0x9f000) {
 222                 mem_map[MAP_NR(start_low_mem)].reserved = 0;
 223                 start_low_mem += PAGE_SIZE;
 224         }
 225 
 226         while (start_mem < high_memory) {
 227                 mem_map[MAP_NR(start_mem)].reserved = 0;
 228                 start_mem += PAGE_SIZE;
 229         }
 230 #ifdef CONFIG_SCSI
 231         scsi_mem_init(high_memory);
 232 #endif
 233         for (tmp = 0 ; tmp < high_memory ; tmp += PAGE_SIZE) {
 234                 if (mem_map[MAP_NR(tmp)].reserved) {
 235                         if (tmp >= 0xA0000 && tmp < 0x100000)
 236                                 reservedpages++;
 237                         else if (tmp < (unsigned long) &_etext)
 238                                 codepages++;
 239                         else
 240                                 datapages++;
 241                         continue;
 242                 }
 243                 mem_map[MAP_NR(tmp)].count = 1;
 244                 free_page(tmp);
 245         }
 246         tmp = nr_free_pages << PAGE_SHIFT;
 247         printk("Memory: %luk/%luk available (%dk kernel code, %dk reserved, %dk data)\n",
 248                 tmp >> 10,
 249                 high_memory >> 10,
 250                 codepages << (PAGE_SHIFT-10),
 251                 reservedpages << (PAGE_SHIFT-10),
 252                 datapages << (PAGE_SHIFT-10));
 253 /* test if the WP bit is honoured in supervisor mode */
 254         if (wp_works_ok < 0) {
 255                 pg0[0] = pte_val(mk_pte(0, PAGE_READONLY));
 256                 invalidate();
 257                 __asm__ __volatile__("movb 0,%%al ; movb %%al,0": : :"ax", "memory");
 258                 pg0[0] = 0;
 259                 invalidate();
 260                 if (wp_works_ok < 0)
 261                         wp_works_ok = 0;
 262         }
 263         return;
 264 }
 265 
 266 void si_meminfo(struct sysinfo *val)
     /* [previous][next][first][last][top][bottom][index][help] */
 267 {
 268         int i;
 269 
 270         i = high_memory >> PAGE_SHIFT;
 271         val->totalram = 0;
 272         val->sharedram = 0;
 273         val->freeram = nr_free_pages << PAGE_SHIFT;
 274         val->bufferram = buffermem;
 275         while (i-- > 0)  {
 276                 if (mem_map[i].reserved)
 277                         continue;
 278                 val->totalram++;
 279                 if (!mem_map[i].count)
 280                         continue;
 281                 val->sharedram += mem_map[i].count-1;
 282         }
 283         val->totalram <<= PAGE_SHIFT;
 284         val->sharedram <<= PAGE_SHIFT;
 285         return;
 286 }

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