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