main.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  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. #include "init.h"
  15. #include "io.h"
  16. extern void (*consuartputs)(char*, int);
  17. void testPrint(uint8_t c);
  18. void msg(char *s)
  19. {
  20. while (*s)
  21. testPrint(*s++);
  22. }
  23. void die(char *s)
  24. {
  25. msg(s);
  26. while (1);
  27. }
  28. void
  29. ndnr(void)
  30. {
  31. die("ndnr");
  32. }
  33. static void puts(char * s, int n)
  34. {
  35. while (n--)
  36. testPrint(*s++);
  37. }
  38. static int x = 0x123456;
  39. /* mach struct for hart 0. */
  40. /* in many plan 9 implementations this stuff is all reserved in early assembly.
  41. * we don't have to do that. */
  42. static uint64_t m0stack[4096];
  43. static Mach m0;
  44. Sys asys, *sys=&asys;
  45. Conf conf;
  46. uintptr_t kseg0 = KZERO;
  47. char *cputype = "riscv";
  48. /* I forget where this comes from and I don't care just now. */
  49. uint32_t kerndate;
  50. /* general purpose hart startup. We call this via startmach.
  51. * When we enter here, the machp() function is usable.
  52. */
  53. void hart(void)
  54. {
  55. //Mach *mach = machp();
  56. die("not yet");
  57. }
  58. void bsp(void)
  59. {
  60. Mach *mach = machp();
  61. if (mach != &m0)
  62. die("MACH NOT MATCH");
  63. msg("memset mach\n");
  64. memset(mach, 0, sizeof(Mach));
  65. msg("done that\n");
  66. mach->self = (uintptr_t)mach;
  67. msg("SET SELF OK\n");
  68. mach->machno = 0;
  69. mach->online = 1;
  70. mach->NIX.nixtype = NIXTC;
  71. mach->stack = PTR2UINT(m0stack);
  72. *(uintptr_t*)mach->stack = STACKGUARD;
  73. mach->externup = nil;
  74. active.nonline = 1;
  75. active.exiting = 0;
  76. active.nbooting = 0;
  77. /*
  78. * Need something for initial delays
  79. * until a timebase is worked out.
  80. */
  81. mach->cpuhz = 2000000000ll;
  82. mach->cpumhz = 2000;
  83. sys->cyclefreq = mach->cpuhz;
  84. // this is in 386, so ... not yet. i8250console("0");
  85. // probably pull in the one from coreboot for riscv.
  86. consuartputs = puts;
  87. die("Completed hart for bsp OK!\n");
  88. }
  89. void
  90. main(uint32_t mbmagic, uint32_t mbaddress)
  91. {
  92. testPrint('0');
  93. if (x != 0x123456)
  94. die("Data is not set up correctly\n");
  95. //memset(edata, 0, end - edata);
  96. msg("got somewhere");
  97. startmach(bsp, &m0);
  98. }
  99. /* stubs until we implement in assembly */
  100. int corecolor(int _)
  101. {
  102. return -1;
  103. }
  104. Proc *externup(void)
  105. {
  106. return machp()->externup;
  107. }
  108. void errstr(char *s, int i) {
  109. panic("errstr");
  110. }
  111. void
  112. oprof_alarm_handler(Ureg *u)
  113. {
  114. panic((char *)__func__);
  115. }
  116. void
  117. hardhalt(void)
  118. {
  119. panic((char *)__func__);
  120. }
  121. uintmem
  122. physalloc(uint64_t _, int*__, void*___)
  123. {
  124. panic((char *)__func__);
  125. return 0;
  126. }
  127. void
  128. ureg2gdb(Ureg *u, uintptr_t *g)
  129. {
  130. panic((char *)__func__);
  131. }
  132. int
  133. userureg(Ureg*u)
  134. {
  135. panic((char *)__func__);
  136. return -1;
  137. }
  138. uintptr_t
  139. userpc(Ureg*u)
  140. {
  141. panic((char *)__func__);
  142. return 0;
  143. }
  144. int tas32(void *_)
  145. {
  146. panic("tas32");
  147. return -1;
  148. }
  149. int cas32(void*_, uint32_t __, uint32_t ___)
  150. {
  151. panic((char *)__func__);
  152. return -1;
  153. }
  154. void exit(int _)
  155. {
  156. panic((char *)__func__);
  157. }
  158. void fpunoted(void)
  159. {
  160. panic((char *)__func__);
  161. }
  162. void fpunotify(Ureg*_)
  163. {
  164. panic((char *)__func__);
  165. }
  166. void fpusysrfork(Ureg*_)
  167. {
  168. panic((char *)__func__);
  169. }
  170. void kexit(Ureg*_)
  171. {
  172. panic((char *)__func__);
  173. }
  174. char*
  175. seprintphysstats(char*_, char*__)
  176. {
  177. return "NOT YET";
  178. }
  179. void
  180. reboot(void*_, void*__, int32_t ___)
  181. {
  182. panic("reboot");
  183. }
  184. void fpusysprocsetup(Proc *_)
  185. {
  186. panic((char *)__func__);
  187. }
  188. void sysrforkret(void)
  189. {
  190. panic((char *)__func__);
  191. }
  192. void fpusysrforkchild(Proc*_, Proc*__)
  193. {
  194. panic((char *)__func__);
  195. }
  196. int
  197. fpudevprocio(Proc*p, void*v, int32_t _, uintptr_t __, int ___)
  198. {
  199. panic((char *)__func__);
  200. return -1;
  201. }
  202. void
  203. setregisters(Ureg*u, char*f, char*t, int amt)
  204. {
  205. panic((char *)__func__);
  206. }
  207. uint64_t rdtsc(void)
  208. {
  209. panic((char *)__func__);
  210. return 0;
  211. }
  212. int islo(void)
  213. {
  214. panic((char *)__func__);
  215. return 0;
  216. }
  217. void mfence(void)
  218. {
  219. panic((char *)__func__);
  220. }
  221. uintptr_t
  222. dbgpc(Proc*p)
  223. {
  224. panic((char *)__func__);
  225. return 0;
  226. }
  227. void dumpstack(void)
  228. {
  229. panic((char *)__func__);
  230. }
  231. void
  232. dumpgpr(Ureg* ureg)
  233. {
  234. panic((char *)__func__);
  235. }
  236. void
  237. setkernur(Ureg*u, Proc*p)
  238. {
  239. panic((char *)__func__);
  240. }
  241. void
  242. physfree(uintmem data, uint64_t size)
  243. {
  244. panic("physfree %p 0x%lx", data, size);
  245. }
  246. void
  247. stacksnippet(void)
  248. {
  249. //Stackframe *stkfr;
  250. kmprint(" stack:");
  251. // for(stkfr = stackframe(); stkfr != nil; stkfr = stkfr->next)
  252. // kmprint(" %c:%p", ktextaddr(stkfr->pc) ? 'k' : '?', ktextaddr(stkfr->pc) ? (stkfr->pc & 0xfffffff) : stkfr->pc);
  253. kmprint("\n");
  254. }
  255. /* crap. */
  256. /* this should come from build but it's intimately tied in to VGA. Crap. */
  257. Physseg physseg[8];
  258. int nphysseg = 8;
  259. /* bringup -- remove asap. */
  260. void
  261. DONE(void)
  262. {
  263. print("DONE\n");
  264. //prflush();
  265. delay(10000);
  266. ndnr();
  267. }
  268. void
  269. HERE(void)
  270. {
  271. print("here\n");
  272. //prflush();
  273. delay(5000);
  274. }
  275. /* The old plan 9 standby ... wave ... */
  276. /* Keep to debug trap.c */
  277. void wave(int c)
  278. {
  279. testPrint(c);
  280. }
  281. void hi(char *s)
  282. {
  283. if (! s)
  284. s = "<NULL>";
  285. while (*s)
  286. wave(*s++);
  287. }