setmach.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. #include <u.h>
  2. #include <libc.h>
  3. #include <bio.h>
  4. #include <mach.h>
  5. /* table for selecting machine-dependent parameters */
  6. typedef struct machtab Machtab;
  7. struct machtab
  8. {
  9. char *name; /* machine name */
  10. short type; /* executable type */
  11. short boottype; /* bootable type */
  12. int asstype; /* disassembler code */
  13. Mach *mach; /* machine description */
  14. Machdata *machdata; /* machine functions */
  15. };
  16. extern Mach mmips, msparc, m68020, mi386, mi960, m29000,
  17. marm, mmips2be, mmips2le, mpower, malpha;
  18. extern Machdata mipsmach, sparcmach, m68020mach, i386mach, i960mach,
  19. a29000mach, armmach, mipsmach2le, powermach, alphamach;
  20. /*
  21. * machine selection table. machines with native disassemblers should
  22. * follow the plan 9 variant in the table; native modes are selectable
  23. * only by name.
  24. */
  25. Machtab machines[] =
  26. {
  27. { "68020", /*68020*/
  28. F68020,
  29. F68020B,
  30. A68020,
  31. &m68020,
  32. &m68020mach, },
  33. { "68020", /*Next 68040 bootable*/
  34. F68020,
  35. FNEXTB,
  36. A68020,
  37. &m68020,
  38. &m68020mach, },
  39. { "mips2LE", /*plan 9 mips2 little endian*/
  40. FMIPS2LE,
  41. 0,
  42. AMIPS,
  43. &mmips2le,
  44. &mipsmach2le, },
  45. { "mips", /*plan 9 mips*/
  46. FMIPS,
  47. FMIPSB,
  48. AMIPS,
  49. &mmips,
  50. &mipsmach, },
  51. { "mips2", /*plan 9 mips2*/
  52. FMIPS2BE,
  53. FMIPSB,
  54. AMIPS,
  55. &mmips2be,
  56. &mipsmach, }, /* shares debuggers with native mips */
  57. { "mipsco", /*native mips - must follow plan 9*/
  58. FMIPS,
  59. FMIPSB,
  60. AMIPSCO,
  61. &mmips,
  62. &mipsmach, },
  63. { "sparc", /*plan 9 sparc */
  64. FSPARC,
  65. FSPARCB,
  66. ASPARC,
  67. &msparc,
  68. &sparcmach, },
  69. { "sunsparc", /*native sparc - must follow plan 9*/
  70. FSPARC,
  71. FSPARCB,
  72. ASUNSPARC,
  73. &msparc,
  74. &sparcmach, },
  75. { "386", /*plan 9 386*/
  76. FI386,
  77. FI386B,
  78. AI386,
  79. &mi386,
  80. &i386mach, },
  81. { "86", /*8086 - a peach of a machine*/
  82. FI386,
  83. FI386B,
  84. AI8086,
  85. &mi386,
  86. &i386mach, },
  87. { "960", /*i960*/
  88. FI960,
  89. FI960B,
  90. AI960,
  91. &mi960,
  92. &i960mach, },
  93. { "29000", /*29000*/
  94. F29000,
  95. FNONE,
  96. A29000,
  97. &m29000,
  98. &a29000mach, },
  99. { "arm", /*ARM*/
  100. FARM,
  101. FNONE,
  102. AARM,
  103. &marm,
  104. &armmach, },
  105. { "power", /*PowerPC*/
  106. FPOWER,
  107. FPOWERB,
  108. APOWER,
  109. &mpower,
  110. &powermach, },
  111. { "alpha", /*Alpha*/
  112. FALPHA,
  113. FALPHAB,
  114. AALPHA,
  115. &malpha,
  116. &alphamach, },
  117. { 0 }, /*the terminator*/
  118. };
  119. /*
  120. * select a machine by executable file type
  121. */
  122. void
  123. machbytype(int type)
  124. {
  125. Machtab *mp;
  126. for (mp = machines; mp->name; mp++){
  127. if (mp->type == type || mp->boottype == type) {
  128. asstype = mp->asstype;
  129. machdata = mp->machdata;
  130. break;
  131. }
  132. }
  133. }
  134. /*
  135. * select a machine by name
  136. */
  137. int
  138. machbyname(char *name)
  139. {
  140. Machtab *mp;
  141. if (!name) {
  142. asstype = AMIPS;
  143. machdata = &mipsmach;
  144. mach = &mmips;
  145. return 1;
  146. }
  147. for (mp = machines; mp->name; mp++){
  148. if (strcmp(mp->name, name) == 0) {
  149. asstype = mp->asstype;
  150. machdata = mp->machdata;
  151. mach = mp->mach;
  152. return 1;
  153. }
  154. }
  155. return 0;
  156. }