Subversion Repositories HelenOS

Rev

Rev 3403 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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