os161-1.99
 All Data Structures
tlb.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_TLB_H_
00031 #define _MIPS_TLB_H_
00032 
00033 /*
00034  * MIPS-specific TLB access functions.
00035  *
00036  *   tlb_random: write the TLB entry specified by ENTRYHI and ENTRYLO
00037  *        into a "random" TLB slot chosen by the processor.
00038  *
00039  *        IMPORTANT NOTE: never write more than one TLB entry with the
00040  *        same virtual page field.
00041  *
00042  *   tlb_write: same as tlb_random, but you choose the slot.
00043  *
00044  *   tlb_read: read a TLB entry out of the TLB into ENTRYHI and ENTRYLO.
00045  *        INDEX specifies which one to get.
00046  *
00047  *   tlb_probe: look for an entry matching the virtual page in ENTRYHI.
00048  *        Returns the index, or a negative number if no matching entry
00049  *        was found. ENTRYLO is not actually used, but must be set; 0
00050  *        should be passed.
00051  *
00052  *        IMPORTANT NOTE: An entry may be matching even if the valid bit 
00053  *        is not set. To completely invalidate the TLB, load it with
00054  *        translations for addresses in one of the unmapped address
00055  *        ranges - these will never be matched.
00056  */
00057 
00058 void tlb_random(uint32_t entryhi, uint32_t entrylo);
00059 void tlb_write(uint32_t entryhi, uint32_t entrylo, uint32_t index);
00060 void tlb_read(uint32_t *entryhi, uint32_t *entrylo, uint32_t index);
00061 int tlb_probe(uint32_t entryhi, uint32_t entrylo);
00062 
00063 /*
00064  * TLB entry fields.
00065  *
00066  * Note that the MIPS has support for a 6-bit address space ID. In the
00067  * interests of simplicity, we don't use it. The fields related to it
00068  * (TLBLO_GLOBAL and TLBHI_PID) can be left always zero, as can the
00069  * bits that aren't assigned a meaning.
00070  *
00071  * The TLBLO_DIRTY bit is actually a write privilege bit - it is not
00072  * ever set by the processor. If you set it, writes are permitted. If
00073  * you don't set it, you'll get a "TLB Modify" exception when a write
00074  * is attempted.
00075  *
00076  * There is probably no reason in the course of CS161 to use TLBLO_NOCACHE.
00077  */
00078 
00079 /* Fields in the high-order word */
00080 #define TLBHI_VPAGE   0xfffff000
00081 /*      TLBHI_PID     0x00000fc0 */
00082 
00083 /* Fields in the low-order word */
00084 #define TLBLO_PPAGE   0xfffff000
00085 #define TLBLO_NOCACHE 0x00000800
00086 #define TLBLO_DIRTY   0x00000400
00087 #define TLBLO_VALID   0x00000200
00088 /*      TLBLO_GLOBAL  0x00000100 */
00089 
00090 /*
00091  * Values for completely invalid TLB entries. The TLB entry index should
00092  * be passed to TLBHI_INVALID; this prevents loading the same invalid
00093  * entry into multiple TLB slots.
00094  */
00095 #define TLBHI_INVALID(entryno) ((0x80000+(entryno))<<12)
00096 #define TLBLO_INVALID()        (0)
00097 
00098 /*
00099  * Number of TLB entries in the processor.
00100  */
00101 
00102 #define NUM_TLB  64
00103 
00104 
00105 #endif /* _MIPS_TLB_H_ */
 All Data Structures