mem.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /*
  2. * Memory and machine-specific definitions. Used in C and assembler.
  3. */
  4. /*
  5. * Sizes
  6. */
  7. #define BI2BY 8 /* bits per byte */
  8. #define BI2WD 32 /* bits per word */
  9. #define BY2WD 4 /* bytes per word */
  10. #define BY2V 8 /* bytes per double word */
  11. #define BY2PG 4096 /* bytes per page */
  12. #define WD2PG (BY2PG/BY2WD) /* words per page */
  13. #define BY2XPG (4096*1024) /* bytes per big page */
  14. #define PGSHIFT 12 /* log(BY2PG) */
  15. #define ROUND(s, sz) (((s)+((sz)-1))&~((sz)-1))
  16. #define PGROUND(s) ROUND(s, BY2PG)
  17. #define BLOCKALIGN 8
  18. #define MAXMACH 8 /* max # cpus system can run */
  19. #define KSTACK 4096 /* Size of kernel stack */
  20. /*
  21. * Time
  22. */
  23. #define HZ (100) /* clock frequency */
  24. #define MS2HZ (1000/HZ) /* millisec per clock tick */
  25. #define TK2SEC(t) ((t)/HZ) /* ticks to seconds */
  26. /*
  27. * Address spaces
  28. */
  29. #define KZERO 0xF0000000 /* base of kernel address space */
  30. #define KTZERO (KZERO+0x100000) /* first address in kernel text - 9load sits below */
  31. #define VPT (KZERO-VPTSIZE)
  32. #define VPTSIZE BY2XPG
  33. #define NVPT (VPTSIZE/BY2WD)
  34. #define KMAP (VPT-KMAPSIZE)
  35. #define KMAPSIZE BY2XPG
  36. #define VMAP (KMAP-VMAPSIZE)
  37. #define VMAPSIZE (0x10000000-VPTSIZE-KMAPSIZE)
  38. #define UZERO 0 /* base of user address space */
  39. #define UTZERO (UZERO+BY2PG) /* first address in user text */
  40. #define USTKTOP (VMAP-BY2PG) /* byte just beyond user stack */
  41. #define USTKSIZE (16*1024*1024) /* size of user stack */
  42. #define TSTKTOP (USTKTOP-USTKSIZE) /* end of new stack in sysexec */
  43. #define TSTKSIZ 100
  44. /*
  45. * Fundamental addresses - bottom 64kB saved for return to real mode
  46. */
  47. #define CONFADDR (KZERO+0x1200) /* info passed from boot loader */
  48. #define TMPADDR (KZERO+0x2000) /* used for temporary mappings */
  49. #define APBOOTSTRAP (KZERO+0x3000) /* AP bootstrap code */
  50. #define RMUADDR (KZERO+0x7C00) /* real mode Ureg */
  51. #define RMCODE (KZERO+0x8000) /* copy of first page of KTEXT */
  52. #define RMBUF (KZERO+0x9000) /* buffer for user space - known to vga */
  53. #define IDTADDR (KZERO+0x10800) /* idt */
  54. #define REBOOTADDR (0x11000) /* reboot code - physical address */
  55. #define CPU0PDB (KZERO+0x12000) /* bootstrap processor PDB */
  56. #define CPU0PTE (KZERO+0x13000) /* bootstrap processor PTE's for 0-4MB */
  57. #define CPU0GDT (KZERO+0x14000) /* bootstrap processor GDT */
  58. #define MACHADDR (KZERO+0x15000) /* as seen by current processor */
  59. #define CPU0MACH (KZERO+0x16000) /* Mach for bootstrap processor */
  60. #define MACHSIZE BY2PG
  61. /*
  62. * N.B. ramscan knows that CPU0MACH+BY2PG is the end of reserved data
  63. * N.B. _startPADDR knows that CPU0PDB is the first reserved page
  64. * and that there are 5 of them.
  65. */
  66. /*
  67. * known x86 segments (in GDT) and their selectors
  68. */
  69. #define NULLSEG 0 /* null segment */
  70. #define KDSEG 1 /* kernel data/stack */
  71. #define KESEG 2 /* kernel executable */
  72. #define UDSEG 3 /* user data/stack */
  73. #define UESEG 4 /* user executable */
  74. #define TSSSEG 5 /* task segment */
  75. #define APMCSEG 6 /* APM code segment */
  76. #define APMCSEG16 7 /* APM 16-bit code segment */
  77. #define APMDSEG 8 /* APM data segment */
  78. #define KESEG16 9 /* kernel executable 16-bit */
  79. #define NGDT 10 /* number of GDT entries required */
  80. /* #define APM40SEG 8 /* APM segment 0x40 */
  81. #define SELGDT (0<<2) /* selector is in gdt */
  82. #define SELLDT (1<<2) /* selector is in ldt */
  83. #define SELECTOR(i, t, p) (((i)<<3) | (t) | (p))
  84. #define NULLSEL SELECTOR(NULLSEG, SELGDT, 0)
  85. #define KDSEL SELECTOR(KDSEG, SELGDT, 0)
  86. #define KESEL SELECTOR(KESEG, SELGDT, 0)
  87. #define UESEL SELECTOR(UESEG, SELGDT, 3)
  88. #define UDSEL SELECTOR(UDSEG, SELGDT, 3)
  89. #define TSSSEL SELECTOR(TSSSEG, SELGDT, 0)
  90. #define APMCSEL SELECTOR(APMCSEG, SELGDT, 0)
  91. #define APMCSEL16 SELECTOR(APMCSEG16, SELGDT, 0)
  92. #define APMDSEL SELECTOR(APMDSEG, SELGDT, 0)
  93. /* #define APM40SEL SELECTOR(APM40SEG, SELGDT, 0) */
  94. /*
  95. * fields in segment descriptors
  96. */
  97. #define SEGDATA (0x10<<8) /* data/stack segment */
  98. #define SEGEXEC (0x18<<8) /* executable segment */
  99. #define SEGTSS (0x9<<8) /* TSS segment */
  100. #define SEGCG (0x0C<<8) /* call gate */
  101. #define SEGIG (0x0E<<8) /* interrupt gate */
  102. #define SEGTG (0x0F<<8) /* trap gate */
  103. #define SEGTYPE (0x1F<<8)
  104. #define SEGP (1<<15) /* segment present */
  105. #define SEGPL(x) ((x)<<13) /* priority level */
  106. #define SEGB (1<<22) /* granularity 1==4k (for expand-down) */
  107. #define SEGG (1<<23) /* granularity 1==4k (for other) */
  108. #define SEGE (1<<10) /* expand down */
  109. #define SEGW (1<<9) /* writable (for data/stack) */
  110. #define SEGR (1<<9) /* readable (for code) */
  111. #define SEGD (1<<22) /* default 1==32bit (for code) */
  112. /*
  113. * virtual MMU
  114. */
  115. #define PTEMAPMEM (1024*1024)
  116. #define PTEPERTAB (PTEMAPMEM/BY2PG)
  117. #define SEGMAPSIZE 1984
  118. #define SSEGMAPSIZE 16
  119. #define PPN(x) ((x)&~(BY2PG-1))
  120. /*
  121. * physical MMU
  122. */
  123. #define PTEVALID (1<<0)
  124. #define PTEWT (1<<3)
  125. #define PTEUNCACHED (1<<4)
  126. #define PTEWRITE (1<<1)
  127. #define PTERONLY (0<<1)
  128. #define PTEKERNEL (0<<2)
  129. #define PTEUSER (1<<2)
  130. #define PTESIZE (1<<7)
  131. #define PTEGLOBAL (1<<8)
  132. /*
  133. * Macros for calculating offsets within the page directory base
  134. * and page tables.
  135. */
  136. #define PDX(va) ((((ulong)(va))>>22) & 0x03FF)
  137. #define PTX(va) ((((ulong)(va))>>12) & 0x03FF)
  138. #define getpgcolor(a) 0