]> git.lizzy.rs Git - plan9front.git/blob - sys/src/9/sgi/mem.h
pc/pmmc: check pci membar type
[plan9front.git] / sys / src / 9 / sgi / mem.h
1 /*
2  * Memory and machine-specific definitions.  Used in C and assembler.
3  */
4
5 #define MIN(a, b)       ((a) < (b)? (a): (b))
6 #define MAX(a, b)       ((a) > (b)? (a): (b))
7
8 /*
9  * Sizes
10  */
11
12 #define BI2BY           8                       /* bits per byte */
13 #define BI2WD           32                      /* bits per word */
14 #define BY2WD           4                       /* bytes per word */
15 #define BY2V            8                       /* bytes per vlong */
16
17 #define ROUND(s, sz)    (((s)+((sz)-1))&~((sz)-1))
18 #define PGROUND(s)      ROUND(s, BY2PG)
19
20 #define MAXBY2PG (16*1024) /* rounding for UTZERO in executables; see mkfile */
21 #define UTROUND(t)      ROUNDUP((t), MAXBY2PG)
22
23 #ifndef BIGPAGES
24 #define BY2PG           4096                    /* bytes per page */
25 #define PGSHIFT         12                      /* log2(BY2PG) */
26 #define PGSZ            PGSZ4K
27 #else
28 /* 16K pages work very poorly */
29 #define BY2PG           (16*1024)               /* bytes per page */
30 #define PGSHIFT         14                      /* log2(BY2PG) */
31 #define PGSZ            PGSZ16K
32 #endif
33
34 #define KSTACK          (8*1024)                /* Size of kernel stack */
35 #define MACHSIZE        (BY2PG+KSTACK)
36 #define WD2PG           (BY2PG/BY2WD)           /* words per page */
37
38 #define MAXMACH         1   /* max # cpus system can run; see active.machs */
39 #define STACKALIGN(sp)  ((sp) & ~7)             /* bug: assure with alloc */
40 #define BLOCKALIGN      16
41 #define CACHELINESZ     32                      /* mips24k */
42 #define ICACHESIZE      (64*1024)               /* rb450g */
43 #define DCACHESIZE      (32*1024)               /* rb450g */
44
45 #define MASK(w)         FMASK(0, w)
46
47 /*
48  * Time
49  */
50 #define HZ              100                     /* clock frequency */
51 #define MS2HZ           (1000/HZ)               /* millisec per clock tick */
52 #define TK2SEC(t)       ((t)/HZ)                /* ticks to seconds */
53
54 /*
55  * CP0 registers
56  */
57
58 #define INDEX           0
59 #define RANDOM          1
60 #define TLBPHYS0        2       /* aka ENTRYLO0 */
61 #define TLBPHYS1        3       /* aka ENTRYLO1 */
62 #define CONTEXT         4
63 #define PAGEMASK        5
64 #define WIRED           6
65 #define BADVADDR        8
66 #define COUNT           9
67 #define TLBVIRT         10      /* aka ENTRYHI */
68 #define COMPARE         11
69 #define STATUS          12
70 #define CAUSE           13
71 #define EPC             14
72 #define PRID            15
73 #define CONFIG          16
74 #define LLADDR          17
75 #define WATCHLO         18
76 #define WATCHHI         19
77 #define DEBUGREG        23
78 #define DEPC            24
79 #define PERFCOUNT       25
80 #define CACHEECC        26
81 #define CACHEERR        27
82 #define TAGLO           28
83 #define TAGHI           29
84 #define ERROREPC        30
85 #define DESAVE          31
86
87 /*
88  * M(STATUS) bits
89  */
90 #define KMODEMASK       0x0000001f
91 #define IE              0x00000001      /* master interrupt enable */
92 #define EXL             0x00000002      /* exception level */
93 #define ERL             0x00000004      /* error level */
94 #define KSUPER          0x00000008
95 #define KUSER           0x00000010
96 #define KSU             0x00000018
97 #define UX              0x00000020
98 #define SX              0x00000040
99 #define KX              0x00000080
100 #define INTMASK         0x0000ff00
101 #define SW0             0x00000100
102 #define SW1             0x00000200
103 #define INTR0           0x00000100      /* interrupt enable bits */
104 #define INTR1           0x00000200
105 #define INTR2           0x00000400
106 #define INTR3           0x00000800
107 #define INTR4           0x00001000
108 #define INTR5           0x00002000
109 #define INTR6           0x00004000
110 #define INTR7           0x00008000
111 #define DE              0x00010000
112 #define TS              0x00200000      /* tlb shutdown; on 24k at least */
113 #define BEV             0x00400000      /* bootstrap exception vectors */
114 #define RE              0x02000000      /* reverse-endian in user mode */
115 #define FR              0x04000000      /* enable 32 FP regs */
116 #define CU0             0x10000000
117 #define CU1             0x20000000      /* FPU enable */
118
119 /*
120  * M(CONFIG) bits
121  */
122
123 #define CFG_K0          7       /* kseg0 cachability */
124 #define CFG_MM          (1<<18) /* write-through merging enabled */
125
126 /*
127  * M(CAUSE) bits
128  */
129
130 #define BD              (1<<31) /* last excep'n occurred in branch delay slot */
131
132 /*
133  * Exception codes
134  */
135 #define EXCMASK 0x1f            /* mask of all causes */
136 #define CINT     0              /* external interrupt */
137 #define CTLBM    1              /* TLB modification: store to unwritable page */
138 #define CTLBL    2              /* TLB miss (load or fetch) */
139 #define CTLBS    3              /* TLB miss (store) */
140 #define CADREL   4              /* address error (load or fetch) */
141 #define CADRES   5              /* address error (store) */
142 #define CBUSI    6              /* bus error (fetch) */
143 #define CBUSD    7              /* bus error (data load or store) */
144 #define CSYS     8              /* system call */
145 #define CBRK     9              /* breakpoint */
146 #define CRES    10              /* reserved instruction */
147 #define CCPU    11              /* coprocessor unusable */
148 #define COVF    12              /* arithmetic overflow */
149 #define CTRAP   13              /* trap */
150 #define CVCEI   14              /* virtual coherence exception (instruction) */
151 #define CFPE    15              /* floating point exception */
152 #define CTLBRI  19              /* tlb read-inhibit */
153 #define CTLBXI  20              /* tlb execute-inhibit */
154 #define CWATCH  23              /* watch exception */
155 #define CMCHK   24              /* machine checkcore */
156 #define CCACHERR 30             /* cache error */
157 #define CVCED   31              /* virtual coherence exception (data) */
158
159 /*
160  * M(CACHEECC) a.k.a. ErrCtl bits
161  */
162 #define PE      (1<<31)
163 #define LBE     (1<<25)
164 #define WABE    (1<<24)
165
166 /*
167  * Trap vectors
168  */
169
170 #define UTLBMISS        (KSEG0+0x000)
171 #define XEXCEPTION      (KSEG0+0x080)
172 #define CACHETRAP       (KSEG0+0x100)
173 #define EXCEPTION       (KSEG0+0x180)
174
175 /*
176  * Magic registers
177  */
178
179 #define USER            24              /* R24 is up-> */
180 #define MACH            25              /* R25 is m-> */
181
182 #define UREGSIZE        0xA0            /* sizeof(Ureg)+8 */
183
184 /*
185  * MMU
186  */
187 #define PGSZ4K          (0x00<<13)
188 #define PGSZ16K         (0x03<<13)      /* on 24k */
189 #define PGSZ64K         (0x0F<<13)
190 #define PGSZ256K        (0x3F<<13)
191 #define PGSZ1M          (0xFF<<13)
192 #define PGSZ4M          (0x3FF<<13)
193 #define PGSZ8M          (0x7FF<<13)     /* not on 24k */
194 #define PGSZ16M         (0xFFF<<13)
195 #define PGSZ64M         (0x3FFF<<13)    /* on 24k */
196 #define PGSZ256M        (0xFFFF<<13)    /* on 24k */
197
198 /* mips address spaces, tlb-mapped unless marked otherwise */
199 #define KUSEG   0x00000000      /* user process */
200 #define KSEG0   0x80000000      /* kernel (direct mapped, cached) */
201 #define KSEG1   0xA0000000      /* kernel (direct mapped, uncached: i/o) */
202 #define KSEG2   0xC0000000      /* kernel, was used for TSTKTOP */
203 #define KSEG3   0xE0000000      /* kernel, used by kmap */
204 #define KSEGM   0xE0000000      /* mask to check which seg */
205
206 /*
207  * Fundamental addresses
208  */
209
210 #define REBOOTADDR      KADDR(0x1000)   /* just above vectors */
211 #define MACHADDR        0x88014000      /* Mach structures */
212 #define MACHP(n)        ((Mach *)(MACHADDR+(n)*MACHSIZE))
213 #define KMAPADDR        0xE0000000      /* kmap'd addresses */
214 #define SPBADDR         0x80001000
215
216 #define PIDXSHFT        12
217 #ifndef BIGPAGES
218 #define NCOLOR          8
219 #define PIDX            ((NCOLOR-1)<<PIDXSHFT)
220 #define getpgcolor(a)   (((ulong)(a)>>PIDXSHFT) % NCOLOR)
221 #else
222 /* no cache aliases are possible with pages of 16K or larger */
223 #define NCOLOR          1
224 #define PIDX            0
225 #define getpgcolor(a)   0
226 #endif
227 #define KMAPSHIFT       15
228
229 #define PTEGLOBL        (1<<0)
230 #define PTEVALID        (1<<1)
231 #define PTEWRITE        (1<<2)
232 #define PTERONLY        0
233 #define PTEALGMASK      (7<<3)
234 #define PTENONCOHERWT   (0<<3)          /* cached, write-through (slower) */
235 #define PTEUNCACHED     (2<<3)
236 #define PTENONCOHERWB   (3<<3)          /* cached, write-back */
237 #define PTEUNCACHEDACC  (7<<3)
238 /* rest are reserved on 24k */
239 #define PTECOHERXCL     (4<<3)
240 #define PTECOHERXCLW    (5<<3)
241 #define PTECOHERUPDW    (6<<3)
242
243 /* how much faster is it? mflops goes from about .206 (WT) to .37 (WB) */
244 // #define PTECACHED PTENONCOHERWT      /* 24k erratum 48 disallows WB */
245 #define PTECACHED       PTENONCOHERWB
246
247 #define PTEPID(n)       (n)
248 #define PTEMAPMEM       (1024*1024)
249 #define PTEPERTAB       (PTEMAPMEM/BY2PG)
250 #define SEGMAPSIZE      512
251 #define SSEGMAPSIZE     16
252
253 #define STLBLOG         15
254 #define STLBSIZE        (1<<STLBLOG)    /* entries in the soft TLB */
255 /* page # bits that don't fit in STLBLOG bits */
256 #define HIPFNBITS       (BI2WD - (PGSHIFT+1) - STLBLOG)
257 #define KPTELOG         8
258 #define KPTESIZE        (1<<KPTELOG)    /* entries in the kfault soft TLB */
259
260 #define TLBPID(n) ((n)&0xFF)
261 #define NTLBPID 256             /* # of pids (affects size of Mach) */
262 #define NTLB    48              /* # of entries (r4k) */
263 #define TLBOFF  1               /* first tlb entry (0 used within mmuswitch) */
264 #define NKTLB   2               /* # of initial kfault tlb entries */
265 #define TLBROFF (TLBOFF+NKTLB)  /* first large IO window tlb entry */
266
267 /*
268  * Address spaces
269  */
270 #define UZERO   KUSEG                   /* base of user address space */
271 #define UTZERO  (UZERO+MAXBY2PG)        /* 1st user text address; see mkfile */
272 #define USTKTOP (KZERO-BY2PG)           /* byte just beyond user stack */
273 #define USTKSIZE (8*1024*1024)          /* size of user stack */
274 #define KZERO   KSEG0                   /* base of kernel address space */
275 #define KTZERO  (KZERO+0x08020000)      /* first address in kernel text */