xref: /plan9/sys/src/libmach/setmach.c (revision 4d44ba9b9ee4246ddbd96c7fcaf0918ab92ab35a)
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, 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 		FI386B,
94 		AAMD64,
95 		&mamd64,
96 		&i386mach,	},
97 	{	"arm",				/*ARM*/
98 		FARM,
99 		FNONE,
100 		AARM,
101 		&marm,
102 		&armmach,	},
103 	{	"power",			/*PowerPC*/
104 		FPOWER,
105 		FPOWERB,
106 		APOWER,
107 		&mpower,
108 		&powermach,	},
109 	{	"alpha",			/*Alpha*/
110 		FALPHA,
111 		FALPHAB,
112 		AALPHA,
113 		&malpha,
114 		&alphamach,	},
115 	{	"sparc64",			/*plan 9 sparc64 */
116 		FSPARC64,
117 		FSPARCB,			/* XXX? */
118 		ASPARC64,
119 		&msparc64,
120 		&sparc64mach,	},
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