changelog shortlog tags branches changeset files revisions annotate raw help

Mercurial > hg > plan9front / sys/src/libmach/setmach.c

changeset 7186: 4dd5e2428c1d
parent: 4149984789ca
author: cinap_lenrek@felloff.net
date: Fri, 03 May 2019 21:00:17 +0200
permissions: -rw-r--r--
description: libmach: initial arm64 support
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, marm64, mmips2be, mmips2le, mpower, mpower64, msparc64;
21 extern Machdata mipsmach, mipsmachle, sparcmach, m68020mach, i386mach,
22  armmach, arm64mach, mipsmach2le, powermach, 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  { "mipsLE", /*plan 9 mips little endian*/
50  FMIPSLE,
51  0,
52  AMIPS,
53  &mmips,
54  &mipsmachle, },
55  { "mips", /*plan 9 mips*/
56  FMIPS,
57  FMIPSB,
58  AMIPS,
59  &mmips,
60  &mipsmach, },
61  { "mips2", /*plan 9 mips2*/
62  FMIPS2BE,
63  FMIPSB,
64  AMIPS,
65  &mmips2be,
66  &mipsmach, }, /* shares debuggers with native mips */
67  { "mipsco", /*native mips - must follow plan 9*/
68  FMIPS,
69  FMIPSB,
70  AMIPSCO,
71  &mmips,
72  &mipsmach, },
73  { "sparc", /*plan 9 sparc */
74  FSPARC,
75  FSPARCB,
76  ASPARC,
77  &msparc,
78  &sparcmach, },
79  { "sunsparc", /*native sparc - must follow plan 9*/
80  FSPARC,
81  FSPARCB,
82  ASUNSPARC,
83  &msparc,
84  &sparcmach, },
85  { "386", /*plan 9 386*/
86  FI386,
87  FI386B,
88  AI386,
89  &mi386,
90  &i386mach, },
91  { "86", /*8086 - a peach of a machine*/
92  FI386,
93  FI386B,
94  AI8086,
95  &mi386,
96  &i386mach, },
97  { "amd64", /*amd64*/
98  FAMD64,
99  FAMD64B,
100  AAMD64,
101  &mamd64,
102  &i386mach, },
103  { "arm", /*ARM*/
104  FARM,
105  FARMB,
106  AARM,
107  &marm,
108  &armmach, },
109  { "arm64", /*ARM64*/
110  FARM64,
111  FARM64B,
112  AARM64,
113  &marm64,
114  &arm64mach, },
115  { "power", /*PowerPC*/
116  FPOWER,
117  FPOWERB,
118  APOWER,
119  &mpower,
120  &powermach, },
121  { "power64", /*PowerPC*/
122  FPOWER64,
123  FPOWER64B,
124  APOWER64,
125  &mpower64,
126  &powermach, },
127  { "sparc64", /*plan 9 sparc64 */
128  FSPARC64,
129  FSPARCB, /* XXX? */
130  ASPARC64,
131  &msparc64,
132  &sparc64mach, },
133  { 0 }, /*the terminator*/
134 };
135 
136 /*
137  * select a machine by executable file type
138  */
139 void
140 machbytype(int type)
141 {
142  Machtab *mp;
143 
144  for (mp = machines; mp->name; mp++){
145  if (mp->type == type || mp->boottype == type) {
146  asstype = mp->asstype;
147  machdata = mp->machdata;
148  break;
149  }
150  }
151 }
152 /*
153  * select a machine by name
154  */
155 int
156 machbyname(char *name)
157 {
158  Machtab *mp;
159 
160  if (!name) {
161  asstype = AMIPS;
162  machdata = &mipsmach;
163  mach = &mmips;
164  return 1;
165  }
166  for (mp = machines; mp->name; mp++){
167  if (strcmp(mp->name, name) == 0) {
168  asstype = mp->asstype;
169  machdata = mp->machdata;
170  mach = mp->mach;
171  return 1;
172  }
173  }
174  return 0;
175 }