1 /* 2 * Memory and machine-specific definitions. Used in C and assembler. 3 */ 4 5 /* 6 * Sizes 7 */ 8 9 #define BI2BY 8 /* bits per byte */ 10 #define BI2WD 32 /* bits per word */ 11 #define BY2WD 4 /* bytes per word */ 12 #define BY2V 8 /* bytes per vlong */ 13 14 #define MAXBY2PG (16*1024) /* rounding for UTZERO in executables; see mkfile */ 15 #define UTROUND(t) ROUNDUP((t), MAXBY2PG) 16 17 #define BIGPAGES /* use 16K page */ 18 #ifndef BIGPAGES 19 #define BY2PG 4096 /* bytes per page */ 20 #define PGSHIFT 12 /* log2(BY2PG) */ 21 #define PGSZ PGSZ4K 22 #define MACHSIZE (2*BY2PG) 23 #else 24 #define BY2PG (16*1024) /* bytes per page */ 25 #define PGSHIFT 14 /* log2(BY2PG) */ 26 #define PGSZ PGSZ16K 27 #define MACHSIZE BY2PG 28 #endif 29 30 #define KSTACK 8192 /* Size of kernel stack */ 31 #define WD2PG (BY2PG/BY2WD) /* words per page */ 32 33 #define MAXMACH 1 /* max # cpus system can run; see active.machs */ 34 #define STACKALIGN(sp) ((sp) & ~7) /* bug: assure with alloc */ 35 #define BLOCKALIGN 16 36 #define CACHELINESZ 32 /* loongson 2e */ 37 #define ICACHESIZE (64*1024) /* loongson 2e */ 38 #define DCACHESIZE (64*1024) /* loongson 2e */ 39 #define SCACHESIZE (512*1024) /* L2 cache, loongson 2e */ 40 41 #define MASK(w) FMASK(0, w) 42 43 /* 44 * Time 45 */ 46 #define HZ 100 /* clock frequency */ 47 #define MS2HZ (1000/HZ) /* millisec per clock tick */ 48 #define TK2SEC(t) ((t)/HZ) /* ticks to seconds */ 49 50 /* 51 * CP0 registers 52 */ 53 54 #define INDEX 0 55 #define RANDOM 1 56 #define TLBPHYS0 2 /* aka ENTRYLO0 */ 57 #define TLBPHYS1 3 /* aka ENTRYLO1 */ 58 #define CONTEXT 4 59 #define PAGEMASK 5 60 #define WIRED 6 61 #define BADVADDR 8 62 #define COUNT 9 63 #define TLBVIRT 10 /* aka ENTRYHI */ 64 #define COMPARE 11 65 #define STATUS 12 66 #define CAUSE 13 67 #define EPC 14 68 #define PRID 15 69 #define CONFIG 16 70 #define LLADDR 17 71 #define WATCHLO 18 72 #define WATCHHI 19 73 #define XCONTEXT 20 74 #define DIAGNOSE 22 /* loongson 2e */ 75 #define PERFCTL 24 76 #define PERFCOUNT 25 77 #define CACHEECC 26 78 #define CACHEERR 27 79 #define TAGLO 28 80 #define TAGHI 29 81 #define ERROREPC 30 82 83 /* 84 * M(STATUS) bits 85 */ 86 #define KMODEMASK 0x0000001f 87 #define IE 0x00000001 /* master interrupt enable */ 88 #define EXL 0x00000002 /* exception level */ 89 #define ERL 0x00000004 /* error level */ 90 #define KSUPER 0x00000008 91 #define KUSER 0x00000010 92 #define KSU 0x00000018 93 #define UX 0x00000020 /* no [USK]X 64-bit extension bits on 24k */ 94 #define SX 0x00000040 95 #define KX 0x00000080 96 #define INTMASK 0x0000ff00 97 #define INTR0 0x00000100 /* interrupt enable bits */ 98 #define INTR1 0x00000200 99 #define INTR2 0x00000400 100 #define INTR3 0x00000800 101 #define INTR4 0x00001000 102 #define INTR5 0x00002000 103 #define INTR6 0x00004000 104 #define INTR7 0x00008000 105 //#define DE 0x00010000 /* not on 24k */ 106 #define TS 0x00200000 /* tlb shutdown; on 24k at least */ 107 #define BEV 0x00400000 /* bootstrap exception vectors */ 108 #define RE 0x02000000 /* reverse-endian in user mode */ 109 #define FR 0x04000000 /* enable 32 FP regs */ 110 #define CU0 0x10000000 111 #define CU1 0x20000000 /* FPU enable */ 112 113 /* 114 * M(CONFIG) bits 115 */ 116 117 #define CFG_K0 7 /* kseg0 cachability */ 118 119 /* 120 * M(CAUSE) bits 121 */ 122 123 #define BD (1<<31) /* last excep'n occurred in branch delay slot */ 124 125 /* 126 * Exception codes 127 */ 128 #define EXCMASK 0x1f /* mask of all causes */ 129 #define CINT 0 /* external interrupt */ 130 #define CTLBM 1 /* TLB modification: store to unwritable page */ 131 #define CTLBL 2 /* TLB miss (load or fetch) */ 132 #define CTLBS 3 /* TLB miss (store) */ 133 #define CADREL 4 /* address error (load or fetch) */ 134 #define CADRES 5 /* address error (store) */ 135 #define CBUSI 6 /* bus error (fetch) */ 136 #define CBUSD 7 /* bus error (data load or store) */ 137 #define CSYS 8 /* system call */ 138 #define CBRK 9 /* breakpoint */ 139 #define CRES 10 /* reserved instruction */ 140 #define CCPU 11 /* coprocessor unusable */ 141 #define COVF 12 /* arithmetic overflow */ 142 #define CTRAP 13 /* trap */ 143 #define CVCEI 14 /* virtual coherence exception (instruction) */ 144 #define CFPE 15 /* floating point exception */ 145 #define CTLBRI 19 /* tlb read-inhibit */ 146 #define CTLBXI 20 /* tlb execute-inhibit */ 147 #define CWATCH 23 /* watch exception */ 148 #define CMCHK 24 /* machine checkcore */ 149 #define CCACHERR 30 /* cache error */ 150 #define CVCED 31 /* virtual coherence exception (data) */ 151 152 /* 153 * M(CACHEECC) a.k.a. ErrCtl bits 154 */ 155 #define PE (1<<31) 156 #define LBE (1<<25) 157 #define WABE (1<<24) 158 159 /* 160 * FCR31 bits, complement to u.h 161 */ 162 #define FPCINEX (1<<12) /* causes */ 163 #define FPCOVFL (1<<13) 164 #define FPCUNFL (1<<14) 165 #define FPCZDIV (1<<15) 166 #define FPCINVAL (1<<16) 167 #define FPUNIMP (1<<17) 168 #define FPEXCMASK (0x3f<<12) 169 170 #define FPFLUSH (1<<24) 171 172 /* 173 * Trap vectors 174 */ 175 176 #define UTLBMISS (KSEG0+0x000) 177 #define XEXCEPTION (KSEG0+0x080) 178 #define CACHETRAP (KSEG0+0x100) 179 #define EXCEPTION (KSEG0+0x180) 180 181 /* 182 * Magic registers 183 */ 184 185 #define USER 24 /* R24 is up-> */ 186 #define MACH 25 /* R25 is m-> */ 187 188 /* 189 * offsets in ureg.h for l.s 190 */ 191 #define Ureg_status (Uoffset+0) 192 #define Ureg_pc (Uoffset+4) 193 #define Ureg_sp (Uoffset+8) 194 #define Ureg_cause (Uoffset+12) 195 #define Ureg_badvaddr (Uoffset+16) 196 #define Ureg_tlbvirt (Uoffset+20) 197 198 #define Ureg_hi (Uoffset+24) 199 #define Ureg_lo (Uoffset+28) 200 #define Ureg_r31 (Uoffset+32) 201 #define Ureg_r30 (Uoffset+36) 202 #define Ureg_r28 (Uoffset+40) 203 #define Ureg_r27 (Uoffset+44) 204 #define Ureg_r26 (Uoffset+48) 205 #define Ureg_r25 (Uoffset+52) 206 #define Ureg_r24 (Uoffset+56) 207 #define Ureg_r23 (Uoffset+60) 208 #define Ureg_r22 (Uoffset+64) 209 #define Ureg_r21 (Uoffset+68) 210 #define Ureg_r20 (Uoffset+72) 211 #define Ureg_r19 (Uoffset+76) 212 #define Ureg_r18 (Uoffset+80) 213 #define Ureg_r17 (Uoffset+84) 214 #define Ureg_r16 (Uoffset+88) 215 #define Ureg_r15 (Uoffset+92) 216 #define Ureg_r14 (Uoffset+96) 217 #define Ureg_r13 (Uoffset+100) 218 #define Ureg_r12 (Uoffset+104) 219 #define Ureg_r11 (Uoffset+108) 220 #define Ureg_r10 (Uoffset+112) 221 #define Ureg_r9 (Uoffset+116) 222 #define Ureg_r8 (Uoffset+120) 223 #define Ureg_r7 (Uoffset+124) 224 #define Ureg_r6 (Uoffset+128) 225 #define Ureg_r5 (Uoffset+132) 226 #define Ureg_r4 (Uoffset+136) 227 #define Ureg_r3 (Uoffset+140) 228 #define Ureg_r2 (Uoffset+144) 229 #define Ureg_r1 (Uoffset+148) 230 231 /* ch and carrera used these defs */ 232 /* Sizeof(Ureg) + (R5,R6) + 16 bytes slop + retpc + ur */ 233 // #define UREGSIZE ((Ureg_r1+4-Uoffset) + 2*BY2V + 16 + BY2WD + BY2WD) 234 // #define Uoffset 8 235 236 // #define UREGSIZE (Ureg_r1 + 4 - Uoffset) /* this ought to work */ 237 #define UREGSIZE ((Ureg_r1+4-Uoffset) + 2*BY2V + 16 + BY2WD + BY2WD) 238 #define Uoffset 0 239 #define Notuoffset 8 240 241 /* 242 * MMU 243 */ 244 #define PGSZ4K (0x00<<13) 245 #define PGSZ16K (0x03<<13) 246 #define PGSZ64K (0x0F<<13) 247 #define PGSZ256K (0x3F<<13) 248 #define PGSZ1M (0xFF<<13) 249 #define PGSZ4M (0x3FF<<13) 250 #define PGSZ8M (0x7FF<<13) /* not on loongson 2e */ 251 #define PGSZ16M (0xFFF<<13) 252 #define PGSZ64M (0x3FFF<<13) /* not on loongson 2e */ 253 #define PGSZ256M (0xFFFF<<13) /* not on loongson 2e */ 254 255 /* mips address spaces, tlb-mapped unless marked otherwise */ 256 #define KUSEG 0x00000000 /* user process */ 257 #define KSEG0 0x80000000 /* kernel (direct mapped, cached) */ 258 #define KSEG1 0xA0000000 /* kernel (direct mapped, uncached: i/o) */ 259 #define KSEG2 0xC0000000 /* kernel, used for TSTKTOP */ 260 #define KSEG3 0xE0000000 /* kernel, used by kmap */ 261 #define KSEGM 0xE0000000 /* mask to check which seg */ 262 263 /* 264 * Fundamental addresses 265 */ 266 267 #define CONFADDR (KZERO+0x1000) /* just above vectors, only for reboot */ 268 #define CONFARGV (KZERO+0x2000) /* used by assembler */ 269 #define REBOOTADDR (KZERO+0x3000) 270 #define MACHADDR (KTZERO-MAXMACH*MACHSIZE) /* Mach structures */ 271 #define MACHP(n) ((Mach *)(MACHADDR+(n)*MACHSIZE)) 272 #define ROM 0xbfc00000 273 #define KMAPADDR 0xE0000000 /* kmap'd addresses */ 274 #define WIREDADDR 0xE2000000 /* address wired kernel space */ 275 276 #define PHYSCONS (KSEG1|0x1fd003f8) /* i8250 uart */ 277 278 #define PIDXSHFT 12 279 #ifndef BIGPAGES 280 #define NCOLOR 8 281 #define PIDX ((NCOLOR-1)<<PIDXSHFT) 282 #define getpgcolor(a) (((ulong)(a)>>PIDXSHFT) % NCOLOR) 283 #else 284 /* no cache aliases are possible with pages of 16K or larger */ 285 #define NCOLOR 1 286 #define PIDX 0 287 #define getpgcolor(a) 0 288 #endif 289 #define KMAPSHIFT 15 290 291 #define PTEGLOBL (1<<0) 292 #define PTEVALID (1<<1) 293 #define PTEWRITE (1<<2) 294 #define PTERONLY 0 295 #define PTEALGMASK (7<<3) 296 #define PTENONCOHERWT (0<<3) /* cached, write-through (slower) */ 297 #define PTEUNCACHED (2<<3) 298 #define PTENONCOHERWB (3<<3) /* cached, write-back */ 299 #define PTEUNCACHEDACC (7<<3) 300 /* rest are reserved on 24k */ 301 #define PTECOHERXCL (4<<3) 302 #define PTECOHERXCLW (5<<3) 303 #define PTECOHERUPDW (6<<3) 304 305 #define PTECACHABILITY PTENONCOHERWB /* loongson 2E only allows this */ 306 307 #define PTEPID(n) (n) 308 #define PTEMAPMEM (1024*1024) 309 #define PTEPERTAB (PTEMAPMEM/BY2PG) 310 #define SEGMAPSIZE 512 311 #define SSEGMAPSIZE 16 312 313 #define STLBLOG 15 314 #define STLBSIZE (1<<STLBLOG) /* entries in the soft TLB */ 315 /* page # bits that don't fit in STLBLOG bits */ 316 #define HIPFNBITS (BI2WD - (PGSHIFT+1) - STLBLOG) 317 #define KPTELOG 8 318 #define KPTESIZE (1<<KPTELOG) /* entries in the kfault soft TLB */ 319 320 #define TLBPID(n) ((n)&0xFF) 321 #define NTLBPID 256 /* # of pids (affects size of Mach) */ 322 #define NTLB 64 /* # of entries */ 323 #define TLBOFF 1 /* first tlb entry (0 used within mmuswitch) */ 324 #define WTLBOFF TLBOFF /* first large IO window tlb entry */ 325 #define NWTLB 0 /* # of large IO window tlb entries */ 326 #define KTLBOFF (WTLBOFF+NWTLB) /* first kfault tlb entry */ 327 #define NKTLB 4 /* # of initial kfault tlb entries */ 328 #define TLBROFF (KTLBOFF+NKTLB) /* offset of first randomly-indexed entry */ 329 330 /* 331 * Address spaces 332 */ 333 #define UZERO KUSEG /* base of user address space */ 334 #define UTZERO (UZERO+MAXBY2PG) /* 1st user text address; see mkfile */ 335 #define USTKTOP (KZERO-BY2PG) /* byte just beyond user stack */ 336 #define USTKSIZE (8*1024*1024) /* size of user stack */ 337 #define TSTKTOP (KSEG2+USTKSIZE-BY2PG) /* top of temporary stack */ 338 #define TSTKSIZ (1024*1024/BY2PG) /* can be at most UTSKSIZE/BY2PG */ 339 #define KZERO KSEG0 /* base of kernel address space */ 340 #define KTZERO (KZERO+0x100000) /* first address in kernel text */ 341 #define MEMSIZE (256*MB) /* default memory for loongson 2e */ 342 #define PCIMEM 0x10000000 /* pci phys address start */ 343 #define IOBASE (KSEG1|0x1fd00000) /* i/o port base address */ 344 #define PCICFG (KSEG1|0x1fe00000) /* pci config base address */ 345 #define PCIDEVCFG (KSEG1|0x1fe80000) /* pci device config */ 346 #define HIGHMEM 0x20000000 /* mem above 256 MB phys address, loongson 2e */ 347