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, mriscv, mriscv64;
20 extern Machdata mipsmach, sparcmach, i386mach,
21 armmach, mipsmach2le, powermach, riscvmach, riscv64mach;
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 { "riscv",
103 FRISCV,
104 FRISCVB,
105 ARISCV,
106 &mriscv,
107 &riscvmach, },
108 { "riscv64",
109 FRISCV64,
110 FRISCV64B,
111 ARISCV64,
112 &mriscv64,
113 &riscv64mach, },
114 { 0 }, /*the terminator*/
115 };
116
117 /*
118 * select a machine by executable file type
119 */
120 void
machbytype(int type)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
machbyname(char * name)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