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

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