mem.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /*
  2. * Memory and machine-specific definitions. Used in C and assembler.
  3. */
  4. #define KiB 1024u /* Kibi 0x0000000000000400 */
  5. #define MiB 1048576u /* Mebi 0x0000000000100000 */
  6. #define GiB 1073741824u /* Gibi 000000000040000000 */
  7. #define HOWMANY(x, y) (((x)+((y)-1))/(y))
  8. #define ROUNDUP(x, y) (HOWMANY((x), (y))*(y)) /* ceiling */
  9. #define ROUNDDN(x, y) (((x)/(y))*(y)) /* floor */
  10. #define MIN(a, b) ((a) < (b)? (a): (b))
  11. #define MAX(a, b) ((a) > (b)? (a): (b))
  12. /*
  13. * Not sure where these macros should go.
  14. * This probably isn't right but will do for now.
  15. * The macro names are problematic too.
  16. */
  17. /*
  18. * In B(o), 'o' is the bit offset in the register.
  19. * For multi-bit fields use F(v, o, w) where 'v' is the value
  20. * of the bit-field of width 'w' with LSb at bit offset 'o'.
  21. */
  22. #define B(o) (1<<(o))
  23. #define F(v, o, w) (((v) & ((1<<(w))-1))<<(o))
  24. #define FCLR(d, o, w) ((d) & ~(((1<<(w))-1)<<(o)))
  25. #define FEXT(d, o, w) (((d)>>(o)) & ((1<<(w))-1))
  26. #define FINS(d, o, w, v) (FCLR((d), (o), (w))|F((v), (o), (w)))
  27. #define FSET(d, o, w) ((d)|(((1<<(w))-1)<<(o)))
  28. #define FMASK(o, w) (((1<<(w))-1)<<(o))
  29. /*
  30. * Sizes
  31. */
  32. #define PGSIZE (4*KiB) /* bytes per page */
  33. #define PGSHIFT 12 /* log(PGZIZE) */
  34. #define PGROUND(s) ROUNDUP(s, PGSIZE)
  35. #define ROUND(s, sz) (((s)+(sz-1))&~(sz-1))
  36. #define MAXMACH 1 /* max # cpus system can run */
  37. #define MACHSIZE (PGSIZE)
  38. #define KSTKSIZE (8*KiB)
  39. #define STACKALIGN(sp) ((sp) & ~3) /* bug: assure with alloc */
  40. /*
  41. * Address spaces.
  42. * KTZERO is used by kprof and dumpstack (if any).
  43. *
  44. * KZERO is mapped to physical 0.
  45. * u-boot claims to take 0 - 8MB.
  46. *
  47. * This should leave 12K from KZERO to L1-MACHSIZE.
  48. * cpu0's Mach struct is at L1 - MACHSIZE(4K) to L1 (12K to 16K above KZERO).
  49. * PTEs are stored from L1 to L1+32K (16K to 48K above KZERO).
  50. * KTZERO may be anywhere after KZERO + 48K.
  51. * vectors are at 0.
  52. */
  53. #define KSEG0 0x60000000 /* kernel segment */
  54. #define KSEGM 0xE0000000 /* mask to check segment */
  55. #define KZERO KSEG0 /* kernel address space */
  56. #define L1 (KZERO+16*KiB) /* tt ptes: 16KiB aligned */
  57. // #define KTZERO (KZERO+0x8000) /* kernel text start */
  58. #define KTZERO (KZERO+0x800000) /* kernel text start */
  59. #define UZERO 0 /* user segment */
  60. #define UTZERO (UZERO+BY2PG) /* user text start */
  61. #define USTKTOP KZERO /* user segment end +1 */
  62. #define USTKSIZE (8*1024*1024) /* user stack size */
  63. #define TSTKTOP (USTKTOP-USTKSIZE) /* sysexec temporary stack */
  64. #define TSTKSIZ 256
  65. #define REBOOTADDR KADDR(0x100) /* reboot code - physical address */
  66. /*
  67. * Time.
  68. * Does this need to be here? Used in assembler?
  69. */
  70. #define HZ 100 /* clock frequency */
  71. #define MS2HZ (1000/HZ) /* millisec per clock tick */
  72. #define TK2SEC(t) ((t)/HZ) /* ticks to seconds */
  73. /*
  74. * More accurate time
  75. */
  76. #define CLOCKFREQ (200*1000*1000) /* TCLK on sheeva: 200MHz */
  77. //#define MS2TMR(t) ((ulong)(((uvlong)(t)*CLOCKFREQ)/1000))
  78. //#define US2TMR(t) ((ulong)(((uvlong)(t)*CLOCKFREQ)/1000000))
  79. /*
  80. * Legacy...
  81. */
  82. #define BLOCKALIGN 32 /* only used in allocb.c */
  83. #define KSTACK KSTKSIZE
  84. /*
  85. * Sizes
  86. */
  87. #define BI2BY 8 /* bits per byte */
  88. #define BY2PG PGSIZE
  89. #define BY2SE 4
  90. #define BY2WD 4
  91. #define BY2V 8 /* only used in xalloc.c */
  92. #define PTEMAPMEM (1024*1024)
  93. #define PTEPERTAB (PTEMAPMEM/BY2PG)
  94. #define SEGMAPSIZE 1984
  95. #define SSEGMAPSIZE 16
  96. #define PPN(x) ((x)&~(BY2PG-1))
  97. /*
  98. * With a little work these move to port.
  99. */
  100. #define PTEVALID (1<<0)
  101. #define PTERONLY 0
  102. #define PTEWRITE (1<<1)
  103. #define PTEUNCACHED (1<<2)
  104. #define PTEKERNEL (1<<3)
  105. /*
  106. * Physical machine information from here on.
  107. */
  108. #define PHYSDRAM 0
  109. #define PHYSNAND 0xd8000000
  110. #define FLASHSIZE (128*MiB)
  111. #define PHYSSPIFLASH 0xe8000000
  112. // #define PHYSENV (PHYSFLASH+256*KiB)
  113. // #define ENVSIZE (64*KiB)
  114. #define PHYSBOOTROM 0xffff0000 /* boot rom */
  115. #define PHYSIO 0xf1000000 /* Regbase in io.h */
  116. #define PHYSCONS 0xf1012000 /* uart */
  117. //#define PHYSNAND 0xf9000000
  118. #define VIRTIO PHYSIO