main.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. #include "u.h"
  2. #include "../port/lib.h"
  3. #include "mem.h"
  4. #include "dat.h"
  5. #include "fns.h"
  6. #include "../port/error.h"
  7. #include "io.h"
  8. #include "version.h"
  9. Mach *m = (Mach*)MACHADDR;
  10. Proc *up = 0;
  11. Vectorpage *page0 = (Vectorpage*)KZERO; /* doubly-mapped to AIVECADDR */
  12. Conf conf;
  13. extern ulong kerndate;
  14. extern int cflag;
  15. extern int main_pool_pcnt;
  16. extern int heap_pool_pcnt;
  17. extern int image_pool_pcnt;
  18. ulong cpuidlecount;
  19. static void
  20. poolsizeinit(void)
  21. {
  22. ulong nb;
  23. nb = conf.npage*BY2PG;
  24. poolsize(mainmem, (nb*main_pool_pcnt)/100, 0);
  25. poolsize(heapmem, (nb*heap_pool_pcnt)/100, 0);
  26. poolsize(imagmem, (nb*image_pool_pcnt)/100, 1);
  27. }
  28. void
  29. main(void)
  30. {
  31. memset(edata, 0, end-edata); /* clear the BSS */
  32. memset(m, 0, sizeof(Mach)); /* clear the mach struct */
  33. conf.nmach = 1;
  34. archreset();
  35. dmareset();
  36. quotefmtinstall();
  37. confinit();
  38. xinit();
  39. mmuinit();
  40. poolinit();
  41. poolsizeinit();
  42. trapinit();
  43. clockinit();
  44. printinit();
  45. screeninit();
  46. procinit();
  47. links();
  48. chandevreset();
  49. eve = strdup("inferno");
  50. archconsole();
  51. kbdinit();
  52. print("%ld MHz id %8.8lux\n", (m->cpuhz+500000)/1000000, getcpuid());
  53. print("\nInferno %s\n", VERSION);
  54. print("Vita Nuova\n");
  55. print("conf %s (%lud) jit %d\n\n",conffile, kerndate, cflag);
  56. userinit();
  57. schedinit();
  58. }
  59. void
  60. reboot(void)
  61. {
  62. exit(0);
  63. }
  64. void
  65. halt(void)
  66. {
  67. spllo();
  68. print("cpu halted\n");
  69. for(;;){
  70. /* nothing to do */
  71. }
  72. }
  73. void
  74. confinit(void)
  75. {
  76. ulong base;
  77. archconfinit();
  78. base = PGROUND((ulong)end);
  79. conf.base0 = base;
  80. conf.base1 = 0;
  81. conf.npage1 = 0;
  82. conf.npage0 = (conf.topofmem - base)/BY2PG;
  83. conf.npage = conf.npage0 + conf.npage1;
  84. conf.ialloc = (((conf.npage*(main_pool_pcnt))/100)/2)*BY2PG;
  85. conf.nproc = 100 + ((conf.npage*BY2PG)/MB)*5;
  86. conf.nmach = 1;
  87. }
  88. void
  89. init0(void)
  90. {
  91. Osenv *o;
  92. char buf[2*KNAMELEN];
  93. up->nerrlab = 0;
  94. spllo();
  95. if(waserror())
  96. panic("init0 %r");
  97. /*
  98. * These are o.k. because rootinit is null.
  99. * Then early kproc's will have a root and dot.
  100. */
  101. o = up->env;
  102. o->pgrp->slash = namec("#/", Atodir, 0, 0);
  103. cnameclose(o->pgrp->slash->name);
  104. o->pgrp->slash->name = newcname("/");
  105. o->pgrp->dot = cclone(o->pgrp->slash);
  106. chandevinit();
  107. if(!waserror()){
  108. ksetenv("cputype", "arm", 0);
  109. snprint(buf, sizeof(buf), "arm %s", conffile);
  110. ksetenv("terminal", buf, 0);
  111. poperror();
  112. }
  113. poperror();
  114. disinit("/osinit.dis");
  115. }
  116. void
  117. userinit(void)
  118. {
  119. Proc *p;
  120. Osenv *o;
  121. p = newproc();
  122. o = p->env;
  123. o->fgrp = newfgrp(nil);
  124. o->pgrp = newpgrp();
  125. o->egrp = newegrp();
  126. kstrdup(&o->user, eve);
  127. strcpy(p->text, "interp");
  128. p->fpstate = FPINIT;
  129. /*
  130. * Kernel Stack
  131. *
  132. * N.B. The -12 for the stack pointer is important.
  133. * 4 bytes for gotolabel's return PC
  134. */
  135. p->sched.pc = (ulong)init0;
  136. p->sched.sp = (ulong)p->kstack+KSTACK-8;
  137. ready(p);
  138. }
  139. void
  140. exit(int inpanic)
  141. {
  142. up = 0;
  143. /* Shutdown running devices */
  144. chandevshutdown();
  145. if(inpanic && 0){
  146. print("Hit the reset button\n");
  147. for(;;)
  148. clockpoll();
  149. }
  150. archreboot();
  151. }
  152. static void
  153. linkproc(void)
  154. {
  155. spllo();
  156. if (waserror())
  157. print("error() underflow: %r\n");
  158. else
  159. (*up->kpfun)(up->arg);
  160. pexit("end proc", 1);
  161. }
  162. void
  163. kprocchild(Proc *p, void (*func)(void*), void *arg)
  164. {
  165. p->sched.pc = (ulong)linkproc;
  166. p->sched.sp = (ulong)p->kstack+KSTACK-8;
  167. p->kpfun = func;
  168. p->arg = arg;
  169. }
  170. void
  171. idlehands(void)
  172. {
  173. cpuidlecount++;
  174. INTRREG->iccr = 1; /* only unmasked interrupts will stop idle mode */
  175. idle();
  176. }
  177. /* stubs */
  178. void
  179. setfsr(ulong)
  180. {
  181. }
  182. ulong
  183. getfsr()
  184. {
  185. return 0;
  186. }
  187. void
  188. setfcr(ulong)
  189. {
  190. }
  191. ulong
  192. getfcr()
  193. {
  194. return 0;
  195. }
  196. void
  197. fpinit(void)
  198. {
  199. }
  200. void
  201. FPsave(void*)
  202. {
  203. }
  204. void
  205. FPrestore(void*)
  206. {
  207. }