1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/*
* Memory and machine-specific definitions. Used in C and assembler.
*/
/*
* Sizes
*/
#define BI2BY 8 /* bits per byte */
#define BI2WD 32 /* bits per word */
#define BY2WD 4 /* bytes per word */
#define BY2PG 4096 /* bytes per page */
#define WD2PG (BY2PG/BY2WD) /* words per page */
#define PGSHIFT 12 /* log(BY2PG) */
#define PGROUND(s) (((s)+(BY2PG-1))&~(BY2PG-1))
#define MAXMACH 1 /* max # cpus system can run */
/*
* Time
*/
#define HZ 20 /* clock frequency */
#define MS2HZ (1000/HZ) /* millisec per clock tick */
#define TK2SEC(t) ((t)/HZ) /* ticks to seconds */
#define TK2MS(t) ((((ulong)(t))*1000)/HZ) /* ticks to milliseconds */
#define MS2TK(t) ((((ulong)(t))*HZ)/1000) /* milliseconds to ticks */
/*
* PSR bits
*/
#define PSREC 0x00002000
#define PSREF 0x00001000
#define PSRSUPER 0x00000080
#define PSRPSUPER 0x00000040
#define PSRET 0x00000020
#define SPL(n) (n<<8)
/*
* Magic registers
*/
#define MACH 6 /* R6 is m-> */
#define USER 5 /* R5 is u-> */
/*
* Fundamental addresses
*/
#define USERADDR 0xE0000000
#define UREGADDR (USERADDR+BY2PG-((32+6)*BY2WD))
#define BOOTSTACK (KTZERO-0*BY2PG)
#define TRAPS (KTZERO-2*BY2PG)
/*
* MMU
*/
#define VAMASK 0x3FFFFFFF
#define BY2SEGM (1<<18)
#define PG2SEGM (1<<6)
#define NTLBPID (1+MAXCONTEXT) /* TLBPID 0 is unallocated */
#define MAXCONTEXT 16
#define CONTEXT 0x30000000 /* in ASI 2 */
/*
* MMU regions
*/
#define INVALIDSEGM 0xFFFC0000 /* highest seg of VA reserved as invalid */
#define INVALIDPMEG (conf.npmeg-1)
#define ROMPMEG (conf.npmeg-2)
#define ROMSEGM 0xFFE80000
#define ROMEND 0xFFEC0000
#define PG2ROM ((ROMEND-ROMSEGM)/BY2PG)
#define NIOSEGM ((MB/BY2SEGM) + 4) /* 1M for screen + overhead */
#define IOSEGM0 (ROMSEGM-NIOSEGM*BY2SEGM)
#define IOPMEG0 (ROMPMEG-NIOSEGM)
#define IOEND ROMSEGM
#define TOPPMEG IOPMEG0
/*
* MMU entries
*/
#define PTEVALID (1<<31)
#define PTERONLY (0<<30)
#define PTEWRITE (1<<30)
#define PTEKERNEL (1<<29)
#define PTENOCACHE (1<<28)
#define PTEMAINMEM (0<<26)
#define PTEIO (1<<26)
#define PTEACCESS (1<<25)
#define PTEMODIFY (1<<24)
#define PTEPROBEMEM (PTEVALID|PTEKERNEL|PTENOCACHE|PTEWRITE|PTEMAINMEM)
#define PTEPROBEIO (PTEVALID|PTEKERNEL|PTENOCACHE|PTEWRITE|PTEIO)
#define PTEUNCACHED 0
#define PTEMAPMEM (1024*1024)
#define PTEPERTAB (PTEMAPMEM/BY2PG)
#define SEGMAPSIZE 16
#define INVALIDPTE 0
#define PPN(pa) ((pa>>12)&0xFFFF)
/*
* Weird addresses etc. in System ASI (2)
*/
#define CACHETAGS 0x80000000
#define CACHEDATA 0x90000000
#define SER 0x60000000
#define SEVAR 0x60000004
#define ASER 0x60000008
#define ASEVAR 0x6000000C
#define ENAB 0x40000000
#define ENABRESET 0x04
#define ENABCACHE 0x10
#define ENABDMA 0x20
/*
* Virtual addresses
*/
#define VTAG(va) ((va>>22)&0x03F)
#define VPN(va) ((va>>13)&0x1FF)
/*
* Address spaces
*/
#define UZERO 0x00000000 /* base of user address space */
#define UTZERO (UZERO+BY2PG) /* first address in user text */
#define TSTKTOP 0x10000000 /* end of new stack in sysexec */
#define TSTKSIZ 32
#define USTKTOP (TSTKTOP-TSTKSIZ*BY2PG) /* byte just beyond user stack */
#define KZERO 0xE0000000 /* base of kernel address space */
#define KTZERO (KZERO+4*BY2PG) /* first address in kernel text */
#define USTKSIZE (4*1024*1024) /* size of user stack */
#define MACHSIZE 4096