msaturn.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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. *(ulong*)Ier=0;
  48. for(i=0; i<nelem(intprio)/2; i++)
  49. ((uchar*)Ipri)[i] = (intprio[2*i]<<4)|intprio[2*i+1];
  50. }
  51. int
  52. vectorenable(Vctl*v)
  53. {
  54. int i;
  55. for(i=0; i<nelem(intprio); i++)
  56. if(v->irq==intprio[i]){
  57. *(ulong*)Ier |= 1<<(31-i);
  58. return v->irq;
  59. }
  60. print("intrenable: cannot enable intr %d\n", v->irq);
  61. return -1;
  62. }
  63. void
  64. vectordisable(Vctl*v)
  65. {
  66. int i;
  67. for(i=0; i<nelem(intprio); i++)
  68. if(v->irq==intprio[i]){
  69. *(ulong*)Ier &= ~(1<<(31-i));
  70. return;
  71. }
  72. }
  73. int
  74. intvec(void)
  75. {
  76. ushort iar;
  77. int i;
  78. iar = *(ushort*)Iar; // push(prio) onto stack
  79. for(i=0; i<nelem(intprio); i++)
  80. if(iar==intprio[i])
  81. return iar;
  82. iprint("saturnint: no vector %d\n", iar);
  83. intack();
  84. return -1;
  85. }
  86. void
  87. intack(void)
  88. {
  89. *(ushort*)Ithresh = 0; // pop(prio) stack
  90. }
  91. void
  92. machinit(void)
  93. {
  94. int rrate;
  95. ulong hid;
  96. extern char* plan9inistr;
  97. ulong l2cr;
  98. memset(m, 0, sizeof(*m));
  99. m->cputype = getpvr()>>16;
  100. m->imap = (Imap*)INTMEM;
  101. m->loopconst = 1096;
  102. rrate = (*(ushort*)Syscfg >> 6) & 3;
  103. switch(rrate){
  104. case 0:
  105. m->bushz = 66666666;
  106. break;
  107. case 1:
  108. m->bushz = 83333333;
  109. break;
  110. case 2:
  111. m->bushz = 100000000;
  112. break;
  113. case 3:
  114. m->bushz = 133333333;
  115. break;
  116. }
  117. if(getpll() == 0x80000000)
  118. m->cpuhz = 300000000;
  119. else
  120. m->cpuhz = 200000000; /* 750FX? */
  121. m->cyclefreq = m->bushz / 4;
  122. active.machs = 1;
  123. active.exiting = 0;
  124. putmsr(getmsr() | MSR_ME);
  125. dcflush((void*)KZERO, 0x2000000);
  126. l2cr = getl2cr();
  127. putl2cr(l2cr|BIT(10));
  128. kfpinit();
  129. hid=gethid0();
  130. hid |= BIT(28)|BIT(26)|BIT(24);
  131. puthid0(hid);
  132. plan9inistr =
  133. "console=0\n"
  134. "ether0=type=saturn\n"
  135. "fs=135.104.9.42\n"
  136. "auth=135.104.9.7\n"
  137. "authdom=cs.bell-labs.com\n"
  138. "sys=ucu\n"
  139. "ntp=135.104.9.52\n";
  140. }
  141. void
  142. sharedseginit(void)
  143. {
  144. }
  145. void
  146. trapinit(void)
  147. {
  148. int i;
  149. for(i = 0x0; i < 0x2000; i += 0x100)
  150. sethvec(i, trapvec);
  151. dcflush(KADDR(0), 0x2000);
  152. icflush(KADDR(0), 0x2000);
  153. putmsr(getmsr() & ~MSR_IP);
  154. }
  155. void
  156. reboot(void*, void*, ulong)
  157. {
  158. }