The Go Programming Language

Text file src/libmach/setmach.c

     1	// Inferno libmach/setmach.c
     2	// http://code.google.com/p/inferno-os/source/browse/utils/libmach/setmach.c
     3	//
     4	//	Copyright © 1994-1999 Lucent Technologies Inc.
     5	//	Power PC support Copyright © 1995-2004 C H Forsyth (forsyth@terzarima.net).
     6	//	Portions Copyright © 1997-1999 Vita Nuova Limited.
     7	//	Portions Copyright © 2000-2007 Vita Nuova Holdings Limited (www.vitanuova.com).
     8	//	Revisions Copyright © 2000-2004 Lucent Technologies Inc. and others.
     9	//	Portions Copyright © 2009 The Go Authors.  All rights reserved.
    10	//
    11	// Permission is hereby granted, free of charge, to any person obtaining a copy
    12	// of this software and associated documentation files (the "Software"), to deal
    13	// in the Software without restriction, including without limitation the rights
    14	// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    15	// copies of the Software, and to permit persons to whom the Software is
    16	// furnished to do so, subject to the following conditions:
    17	//
    18	// The above copyright notice and this permission notice shall be included in
    19	// all copies or substantial portions of the Software.
    20	//
    21	// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    22	// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    23	// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
    24	// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    25	// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    26	// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    27	// THE SOFTWARE.
    28	
    29	#include	<u.h>
    30	#include	<libc.h>
    31	#include	<bio.h>
    32	#include	<mach.h>
    33			/* table for selecting machine-dependent parameters */
    34	
    35	typedef	struct machtab Machtab;
    36	
    37	struct machtab
    38	{
    39		char		*name;			/* machine name */
    40		short		type;			/* executable type */
    41		short		boottype;		/* bootable type */
    42		int		asstype;		/* disassembler code */
    43		Mach		*mach;			/* machine description */
    44		Machdata	*machdata;		/* machine functions */
    45	};
    46	
    47	/*
    48	extern	Mach		mmips, msparc, m68020, mi386, mamd64,
    49				marm, mmips2be, mmips2le, mpower, mpower64, malpha, msparc64;
    50	extern	Machdata	mipsmach, sparcmach, m68020mach, i386mach,
    51				armmach, mipsmach2le, powermach, alphamach, sparc64mach;
    52	*/
    53	extern	Mach		mi386, mamd64, marm;
    54	extern	Machdata		i386mach, armmach;
    55	
    56	/*
    57	 *	machine selection table.  machines with native disassemblers should
    58	 *	follow the plan 9 variant in the table; native modes are selectable
    59	 *	only by name.
    60	 */
    61	Machtab	machines[] =
    62	{
    63		{	"386",				/*plan 9 386*/
    64			FI386,
    65			FI386B,
    66			AI386,
    67			&mi386,
    68			&i386mach,	},
    69		{	"amd64",			/*amd64*/
    70			FAMD64,
    71			FAMD64B,
    72			AAMD64,
    73			&mamd64,
    74			&i386mach,	},
    75		{	"arm",				/*ARM*/
    76			FARM,
    77			FARMB,
    78			AARM,
    79			&marm,
    80			&armmach,	},
    81	#ifdef unused
    82		{	"68020",			/*68020*/
    83			F68020,
    84			F68020B,
    85			A68020,
    86			&m68020,
    87			&m68020mach,	},
    88		{	"68020",			/*Next 68040 bootable*/
    89			F68020,
    90			FNEXTB,
    91			A68020,
    92			&m68020,
    93			&m68020mach,	},
    94		{	"mips2LE",			/*plan 9 mips2 little endian*/
    95			FMIPS2LE,
    96			0,
    97			AMIPS,
    98			&mmips2le,
    99			&mipsmach2le, 	},
   100		{	"mips",				/*plan 9 mips*/
   101			FMIPS,
   102			FMIPSB,
   103			AMIPS,
   104			&mmips,
   105			&mipsmach, 	},
   106		{	"mips2",			/*plan 9 mips2*/
   107			FMIPS2BE,
   108			FMIPSB,
   109			AMIPS,
   110			&mmips2be,
   111			&mipsmach, 	},		/* shares debuggers with native mips */
   112		{	"mipsco",			/*native mips - must follow plan 9*/
   113			FMIPS,
   114			FMIPSB,
   115			AMIPSCO,
   116			&mmips,
   117			&mipsmach,	},
   118		{	"sparc",			/*plan 9 sparc */
   119			FSPARC,
   120			FSPARCB,
   121			ASPARC,
   122			&msparc,
   123			&sparcmach,	},
   124		{	"sunsparc",			/*native sparc - must follow plan 9*/
   125			FSPARC,
   126			FSPARCB,
   127			ASUNSPARC,
   128			&msparc,
   129			&sparcmach,	},
   130		{	"86",				/*8086 - a peach of a machine*/
   131			FI386,
   132			FI386B,
   133			AI8086,
   134			&mi386,
   135			&i386mach,	},
   136		{	"power",			/*PowerPC*/
   137			FPOWER,
   138			FPOWERB,
   139			APOWER,
   140			&mpower,
   141			&powermach,	},
   142		{	"power64",			/*PowerPC*/
   143			FPOWER64,
   144			FPOWER64B,
   145			APOWER64,
   146			&mpower64,
   147			&powermach,	},
   148		{	"alpha",			/*Alpha*/
   149			FALPHA,
   150			FALPHAB,
   151			AALPHA,
   152			&malpha,
   153			&alphamach,	},
   154		{	"sparc64",			/*plan 9 sparc64 */
   155			FSPARC64,
   156			FSPARCB,			/* XXX? */
   157			ASPARC64,
   158			&msparc64,
   159			&sparc64mach,	},
   160	#endif
   161		{	0		},		/*the terminator*/
   162	};
   163	
   164	/*
   165	 *	select a machine by executable file type
   166	 */
   167	void
   168	machbytype(int type)
   169	{
   170		Machtab *mp;
   171	
   172		for (mp = machines; mp->name; mp++){
   173			if (mp->type == type || mp->boottype == type) {
   174				asstype = mp->asstype;
   175				machdata = mp->machdata;
   176				break;
   177			}
   178		}
   179	}
   180	/*
   181	 *	select a machine by name
   182	 */
   183	int
   184	machbyname(char *name)
   185	{
   186		Machtab *mp;
   187	
   188		if (!name) {
   189			asstype = AAMD64;
   190			machdata = &i386mach;
   191			mach = &mamd64;
   192			return 1;
   193		}
   194		for (mp = machines; mp->name; mp++){
   195			if (strcmp(mp->name, name) == 0) {
   196				asstype = mp->asstype;
   197				machdata = mp->machdata;
   198				mach = mp->mach;
   199				return 1;
   200			}
   201		}
   202		return 0;
   203	}

release.r60.3. Except as noted, this content is licensed under a Creative Commons Attribution 3.0 License.