makerom.h 6.36 KB
#ifndef _MAKEROM_H_
#define	_MAKEROM_H_

/**************************************************************************
 *									  *
 *		 Copyright (C) 1994, Silicon Graphics, Inc.		  *
 *									  *
 *  These coded instructions, statements, and computer programs  contain  *
 *  unpublished  proprietary  information of Silicon Graphics, Inc., and  *
 *  are protected by Federal copyright law.  They  may  not be disclosed  *
 *  to  third  parties  or copied or duplicated in any form, in whole or  *
 *  in part, without the prior written consent of Silicon Graphics, Inc.  *
 *									  *
 **************************************************************************/

#ifdef __sgi__
#include <libelf.h>
#else
#include <elf.h>
#include <libelf/libelf.h>
#endif
#include <limits.h>
#include <stdio.h>

/* Patches for IRIX 6.X and MIPSpro 7.1 have been incorporated into the
 *   mainline source code.
 * The patch affected areas in the files makerom.c, elspec.c, and segment.c.
 *
 * Modifications made by Mark A. DeLoura, markdel@noa.com.
 * Completed on 3/4/97.
 */

/* Patches which enable the 'romalign' keyword which was
 *   added to makerom by Kyoto Micro have been incorporated into the
 *   mainline source code.
 * 
 * Their modifications were incorporated into this branch of makerom
 *   on 6/5/97 by Mark.
 */

/* Patches to use the 'objectList' flag to the linker in the final
 *   link stage were incorporated into the mainline source code.
 *
 * Modifications made by Mark A. DeLoura, markdel@noa.com.
 * Completed on 6/3/97.
 */

/* Patches to do automatic alignment of sections, based on the 
 *   requested alignment in the ELF object files, have been 
 *   incorporated into the mainline source code.  This patch gets
 *   around the fact that various linker versions treat the alignment
 *   in different ways.  By doing the alignment ourselves, we ensure
 *   that it is treated properly, and we get around operating system
 *   version checks for the linker.  Well, mostly.
 *
 * These changes were quite extensive and were completed on 6/25/97
 *   by Mark A. DeLoura.
 */

// Some defines for existing sections.
//
#define NO_SECTIONS  0
#define TEXT_EXISTS  1
#define DATA_EXISTS  2
#define SDATA_EXISTS 4
#define BSS_EXISTS   8
#define SBSS_EXISTS 16

typedef struct Path_s {
  struct Path_s *next;
  char	      *name;

  unsigned int		  textSize;
  unsigned int		  dataSize;
  unsigned int		  sdataSize;
  unsigned int		  sbssSize;
  unsigned int		  bssSize;

  unsigned int		  textAlign;
  unsigned int		  dataAlign;
  unsigned int		  sdataAlign;
  unsigned int		  sbssAlign;
  unsigned int		  bssAlign;

  unsigned int		  textStart;
  unsigned int		  dataStart;
  unsigned int		  sdataStart;
  unsigned int		  sbssStart;
  unsigned int		  bssStart;

  unsigned int             sectionsExisting;
} Path;

typedef struct Segment_s {
  struct Segment_s *next;	
  char		 *name;
  struct Path_s	 *pathList;
  struct Wave_s	 *wave;
  unsigned int	  address;
  int		  addrFunc;
  struct Segment_s *afterSeg1;
  struct Segment_s *afterSeg2;
  unsigned int	  align;
  unsigned int	  romOffset;
  int		  flags;
  unsigned int		  textSize;
  unsigned int		  dataSize;
  unsigned int		  sdataSize;
  unsigned int		  sbssSize;
  unsigned int		  bssSize;
  unsigned int		  totalSize;
  unsigned int		  maxSize;

  int		  romalign;

  unsigned int		  textAlign;
  unsigned int		  dataAlign;
  unsigned int		  sdataAlign;
  unsigned int		  sbssAlign;
  unsigned int		  bssAlign;

  unsigned int             sectionsExisting;

  unsigned int		  textStart;
  unsigned int		  dataStart;
  unsigned int		  sdataStart;
  unsigned int		  sbssStart;
  unsigned int		  bssStart;

} Segment;

typedef struct SegmentChain_s {
  struct SegmentChain_s *next;
  struct Segment_s      *segment;
} SegmentChain;

typedef struct Wave_s {
  struct Wave_s	*next;
  char		*name;
  SegmentChain	*segmentChain;
  Elf		*elf;
  Elf32_Ehdr	*ehdr;
  char		elspecFile[_POSIX_PATH_MAX];
  int		fd;
  size_t	searchIndex;	/* Index used in segment.c:lookupShdr() */
} Wave;

#define	SEGFLAG_BOOT	0x1
#define	SEGFLAG_OBJECT	0x2
#define	SEGFLAG_RAW	0x4

#define ADDRESS_NULL    -1

#define ADDRFUNC_NULL   0
#define	AFTERFUNC_UNARY	0x1
#define	AFTERFUNC_MAX	0x2
#define	AFTERFUNC_MIN	0x3
#define ADDRFUNC_ADDRESS 0x4
#define ADDRFUNC_SEGMENT 0x5

#define SizeofEntryRoutine 0x50

#define	ALIGN128(i)	((((i) + 0xf) / 0x10) * 0x10)
#define	ISALIGN128(i)	(((i) & 0xf) == 0)

#define	MIN_ADDRESS	0x00000400
#define	MAX_BOOTSIZE	0x100000

#define OS_VERSION_53    0
#define OS_VERSION_62    1
#define OS_VERSION_63    2
#define OS_VERSION_64    3
#define OS_VERSION_OTHER 4

#define IDO_VERSION_53    0
#define IDO_VERSION_70    1
#define IDO_VERSION_71    2
#define IDO_VERSION_OTHER 3

#ifndef MAX
#define MAX(a,b) (((a)>(b))?(a):(b))
#endif
#ifndef MIN
#define MIN(a,b) (((a)<(b))?(a):(b))
#endif

#define FILLBUFFER 0x2000



/*
 * exports from coff.c
 */
extern int	readCoff(char *, unsigned int *);

/*
 * exports from elspec.c
 */
extern int	createElspec(Wave *);
extern int	runLinker(Wave *, char *, char *);

/*
 * exports from makerom.c
 */
extern int	main(int, char *[]);
extern int	execCommand(char *);

extern Segment		*segmentList;
extern Wave		*waveList;
extern char		*fileName;
extern char		*bootEntryName;
extern char		*bootStackName;
extern unsigned int	bootStackOffset;
extern int		debug;
extern int		cosim;
extern int		emulator;
extern int		loadMap;
extern int		nofont;
extern int		gcord;
extern unsigned char	*bootBuf, *headerBuf, *pif2bootBuf, *fontBuf;
extern int		bootWordAlignedByteSize;
extern int		pif2bootWordAlignedByteSize;
extern int		headerWordAlignedByteSize;
extern int		fontdataWordAlignedByteSize;
extern int		bootAddress;
extern int  		finalromSize;
extern char 		fillData;
extern int  		offset;
extern int		irixVersion;
extern int		booter;

/*
 * exports from segment.c
 */
extern int	scanSegments(void);
extern int	checkSizes(void);
extern int	checkOverlaps(void);
extern int	createSegmentSymbols(char *, char *);
extern int	createRomImage(char *, char *);
extern int	createEntryFile(char *, char *);
extern unsigned int	ALIGNn(unsigned int romalign,int n);


/*
 * exports from specgram.y (and y.tab.c)
 */
extern int	yyparse(void);
extern void	yyerror(char *);


/*
 * exports from speclex.l (and lex.yy.c)
 */
extern int	yylex(void);

extern int	lineNumber;

extern FILE	*yyin;
extern int	yylineno;
#ifdef __sgi_
extern char	yytext[];
#else
extern char	*yytext;
#endif

#endif /* !_MAKEROM_H */