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