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