Source('types.cc')
GTest('types.test', 'types.test.cc', 'types.cc')
-Source('loader/aout_object.cc')
Source('loader/dtb_file.cc')
-Source('loader/ecoff_object.cc')
Source('loader/elf_object.cc')
Source('loader/image_file_data.cc')
GTest('loader/image_file_data.test', 'loader/image_file_data.test.cc',
GTest('circular_queue.test', 'circular_queue.test.cc')
GTest('sat_counter.test', 'sat_counter.test.cc')
GTest('refcnt.test','refcnt.test.cc')
-GTest('loader/exec_ecoff.test', 'loader/exec_ecoff.test.cc')
-GTest('loader/exec_aout.test', 'loader/exec_aout.test.cc')
GTest('condcodes.test', 'condcodes.test.cc')
GTest('chunk_generator.test', 'chunk_generator.test.cc')
+++ /dev/null
-/*
- * Copyright (c) 2003-2005 The Regents of The University of Michigan
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * Authors: Steve Reinhardt
- */
-
-#include "base/loader/aout_object.hh"
-
-#include <string>
-
-#include "base/loader/exec_aout.h"
-#include "base/loader/symtab.hh"
-#include "base/trace.hh"
-#include "debug/Loader.hh"
-
-using namespace std;
-
-ObjectFile *
-AoutObjectFileFormat::load(ImageFileDataPtr ifd)
-{
- if (!N_BADMAG(*(const aout_exechdr *)ifd->data()))
- return new AoutObject(ifd);
- else
- return nullptr;
-}
-
-namespace
-{
-
-AoutObjectFileFormat aoutObjectFileFormat;
-
-} // anonymous namespace
-
-
-AoutObject::AoutObject(ImageFileDataPtr ifd) : ObjectFile(ifd)
-{
- execHdr = (const aout_exechdr *)imageData->data();
- entry = execHdr->entry;
-
- // Right now this is only used for Alpha PAL code.
- arch = Alpha;
-}
-
-MemoryImage
-AoutObject::buildImage() const
-{
- MemoryImage image({
- MemoryImage::Segment{ "text", N_TXTADDR(*execHdr), imageData,
- N_TXTOFF(*execHdr), execHdr->tsize },
- MemoryImage::Segment{ "data", N_DATADDR(*execHdr), imageData,
- N_DATOFF(*execHdr), execHdr->dsize },
- MemoryImage::Segment{ "bss", N_BSSADDR(*execHdr), execHdr->bsize}
- });
-
- for (auto M5_VAR_USED &seg: image.segments())
- DPRINTFR(Loader, "%s\n", seg);
-
- return image;
-}
+++ /dev/null
-/*
- * Copyright (c) 2003-2005 The Regents of The University of Michigan
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * Authors: Steve Reinhardt
- */
-
-#ifndef __AOUT_OBJECT_HH__
-#define __AOUT_OBJECT_HH__
-
-#include "base/loader/object_file.hh"
-
-// forward decls: avoid including exec_aout.h here
-struct aout_exechdr;
-
-class AoutObject : public ObjectFile
-{
- protected:
- const aout_exechdr *execHdr;
-
- public:
- AoutObject(ImageFileDataPtr ifd);
-
- MemoryImage buildImage() const override;
-};
-
-class AoutObjectFileFormat : public ObjectFileFormat
-{
- public:
- ObjectFile *load(ImageFileDataPtr data) override;
-};
-
-#endif // __AOUT_OBJECT_HH__
+++ /dev/null
-/*
- * Copyright (c) 2003, 2005-2006 The Regents of The University of Michigan
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * Authors: Steve Reinhardt
- */
-
-/*
- * Taken from binutils-2.14.90.0.5 include/coff/sym.h
- */
-
-/* Declarations of internal format of MIPS ECOFF symbols.
- Originally contributed by MIPS Computer Systems and Third Eye Software.
- Changes contributed by Cygnus Support are in the public domain.
-
- This file is just aggregated with the files that make up the GNU
- release; it is not considered part of GAS, GDB, or other GNU
- programs. */
-
-/*
- * |-----------------------------------------------------------|
- * | Copyright (c) 1992, 1991, 1990 MIPS Computer Systems, Inc.|
- * | MIPS Computer Systems, Inc. grants reproduction and use |
- * | rights to all parties, PROVIDED that this comment is |
- * | maintained in the copy. |
- * |-----------------------------------------------------------|
- */
-#ifndef _SYM_H
-#define _SYM_H
-
-/* (C) Copyright 1984 by Third Eye Software, Inc.
- *
- * Third Eye Software, Inc. grants reproduction and use rights to
- * all parties, PROVIDED that this comment is maintained in the copy.
- *
- * Third Eye makes no claims about the applicability of this
- * symbol table to a particular use.
- */
-
-/*
- * This file contains the definition of the Third Eye Symbol Table.
- *
- * Symbols are assumed to be in 'encounter order' - i.e. the order that
- * the things they represent were encountered by the compiler/assembler/loader.
- * EXCEPT for globals! These are assumed to be bunched together,
- * probably right after the last 'normal' symbol. Globals ARE sorted
- * in ascending order.
- *
- * -----------------------------------------------------------------------
- * A brief word about Third Eye naming/use conventions:
- *
- * All arrays and index's are 0 based.
- * All "ifooMax" values are the highest legal value PLUS ONE. This makes
- * them good for allocating arrays, etc. All checks are "ifoo < ifooMax".
- *
- * "isym" Index into the SYMbol table.
- * "ipd" Index into the Procedure Descriptor array.
- * "ifd" Index into the File Descriptor array.
- * "iss" Index into String Space.
- * "cb" Count of Bytes.
- * "rgPd" array whose domain is "0..ipdMax-1" and RanGe is PDR.
- * "rgFd" array whose domain is "0..ifdMax-1" and RanGe is FDR.
- */
-
-
-/*
- * Symbolic Header (HDR) structure.
- * As long as all the pointers are set correctly,
- * we don't care WHAT order the various sections come out in!
- *
- * A file produced solely for the use of CDB will probably NOT have
- * any instructions or data areas in it, as these are available
- * in the original.
- */
-
-typedef struct ecoff_symhdr {
- coff_short magic; /* to verify validity of the table */
- coff_short vstamp; /* version stamp */
- coff_int ilineMax; /* number of line number entries */
- coff_int idnMax; /* max index into dense number table */
- coff_int ipdMax; /* number of procedures */
- coff_int isymMax; /* number of local symbols */
- coff_int ioptMax; /* max index into optimization symbol entries */
- coff_int iauxMax; /* number of auxillary symbol entries */
- coff_int issMax; /* max index into local strings */
- coff_int issExtMax; /* max index into external strings */
- coff_int ifdMax; /* number of file descriptor entries */
- coff_int crfd; /* number of relative file descriptor entries */
- coff_int iextMax; /* max index into external symbols */
- coff_addr cbLine; /* number of bytes for line number entries */
- coff_addr cbLineOffset; /* offset to start of line number entries*/
- coff_addr cbDnOffset; /* offset to start dense number table */
- coff_addr cbPdOffset; /* offset to procedure descriptor table */
- coff_addr cbSymOffset; /* offset to start of local symbols*/
- coff_addr cbOptOffset; /* offset to optimization symbol entries */
- coff_addr cbAuxOffset; /* offset to start of auxillary symbol entries*/
- coff_addr cbSsOffset; /* offset to start of local strings */
- coff_addr cbSsExtOffset; /* offset to start of external strings */
- coff_addr cbFdOffset; /* offset to file descriptor table */
- coff_addr cbRfdOffset; /* offset to relative file descriptor table */
- coff_addr cbExtOffset; /* offset to start of external symbol entries*/
- /* If you add machine dependent fields, add them here */
-} HDRR, *pHDRR;
-#define cbHDRR sizeof(HDRR)
-#define hdrNil ((pHDRR)0)
-
-/*
- * The FDR and PDR structures speed mapping of address <-> name.
- * They are sorted in ascending memory order and are kept in
- * memory by CDB at runtime.
- */
-
-/*
- * File Descriptor
- *
- * There is one of these for EVERY FILE, whether compiled with
- * full debugging symbols or not. The name of a file should be
- * the path name given to the compiler. This allows the user
- * to simply specify the names of the directories where the COMPILES
- * were done, and we will be able to find their files.
- * A field whose comment starts with "R - " indicates that it will be
- * setup at runtime.
- */
-typedef struct ecoff_fdr {
- coff_addr adr; /* memory address of beginning of file */
- coff_addr cbLineOffset; /* byte offset from header for this file ln's */
- coff_addr cbLine; /* size of lines for this file */
- coff_addr cbSs; /* number of bytes in the ss */
- coff_int rss; /* file name (of source, if known) */
- coff_int issBase; /* file's string space */
- coff_int isymBase; /* beginning of symbols */
- coff_int csym; /* count file's of symbols */
- coff_int ilineBase; /* file's line symbols */
- coff_int cline; /* count of file's line symbols */
- coff_int ioptBase; /* file's optimization entries */
- coff_int copt; /* count of file's optimization entries */
- coff_int ipdFirst; /* start of procedures for this file */
- coff_int cpd; /* count of procedures for this file */
- coff_int iauxBase; /* file's auxiliary entries */
- coff_int caux; /* count of file's auxiliary entries */
- coff_int rfdBase; /* index into the file indirect table */
- coff_int crfd; /* count file indirect entries */
- unsigned lang: 5; /* language for this file */
- unsigned fMerge : 1; /* whether this file can be merged */
- unsigned fReadin : 1; /* true if it was read in (not just created) */
- unsigned fBigendian : 1;/* if set, was compiled on big endian machine */
- /* aux's will be in compile host's sex */
- unsigned glevel : 2; /* level this file was compiled with */
- unsigned reserved : 22; /* reserved for future use */
- coff_uint reserved2;
-} FDR, *pFDR;
-#define cbFDR sizeof(FDR)
-#define fdNil ((pFDR)0)
-#define ifdNil -1
-#define ifdTemp 0
-#define ilnNil -1
-
-
-/*
- * Procedure Descriptor
- *
- * There is one of these for EVERY TEXT LABEL.
- * If a procedure is in a file with full symbols, then isym
- * will point to the PROC symbols, else it will point to the
- * global symbol for the label.
- */
-
-typedef struct pdr {
- coff_addr adr; /* memory address of start of procedure */
- coff_addr cbLineOffset; /* byte offset for this procedure from the fd base */
- coff_int isym; /* start of local symbol entries */
- coff_int iline; /* start of line number entries*/
- coff_uint regmask; /* save register mask */
- coff_int regoffset; /* save register offset */
- coff_int iopt; /* start of optimization symbol entries*/
- coff_uint fregmask; /* save floating point register mask */
- coff_int fregoffset; /* save floating point register offset */
- coff_int frameoffset; /* frame size */
- coff_int lnLow; /* lowest line in the procedure */
- coff_int lnHigh; /* highest line in the procedure */
- /* These fields are new for 64 bit ECOFF. */
- unsigned gp_prologue : 8; /* byte size of GP prologue */
- unsigned gp_used : 1; /* true if the procedure uses GP */
- unsigned reg_frame : 1; /* true if register frame procedure */
- unsigned prof : 1; /* true if compiled with -pg */
- unsigned reserved : 13; /* reserved: must be zero */
- unsigned localoff : 8; /* offset of local variables from vfp */
- coff_short framereg; /* frame pointer register */
- coff_short pcreg; /* offset or reg of return pc */
-} PDR, *pPDR;
-#define cbPDR sizeof(PDR)
-#define pdNil ((pPDR) 0)
-#define ipdNil -1
-
-/*
- * Line Numbers
- *
- * Line Numbers are segregated from the normal symbols because they
- * are [1] smaller , [2] are of no interest to your
- * average loader, and [3] are never needed in the middle of normal
- * scanning and therefore slow things down.
- *
- * By definition, the first LINER for any given procedure will have
- * the first line of a procedure and represent the first address.
- */
-
-typedef coff_int LINER, *pLINER;
-#define lineNil ((pLINER)0)
-#define cbLINER sizeof(LINER)
-#define ilineNil -1
-
-
-
-/*
- * The Symbol Structure (GFW, to those who Know!)
- */
-
-typedef struct ecoff_sym {
- coff_long value; /* value of symbol */
- coff_int iss; /* index into String Space of name */
- unsigned st : 6; /* symbol type */
- unsigned sc : 5; /* storage class - text, data, etc */
- unsigned reserved : 1; /* reserved */
- unsigned index : 20; /* index into sym/aux table */
-} SYMR, *pSYMR;
-#define symNil ((pSYMR)0)
-#define cbSYMR sizeof(SYMR)
-#define isymNil -1
-#define indexNil 0xfffff
-#define issNil -1
-#define issNull 0
-
-
-/* The following converts a memory resident string to an iss.
- * This hack is recognized in SbFIss, in sym.c of the debugger.
- */
-#define IssFSb(sb) (0x80000000 | ((coff_ulong)(sb)))
-
-/* E X T E R N A L S Y M B O L R E C O R D
- *
- * Same as the SYMR except it contains file context to determine where
- * the index is.
- */
-typedef struct ecoff_extsym {
- SYMR asym; /* symbol for the external */
- unsigned jmptbl:1; /* symbol is a jump table entry for shlibs */
- unsigned cobol_main:1; /* symbol is a cobol main procedure */
- unsigned weakext:1; /* symbol is weak external */
- unsigned reserved:29; /* reserved for future use */
- coff_int ifd; /* where the iss and index fields point into */
-} EXTR, *pEXTR;
-#define extNil ((pEXTR)0)
-#define cbEXTR sizeof(EXTR)
-
-
-/* A U X I L L A R Y T Y P E I N F O R M A T I O N */
-
-/*
- * Type Information Record
- */
-typedef struct {
- unsigned fBitfield : 1; /* set if bit width is specified */
- unsigned continued : 1; /* indicates additional TQ info in next AUX */
- unsigned bt : 6; /* basic type */
- unsigned tq4 : 4;
- unsigned tq5 : 4;
- /* ---- 16 bit boundary ---- */
- unsigned tq0 : 4;
- unsigned tq1 : 4; /* 6 type qualifiers - tqPtr, etc. */
- unsigned tq2 : 4;
- unsigned tq3 : 4;
-} TIR, *pTIR;
-#define cbTIR sizeof(TIR)
-#define tiNil ((pTIR)0)
-#define itqMax 6
-
-/*
- * Relative symbol record
- *
- * If the rfd field is 4095, the index field indexes into the global symbol
- * table.
- */
-
-typedef struct {
- unsigned rfd : 12; /* index into the file indirect table */
- unsigned index : 20; /* index int sym/aux/iss tables */
-} RNDXR, *pRNDXR;
-#define cbRNDXR sizeof(RNDXR)
-#define rndxNil ((pRNDXR)0)
-
-/* dense numbers or sometimes called block numbers are stored in this type,
- * a rfd of 0xffffffff is an index into the global table.
- */
-typedef struct {
- coff_uint rfd; /* index into the file table */
- coff_uint index; /* index int sym/aux/iss tables */
-} DNR, *pDNR;
-#define cbDNR sizeof(DNR)
-#define dnNil ((pDNR)0)
-
-
-
-/*
- * Auxillary information occurs only if needed.
- * It ALWAYS occurs in this order when present.
-
- isymMac used by stProc only
- TIR type info
- TIR additional TQ info (if first TIR was not enough)
- rndx if (bt == btStruct,btUnion,btEnum,btSet,btRange,
- btTypedef):
- rsym.index == iaux for btSet or btRange
- else rsym.index == isym
- dimLow btRange, btSet
- dimMac btRange, btSet
- rndx0 As many as there are tq arrays
- dimLow0
- dimHigh0
- ...
- rndxMax-1
- dimLowMax-1
- dimHighMax-1
- width in bits if (bit field), width in bits.
- */
-#define cAuxMax (6 + (idimMax*3))
-
-/* a union of all possible info in the AUX universe */
-typedef union {
- TIR ti; /* type information record */
- RNDXR rndx; /* relative index into symbol table */
- coff_int dnLow; /* low dimension */
- coff_int dnHigh; /* high dimension */
- coff_int isym; /* symbol table index (end of proc) */
- coff_int iss; /* index into string space (not used) */
- coff_int width; /* width for non-default sized struc fields */
- coff_int count; /* count of ranges for variant arm */
-} AUXU, *pAUXU;
-#define cbAUXU sizeof(AUXU)
-#define auxNil ((pAUXU)0)
-#define iauxNil -1
-
-
-/*
- * Optimization symbols
- *
- * Optimization symbols contain some overlap information with the normal
- * symbol table. In particular, the proc information
- * is somewhat redundant but necessary to easily find the other information
- * present.
- *
- * All of the offsets are relative to the beginning of the last otProc
- */
-
-typedef struct {
- unsigned ot: 8; /* optimization type */
- unsigned value: 24; /* address where we are moving it to */
- RNDXR rndx; /* points to a symbol or opt entry */
- coff_ulong offset; /* relative offset this occured */
-} OPTR, *pOPTR;
-#define optNil ((pOPTR) 0)
-#define cbOPTR sizeof(OPTR)
-#define ioptNil -1
-
-/*
- * File Indirect
- *
- * When a symbol is referenced across files the following procedure is used:
- * 1) use the file index to get the File indirect entry.
- * 2) use the file indirect entry to get the File descriptor.
- * 3) add the sym index to the base of that file's sym table
- *
- */
-
-typedef coff_long RFDT, *pRFDT;
-#define cbRFDT sizeof(RFDT)
-#define rfdNil -1
-
-/*
- * The file indirect table in the mips loader is known as an array of FITs.
- * This is done to keep the code in the loader readable in the area where
- * these tables are merged. Note this is only a name change.
- */
-typedef coff_int FIT, *pFIT;
-#define cbFIT sizeof(FIT)
-#define ifiNil -1
-#define fiNil ((pFIT) 0)
-
-#ifdef _LANGUAGE_PASCAL
-#define ifdNil -1
-#define ilnNil -1
-#define ipdNil -1
-#define ilineNil -1
-#define isymNil -1
-#define indexNil 16#fffff
-#define issNil -1
-#define issNull 0
-#define itqMax 6
-#define iauxNil -1
-#define ioptNil -1
-#define rfdNil -1
-#define ifiNil -1
-#endif /* _LANGUAGE_PASCAL */
-
-
-/* Dense numbers
- *
- * Rather than use file index, symbol index pairs to represent symbols
- * and globals, we use dense number so that they can be easily embeded
- * in intermediate code and the programs that process them can
- * use direct access tabls instead of hash table (which would be
- * necesary otherwise because of the sparse name space caused by
- * file index, symbol index pairs. Dense number are represented
- * by RNDXRs.
- */
-
-/*
- * The following table defines the meaning of each SYM field as
- * a function of the "st". (scD/B == scData OR scBss)
- *
- * Note: the value "isymMac" is used by symbols that have the concept
- * of enclosing a block of related information. This value is the
- * isym of the first symbol AFTER the end associated with the primary
- * symbol. For example if a procedure was at isym==90 and had an
- * isymMac==155, the associated end would be at isym==154, and the
- * symbol at 155 would probably (although not necessarily) be the
- * symbol for the next procedure. This allows rapid skipping over
- * internal information of various sorts. "stEnd"s ALWAYS have the
- * isym of the primary symbol that started the block.
- *
-
-ST SC VALUE INDEX
--------- ------ -------- ------
-stFile scText address isymMac
-stLabel scText address ---
-stGlobal scD/B address iaux
-stStatic scD/B address iaux
-stParam scAbs offset iaux
-stLocal scAbs offset iaux
-stProc scText address iaux (isymMac is first AUX)
-stStaticProc scText address iaux (isymMac is first AUX)
-
-stMember scNil ordinal --- (if member of enum)
- (mipsread thinks the case below has a bit, not byte, offset.)
-stMember scNil byte offset iaux (if member of struct/union)
-stMember scBits bit offset iaux (bit field spec)
-
-stBlock scText address isymMac (text block)
- (the code seems to think that rather than scNil, we see scInfo for
- the two cases below.)
-stBlock scNil cb isymMac (struct/union member define)
-stBlock scNil cMembers isymMac (enum member define)
-
- (New types added by SGI to simplify things:)
-stStruct scInfo cb isymMac (struct type define)
-stUnion scInfo cb isymMac (union type define)
-stEnum scInfo cMembers isymMac (enum type define)
-
-stEnd scText address isymStart
-stEnd scNil ------- isymStart (struct/union/enum)
-
-stTypedef scNil ------- iaux
-stRegReloc sc??? value old register number
-stForward sc??? new address isym to original symbol
-
-stConstant scInfo value --- (scalar)
-stConstant scInfo iss --- (complex, e.g. string)
-
- *
- */
-#endif
+++ /dev/null
-/*
- * Copyright (c) 2003, 2005-2006 The Regents of The University of Michigan
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * Authors: Steve Reinhardt
- */
-
-/*
- * Taken from binutils-2.14.90.0.5 include/coff/symconst.h
- */
-
-/* Declarations of constants for internal format of MIPS ECOFF symbols.
- Originally contributed by MIPS Computer Systems and Third Eye Software.
- Changes contributed by Cygnus Support are in the public domain.
-
- This file is just aggregated with the files that make up the GNU
- release; it is not considered part of GAS, GDB, or other GNU
- programs. */
-
-/*
- * |-----------------------------------------------------------|
- * | Copyright (c) 1992, 1991, 1990 MIPS Computer Systems, Inc.|
- * | MIPS Computer Systems, Inc. grants reproduction and use |
- * | rights to all parties, PROVIDED that this comment is |
- * | maintained in the copy. |
- * |-----------------------------------------------------------|
- */
-
-/* (C) Copyright 1984 by Third Eye Software, Inc.
- *
- * Third Eye Software, Inc. grants reproduction and use rights to
- * all parties, PROVIDED that this comment is maintained in the copy.
- *
- * Third Eye makes no claims about the applicability of this
- * symbol table to a particular use.
- */
-
-/* glevels for field in FDR */
-#define GLEVEL_0 2
-#define GLEVEL_1 1
-#define GLEVEL_2 0 /* for upward compat reasons. */
-#define GLEVEL_3 3
-
-/* magic number fo symheader */
-#define magicSym 0x7009
-/* The Alpha uses this value instead, for some reason. */
-#define magicSym2 0x1992
-
-/* Language codes */
-#define langC 0
-#define langPascal 1
-#define langFortran 2
-#define langAssembler 3 /* one Assembley inst might map to many mach */
-#define langMachine 4
-#define langNil 5
-#define langAda 6
-#define langPl1 7
-#define langCobol 8
-#define langStdc 9 /* FIXME: Collides with SGI langCplusplus */
-#define langCplusplus 9 /* FIXME: Collides with langStdc */
-#define langCplusplusV2 10 /* SGI addition */
-#define langMax 11 /* maximun allowed 32 -- 5 bits */
-
-/* The following are value definitions for the fields in the SYMR */
-
-/*
- * Storage Classes
- */
-
-#define scNil 0
-#define scText 1 /* text symbol */
-#define scData 2 /* initialized data symbol */
-#define scBss 3 /* un-initialized data symbol */
-#define scRegister 4 /* value of symbol is register number */
-#define scAbs 5 /* value of symbol is absolute */
-#define scUndefined 6 /* who knows? */
-#define scCdbLocal 7 /* variable's value is IN se->va.?? */
-#define scBits 8 /* this is a bit field */
-#define scCdbSystem 9 /* variable's value is IN CDB's address space */
-#define scDbx 9 /* overlap dbx internal use */
-#define scRegImage 10 /* register value saved on stack */
-#define scInfo 11 /* symbol contains debugger information */
-#define scUserStruct 12 /* address in struct user for current process */
-#define scSData 13 /* load time only small data */
-#define scSBss 14 /* load time only small common */
-#define scRData 15 /* load time only read only data */
-#define scVar 16 /* Var parameter (fortran,pascal) */
-#define scCommon 17 /* common variable */
-#define scSCommon 18 /* small common */
-#define scVarRegister 19 /* Var parameter in a register */
-#define scVariant 20 /* Variant record */
-#define scSUndefined 21 /* small undefined(external) data */
-#define scInit 22 /* .init section symbol */
-#define scBasedVar 23 /* Fortran or PL/1 ptr based var */
-#define scXData 24 /* exception handling data */
-#define scPData 25 /* Procedure section */
-#define scFini 26 /* .fini section */
-#define scRConst 27 /* .rconst section */
-#define scMax 32
-
-
-/*
- * Symbol Types
- */
-
-#define stNil 0 /* Nuthin' special */
-#define stGlobal 1 /* external symbol */
-#define stStatic 2 /* static */
-#define stParam 3 /* procedure argument */
-#define stLocal 4 /* local variable */
-#define stLabel 5 /* label */
-#define stProc 6 /* " " Procedure */
-#define stBlock 7 /* beginnning of block */
-#define stEnd 8 /* end (of anything) */
-#define stMember 9 /* member (of anything - struct/union/enum */
-#define stTypedef 10 /* type definition */
-#define stFile 11 /* file name */
-#define stRegReloc 12 /* register relocation */
-#define stForward 13 /* forwarding address */
-#define stStaticProc 14 /* load time only static procs */
-#define stConstant 15 /* const */
-#define stStaParam 16 /* Fortran static parameters */
- /* These new symbol types have been recently added to SGI machines. */
-#define stStruct 26 /* Beginning of block defining a struct type */
-#define stUnion 27 /* Beginning of block defining a union type */
-#define stEnum 28 /* Beginning of block defining an enum type */
-#define stIndirect 34 /* Indirect type specification */
- /* Pseudo-symbols - internal to debugger */
-#define stStr 60 /* string */
-#define stNumber 61 /* pure number (ie. 4 NOR 2+2) */
-#define stExpr 62 /* 2+2 vs. 4 */
-#define stType 63 /* post-coersion SER */
-#define stMax 64
-
-/* definitions for fields in TIR */
-
-/* type qualifiers for ti.tq0 -> ti.(itqMax-1) */
-#define tqNil 0 /* bt is what you see */
-#define tqPtr 1 /* pointer */
-#define tqProc 2 /* procedure */
-#define tqArray 3 /* duh */
-#define tqFar 4 /* longer addressing - 8086/8 land */
-#define tqVol 5 /* volatile */
-#define tqConst 6 /* const */
-#define tqMax 8
-
-/* basic types as seen in ti.bt */
-#define btNil 0 /* undefined (also, enum members) */
-#define btAdr 1 /* address - integer same size as pointer */
-#define btChar 2 /* character */
-#define btUChar 3 /* unsigned character */
-#define btShort 4 /* short */
-#define btUShort 5 /* unsigned short */
-#define btInt 6 /* int */
-#define btUInt 7 /* unsigned int */
-#define btLong 8 /* long */
-#define btULong 9 /* unsigned long */
-#define btFloat 10 /* float (real) */
-#define btDouble 11 /* Double (real) */
-#define btStruct 12 /* Structure (Record) */
-#define btUnion 13 /* Union (variant) */
-#define btEnum 14 /* Enumerated */
-#define btTypedef 15 /* defined via a typedef, isymRef points */
-#define btRange 16 /* subrange of int */
-#define btSet 17 /* pascal sets */
-#define btComplex 18 /* fortran complex */
-#define btDComplex 19 /* fortran double complex */
-#define btIndirect 20 /* forward or unnamed typedef */
-#define btFixedDec 21 /* Fixed Decimal */
-#define btFloatDec 22 /* Float Decimal */
-#define btString 23 /* Varying Length Character String */
-#define btBit 24 /* Aligned Bit String */
-#define btPicture 25 /* Picture */
-#define btVoid 26 /* void */
-#define btLongLong 27 /* long long */
-#define btULongLong 28 /* unsigned long long */
-#define btMax 64
+++ /dev/null
-/*
- * Copyright (c) 2003-2005 The Regents of The University of Michigan
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * Authors: Steve Reinhardt
- */
-
-#include "base/loader/ecoff_object.hh"
-
-#include <string>
-
-#include "base/loader/symtab.hh"
-#include "base/logging.hh"
-#include "base/trace.hh"
-#include "base/types.hh"
-#include "debug/Loader.hh"
-
-// Only alpha will be able to load ecoff files for now.
-// base/types.hh and ecoff_machdep.h must be before the other .h files
-// because they are are gathered from other code bases and require some
-// typedefs from those files.
-#include "arch/alpha/ecoff_machdep.h"
-#include "base/loader/coff_sym.h"
-#include "base/loader/coff_symconst.h"
-#include "base/loader/exec_ecoff.h"
-
-using namespace std;
-
-ObjectFile *
-EcoffObjectFormat::load(ImageFileDataPtr ifd)
-{
- if (((const ecoff_filehdr *)ifd->data())->f_magic == ECOFF_MAGIC_ALPHA)
- return new EcoffObject(ifd);
- else
- return nullptr;
-}
-
-namespace
-{
-
-EcoffObjectFormat ecoffObjectFormat;
-
-} // anonymous namespace
-
-
-EcoffObject::EcoffObject(ImageFileDataPtr ifd) : ObjectFile(ifd)
-{
- execHdr = (const ecoff_exechdr *)imageData->data();
- fileHdr = &(execHdr->f);
- aoutHdr = &(execHdr->a);
-
- entry = aoutHdr->entry;
- // it's Alpha ECOFF
- arch = Alpha;
- opSys = Tru64;
-}
-
-MemoryImage
-EcoffObject::buildImage() const
-{
- MemoryImage image({
- { "text", aoutHdr->text_start, imageData,
- ECOFF_TXTOFF(execHdr), aoutHdr->tsize },
- { "data", aoutHdr->data_start, imageData,
- ECOFF_DATOFF(execHdr), aoutHdr->dsize },
- { "bss", aoutHdr->bss_start, aoutHdr->bsize }
- });
-
- for (auto M5_VAR_USED &seg: image.segments())
- DPRINTFR(Loader, "%s\n", seg);
-
- return image;
-}
-
-bool
-EcoffObject::loadAllSymbols(SymbolTable *symtab, Addr base, Addr offset,
- Addr addr_mask)
-{
- bool retval = loadGlobalSymbols(symtab, base, offset, addr_mask);
- retval = retval && loadLocalSymbols(symtab, base, offset, addr_mask);
- return retval;
-}
-
-bool
-EcoffObject::loadGlobalSymbols(SymbolTable *symtab, Addr base, Addr offset,
- Addr addr_mask)
-{
- if (!symtab)
- return false;
-
- if (fileHdr->f_magic != ECOFF_MAGIC_ALPHA) {
- warn("loadGlobalSymbols: wrong magic on %s\n", imageData->filename());
- return false;
- }
-
- auto *syms = (const ecoff_symhdr *)(imageData->data() + fileHdr->f_symptr);
- if (syms->magic != magicSym2) {
- warn("loadGlobalSymbols: bad symbol header magic on %s\n",
- imageData->filename());
- return false;
- }
-
- auto *ext_syms = (const ecoff_extsym *)(
- imageData->data() + syms->cbExtOffset);
-
- auto *ext_strings =
- (const char *)(imageData->data() + syms->cbSsExtOffset);
- for (int i = 0; i < syms->iextMax; i++) {
- const ecoff_sym *entry = &(ext_syms[i].asym);
- if (entry->iss != -1)
- symtab->insert(entry->value, ext_strings + entry->iss);
- }
-
- return true;
-}
-
-bool
-EcoffObject::loadLocalSymbols(SymbolTable *symtab, Addr base, Addr offset,
- Addr addr_mask)
-{
- if (!symtab)
- return false;
-
- if (fileHdr->f_magic != ECOFF_MAGIC_ALPHA) {
- warn("loadGlobalSymbols: wrong magic on %s\n", imageData->filename());
- return false;
- }
-
- auto *syms = (const ecoff_symhdr *)(imageData->data() + fileHdr->f_symptr);
- if (syms->magic != magicSym2) {
- warn("loadGlobalSymbols: bad symbol header magic on %s\n",
- imageData->filename());
- return false;
- }
-
- auto *local_syms =
- (const ecoff_sym *)(imageData->data() + syms->cbSymOffset);
- auto *local_strings = (const char *)(imageData->data() + syms->cbSsOffset);
- auto *fdesc = (const ecoff_fdr *)(imageData->data() + syms->cbFdOffset);
-
- for (int i = 0; i < syms->ifdMax; i++) {
- auto *entry = (const ecoff_sym *)(local_syms + fdesc[i].isymBase);
- auto *strings = (const char *)(local_strings + fdesc[i].issBase);
- for (int j = 0; j < fdesc[i].csym; j++) {
- if (entry[j].st == stGlobal || entry[j].st == stProc)
- if (entry[j].iss != -1)
- symtab->insert(entry[j].value, strings + entry[j].iss);
- }
- }
-
- for (int i = 0; i < syms->isymMax; i++) {
- const ecoff_sym *entry = &(local_syms[i]);
- if (entry->st == stProc)
- symtab->insert(entry->value, local_strings + entry->iss);
- }
-
- return true;
-}
+++ /dev/null
-/*
- * Copyright (c) 2003-2005 The Regents of The University of Michigan
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * Authors: Steve Reinhardt
- */
-
-#ifndef __BASE_LOADER_ECOFF_OBJECT_HH__
-#define __BASE_LOADER_ECOFF_OBJECT_HH__
-
-#include "base/loader/object_file.hh"
-
-// forward decls: avoid including exec_ecoff.h here
-struct ecoff_exechdr;
-struct ecoff_filehdr;
-struct ecoff_aouthdr;
-
-class EcoffObjectFormat : public ObjectFileFormat
-{
- public:
- ObjectFile *load(ImageFileDataPtr data) override;
-};
-
-class EcoffObject : public ObjectFile
-{
- protected:
- const ecoff_exechdr *execHdr;
- const ecoff_filehdr *fileHdr;
- const ecoff_aouthdr *aoutHdr;
-
- public:
- EcoffObject(ImageFileDataPtr ifd);
-
- MemoryImage buildImage() const override;
-
- bool loadAllSymbols(SymbolTable *symtab, Addr base=0,
- Addr offset=0, Addr addr_mask=MaxAddr) override;
- bool loadGlobalSymbols(SymbolTable *symtab, Addr base=0,
- Addr offset=0, Addr addr_mask=MaxAddr) override;
- bool loadLocalSymbols(SymbolTable *symtab, Addr base=0,
- Addr offset=0, Addr addr_mask=MaxAddr) override;
-};
-
-#endif // __BASE_LOADER_ECOFF_OBJECT_HH__
fatal("The binary you're trying to load is compiled for 64-bit "
"Power. M5\n only supports 32-bit Power. Please "
"recompile your binary.\n");
- } else if (eclass == ELFCLASS64) {
- // Since we don't know how to check for alpha right now, we'll
- // just assume if it wasn't something else and it's 64 bit, that's
- // what it must be.
- arch = Alpha;
} else {
warn("Unknown architecture: %d\n", emach);
}
+++ /dev/null
-/*
- * Taken from NetBSD sys/exec_aout.h
- */
-
-/* $NetBSD: exec_aout.h,v 1.29 2002/12/10 17:14:31 thorpej Exp $ */
-
-/*
- * Copyright (c) 1993, 1994 Christopher G. Demetriou
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by Christopher G. Demetriou.
- * 4. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef _SYS_EXEC_AOUT_H_
-#define _SYS_EXEC_AOUT_H_
-
-#ifndef N_PAGSIZ
-#define N_PAGSIZ(ex) (AOUT_LDPGSZ)
-#endif
-
-/* a_magic */
-#define OMAGIC 0407 /* old impure format */
-#define NMAGIC 0410 /* read-only text */
-#define ZMAGIC 0413 /* demand load format */
-
-#define N_ALIGN(ex,x) \
- (N_GETMAGIC(ex) == ZMAGIC ? \
- ((x) + AOUT_LDPGSZ - 1) & ~(AOUT_LDPGSZ - 1) : (x))
-
-/* Valid magic number check. */
-#define N_BADMAG(ex) \
- (N_GETMAGIC(ex) != NMAGIC && N_GETMAGIC(ex) != OMAGIC && \
- N_GETMAGIC(ex) != ZMAGIC)
-
-//Only alpha will be able to load aout for now
-#include "arch/alpha/aout_machdep.h"
-
-#endif /* !_SYS_EXEC_AOUT_H_ */
+++ /dev/null
-/*
- * Copyright (c) 2019 The Regents of the University of California
- * All rights reserved
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * Authors: Bobby R. Bruce
- */
-
-
-#include <gtest/gtest.h>
-
-#include "base/loader/exec_aout.h"
-
-#define OMAGIC_STRUCT (*((const aout_exechdr *)omagic))
-#define NMAGIC_STRUCT (*((const aout_exechdr *)nmagic))
-#define ZMAGIC_STRUCT (*((const aout_exechdr *)zmagic))
-#define NO_MAGIC_STRUCT (*((const aout_exechdr *)no_magic))
-
-#if (defined(_BIG_ENDIAN) || !defined(_LITTLE_ENDIAN))\
- && BYTE_ORDER==BIG_ENDIAN
-const uint8_t omagic[] {
- 0x01, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00
-};
-
-const uint8_t nmagic[] {
- 0x01, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00
-};
-
-const uint8_t zmagic[] {
- 0x01, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00
-};
-
-const uint8_t no_magic[] {
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x01, 0x00
-};
-#elif defined(_LITTLE_ENDIAN) || BYTE_ORDER==LITTLE_ENDIAN
-const uint8_t omagic[] {
- 0x07, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00
-};
-
-const uint8_t nmagic[] {
- 0x08, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00
-};
-
-const uint8_t zmagic[] {
- 0x0B, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00
-};
-
-const uint8_t no_magic[] {
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x01
-};
-#else
- #error Invalid Endianess
-#endif
-
-TEST(ExecAoutTest, IsNotBadMagicNumber)
-{
- EXPECT_FALSE(N_BADMAG(OMAGIC_STRUCT));
- EXPECT_FALSE(N_BADMAG(NMAGIC_STRUCT));
- EXPECT_FALSE(N_BADMAG(ZMAGIC_STRUCT));
-}
-
-TEST(ExecAoutTest, IsBadMagicNumber)
-{
- EXPECT_TRUE(N_BADMAG(NO_MAGIC_STRUCT));
-}
-
-TEST(ExecAoutTest, AlignNotZmagic)
-{
- /*
- * N_ALIGN will return x if the aout_exechdr does not have ZMAGIC as a
- * magic number.
- */
- int64_t x = 0xABCD;
- EXPECT_EQ(x, N_ALIGN(OMAGIC_STRUCT, x));
- EXPECT_EQ(x, N_ALIGN(NMAGIC_STRUCT, x));
- EXPECT_EQ(x, N_ALIGN(NO_MAGIC_STRUCT, x));
-}
-
-TEST(ExecAoutTest, AlignIsZmagic)
-{
- /*
- * N_ALIGN will round up X by AOUT_LDPGSZ (1 << 13) if the aout_exechdr
- * has ZMAGIC as a magic number.
- */
- int64_t x = (1 << 20) + (1 << 18) + (1 << 12) + (1 << 5) + 1;
- EXPECT_EQ((1 << 20) + (1 << 18) + (1 << 13), N_ALIGN(ZMAGIC_STRUCT, x));
-}
-
-TEST(ExecAoutTest, AlignIsZmagicNoRounding)
-{
- /*
- * In this case, there's no rounding needed.
- */
- int64_t x = (1 << 20) + (1 << 18) + (1 << 13);
- EXPECT_EQ(x, N_ALIGN(ZMAGIC_STRUCT, x));
-}
\ No newline at end of file
+++ /dev/null
-/*
- * Taken from NetBSD sys/exec_ecoff.h
- */
-
-/* $NetBSD: exec_ecoff.h,v 1.13 2003/01/18 09:53:18 thorpej Exp $ */
-
-/*
- * Copyright (c) 1994 Adam Glass
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by Adam Glass.
- * 4. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef _SYS_EXEC_ECOFF_H_
-#define _SYS_EXEC_ECOFF_H_
-
-#include "arch/alpha/ecoff_machdep.h"
-
-struct ecoff_filehdr {
- coff_ushort f_magic; /* magic number */
- coff_ushort f_nscns; /* # of sections */
- coff_uint f_timdat; /* time and date stamp */
- coff_ulong f_symptr; /* file offset of symbol table */
- coff_uint f_nsyms; /* # of symbol table entries */
- coff_ushort f_opthdr; /* sizeof the optional header */
- coff_ushort f_flags; /* flags??? */
-};
-
-struct ecoff_aouthdr {
- coff_ushort magic;
- coff_ushort vstamp;
- ECOFF_PAD
- coff_ulong tsize;
- coff_ulong dsize;
- coff_ulong bsize;
- coff_ulong entry;
- coff_ulong text_start;
- coff_ulong data_start;
- coff_ulong bss_start;
- ECOFF_MACHDEP;
-};
-
-struct ecoff_scnhdr { /* needed for size info */
- char s_name[8]; /* name */
- coff_ulong s_paddr; /* physical addr? for ROMing?*/
- coff_ulong s_vaddr; /* virtual addr? */
- coff_ulong s_size; /* size */
- coff_ulong s_scnptr; /* file offset of raw data */
- coff_ulong s_relptr; /* file offset of reloc data */
- coff_ulong s_lnnoptr; /* file offset of line data */
- coff_ushort s_nreloc; /* # of relocation entries */
- coff_ushort s_nlnno; /* # of line entries */
- coff_uint s_flags; /* flags */
-};
-
-struct ecoff_exechdr {
- struct ecoff_filehdr f;
- struct ecoff_aouthdr a;
-};
-
-#define ECOFF_HDR_SIZE (sizeof(struct ecoff_exechdr))
-
-#define ECOFF_OMAGIC 0407
-#define ECOFF_NMAGIC 0410
-#define ECOFF_ZMAGIC 0413
-
-#define ECOFF_ROUND(value, by) \
- (((value) + (by) - 1) & ~((by) - 1))
-
-#define ECOFF_BLOCK_ALIGN(ep, value) \
- ((ep)->a.magic == ECOFF_ZMAGIC ? ECOFF_ROUND((value), ECOFF_LDPGSZ) : \
- (value))
-
-#define ECOFF_TXTOFF(ep) \
- ((ep)->a.magic == ECOFF_ZMAGIC ? 0 : \
- ECOFF_ROUND(ECOFF_HDR_SIZE + (ep)->f.f_nscns * \
- sizeof(struct ecoff_scnhdr), ECOFF_SEGMENT_ALIGNMENT(ep)))
-
-#define ECOFF_DATOFF(ep) \
- (ECOFF_BLOCK_ALIGN((ep), ECOFF_TXTOFF(ep) + (ep)->a.tsize))
-
-#define ECOFF_SEGMENT_ALIGN(ep, value) \
- (ECOFF_ROUND((value), ((ep)->a.magic == ECOFF_ZMAGIC ? ECOFF_LDPGSZ : \
- ECOFF_SEGMENT_ALIGNMENT(ep))))
-
-#endif /* !_SYS_EXEC_ECOFF_H_ */
+++ /dev/null
-/*
- * Copyright (c) 2019 The Regents of the University of California
- * All rights reserved
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * Authors: Bobby R. Bruce
- */
-
-
-#include <gtest/gtest.h>
-
-#include "base/loader/exec_ecoff.h"
-
-#define OMAGIC_STRUCT (*((const ecoff_exechdr *)omagic))
-#define NMAGIC_STRUCT (*((const ecoff_exechdr *)nmagic))
-#define ZMAGIC_STRUCT (*((const ecoff_exechdr *)zmagic))
-#define NO_MAGIC_STRUCT (*((const ecoff_exechdr *)no_magic))
-
-#if (defined(_BIG_ENDIAN) || !defined(_LITTLE_ENDIAN))\
- && BYTE_ORDER==BIG_ENDIAN
-const uint8_t zmagic[] = {
- // ecoff_filehdr
- 0x01, 0x0B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-
- // ecoff_aouthdr
- 0x01, 0x0B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x0A, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
-};
-
-const uint8_t nmagic[] = {
- //ecoff_filehdr
- 0x01, 0x08, 0x00, 0x0F, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
-
- //ecoff_aouthdr
- 0x01, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x0A, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
-};
-
-const uint8_t omagic[] = {
- //ecoff_filehdr
- 0x01, 0x07, 0x00, 0x0A, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-
- //ecoff_aouthdr
- 0x01, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
-};
-#elif defined(_LITTLE_ENDIAN) || BYTE_ORDER==LITTLE_ENDIAN
-const uint8_t zmagic[] = {
- // ecoff_filehdr
- 0x0B, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-
- // ecoff_aouthdr
- 0x0B, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
-};
-
-const uint8_t nmagic[] = {
- //ecoff_filehdr
- 0x08, 0x01, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00,
-
- //ecoff_aouthdr
- 0x08, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x0A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
-};
-
-const uint8_t omagic[] = {
- //ecoff_filehdr
- 0x07, 0x01, 0x0A, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-
- //ecoff_aouthdr
- 0x07, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
-};
-#else
- #error Invalid Endianess
-#endif
-
-
-
-TEST(ExecEcoffTest, Round)
-{
- /*
- * Note: ECOFF_ROUND always rounds up.
- */
- EXPECT_EQ((1 << 10) + (1 << 8) + (1 << 6),
- ECOFF_ROUND((1 << 10) + (1 << 8) + (1 << 5) + (1 << 4) + (1 << 1),
- (1 << 5)));
-
- EXPECT_EQ((1 << 10) + (1 << 8) + (1 << 5),
- ECOFF_ROUND((1 << 10) + (1 << 8) + (1 << 4) + (1 << 1),
- (1 << 5)));
-
- EXPECT_EQ((1 << 10) + (1 << 8) + (1 << 6),
- ECOFF_ROUND((1 << 10) + (1 << 8) + (1 << 5) + (1 << 1),
- (1 << 5)));
-}
-
-TEST(ExecEcoffTest, NoRounding)
-{
- EXPECT_EQ((1 << 10) + (1 << 8) + (1 << 5),
- ECOFF_ROUND((1 << 10) + (1 << 8) + (1 << 5),
- (1 << 5)));
-}
-
-TEST(ExecEcoffTest, BlockAlignWithoutZmagic)
-{
- /*
- * ECOFF_BLOCK_ALIGN will return "value" if "ep->a.magic" is not
- * ECOFF_ZMAGIC.
- */
- u_int64_t value = 0XFFFF;
-
- EXPECT_EQ(value, ECOFF_BLOCK_ALIGN(&OMAGIC_STRUCT, value));
- EXPECT_EQ(value, ECOFF_BLOCK_ALIGN(&OMAGIC_STRUCT, value));
-}
-
-TEST(ExecEcoffTest, BlockAlignWithZmagic)
-{
- /*
- * ECOFF_BLOCK_ALIGN will return "value" rounded ECOFF_LDPGSZ (1 << 12)
- * if "ep->a.magic" is ECOFF_ZMAGIC. This uses ECOFF_ROUND, so will only
- * round up.
- */
- u_int64_t value1 = (1 << 14) + (1 << 13) + (1 << 10) + (1 << 8);
- u_int64_t expected_output1 = (1 << 14) + (1 << 13) + (1 << 12);
- EXPECT_EQ(expected_output1, ECOFF_BLOCK_ALIGN(&ZMAGIC_STRUCT, value1));
-
- u_int64_t value2 = (1 << 10) + (1 << 8);
- u_int64_t expected_output2 = (1 << 12) ;
- EXPECT_EQ(expected_output2, ECOFF_BLOCK_ALIGN(&ZMAGIC_STRUCT, value2));
-}
-
-TEST(ExecEcoffTest, SegmentAlignWithZmagic)
-{
- /*
- * ECOFF_SEGMENT_ALIGN will round "value" rounded by ECOFF_LDPGZ (1 << 12)
- * if "ep->amagic" is ECOFF_ZMAGIC.
- */
- u_int64_t value1 = (1 << 14) + (1 << 13) + (1 << 10) + (1 << 8);
- u_int64_t expected_output1 = (1 << 14) + (1 << 13) + (1 << 12);
- EXPECT_EQ(expected_output1, ECOFF_SEGMENT_ALIGN(&ZMAGIC_STRUCT, value1));
-
- u_int64_t value2 = (1 << 10) + (1 << 8);
- u_int64_t expected_output2 = (1 << 12) ;
- EXPECT_EQ(expected_output2, ECOFF_SEGMENT_ALIGN(&ZMAGIC_STRUCT, value2));
-}
-
-TEST(ExecEcoffTest, SegmentAlignWithoutZmagic)
-{
- /*
- * ECOFF_SEGMENT_ALIGN will return value rounded by the
- * ECOFF_SEGMENT_ALIGNMENT of ep (ECOFF_SEGMENT_ALIGNMENT is defined in
- * "arch/alpha/ecoff_machdep.h") if "ep->amagic" is not ECOFF_ZMAGIC.
- *
- * ECOFF_SEGMENT_ALIGNMENT(ep) will return 8 if the 2nd LSB in
- * "(ep)->f.f_flags" is 0 and 16 if it is 1.
- *
- * "(nmagic)->f.f_flags" is 0x2, and therefore ECOFF_SEGMENT_ALIGN will
- * round value by (1 << 4). "(omagic)->f.f_flags" is 0x0 and, in this
- * case, ECOFF_SEGMENT_ALIGN will round value by (1 << 3).
- */
-
- u_int64_t value = (1 << 14) + (1 << 13) + (1 << 8) + (1 << 4) + (1 << 2)
- + (1 << 1);
-
- EXPECT_EQ((1 << 14) + (1 << 13) + (1 << 8) + (1 << 5),
- ECOFF_SEGMENT_ALIGN(&NMAGIC_STRUCT, value)); // Round by (1 << 4).
- EXPECT_EQ((1 << 14) + (1 << 13) + (1 << 8) + (1 << 4) + (1 << 3),
- ECOFF_SEGMENT_ALIGN(&OMAGIC_STRUCT, value)); // Round by (1 << 3).
-}
-
-TEST(ExecEcoffTest, TxtOffWithMagic)
-{
- /*
- * ECOFF_TXTOFF will return 0 if "(ep)->a.magic" is ECOFF_ZMAGIC
- */
- EXPECT_EQ(0, ECOFF_TXTOFF(&ZMAGIC_STRUCT));
-}
-
-TEST(ExecEcoffTest, TxtOffWithoutMagic)
-{
- /*
- * If "(ep)->a.magic" is not ECOFF_ZMAGIC, ECOFF_TXTOFF will return
- * "(ep)->f.f_nscns" multiplied by ECOFF_HDR_SIZE (sizeof ecoff_scnhdr)
- * plus the size of ecoff_exechdr, roundeded by ECOFF_SEGMENT_ALIGNMENT.
- * The value of ECOFF_SEGMENT_ALIGNMENT will return (1 << 3) if the 2nd
- * LSB in "(ep)->f.f_flags" is 0 and (1 << 4) if it's one.
- *
- * In our setup (omagic)->f.f_flags is 0x0 and (nmagic)->f.f_flags is 0x2.
- * (omagic)->f.f_nscns is 0xA, and (nmagic)->f.f_nscns is 0xF.
- */
-
- /*
- * (sizeof omagic) * 0xA + (sizeof omagic), rounded by (1 << 3).
- */
- u_int64_t expected_output_omagic = ECOFF_ROUND(
- (sizeof(struct ecoff_scnhdr)) * 0xA
- + (sizeof(struct ecoff_exechdr)),
- (1 << 3));
- EXPECT_EQ(expected_output_omagic, ECOFF_TXTOFF(&OMAGIC_STRUCT));
-
- /*
- * (sizeof nmagic) * 0xF + (sizeof nmagic), rounded by (1 << 4).
- */
- u_int64_t expected_output_nmagic = ECOFF_ROUND(
- (sizeof(struct ecoff_scnhdr) * 0xF
- + (sizeof(struct ecoff_exechdr))),
- (1 << 4));
- EXPECT_EQ(expected_output_nmagic, ECOFF_TXTOFF(&NMAGIC_STRUCT));
-}
-
-TEST(ExecEcoffTest, DatOffWithMagic)
-{
- /*
- * f (ep)->a.magic is ECOFF_ZMAGIC, ECOFF_DATOFF will return
- * (ep)->a.tsize plus ECOFF_TXT(ep), rounded by ECOFF_LDPGSZ (1 << 12).
- *
- * (zmagic)->a.tsize is 0xF.
- */
-
- u_int64_t expected_output = ECOFF_ROUND(
- 0xF + ECOFF_TXTOFF(&ZMAGIC_STRUCT), (1 << 12));
- EXPECT_EQ(expected_output, ECOFF_DATOFF(&ZMAGIC_STRUCT));
-}
-
-TEST(ExecEcoffTest, DatOffWithoutMagic)
-{
- /*
- * ECOFF_DATOFF will return (ep)->a.tsize plus ECOFF_TXTOFF(ep) if
- * (ep)->a.magic is not ECOFF_ZMAGIC.
- *
- * (nmagic)->a.tsize is 0xA.
- * (omagic)->a.tsize is 0x1.
- */
-
- u_int64_t expected_output_nmagic = 0xA + ECOFF_TXTOFF(&NMAGIC_STRUCT);
- EXPECT_EQ(expected_output_nmagic, ECOFF_DATOFF(&NMAGIC_STRUCT));
-
- u_int64_t expected_output_omagic = 0x1 + ECOFF_TXTOFF(&OMAGIC_STRUCT);
- EXPECT_EQ(expected_output_omagic, ECOFF_DATOFF(&OMAGIC_STRUCT));
-}
\ No newline at end of file
enum Arch {
UnknownArch,
- Alpha,
SPARC64,
SPARC32,
Mips,