xref: /plan9/sys/src/libmach/setmach.c (revision ff8c3af2f44d95267f67219afa20ba82ff6cf7e4)
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, mi960, m29000,
20 			marm, mmips2be, mmips2le, mpower, malpha;
21 extern	Machdata	mipsmach, sparcmach, m68020mach, i386mach, i960mach,
22 			a29000mach, armmach, mipsmach2le, powermach, alphamach;
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 	{	"960",				/*i960*/
92 		FI960,
93 		FI960B,
94 		AI960,
95 		&mi960,
96 		&i960mach,	},
97 	{	"29000",			/*29000*/
98 		F29000,
99 		FNONE,
100 		A29000,
101 		&m29000,
102 		&a29000mach,	},
103 	{	"arm",				/*ARM*/
104 		FARM,
105 		FNONE,
106 		AARM,
107 		&marm,
108 		&armmach,	},
109 	{	"power",			/*PowerPC*/
110 		FPOWER,
111 		FPOWERB,
112 		APOWER,
113 		&mpower,
114 		&powermach,	},
115 	{	"alpha",				/*Alpha*/
116 		FALPHA,
117 		FALPHAB,
118 		AALPHA,
119 		&malpha,
120 		&alphamach,	},
121 	{	0		},		/*the terminator*/
122 };
123 
124 /*
125  *	select a machine by executable file type
126  */
127 void
128 machbytype(int type)
129 {
130 	Machtab *mp;
131 
132 	for (mp = machines; mp->name; mp++){
133 		if (mp->type == type || mp->boottype == type) {
134 			asstype = mp->asstype;
135 			machdata = mp->machdata;
136 			break;
137 		}
138 	}
139 }
140 /*
141  *	select a machine by name
142  */
143 int
144 machbyname(char *name)
145 {
146 	Machtab *mp;
147 
148 	if (!name) {
149 		asstype = AMIPS;
150 		machdata = &mipsmach;
151 		mach = &mmips;
152 		return 1;
153 	}
154 	for (mp = machines; mp->name; mp++){
155 		if (strcmp(mp->name, name) == 0) {
156 			asstype = mp->asstype;
157 			machdata = mp->machdata;
158 			mach = mp->mach;
159 			return 1;
160 		}
161 	}
162 	return 0;
163 }
164