multiboot.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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. typedef struct Mbi Mbi;
  15. struct Mbi {
  16. uint32_t flags;
  17. uint32_t memlower;
  18. uint32_t memupper;
  19. uint32_t bootdevice;
  20. uint32_t cmdline;
  21. uint32_t modscount;
  22. uint32_t modsaddr;
  23. uint32_t syms[4];
  24. uint32_t mmaplength;
  25. uint32_t mmapaddr;
  26. uint32_t driveslength;
  27. uint32_t drivesaddr;
  28. uint32_t configtable;
  29. uint32_t bootloadername;
  30. uint32_t apmtable;
  31. uint32_t vbe[6];
  32. };
  33. enum { /* flags */
  34. Fmem = 0x00000001, /* mem* valid */
  35. Fbootdevice = 0x00000002, /* bootdevice valid */
  36. Fcmdline = 0x00000004, /* cmdline valid */
  37. Fmods = 0x00000008, /* mod* valid */
  38. Fsyms = 0x00000010, /* syms[] has a.out info */
  39. Felf = 0x00000020, /* syms[] has ELF info */
  40. Fmmap = 0x00000040, /* mmap* valid */
  41. Fdrives = 0x00000080, /* drives* valid */
  42. Fconfigtable = 0x00000100, /* configtable* valid */
  43. Fbootloadername = 0x00000200, /* bootloadername* valid */
  44. Fapmtable = 0x00000400, /* apmtable* valid */
  45. Fvbe = 0x00000800, /* vbe[] valid */
  46. };
  47. typedef struct Mod Mod;
  48. struct Mod {
  49. uint32_t modstart;
  50. uint32_t modend;
  51. uint32_t string;
  52. uint32_t reserved;
  53. };
  54. typedef struct MMap MMap;
  55. struct MMap {
  56. uint32_t size;
  57. uint32_t base[2];
  58. uint32_t length[2];
  59. uint32_t type;
  60. };
  61. int
  62. multiboot(uint32_t magic, uint32_t pmbi, int vflag)
  63. {
  64. char *p;
  65. int i, n;
  66. Mbi *mbi;
  67. Mod *mod;
  68. MMap *mmap;
  69. uint64_t addr, len;
  70. if(vflag)
  71. print("magic %#x pmbi %#x\n", magic, pmbi);
  72. if(magic != 0x2badb002)
  73. print("no magic in multiboot\n");//return -1;
  74. mbi = KADDR(pmbi);
  75. if(vflag)
  76. print("flags %#x\n", mbi->flags);
  77. if(mbi->flags & Fcmdline){
  78. p = KADDR(mbi->cmdline);
  79. if(vflag)
  80. print("cmdline <%s>\n", p);
  81. else
  82. optionsinit(p);
  83. }
  84. if(mbi->flags & Fmods){
  85. for(i = 0; i < mbi->modscount; i++){
  86. mod = KADDR(mbi->modsaddr + i*16);
  87. if(mod->string != 0)
  88. p = KADDR(mod->string);
  89. else
  90. p = "";
  91. if(vflag)
  92. print("mod %#x %#x <%s>\n",
  93. mod->modstart, mod->modend, p);
  94. else
  95. asmmodinit(mod->modstart, mod->modend, p);
  96. }
  97. }
  98. if(mbi->flags & Fmmap){
  99. mmap = KADDR(mbi->mmapaddr);
  100. n = 0;
  101. while(n < mbi->mmaplength){
  102. addr = (((uint64_t)mmap->base[1])<<32)|mmap->base[0];
  103. len = (((uint64_t)mmap->length[1])<<32)|mmap->length[0];
  104. switch(mmap->type){
  105. default:
  106. if(vflag)
  107. print("type %u", mmap->type);
  108. break;
  109. case 1:
  110. if(vflag)
  111. print("Memory");
  112. else
  113. asmmapinit(addr, len, mmap->type);
  114. break;
  115. case 2:
  116. if(vflag)
  117. print("reserved");
  118. else
  119. asmmapinit(addr, len, mmap->type);
  120. break;
  121. case 3:
  122. if(vflag)
  123. print("ACPI Reclaim Memory");
  124. else
  125. asmmapinit(addr, len, mmap->type);
  126. break;
  127. case 4:
  128. if(vflag)
  129. print("ACPI NVS Memory");
  130. else
  131. asmmapinit(addr, len, mmap->type);
  132. break;
  133. }
  134. if(vflag)
  135. print("\n\t%#16.16llx %#16.16llx (%llu)\n",
  136. addr, addr+len, len);
  137. n += mmap->size+sizeof(mmap->size);
  138. mmap = KADDR(mbi->mmapaddr+n);
  139. }
  140. }
  141. if(vflag && (mbi->flags & Fbootloadername)){
  142. p = KADDR(mbi->bootloadername);
  143. print("bootloadername <%s>\n", p);
  144. }
  145. return 0;
  146. }