mem.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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 vlong */
  11. #define BY2PG 8192 /* bytes per page */
  12. #define WD2PG (BY2PG/BY2WD) /* words per page */
  13. #define PGSHIFT 13 /* log(BY2PG) */
  14. #define ROUND(s, sz) (((s)+((sz)-1))&~((sz)-1))
  15. #define PGROUND(s) ROUND(s, BY2PG)
  16. #define BLOCKALIGN 8
  17. #define BY2PTE 8 /* bytes per pte entry */
  18. #define PTE2PG (BY2PG/BY2PTE) /* pte entries per page */
  19. #define MAXMACH 1 /* max # cpus system can run */
  20. #define KSTACK 4096 /* Size of kernel stack */
  21. /*
  22. * Time
  23. */
  24. #define HZ 100 /* clock frequency */
  25. #define MS2HZ (1000/HZ)
  26. #define TK2SEC(t) ((t)/HZ) /* ticks to seconds */
  27. /*
  28. * Magic registers
  29. */
  30. #define MACH 15 /* R15 is m-> */
  31. #define USER 14 /* R14 is up-> */
  32. /*
  33. * Fundamental addresses
  34. */
  35. /* XXX MACHADDR, MACHP(n) */
  36. /*
  37. * MMU
  38. *
  39. * A PTE is 64 bits, but a ulong is 32! Hence we encode
  40. * the PTEs specially for fault.c, and decode them in putmmu().
  41. * This means that we can only map the first 2G of physical
  42. * space via putmmu() - ie only physical memory, not devices.
  43. */
  44. #define PTEVALID 0x3301
  45. #define PTEKVALID 0x1101
  46. #define PTEASM 0x0010
  47. #define PTEGH(s) ((s)<<5)
  48. #define PTEWRITE 0
  49. #define PTERONLY 0x4
  50. #define PTEUNCACHED 0
  51. #define PPN(n) (((n)>>PGSHIFT)<<14)
  52. #define FIXPTE(x) ((((uvlong)(x)>>14)<<32)|((x) & 0x3fff))
  53. #define PTEPFN(pa) (((uvlong)(pa)>>PGSHIFT)<<32)
  54. #define NCOLOR 1
  55. #define getpgcolor(a) 0
  56. #define PTEMAPMEM (1024*1024)
  57. #define PTEPERTAB (PTEMAPMEM/BY2PG)
  58. #define SEGMAPSIZE 512
  59. #define SSEGMAPSIZE 16
  60. /*
  61. * Address spaces
  62. */
  63. #define UZERO 0 /* base of user address space */
  64. #define UTZERO (UZERO+BY2PG) /* first address in user text */
  65. #define USTKTOP (TSTKTOP-TSTKSIZ*BY2PG) /* byte just beyond user stack */
  66. #define TSTKTOP KZERO /* top of temporary stack */
  67. #define TSTKSIZ 100
  68. #define KZERO 0x80000000 /* base of kernel address space */
  69. #define KTZERO (KZERO+0x400000) /* first address in kernel text */
  70. #define USTKSIZE (4*1024*1024) /* size of user stack */
  71. /*
  72. * Processor Status (as returned by rdps)
  73. */
  74. #define UMODE 0x8
  75. #define IPL 0x7
  76. #define isphys(x) (((ulong)x&KZERO)!=0)