tlb.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /*
  2. * Copyright (c) 2000, 2001, 2002, 2003, 2004, 2005, 2008, 2009
  3. * The President and Fellows of Harvard College.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions
  7. * are met:
  8. * 1. Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. * 2. Redistributions in binary form must reproduce the above copyright
  11. * notice, this list of conditions and the following disclaimer in the
  12. * documentation and/or other materials provided with the distribution.
  13. * 3. Neither the name of the University nor the names of its contributors
  14. * may be used to endorse or promote products derived from this software
  15. * without specific prior written permission.
  16. *
  17. * THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY AND CONTRIBUTORS ``AS IS'' AND
  18. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  19. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  20. * ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OR CONTRIBUTORS BE LIABLE
  21. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  22. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  23. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  24. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  25. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  26. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  27. * SUCH DAMAGE.
  28. */
  29. #ifndef _MIPS_TLB_H_
  30. #define _MIPS_TLB_H_
  31. /*
  32. * MIPS-specific TLB access functions.
  33. *
  34. * tlb_random: write the TLB entry specified by ENTRYHI and ENTRYLO
  35. * into a "random" TLB slot chosen by the processor.
  36. *
  37. * IMPORTANT NOTE: never write more than one TLB entry with the
  38. * same virtual page field.
  39. *
  40. * tlb_write: same as tlb_random, but you choose the slot.
  41. *
  42. * tlb_read: read a TLB entry out of the TLB into ENTRYHI and ENTRYLO.
  43. * INDEX specifies which one to get.
  44. *
  45. * tlb_probe: look for an entry matching the virtual page in ENTRYHI.
  46. * Returns the index, or a negative number if no matching entry
  47. * was found. ENTRYLO is not actually used, but must be set; 0
  48. * should be passed.
  49. *
  50. * IMPORTANT NOTE: An entry may be matching even if the valid bit
  51. * is not set. To completely invalidate the TLB, load it with
  52. * translations for addresses in one of the unmapped address
  53. * ranges - these will never be matched.
  54. */
  55. void tlb_random(uint32_t entryhi, uint32_t entrylo);
  56. void tlb_write(uint32_t entryhi, uint32_t entrylo, uint32_t index);
  57. void tlb_read(uint32_t *entryhi, uint32_t *entrylo, uint32_t index);
  58. int tlb_probe(uint32_t entryhi, uint32_t entrylo);
  59. /*
  60. * TLB entry fields.
  61. *
  62. * Note that the MIPS has support for a 6-bit address space ID. In the
  63. * interests of simplicity, we don't use it. The fields related to it
  64. * (TLBLO_GLOBAL and TLBHI_PID) can be left always zero, as can the
  65. * bits that aren't assigned a meaning.
  66. *
  67. * The TLBLO_DIRTY bit is actually a write privilege bit - it is not
  68. * ever set by the processor. If you set it, writes are permitted. If
  69. * you don't set it, you'll get a "TLB Modify" exception when a write
  70. * is attempted.
  71. *
  72. * There is probably no reason in the course of CS161 to use TLBLO_NOCACHE.
  73. */
  74. /* Fields in the high-order word */
  75. #define TLBHI_VPAGE 0xfffff000
  76. /* TLBHI_PID 0x00000fc0 */
  77. /* Fields in the low-order word */
  78. #define TLBLO_PPAGE 0xfffff000
  79. #define TLBLO_NOCACHE 0x00000800
  80. #define TLBLO_DIRTY 0x00000400
  81. #define TLBLO_VALID 0x00000200
  82. /* TLBLO_GLOBAL 0x00000100 */
  83. /*
  84. * Values for completely invalid TLB entries. The TLB entry index should
  85. * be passed to TLBHI_INVALID; this prevents loading the same invalid
  86. * entry into multiple TLB slots.
  87. */
  88. #define TLBHI_INVALID(entryno) ((0x80000+(entryno))<<12)
  89. #define TLBLO_INVALID() (0)
  90. /*
  91. * Number of TLB entries in the processor.
  92. */
  93. #define NUM_TLB 64
  94. #endif /* _MIPS_TLB_H_ */