]> git.lizzy.rs Git - plan9front.git/blob - sys/src/9/pc/mem.h
kernel: expose no execute bit to portable mmu code as SG_NOEXEC / PTENOEXEC, add...
[plan9front.git] / sys / src / 9 / pc / 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 #define BI2BY           8                       /* bits per byte */
12 #define BI2WD           32                      /* bits per word */
13 #define BY2WD           4                       /* bytes per word */
14 #define BY2V            8                       /* bytes per double word */
15 #define BY2PG           4096                    /* bytes per page */
16 #define WD2PG           (BY2PG/BY2WD)           /* words per page */
17 #define BY2XPG          (4096*1024)             /* bytes per big page */
18 #define PGSHIFT         12                      /* log(BY2PG) */
19 #define ROUND(s, sz)    (((s)+((sz)-1))&~((sz)-1))
20 #define PGROUND(s)      ROUND(s, BY2PG)
21 #define BLOCKALIGN      8
22 #define FPalign         16
23
24 /*
25  * In 32-bit mode, the MAXMACH limit is 32 without
26  * changing the way active.machs is defined and used
27  * (unfortunately, it is also used in the port code).
28  */
29 #define MAXMACH         32                      /* max # cpus system can run */
30 #define KSTACK          4096                    /* Size of kernel stack */
31
32 /*
33  * Time
34  */
35 #define HZ              (100)                   /* clock frequency */
36 #define MS2HZ           (1000/HZ)               /* millisec per clock tick */
37 #define TK2SEC(t)       ((t)/HZ)                /* ticks to seconds */
38
39 /*
40  *  Address spaces
41  */
42 #define KZERO           0xF0000000              /* base of kernel address space */
43 #define KTZERO          (KZERO+0x100000)        /* first address in kernel text - 9load sits below */
44 #define VPT             (KZERO-VPTSIZE)
45 #define VPTSIZE         BY2XPG
46 #define NVPT            (VPTSIZE/BY2WD)
47 #define KMAP            (VPT-KMAPSIZE)
48 #define KMAPSIZE        BY2XPG
49 #define VMAP            (KMAP-VMAPSIZE)
50 #define VMAPSIZE        (0x10000000-VPTSIZE-KMAPSIZE)
51 #define UZERO           0                       /* base of user address space */
52 #define UTZERO          (UZERO+BY2PG)           /* first address in user text */
53 #define USTKTOP         (VMAP-BY2PG)            /* byte just beyond user stack */
54 #define USTKSIZE        (16*1024*1024)          /* size of user stack */
55
56 /*
57  * Fundamental addresses - bottom 64kB saved for return to real mode
58  */
59 #define CONFADDR        (KZERO+0x1200)          /* info passed from boot loader */
60 #define APBOOTSTRAP     (KZERO+0x7000)          /* AP bootstrap code (overlaps CONFADDR) */
61 #define TMPADDR         (KZERO+0x8000)          /* used for temporary mappings */
62 #define IDTADDR         (KZERO+0x10800)         /* idt */
63 #define REBOOTADDR      (0x11000)               /* reboot code - physical address */
64 #define CPU0PDB         (KZERO+0x12000)         /* bootstrap processor PDB */
65 #define CPU0PTE         (KZERO+0x13000)         /* bootstrap processor PTE's for 0-4MB */
66 #define CPU0PTE1        (KZERO+0x14000)         /* bootstrap processor PTE's for 4-8MB */
67 #define CPU0PTE2        (KZERO+0x15000)         /* bootstrap processor PTE's for 8-12MB */
68 #define CPU0PTE3        (KZERO+0x16000)         /* bootstrap processor PTE's for 12-16MB */
69 #define CPU0GDT         (KZERO+0x17000)         /* bootstrap processor GDT */
70 #define MACHADDR        (KZERO+0x18000)         /* as seen by current processor */
71 #define CPU0MACH        (KZERO+0x19000)         /* Mach for bootstrap processor */
72 #define MACHSIZE        BY2PG
73 #define CPU0END         (CPU0MACH+BY2PG)
74 /*
75  * N.B.  ramscan knows that CPU0END is the end of reserved data
76  * N.B.  _startPADDR knows that CPU0PDB is the first reserved page
77  * and that there are 6 of them.
78  */
79
80 /*
81  * Where configuration info is left for the loaded programme.
82  * There are 24064 bytes available at CONFADDR.
83  */
84 #define BOOTLINE        ((char*)CONFADDR)
85 #define BOOTLINELEN     64
86 #define BOOTARGS        ((char*)(CONFADDR+BOOTLINELEN))
87 #define BOOTARGSLEN     (0x6000-0x200-BOOTLINELEN)
88
89 /*
90  *  known x86 segments (in GDT) and their selectors
91  */
92 #define NULLSEG 0       /* null segment */
93 #define KDSEG   1       /* kernel data/stack */
94 #define KESEG   2       /* kernel executable */ 
95 #define UDSEG   3       /* user data/stack */
96 #define UESEG   4       /* user executable */
97 #define TSSSEG  5       /* task segment */
98 #define APMCSEG         6       /* APM code segment */
99 #define APMCSEG16       7       /* APM 16-bit code segment */
100 #define APMDSEG         8       /* APM data segment */
101 #define KESEG16         9       /* kernel executable 16-bit */
102 #define LDTSEG          10      /* local descriptor table */
103 #define PROCSEG0        11      /* per process descriptor0 */
104 #define NPROCSEG        3       /* number of per process descriptors */
105 #define NGDT            14      /* number of GDT entries required */
106
107 #define SELGDT  (0<<2)  /* selector is in gdt */
108 #define SELLDT  (1<<2)  /* selector is in ldt */
109
110 #define SELECTOR(i, t, p)       (((i)<<3) | (t) | (p))
111
112 #define NULLSEL SELECTOR(NULLSEG, SELGDT, 0)
113 #define KDSEL   SELECTOR(KDSEG, SELGDT, 0)
114 #define KESEL   SELECTOR(KESEG, SELGDT, 0)
115 #define UESEL   SELECTOR(UESEG, SELGDT, 3)
116 #define UDSEL   SELECTOR(UDSEG, SELGDT, 3)
117 #define TSSSEL  SELECTOR(TSSSEG, SELGDT, 0)
118 #define APMCSEL         SELECTOR(APMCSEG, SELGDT, 0)
119 #define APMCSEL16       SELECTOR(APMCSEG16, SELGDT, 0)
120 #define APMDSEL         SELECTOR(APMDSEG, SELGDT, 0)
121 #define LDTSEL  SELECTOR(LDTSEG, SELGDT, 0)
122
123 /*
124  *  fields in segment descriptors
125  */
126 #define SEGDATA (0x10<<8)       /* data/stack segment */
127 #define SEGEXEC (0x18<<8)       /* executable segment */
128 #define SEGTSS  (0x9<<8)        /* TSS segment */
129 #define SEGCG   (0x0C<<8)       /* call gate */
130 #define SEGIG   (0x0E<<8)       /* interrupt gate */
131 #define SEGTG   (0x0F<<8)       /* trap gate */
132 #define SEGLDT  (0x02<<8)       /* local descriptor table */
133 #define SEGTYPE (0x1F<<8)
134
135 #define SEGP    (1<<15)         /* segment present */
136 #define SEGPL(x) ((x)<<13)      /* priority level */
137 #define SEGB    (1<<22)         /* granularity 1==4k (for expand-down) */
138 #define SEGG    (1<<23)         /* granularity 1==4k (for other) */
139 #define SEGE    (1<<10)         /* expand down */
140 #define SEGW    (1<<9)          /* writable (for data/stack) */
141 #define SEGR    (1<<9)          /* readable (for code) */
142 #define SEGD    (1<<22)         /* default 1==32bit (for code) */
143
144 /*
145  *  virtual MMU
146  */
147 #define PTEMAPMEM       (1024*1024)     
148 #define PTEPERTAB       (PTEMAPMEM/BY2PG)
149 #define SEGMAPSIZE      1984
150 #define SSEGMAPSIZE     16
151 #define PPN(x)          ((x)&~(BY2PG-1))
152
153 /*
154  *  physical MMU
155  */
156 #define PTEVALID        (1<<0)
157 #define PTEWT           (1<<3)
158 #define PTEUNCACHED     (1<<4)
159 #define PTECACHED       (0<<4)
160 #define PTEWRITE        (1<<1)
161 #define PTERONLY        (0<<1)
162 #define PTEKERNEL       (0<<2)
163 #define PTEUSER         (1<<2)
164 #define PTESIZE         (1<<7)
165 #define PTEGLOBAL       (1<<8)
166
167 /*
168  * Macros for calculating offsets within the page directory base
169  * and page tables. 
170  */
171 #define PDX(va)         ((((ulong)(va))>>22) & 0x03FF)
172 #define PTX(va)         ((((ulong)(va))>>12) & 0x03FF)
173
174 #define getpgcolor(a)   0
175