archriscv.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. #include "u.h"
  10. #include "../port/lib.h"
  11. #include "mem.h"
  12. #include "dat.h"
  13. #include "fns.h"
  14. #undef DBG
  15. #define DBG iprint
  16. void
  17. cpuiddump(void)
  18. {
  19. print("riscv\n");
  20. }
  21. int64_t
  22. archhz(void)
  23. {
  24. return 1024*1024*1024ULL;
  25. }
  26. int
  27. archmmu(void)
  28. {
  29. /*
  30. * Should the check for machp()->machno != 0 be here
  31. * or in the caller (mmuinit)?
  32. *
  33. * To do here:
  34. * check and enable Pse;
  35. * Pge; Nxe.
  36. */
  37. /*
  38. * How many page sizes are there?
  39. * Always have 4*KiB, but need to check
  40. * configured correctly.
  41. */
  42. assert(PGSZ == 4*KiB);
  43. sys->pgszlg2[0] = 12;
  44. sys->pgszmask[0] = (1<<12)-1;
  45. sys->pgsz[0] = 1<<12;
  46. sys->npgsz = 1;
  47. sys->pgszlg2[1] = 21;
  48. sys->pgszmask[1] = (1<<21)-1;
  49. sys->pgsz[1] = 1<<21;
  50. sys->npgsz = 2;
  51. sys->pgszlg2[2] = 30;
  52. sys->pgszmask[2] = (1<<30)-1;
  53. sys->pgsz[2] = 1<<30;
  54. sys->npgsz = 3;
  55. return sys->npgsz;
  56. }
  57. static int
  58. fmtP(Fmt* f)
  59. {
  60. uintmem pa;
  61. pa = va_arg(f->args, uintmem);
  62. if(f->flags & FmtSharp)
  63. return fmtprint(f, "%#16.16llx", pa);
  64. return fmtprint(f, "%llu", pa);
  65. }
  66. static int
  67. fmtL(Fmt* f)
  68. {
  69. Mpl pl;
  70. pl = va_arg(f->args, Mpl);
  71. return fmtprint(f, "%#16.16llx", pl);
  72. }
  73. static int
  74. fmtR(Fmt* f)
  75. {
  76. uint64_t r;
  77. r = va_arg(f->args, uint64_t);
  78. return fmtprint(f, "%#16.16llx", r);
  79. }
  80. /* virtual address fmt */
  81. static int
  82. fmtW(Fmt *f)
  83. {
  84. uint64_t va;
  85. va = va_arg(f->args, uint64_t);
  86. return fmtprint(f, "%#llx=0x[%llx][%llx][%llx][%llx][%llx]", va,
  87. PTLX(va, 3), PTLX(va, 2), PTLX(va, 1), PTLX(va, 0),
  88. va & ((1<<PGSHFT)-1));
  89. }
  90. void
  91. archfmtinstall(void)
  92. {
  93. /*
  94. * Architecture-specific formatting. Not as neat as they
  95. * could be (e.g. there's no defined type for a 'register':
  96. * L - Mpl, mach priority level
  97. * P - uintmem, physical address
  98. * R - register
  99. * With a little effort these routines could be written
  100. * in a fairly architecturally-independent manner, relying
  101. * on the compiler to optimise-away impossible conditions,
  102. * and/or by exploiting the innards of the fmt library.
  103. */
  104. fmtinstall('P', fmtP);
  105. fmtinstall('L', fmtL);
  106. fmtinstall('R', fmtR);
  107. fmtinstall('W', fmtW);
  108. }
  109. void
  110. archidle(void)
  111. {
  112. panic("archidle"); // halt();
  113. }
  114. void
  115. microdelay(int microsecs)
  116. {
  117. print("microdelay\n");
  118. /*
  119. uint64_t r, t;
  120. r = rdtsc();
  121. for(t = r + (sys->cyclefreq*microsecs)/1000000ull; r < t; r = rdtsc())
  122. ;
  123. */
  124. }
  125. void
  126. millidelay(int millisecs)
  127. {
  128. print("millidelay\n");
  129. /*
  130. uint64_t r, t;
  131. r = rdtsc();
  132. for(t = r + (sys->cyclefreq*millisecs)/1000ull; r < t; r = rdtsc())
  133. ;
  134. */
  135. }