Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
script3r
GitHub Repository: script3r/os161
Path: blob/master/kern/arch/mips/include/vm.h
2093 views
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
30
#ifndef _MIPS_VM_H_
31
#define _MIPS_VM_H_
32
33
struct addrspace; /* opaque */
34
35
/*
36
* Machine-dependent VM system definitions.
37
*/
38
39
#define PAGE_SIZE 4096 /* size of VM page */
40
#define PAGE_FRAME 0xfffff000 /* mask for getting page number from addr */
41
42
/*
43
* MIPS-I hardwired memory layout:
44
* 0xc0000000 - 0xffffffff kseg2 (kernel, tlb-mapped)
45
* 0xa0000000 - 0xbfffffff kseg1 (kernel, unmapped, uncached)
46
* 0x80000000 - 0x9fffffff kseg0 (kernel, unmapped, cached)
47
* 0x00000000 - 0x7fffffff kuseg (user, tlb-mapped)
48
*
49
* (mips32 is a little different)
50
*/
51
52
#define MIPS_KUSEG 0x00000000
53
#define MIPS_KSEG0 0x80000000
54
#define MIPS_KSEG1 0xa0000000
55
#define MIPS_KSEG2 0xc0000000
56
57
/*
58
* The first 512 megs of physical space can be addressed in both kseg0 and
59
* kseg1. We use kseg0 for the kernel. This macro returns the kernel virtual
60
* address of a given physical address within that range. (We assume we're
61
* not using systems with more physical space than that anyway.)
62
*
63
* N.B. If you, say, call a function that returns a paddr or 0 on error,
64
* check the paddr for being 0 *before* you use this macro. While paddr 0
65
* is not legal for memory allocation or memory management (it holds
66
* exception handler code) when converted to a vaddr it's *not* NULL, *is*
67
* a valid address, and will make a *huge* mess if you scribble on it.
68
*/
69
#define PADDR_TO_KVADDR(paddr) ((paddr)+MIPS_KSEG0)
70
#define KVADDR_TO_PADDR(vaddr) ((vaddr)-MIPS_KSEG0)
71
72
/*
73
* The top of user space. (Actually, the address immediately above the
74
* last valid user address.)
75
*/
76
#define USERSPACETOP MIPS_KSEG0
77
78
/*
79
* The starting value for the stack pointer at user level. Because
80
* the stack is subtract-then-store, this can start as the next
81
* address after the stack area.
82
*
83
* We put the stack at the very top of user virtual memory because it
84
* grows downwards.
85
*/
86
#define USERSTACK USERSPACETOP
87
#define USERSTACKSIZE (256 * PAGE_SIZE)
88
#define USERSTACKBASE (USERSTACK - USERSTACKSIZE)
89
#define INVALID_VADDR 0xcafebabe
90
91
/*
92
* Interface to the low-level module that looks after the amount of
93
* physical memory we have.
94
*
95
* ram_getsize returns the lowest valid physical address, and one past
96
* the highest valid physical address. (Both are page-aligned.) This
97
* is the memory that is available for use during operation, and
98
* excludes the memory the kernel is loaded into and memory that is
99
* grabbed in the very early stages of bootup.
100
*
101
* ram_stealmem can be used before ram_getsize is called to allocate
102
* memory that cannot be freed later. This is intended for use early
103
* in bootup before VM initialization is complete.
104
*/
105
106
void ram_bootstrap(void);
107
paddr_t ram_stealmem(unsigned long npages);
108
void ram_getsize(paddr_t *lo, paddr_t *hi);
109
110
void vm_map( vaddr_t, paddr_t, int );
111
void vm_unmap( vaddr_t );
112
113
114
/*
115
* TLB shootdown bits.
116
*
117
* We'll take up to 16 invalidations before just flushing the whole TLB.
118
*/
119
120
struct tlbshootdown {
121
int ts_tlb_ix;
122
unsigned ts_cme_ix;
123
};
124
125
#define TLBSHOOTDOWN_MAX 16
126
127
128
#endif /* _MIPS_VM_H_ */
129
130