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, mi386, mamd64, 19 marm, mmips2be, mmips2le, mpower, mpower64; 20 extern Machdata mipsmach, sparcmach, i386mach, 21 armmach, mipsmach2le, powermach; 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 { "mips2LE", /*plan 9 mips2 little endian*/ 31 FMIPS2LE, 32 0, 33 AMIPS, 34 &mmips2le, 35 &mipsmach2le, }, 36 { "mips", /*plan 9 mips*/ 37 FMIPS, 38 FMIPSB, 39 AMIPS, 40 &mmips, 41 &mipsmach, }, 42 { "mips2", /*plan 9 mips2*/ 43 FMIPS2BE, 44 FMIPSB, 45 AMIPS, 46 &mmips2be, 47 &mipsmach, }, /* shares debuggers with native mips */ 48 { "mipsco", /*native mips - must follow plan 9*/ 49 FMIPS, 50 FMIPSB, 51 AMIPSCO, 52 &mmips, 53 &mipsmach, }, 54 { "sparc", /*plan 9 sparc */ 55 FSPARC, 56 FSPARCB, 57 ASPARC, 58 &msparc, 59 &sparcmach, }, 60 { "sunsparc", /*native sparc - must follow plan 9*/ 61 FSPARC, 62 FSPARCB, 63 ASUNSPARC, 64 &msparc, 65 &sparcmach, }, 66 { "386", /*plan 9 386*/ 67 FI386, 68 FI386B, 69 AI386, 70 &mi386, 71 &i386mach, }, 72 { "86", /*8086 - a peach of a machine*/ 73 FI386, 74 FI386B, 75 AI8086, 76 &mi386, 77 &i386mach, }, 78 { "amd64", /*amd64*/ 79 FAMD64, 80 FAMD64B, 81 AAMD64, 82 &mamd64, 83 &i386mach, }, 84 { "arm", /*ARM*/ 85 FARM, 86 FARMB, 87 AARM, 88 &marm, 89 &armmach, }, 90 { "power", /*PowerPC*/ 91 FPOWER, 92 FPOWERB, 93 APOWER, 94 &mpower, 95 &powermach, }, 96 { "power64", /*PowerPC*/ 97 FPOWER64, 98 FPOWER64B, 99 APOWER64, 100 &mpower64, 101 &powermach, }, 102 { 0 }, /*the terminator*/ 103 }; 104 105 /* 106 * select a machine by executable file type 107 */ 108 void 109 machbytype(int type) 110 { 111 Machtab *mp; 112 113 for (mp = machines; mp->name; mp++){ 114 if (mp->type == type || mp->boottype == type) { 115 asstype = mp->asstype; 116 machdata = mp->machdata; 117 break; 118 } 119 } 120 } 121 /* 122 * select a machine by name 123 */ 124 int 125 machbyname(char *name) 126 { 127 Machtab *mp; 128 129 if (!name) { 130 asstype = AMIPS; 131 machdata = &mipsmach; 132 mach = &mmips; 133 return 1; 134 } 135 for (mp = machines; mp->name; mp++){ 136 if (strcmp(mp->name, name) == 0) { 137 asstype = mp->asstype; 138 machdata = mp->machdata; 139 mach = mp->mach; 140 return 1; 141 } 142 } 143 return 0; 144 } 145