main.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. static void puts(char * s, int n)
  29. {
  30. while (n--)
  31. testPrint(*s++);
  32. }
  33. static int x = 0x123456;
  34. /* mach struct for hart 0. */
  35. /* in many plan 9 implementations this stuff is all reserved in early assembly.
  36. * we don't have to do that. */
  37. static uint64_t m0stack[4096];
  38. static Mach m0;
  39. /* general purpose hart startup. We call this via startmach.
  40. * When we enter here, the machp() function is usable.
  41. */
  42. void hart(void)
  43. {
  44. //Mach *mach = machp();
  45. die("not yet");
  46. }
  47. void bsp(void)
  48. {
  49. Mach *mach = machp();
  50. if (mach != &m0)
  51. die("MACH NOT MATCH");
  52. msg("memset mach\n");
  53. memset(mach, 0, sizeof(Mach));
  54. msg("done that\n");
  55. mach->self = (uintptr_t)mach;
  56. msg("SET SELF OK\n");
  57. mach->machno = 0;
  58. mach->online = 1;
  59. mach->NIX.nixtype = NIXTC;
  60. mach->stack = PTR2UINT(m0stack);
  61. *(uintptr_t*)mach->stack = STACKGUARD;
  62. mach->externup = nil;
  63. active.nonline = 1;
  64. active.exiting = 0;
  65. active.nbooting = 0;
  66. /*
  67. * Need something for initial delays
  68. * until a timebase is worked out.
  69. */
  70. mach->cpuhz = 2000000000ll;
  71. mach->cpumhz = 2000;
  72. sys->cyclefreq = mach->cpuhz;
  73. // this is in 386, so ... not yet. i8250console("0");
  74. // probably pull in the one from coreboot for riscv.
  75. consuartputs = puts;
  76. die("Completed hart for bsp OK!\n");
  77. }
  78. void
  79. main(uint32_t mbmagic, uint32_t mbaddress)
  80. {
  81. testPrint('0');
  82. if (x != 0x123456)
  83. die("Data is not set up correctly\n");
  84. //memset(edata, 0, end - edata);
  85. msg("got somewhere");
  86. startmach(bsp, &m0);
  87. }