msaturn.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. #include "u.h"
  2. #include "../port/lib.h"
  3. #include "mem.h"
  4. #include "dat.h"
  5. #include "fns.h"
  6. #include "io.h"
  7. #include "../port/error.h"
  8. #include "msaturn.h"
  9. enum {
  10. Isr = Saturn + 0x0400,
  11. Ipol = Saturn + 0x0404,
  12. Issr = Saturn + 0x0500,
  13. Ier = Saturn + 0x0504,
  14. Ipri = Saturn + 0x0600,
  15. Ithresh = Saturn + 0x0706,
  16. #define Iar Ithresh
  17. };
  18. enum{
  19. Syscfg = Saturn + 0x0100,
  20. };
  21. static uchar intprio[] = {
  22. Vecuart0, // uart 0
  23. Vecunused, // uart 1
  24. Vecunused, // sint
  25. Vectimer0, // timer 0
  26. Vecunused, // timer 1
  27. Vecether, // ethernet
  28. Vecunused, // tea
  29. Vecunused, // irq0
  30. Vecunused, // irq1
  31. Vecunused, // irq2
  32. Vecunused, // irq3
  33. Vecunused, // irq4
  34. Vecunused, // irq5
  35. Vecunused, // irq6
  36. Vecunused, // irq7
  37. Vecunused, // irq8
  38. };
  39. void
  40. intend(int)
  41. {
  42. }
  43. void
  44. hwintrinit(void)
  45. {
  46. int i;
  47. ushort iar;
  48. *(ulong*)Ier=0;
  49. if(0){
  50. iar=*(ushort*)Iar; // reset the stack
  51. if(iar != 0xf)
  52. panic("saturnintinit: iar not at 0xf (-> %d)\n", iar);
  53. intack();
  54. }
  55. for(i=0; i<nelem(intprio)/2; i++)
  56. ((uchar*)Ipri)[i] = (intprio[2*i]<<4)|intprio[2*i+1];
  57. }
  58. int
  59. vectorenable(Vctl*v)
  60. {
  61. int i;
  62. for(i=0; i<nelem(intprio); i++)
  63. if(v->irq==intprio[i]){
  64. *(ulong*)Ier |= 1<<(31-i);
  65. return v->irq;
  66. }
  67. print("intrenable: cannot enable intr %d\n", v->irq);
  68. return -1;
  69. }
  70. void
  71. vectordisable(Vctl*v)
  72. {
  73. int i;
  74. for(i=0; i<nelem(intprio); i++)
  75. if(v->irq==intprio[i]){
  76. *(ulong*)Ier &= ~(1<<(31-i));
  77. return;
  78. }
  79. }
  80. int
  81. intvec(void)
  82. {
  83. ushort iar;
  84. int i;
  85. iar = *(ushort*)Iar; // push(prio) onto stack
  86. for(i=0; i<nelem(intprio); i++)
  87. if(iar==intprio[i])
  88. return iar;
  89. iprint("saturnint: no vector %d\n", iar);
  90. intack();
  91. return -1;
  92. }
  93. void
  94. intack(void)
  95. {
  96. *(ushort*)Ithresh = 0; // pop(prio) stack
  97. }
  98. void
  99. machinit(void)
  100. {
  101. int rrate;
  102. ulong hid;
  103. extern char* plan9inistr;
  104. memset(m, 0, sizeof(*m));
  105. m->cputype = getpvr()>>16;
  106. m->imap = (Imap*)INTMEM;
  107. m->loopconst = 1096;
  108. rrate = (*(ushort*)Syscfg >> 6) & 3;
  109. switch(rrate){
  110. case 0:
  111. m->bushz = 66666666;
  112. break;
  113. case 1:
  114. m->bushz = 83333333;
  115. break;
  116. case 2:
  117. m->bushz = 100000000;
  118. break;
  119. case 3:
  120. m->bushz = 133333333;
  121. break;
  122. }
  123. active.machs = 1;
  124. active.exiting = 0;
  125. putmsr(getmsr() | MSR_ME);
  126. /* disable the l2 cache because it slows down the processor.
  127. the only way (that i know) to get a consistent memory view
  128. with l2 enabled is by enabling write-through operations in
  129. the bats and ptes. disabling write-through and only using the
  130. l1 caches improves performance */
  131. l2disable();
  132. kfpinit();
  133. hid=gethid0();
  134. hid |= BIT(28)|BIT(26)|BIT(24);
  135. puthid0(hid);
  136. plan9inistr =
  137. "console=0\n"
  138. "ether0=type=saturn\n"
  139. "fs=135.104.9.42\n"
  140. "auth=135.104.9.7\n"
  141. "authdom=cs.bell-labs.com\n"
  142. "sys=ucu\n"
  143. "ntp=135.104.9.52\n";
  144. }
  145. void
  146. sharedseginit(void)
  147. {
  148. }
  149. void
  150. trapinit(void)
  151. {
  152. int i;
  153. for(i = 0x0; i < 0x2000; i += 0x100)
  154. sethvec(i, trapvec);
  155. dcflush(KADDR(0), 0x2000);
  156. icflush(KADDR(0), 0x2000);
  157. putmsr(getmsr() & ~MSR_IP);
  158. }