setmach.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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 <libc.h>
  11. #include <bio.h>
  12. #include <mach.h>
  13. /* table for selecting machine-dependent parameters */
  14. typedef struct machtab Machtab;
  15. struct machtab
  16. {
  17. char *name; /* machine name */
  18. int16_t type; /* executable type */
  19. int16_t boottype; /* bootable type */
  20. int asstype; /* disassembler code */
  21. Mach *mach; /* machine description */
  22. Machdata *machdata; /* machine functions */
  23. };
  24. extern Mach mmips, msparc, m68020, mi386, mamd64,
  25. marm, mmips2be, mmips2le, mpower, mpower64, malpha, msparc64;
  26. extern Machdata mipsmach, mipsmachle, sparcmach, m68020mach, i386mach,
  27. armmach, mipsmach2le, powermach, alphamach, sparc64mach;
  28. /*
  29. * machine selection table. machines with native disassemblers should
  30. * follow the plan 9 variant in the table; native modes are selectable
  31. * only by name.
  32. */
  33. Machtab machines[] =
  34. {
  35. #ifdef FOO
  36. { "68020", /*68020*/
  37. F68020,
  38. F68020B,
  39. A68020,
  40. &m68020,
  41. &m68020mach, },
  42. { "68020", /*Next 68040 bootable*/
  43. F68020,
  44. FNEXTB,
  45. A68020,
  46. &m68020,
  47. &m68020mach, },
  48. { "mips2LE", /*plan 9 mips2 little endian*/
  49. FMIPS2LE,
  50. 0,
  51. AMIPS,
  52. &mmips2le,
  53. &mipsmach2le, },
  54. { "mipsLE", /*plan 9 mips little endian*/
  55. FMIPSLE,
  56. 0,
  57. AMIPS,
  58. &mmips,
  59. &mipsmachle, },
  60. { "mips", /*plan 9 mips*/
  61. FMIPS,
  62. FMIPSB,
  63. AMIPS,
  64. &mmips,
  65. &mipsmach, },
  66. { "mips2", /*plan 9 mips2*/
  67. FMIPS2BE,
  68. FMIPSB,
  69. AMIPS,
  70. &mmips2be,
  71. &mipsmach, }, /* shares debuggers with native mips */
  72. { "mipsco", /*native mips - must follow plan 9*/
  73. FMIPS,
  74. FMIPSB,
  75. AMIPSCO,
  76. &mmips,
  77. &mipsmach, },
  78. { "sparc", /*plan 9 sparc */
  79. FSPARC,
  80. FSPARCB,
  81. ASPARC,
  82. &msparc,
  83. &sparcmach, },
  84. { "sunsparc", /*native sparc - must follow plan 9*/
  85. FSPARC,
  86. FSPARCB,
  87. ASUNSPARC,
  88. &msparc,
  89. &sparcmach, },
  90. { "386", /*plan 9 386*/
  91. FI386,
  92. FI386B,
  93. AI386,
  94. &mi386,
  95. &i386mach, },
  96. { "86", /*8086 - a peach of a machine*/
  97. FI386,
  98. FI386B,
  99. AI8086,
  100. &mi386,
  101. &i386mach, },
  102. #endif
  103. { "amd64", /*amd64*/
  104. FAMD64,
  105. FAMD64B,
  106. AAMD64,
  107. &mamd64,
  108. &i386mach, },
  109. #ifdef FOO
  110. { "arm", /*ARM*/
  111. FARM,
  112. FARMB,
  113. AARM,
  114. &marm,
  115. &armmach, },
  116. { "power", /*PowerPC*/
  117. FPOWER,
  118. FPOWERB,
  119. APOWER,
  120. &mpower,
  121. &powermach, },
  122. { "power64", /*PowerPC*/
  123. FPOWER64,
  124. FPOWER64B,
  125. APOWER64,
  126. &mpower64,
  127. &powermach, },
  128. { "alpha", /*Alpha*/
  129. FALPHA,
  130. FALPHAB,
  131. AALPHA,
  132. &malpha,
  133. &alphamach, },
  134. { "sparc64", /*plan 9 sparc64 */
  135. FSPARC64,
  136. FSPARCB, /* XXX? */
  137. ASPARC64,
  138. &msparc64,
  139. &sparc64mach, },
  140. #endif
  141. { 0 }, /*the terminator*/
  142. };
  143. /*
  144. * select a machine by executable file type
  145. */
  146. void
  147. machbytype(int type)
  148. {
  149. Machtab *mp;
  150. for (mp = machines; mp->name; mp++){
  151. if (mp->type == type || mp->boottype == type) {
  152. asstype = mp->asstype;
  153. machdata = mp->machdata;
  154. break;
  155. }
  156. }
  157. }
  158. /*
  159. * select a machine by name
  160. */
  161. int
  162. machbyname(char *name)
  163. {
  164. Machtab *mp;
  165. #ifdef FOO
  166. if (!name) {
  167. asstype = AMIPS;
  168. machdata = &mipsmach;
  169. mach = &mmips;
  170. return 1;
  171. }
  172. #endif
  173. for (mp = machines; mp->name; mp++){
  174. if (strcmp(mp->name, name) == 0) {
  175. asstype = mp->asstype;
  176. machdata = mp->machdata;
  177. mach = mp->mach;
  178. return 1;
  179. }
  180. }
  181. return 0;
  182. }