]> git.lizzy.rs Git - plan9front.git/blob - sys/src/boot/pc/mem.h
let the kernel set dma mode for ata by default
[plan9front.git] / sys / src / boot / pc / mem.h
1 /*
2  * Memory and machine-specific definitions.  Used in C and assembler.
3  */
4
5 /*
6  * Sizes
7  */
8 #define BI2BY           8                       /* bits per byte */
9 #define BI2WD           32                      /* bits per word */
10 #define BY2WD           4                       /* bytes per word */
11 #define BY2PG           4096                    /* bytes per page */
12 #define WD2PG           (BY2PG/BY2WD)           /* words per page */
13 #define PGSHIFT         12                      /* log(BY2PG) */
14 #define PGROUND(s)      (((s)+(BY2PG-1))&~(BY2PG-1))
15
16 #define MAXMACH         1                       /* max # cpus system can run */
17
18 /*
19  * Time
20  */
21 #define HZ              (100)                           /* clock frequency */
22 #define MS2HZ           (1000/HZ)                       /* millisec per clock tick */
23 #define TK2SEC(t)       ((t)/HZ)                        /* ticks to seconds */
24 #define TK2MS(x)        ((x)*(1000/HZ))
25 #define MS2TK(t)        ((((ulong)(t))*HZ)/1000)        /* milliseconds to ticks */
26
27 /*
28  * Fundamental addresses
29  */
30 #define IDTADDR         0x80000800              /* idt */
31 #define APBOOTSTRAP     0x80001000              /* AP bootstrap code */
32 #define CONFADDR        0x80001200              /* info passed from boot loader */
33 #define CPU0PDB         0x80002000              /* bootstrap processor PDB */
34 #define CPU0PTE         0x80003000              /* bootstrap processor PTE's for 0-4MB */
35 #define MACHADDR        0x80004000              /* as seen by current processor */
36 #define CPU0MACH        0x80005000              /* Mach for bootstrap processor */
37 #define BIOSXCHG        0x80006000              /* To exchange data with the BIOS */
38 #define MACHSIZE        (BY2PG*8)               /* stack size */
39
40 /*
41  *  Address spaces
42  *
43  *  Kernel is at 2GB-4GB
44  */
45 #define KZERO           0x80000000              /* base of kernel address space */
46 #define KTZERO          KZERO                   /* first address in kernel text */
47 #define ROMBIOS         (KZERO|0xF0000)
48
49 /*
50  *  known 80386 segments (in GDT) and their selectors
51  */
52 #define NULLSEG 0       /* null segment */
53 #define KDSEG   1       /* kernel data/stack */
54 #define KESEG   2       /* kernel executable */ 
55 #define UDSEG   3       /* user data/stack */
56 #define UESEG   4       /* user executable */
57 #define SYSGATE 5       /* system call gate */
58 #define TSSSEG  6       /* task segment */
59
60 #define SELGDT  (0<<3)  /* selector is in gdt */
61 #define SELLDT  (1<<3)  /* selector is in ldt */
62
63 #define SELECTOR(i, t, p)       (((i)<<3) | (t) | (p))
64
65 #define NULLSEL SELECTOR(NULLSEG, SELGDT, 0)
66 #define KESEL   SELECTOR(KESEG, SELGDT, 0)
67 #define KDSEL   SELECTOR(KDSEG, SELGDT, 0)
68 #define UESEL   SELECTOR(UESEG, SELGDT, 3)
69 #define UDSEL   SELECTOR(UDSEG, SELGDT, 3)
70 #define TSSSEL  SELECTOR(TSSSEG, SELGDT, 0)
71
72 /*
73  *  fields in segment descriptors
74  */
75 #define SEGDATA (0x10<<8)       /* data/stack segment */
76 #define SEGEXEC (0x18<<8)       /* executable segment */
77 #define SEGTSS  (0x9<<8)        /* TSS segment */
78 #define SEGCG   (0x0C<<8)       /* call gate */
79 #define SEGIG   (0x0E<<8)       /* interrupt gate */
80 #define SEGTG   (0x0F<<8)       /* task gate */
81 #define SEGTYPE (0x1F<<8)
82
83 #define SEGP    (1<<15)         /* segment present */
84 #define SEGPL(x) ((x)<<13)      /* priority level */
85 #define SEGB    (1<<22)         /* granularity 1==4k (for expand-down) */
86 #define SEGG    (1<<23)         /* granularity 1==4k (for other) */
87 #define SEGE    (1<<10)         /* expand down */
88 #define SEGW    (1<<9)          /* writable (for data/stack) */
89 #define SEGR    (1<<9)          /* readable (for code) */
90 #define SEGD    (1<<22)         /* default 1==32bit (for code) */
91
92 /*
93  *  virtual MMU
94  */
95 #define PTEMAPMEM       (1024*1024)     /* ??? */       
96 #define SEGMAPSIZE      16              /* ??? */
97 #define PTEPERTAB       (PTEMAPMEM/BY2PG)       /* ??? */
98 #define PPN(x)          ((x)&~(BY2PG-1))
99
100 /*
101  *  physical MMU
102  */
103 #define PTEVALID        (1<<0)
104 #define PTEUNCACHED     0               /* everything is uncached */
105 #define PTEWRITE        (1<<1)
106 #define PTERONLY        (0<<1)
107 #define PTEKERNEL       (0<<2)
108 #define PTEUSER         (1<<2)
109 #define PTESIZE         (1<<7)
110
111 /*
112  *  flag register bits that we care about
113  */
114 #define IFLAG   0x200