kexec.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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 "tos.h"
  11. #include "../port/lib.h"
  12. #include "mem.h"
  13. #include "dat.h"
  14. #include "fns.h"
  15. #include "../port/error.h"
  16. #include "../port/edf.h"
  17. #include <a.out.h>
  18. #include "kexec.h"
  19. /* XXX: MOVE ME TO K10 */
  20. enum {
  21. Maxslot = 32,
  22. };
  23. typedef struct {
  24. Exec;
  25. uint64_t hdr[1];
  26. } Khdr;
  27. enum {
  28. AsmNONE = 0,
  29. AsmMEMORY = 1,
  30. AsmRESERVED = 2,
  31. AsmACPIRECLAIM = 3,
  32. AsmACPINVS = 4,
  33. AsmDEV = 5,
  34. };
  35. Proc*
  36. setupseg(int core)
  37. {
  38. Proc *up = externup();
  39. Segment *s;
  40. uintptr_t ka;
  41. Proc *p;
  42. static Pgrp *kpgrp;
  43. Segment *tseg;
  44. int sno;
  45. // XXX: we're going to need this for locality domains.
  46. USED(core);
  47. p = newproc();
  48. p->psstate = 0;
  49. p->procmode = 0640;
  50. p->kp = 1;
  51. p->noswap = 1;
  52. p->scallnr = up->scallnr;
  53. memmove(p->arg, up->arg, sizeof(up->arg));
  54. p->nerrlab = 0;
  55. p->slash = up->slash;
  56. p->dot = up->dot;
  57. if(p->dot)
  58. incref(&p->dot->r);
  59. memmove(p->note, up->note, sizeof(p->note));
  60. p->nnote = up->nnote;
  61. p->notified = 0;
  62. p->lastnote = up->lastnote;
  63. p->notify = up->notify;
  64. p->ureg = 0;
  65. p->dbgreg = 0;
  66. kstrdup(&p->user, eve);
  67. if(kpgrp == 0)
  68. kpgrp = newpgrp();
  69. p->pgrp = kpgrp;
  70. incref(&kpgrp->r);
  71. memset(p->time, 0, sizeof(p->time));
  72. p->time[TReal] = sys->ticks;
  73. procpriority(p, PriKproc, 0);
  74. // XXX: kluge 4 pages of address space for this.
  75. // how will it expand up? gives us <50 kprocs as is.
  76. /*
  77. * we create the color and core at allocation time, not execution. This
  78. * is probably not the best idea but it's a start.
  79. */
  80. sno = 0;
  81. // XXX: now that we are asmalloc we are no long proc.
  82. /* Stack */
  83. ka = (uintptr_t)KADDR(asmalloc(0, BIGPGSZ, AsmMEMORY, 1));
  84. tseg = newseg(SG_STACK|SG_READ|SG_WRITE, ka, 1);
  85. tseg = p->seg[sno++];
  86. ka = (uintptr_t)KADDR(asmalloc(0, BIGPGSZ, AsmMEMORY, 1));
  87. s = newseg(SG_TEXT|SG_READ|SG_EXEC, ka, 1);
  88. p->seg[sno++] = s;
  89. // s->color = acpicorecolor(core);
  90. /* Data. Shared. */
  91. // XXX; Now that the address space is all funky how are we going to handle shared data segments?
  92. ka = (uintptr_t)KADDR(asmalloc(0, BIGPGSZ, AsmMEMORY, 2));
  93. s = newseg(SG_DATA|SG_READ|SG_WRITE, ka, 1);
  94. p->seg[sno++] = s;
  95. s->color = tseg->color;
  96. /* BSS. Uses asm from data map. */
  97. p->seg[sno++] = newseg(SG_BSS|SG_READ|SG_WRITE, ka+BIGPGSZ, 1);
  98. p->seg[sno++]->color= tseg->color;
  99. nixprepage(-1);
  100. return p;
  101. }
  102. void
  103. printhello(void)
  104. {
  105. print("hello\n");
  106. }
  107. void
  108. printargs(char *arg)
  109. {
  110. print("%#p %s\n", arg, arg);
  111. }