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