os161-1.99
 All Data Structures
vm.h
00001 /*
00002  * Copyright (c) 2000, 2001, 2002, 2003, 2004, 2005, 2008, 2009
00003  *      The President and Fellows of Harvard College.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  * 1. Redistributions of source code must retain the above copyright
00009  *    notice, this list of conditions and the following disclaimer.
00010  * 2. Redistributions in binary form must reproduce the above copyright
00011  *    notice, this list of conditions and the following disclaimer in the
00012  *    documentation and/or other materials provided with the distribution.
00013  * 3. Neither the name of the University nor the names of its contributors
00014  *    may be used to endorse or promote products derived from this software
00015  *    without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY AND CONTRIBUTORS ``AS IS'' AND
00018  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00020  * ARE DISCLAIMED.  IN NO EVENT SHALL THE UNIVERSITY OR CONTRIBUTORS BE LIABLE
00021  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00022  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00023  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00024  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00025  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00026  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00027  * SUCH DAMAGE.
00028  */
00029 
00030 #ifndef _MIPS_VM_H_
00031 #define _MIPS_VM_H_
00032 
00033 
00034 /*
00035  * Machine-dependent VM system definitions.
00036  */
00037 
00038 #define PAGE_SIZE  4096         /* size of VM page */
00039 #define PAGE_FRAME 0xfffff000   /* mask for getting page number from addr */
00040 
00041 /*
00042  * MIPS-I hardwired memory layout:
00043  *    0xc0000000 - 0xffffffff   kseg2 (kernel, tlb-mapped)
00044  *    0xa0000000 - 0xbfffffff   kseg1 (kernel, unmapped, uncached)
00045  *    0x80000000 - 0x9fffffff   kseg0 (kernel, unmapped, cached)
00046  *    0x00000000 - 0x7fffffff   kuseg (user, tlb-mapped)
00047  *
00048  * (mips32 is a little different)
00049  */
00050 
00051 #define MIPS_KUSEG  0x00000000
00052 #define MIPS_KSEG0  0x80000000
00053 #define MIPS_KSEG1  0xa0000000
00054 #define MIPS_KSEG2  0xc0000000
00055 
00056 /* 
00057  * The first 512 megs of physical space can be addressed in both kseg0 and
00058  * kseg1. We use kseg0 for the kernel. This macro returns the kernel virtual
00059  * address of a given physical address within that range. (We assume we're
00060  * not using systems with more physical space than that anyway.)
00061  *
00062  * N.B. If you, say, call a function that returns a paddr or 0 on error,
00063  * check the paddr for being 0 *before* you use this macro. While paddr 0
00064  * is not legal for memory allocation or memory management (it holds 
00065  * exception handler code) when converted to a vaddr it's *not* NULL, *is*
00066  * a valid address, and will make a *huge* mess if you scribble on it.
00067  */
00068 #define PADDR_TO_KVADDR(paddr) ((paddr)+MIPS_KSEG0)
00069 
00070 /*
00071  * The top of user space. (Actually, the address immediately above the
00072  * last valid user address.)
00073  */
00074 #define USERSPACETOP  MIPS_KSEG0
00075 
00076 /*
00077  * The starting value for the stack pointer at user level.  Because
00078  * the stack is subtract-then-store, this can start as the next
00079  * address after the stack area.
00080  *
00081  * We put the stack at the very top of user virtual memory because it
00082  * grows downwards.
00083  */
00084 #define USERSTACK     USERSPACETOP
00085 
00086 /*
00087  * Interface to the low-level module that looks after the amount of
00088  * physical memory we have.
00089  *
00090  * ram_getsize returns the lowest valid physical address, and one past
00091  * the highest valid physical address. (Both are page-aligned.) This
00092  * is the memory that is available for use during operation, and
00093  * excludes the memory the kernel is loaded into and memory that is
00094  * grabbed in the very early stages of bootup.
00095  *
00096  * ram_stealmem can be used before ram_getsize is called to allocate
00097  * memory that cannot be freed later. This is intended for use early
00098  * in bootup before VM initialization is complete.
00099  */
00100 
00101 void ram_bootstrap(void);
00102 paddr_t ram_stealmem(unsigned long npages);
00103 void ram_getsize(paddr_t *lo, paddr_t *hi);
00104 
00105 /*
00106  * TLB shootdown bits.
00107  *
00108  * We'll take up to 16 invalidations before just flushing the whole TLB.
00109  */
00110 
00111 struct tlbshootdown {
00112         /*
00113          * Change this to what you need for your VM design.
00114          */
00115         struct addrspace *ts_addrspace;
00116         vaddr_t ts_vaddr;
00117 };
00118 
00119 #define TLBSHOOTDOWN_MAX 16
00120 
00121 
00122 #endif /* _MIPS_VM_H_ */
 All Data Structures