[f761f1eb] | 1 | /*
|
---|
[df4ed85] | 2 | * Copyright (c) 2003-2004 Jakub Jermar
|
---|
[f761f1eb] | 3 | * All rights reserved.
|
---|
| 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 | *
|
---|
| 9 | * - Redistributions of source code must retain the above copyright
|
---|
| 10 | * notice, this list of conditions and the following disclaimer.
|
---|
| 11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
| 12 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 13 | * documentation and/or other materials provided with the distribution.
|
---|
| 14 | * - The name of the author may not be used to endorse or promote products
|
---|
| 15 | * derived from this software without specific prior written permission.
|
---|
| 16 | *
|
---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 27 | */
|
---|
| 28 |
|
---|
[2f40fe4] | 29 | /** @addtogroup mips32mm
|
---|
[b45c443] | 30 | * @{
|
---|
| 31 | */
|
---|
| 32 | /** @file
|
---|
| 33 | */
|
---|
| 34 |
|
---|
[06e1e95] | 35 | #ifndef KERN_mips32_TLB_H_
|
---|
| 36 | #define KERN_mips32_TLB_H_
|
---|
[f761f1eb] | 37 |
|
---|
[909c6e3] | 38 | #include <arch/exception.h>
|
---|
| 39 |
|
---|
[54aff98] | 40 | #ifdef TLBCNT
|
---|
| 41 | # define TLB_ENTRY_COUNT TLBCNT
|
---|
| 42 | #else
|
---|
| 43 | # define TLB_ENTRY_COUNT 48
|
---|
| 44 | #endif
|
---|
[ce031f0] | 45 |
|
---|
| 46 | #define TLB_WIRED 1
|
---|
| 47 | #define TLB_KSTACK_WIRED_INDEX 0
|
---|
| 48 |
|
---|
| 49 | #define TLB_PAGE_MASK_16K (0x3<<13)
|
---|
| 50 |
|
---|
[a1a03f9] | 51 | #define PAGE_UNCACHED 2
|
---|
| 52 | #define PAGE_CACHEABLE_EXC_WRITE 5
|
---|
| 53 |
|
---|
[b3f8fb7] | 54 | typedef union {
|
---|
[cc205f1] | 55 | struct {
|
---|
[f15fe51] | 56 | #ifdef BIG_ENDIAN
|
---|
| 57 | unsigned : 2; /* zero */
|
---|
| 58 | unsigned pfn : 24; /* frame number */
|
---|
| 59 | unsigned c : 3; /* cache coherency attribute */
|
---|
| 60 | unsigned d : 1; /* dirty/write-protect bit */
|
---|
| 61 | unsigned v : 1; /* valid bit */
|
---|
| 62 | unsigned g : 1; /* global bit */
|
---|
| 63 | #else
|
---|
[cc205f1] | 64 | unsigned g : 1; /* global bit */
|
---|
| 65 | unsigned v : 1; /* valid bit */
|
---|
| 66 | unsigned d : 1; /* dirty/write-protect bit */
|
---|
| 67 | unsigned c : 3; /* cache coherency attribute */
|
---|
| 68 | unsigned pfn : 24; /* frame number */
|
---|
[8c5e6c7] | 69 | unsigned : 2; /* zero */
|
---|
[f15fe51] | 70 | #endif
|
---|
[cc205f1] | 71 | } __attribute__ ((packed));
|
---|
[7f1c620] | 72 | uint32_t value;
|
---|
[b3f8fb7] | 73 | } entry_lo_t;
|
---|
| 74 |
|
---|
| 75 | typedef union {
|
---|
[cc205f1] | 76 | struct {
|
---|
[f15fe51] | 77 | #ifdef BIG_ENDIAN
|
---|
| 78 | unsigned vpn2 : 19;
|
---|
| 79 | unsigned : 5;
|
---|
| 80 | unsigned asid : 8;
|
---|
| 81 | #else
|
---|
[cc205f1] | 82 | unsigned asid : 8;
|
---|
| 83 | unsigned : 5;
|
---|
| 84 | unsigned vpn2 : 19;
|
---|
[f15fe51] | 85 | #endif
|
---|
[cc205f1] | 86 | } __attribute__ ((packed));
|
---|
[7f1c620] | 87 | uint32_t value;
|
---|
[b3f8fb7] | 88 | } entry_hi_t;
|
---|
[cc205f1] | 89 |
|
---|
[b3f8fb7] | 90 | typedef union {
|
---|
[cc205f1] | 91 | struct {
|
---|
[f15fe51] | 92 | #ifdef BIG_ENDIAN
|
---|
| 93 | unsigned : 7;
|
---|
| 94 | unsigned mask : 12;
|
---|
| 95 | unsigned : 13;
|
---|
| 96 | #else
|
---|
[cc205f1] | 97 | unsigned : 13;
|
---|
| 98 | unsigned mask : 12;
|
---|
| 99 | unsigned : 7;
|
---|
[f15fe51] | 100 | #endif
|
---|
[cc205f1] | 101 | } __attribute__ ((packed));
|
---|
[7f1c620] | 102 | uint32_t value;
|
---|
[b3f8fb7] | 103 | } page_mask_t;
|
---|
[cc205f1] | 104 |
|
---|
[b3f8fb7] | 105 | typedef union {
|
---|
[cc205f1] | 106 | struct {
|
---|
[f15fe51] | 107 | #ifdef BIG_ENDIAN
|
---|
| 108 | unsigned p : 1;
|
---|
| 109 | unsigned : 27;
|
---|
| 110 | unsigned index : 4;
|
---|
| 111 | #else
|
---|
[cc205f1] | 112 | unsigned index : 4;
|
---|
| 113 | unsigned : 27;
|
---|
| 114 | unsigned p : 1;
|
---|
[f15fe51] | 115 | #endif
|
---|
[cc205f1] | 116 | } __attribute__ ((packed));
|
---|
[7f1c620] | 117 | uint32_t value;
|
---|
[b3f8fb7] | 118 | } tlb_index_t;
|
---|
[cc205f1] | 119 |
|
---|
[38a1a84] | 120 | /** Probe TLB for Matching Entry
|
---|
| 121 | *
|
---|
| 122 | * Probe TLB for Matching Entry.
|
---|
| 123 | */
|
---|
| 124 | static inline void tlbp(void)
|
---|
| 125 | {
|
---|
[e7b7be3f] | 126 | asm volatile ("tlbp\n\t");
|
---|
[38a1a84] | 127 | }
|
---|
| 128 |
|
---|
[a1a03f9] | 129 |
|
---|
[ce031f0] | 130 | /** Read Indexed TLB Entry
|
---|
| 131 | *
|
---|
| 132 | * Read Indexed TLB Entry.
|
---|
| 133 | */
|
---|
| 134 | static inline void tlbr(void)
|
---|
| 135 | {
|
---|
[e7b7be3f] | 136 | asm volatile ("tlbr\n\t");
|
---|
[ce031f0] | 137 | }
|
---|
| 138 |
|
---|
| 139 | /** Write Indexed TLB Entry
|
---|
| 140 | *
|
---|
| 141 | * Write Indexed TLB Entry.
|
---|
| 142 | */
|
---|
| 143 | static inline void tlbwi(void)
|
---|
| 144 | {
|
---|
[e7b7be3f] | 145 | asm volatile ("tlbwi\n\t");
|
---|
[ce031f0] | 146 | }
|
---|
| 147 |
|
---|
| 148 | /** Write Random TLB Entry
|
---|
| 149 | *
|
---|
| 150 | * Write Random TLB Entry.
|
---|
| 151 | */
|
---|
| 152 | static inline void tlbwr(void)
|
---|
| 153 | {
|
---|
[e7b7be3f] | 154 | asm volatile ("tlbwr\n\t");
|
---|
[ce031f0] | 155 | }
|
---|
| 156 |
|
---|
[dd14cced] | 157 | #define tlb_invalidate(asid) tlb_invalidate_asid(asid)
|
---|
| 158 |
|
---|
[25d7709] | 159 | extern void tlb_invalid(istate_t *istate);
|
---|
| 160 | extern void tlb_refill(istate_t *istate);
|
---|
| 161 | extern void tlb_modified(istate_t *istate);
|
---|
[f761f1eb] | 162 |
|
---|
| 163 | #endif
|
---|
[b45c443] | 164 |
|
---|
[2f40fe4] | 165 | /** @}
|
---|
[b45c443] | 166 | */
|
---|