First rudimentary version - can dump xo65 headers
git-svn-id: svn://svn.cc65.org/cc65/trunk@230 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
5
src/od65/.cvsignore
Normal file
5
src/od65/.cvsignore
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
.depend
|
||||||
|
od65
|
||||||
|
*.map
|
||||||
|
*.s
|
||||||
|
|
||||||
112
src/od65/dump.c
Normal file
112
src/od65/dump.c
Normal file
@@ -0,0 +1,112 @@
|
|||||||
|
/*****************************************************************************/
|
||||||
|
/* */
|
||||||
|
/* dump.c */
|
||||||
|
/* */
|
||||||
|
/* Dump subroutines for the od65 object file dump utility */
|
||||||
|
/* */
|
||||||
|
/* */
|
||||||
|
/* */
|
||||||
|
/* (C) 2000 Ullrich von Bassewitz */
|
||||||
|
/* Wacholderweg 14 */
|
||||||
|
/* D-70597 Stuttgart */
|
||||||
|
/* EMail: uz@musoftware.de */
|
||||||
|
/* */
|
||||||
|
/* */
|
||||||
|
/* This software is provided 'as-is', without any expressed or implied */
|
||||||
|
/* warranty. In no event will the authors be held liable for any damages */
|
||||||
|
/* arising from the use of this software. */
|
||||||
|
/* */
|
||||||
|
/* Permission is granted to anyone to use this software for any purpose, */
|
||||||
|
/* including commercial applications, and to alter it and redistribute it */
|
||||||
|
/* freely, subject to the following restrictions: */
|
||||||
|
/* */
|
||||||
|
/* 1. The origin of this software must not be misrepresented; you must not */
|
||||||
|
/* claim that you wrote the original software. If you use this software */
|
||||||
|
/* in a product, an acknowledgment in the product documentation would be */
|
||||||
|
/* appreciated but is not required. */
|
||||||
|
/* 2. Altered source versions must be plainly marked as such, and must not */
|
||||||
|
/* be misrepresented as being the original software. */
|
||||||
|
/* 3. This notice may not be removed or altered from any source */
|
||||||
|
/* distribution. */
|
||||||
|
/* */
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* common */
|
||||||
|
#include "objdefs.h"
|
||||||
|
|
||||||
|
/* od65 */
|
||||||
|
#include "fileio.h"
|
||||||
|
#include "dump.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/* Code */
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static void DumpHeaderSection (const char* Name,
|
||||||
|
unsigned long Offset,
|
||||||
|
unsigned long Size)
|
||||||
|
/* Dump a header section */
|
||||||
|
{
|
||||||
|
printf (" %s:\n", Name);
|
||||||
|
printf (" Offset: %8lu\n", Offset);
|
||||||
|
printf (" Size: %8lu\n", Size);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void DumpHeader (FILE* F, unsigned long Offset)
|
||||||
|
/* Dump the header of the given object file */
|
||||||
|
{
|
||||||
|
ObjHeader H;
|
||||||
|
|
||||||
|
/* Output a header */
|
||||||
|
printf (" Header:\n");
|
||||||
|
|
||||||
|
/* Seek to the header position */
|
||||||
|
fseek (F, 0, SEEK_SET);
|
||||||
|
|
||||||
|
/* Read the header */
|
||||||
|
ReadObjHeader (F, &H);
|
||||||
|
|
||||||
|
/* Now dump the information */
|
||||||
|
|
||||||
|
/* Magic */
|
||||||
|
printf (" Magic: 0x%08lX\n", H.Magic);
|
||||||
|
|
||||||
|
/* Version */
|
||||||
|
printf (" Version: %10u\n", H.Version);
|
||||||
|
|
||||||
|
/* Flags */
|
||||||
|
printf (" Flags: 0x%04X (", H.Flags);
|
||||||
|
if (H.Flags & OBJ_FLAGS_DBGINFO) {
|
||||||
|
printf ("OBJ_FLAGS_DBGINFO");
|
||||||
|
}
|
||||||
|
printf (")\n");
|
||||||
|
|
||||||
|
/* Options */
|
||||||
|
DumpHeaderSection ("Options", H.OptionOffs, H.OptionSize);
|
||||||
|
|
||||||
|
/* Files */
|
||||||
|
DumpHeaderSection ("Files", H.FileOffs, H.FileSize);
|
||||||
|
|
||||||
|
/* Segments */
|
||||||
|
DumpHeaderSection ("Segments", H.SegOffs, H.SegSize);
|
||||||
|
|
||||||
|
/* Imports */
|
||||||
|
DumpHeaderSection ("Imports", H.ImportOffs, H.ImportSize);
|
||||||
|
|
||||||
|
/* Exports */
|
||||||
|
DumpHeaderSection ("Exports", H.ExportOffs, H.ExportSize);
|
||||||
|
|
||||||
|
/* Debug symbols */
|
||||||
|
DumpHeaderSection ("Debug symbols", H.DbgSymOffs, H.DbgSymSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
62
src/od65/dump.h
Normal file
62
src/od65/dump.h
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
/*****************************************************************************/
|
||||||
|
/* */
|
||||||
|
/* dump.h */
|
||||||
|
/* */
|
||||||
|
/* Dump subroutines for the od65 object file dump utility */
|
||||||
|
/* */
|
||||||
|
/* */
|
||||||
|
/* */
|
||||||
|
/* (C) 2000 Ullrich von Bassewitz */
|
||||||
|
/* Wacholderweg 14 */
|
||||||
|
/* D-70597 Stuttgart */
|
||||||
|
/* EMail: uz@musoftware.de */
|
||||||
|
/* */
|
||||||
|
/* */
|
||||||
|
/* This software is provided 'as-is', without any expressed or implied */
|
||||||
|
/* warranty. In no event will the authors be held liable for any damages */
|
||||||
|
/* arising from the use of this software. */
|
||||||
|
/* */
|
||||||
|
/* Permission is granted to anyone to use this software for any purpose, */
|
||||||
|
/* including commercial applications, and to alter it and redistribute it */
|
||||||
|
/* freely, subject to the following restrictions: */
|
||||||
|
/* */
|
||||||
|
/* 1. The origin of this software must not be misrepresented; you must not */
|
||||||
|
/* claim that you wrote the original software. If you use this software */
|
||||||
|
/* in a product, an acknowledgment in the product documentation would be */
|
||||||
|
/* appreciated but is not required. */
|
||||||
|
/* 2. Altered source versions must be plainly marked as such, and must not */
|
||||||
|
/* be misrepresented as being the original software. */
|
||||||
|
/* 3. This notice may not be removed or altered from any source */
|
||||||
|
/* distribution. */
|
||||||
|
/* */
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef DUMP_H
|
||||||
|
#define DUMP_H
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/* Code */
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void DumpHeader (FILE* F, unsigned long Offset);
|
||||||
|
/* Dump the header of the given object file */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* End of dump.h */
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
106
src/od65/error.c
Normal file
106
src/od65/error.c
Normal file
@@ -0,0 +1,106 @@
|
|||||||
|
/*****************************************************************************/
|
||||||
|
/* */
|
||||||
|
/* error.c */
|
||||||
|
/* */
|
||||||
|
/* Error handling for the od65 object file dump utility */
|
||||||
|
/* */
|
||||||
|
/* */
|
||||||
|
/* */
|
||||||
|
/* (C) 1998-2000 Ullrich von Bassewitz */
|
||||||
|
/* Wacholderweg 14 */
|
||||||
|
/* D-70597 Stuttgart */
|
||||||
|
/* EMail: uz@musoftware.de */
|
||||||
|
/* */
|
||||||
|
/* */
|
||||||
|
/* This software is provided 'as-is', without any expressed or implied */
|
||||||
|
/* warranty. In no event will the authors be held liable for any damages */
|
||||||
|
/* arising from the use of this software. */
|
||||||
|
/* */
|
||||||
|
/* Permission is granted to anyone to use this software for any purpose, */
|
||||||
|
/* including commercial applications, and to alter it and redistribute it */
|
||||||
|
/* freely, subject to the following restrictions: */
|
||||||
|
/* */
|
||||||
|
/* 1. The origin of this software must not be misrepresented; you must not */
|
||||||
|
/* claim that you wrote the original software. If you use this software */
|
||||||
|
/* in a product, an acknowledgment in the product documentation would be */
|
||||||
|
/* appreciated but is not required. */
|
||||||
|
/* 2. Altered source versions must be plainly marked as such, and must not */
|
||||||
|
/* be misrepresented as being the original software. */
|
||||||
|
/* 3. This notice may not be removed or altered from any source */
|
||||||
|
/* distribution. */
|
||||||
|
/* */
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
|
||||||
|
#include "error.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/* Data */
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* Messages for internal compiler errors */
|
||||||
|
const char _MsgCheckFailed [] =
|
||||||
|
"Check failed: `%s' (= %d), file `%s', line %u\n";
|
||||||
|
const char _MsgPrecondition [] =
|
||||||
|
"Precondition violated: `%s' (= %d), file `%s', line %u\n";
|
||||||
|
const char _MsgFail [] =
|
||||||
|
"%s, file `%s', line %u\n";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/* Code */
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void Warning (const char* Format, ...)
|
||||||
|
/* Print a warning message */
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
va_start (ap, Format);
|
||||||
|
fprintf (stderr, "Warning: ");
|
||||||
|
vfprintf (stderr, Format, ap);
|
||||||
|
putc ('\n', stderr);
|
||||||
|
va_end (ap);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void Error (const char* Format, ...)
|
||||||
|
/* Print an error message and die */
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
va_start (ap, Format);
|
||||||
|
fprintf (stderr, "Error: ");
|
||||||
|
vfprintf (stderr, Format, ap);
|
||||||
|
putc ('\n', stderr);
|
||||||
|
va_end (ap);
|
||||||
|
exit (EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void Internal (const char* Format, ...)
|
||||||
|
/* Print an internal error message and die */
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
va_start (ap, Format);
|
||||||
|
fprintf (stderr, "Internal error: ");
|
||||||
|
vfprintf (stderr, Format, ap);
|
||||||
|
putc ('\n', stderr);
|
||||||
|
va_end (ap);
|
||||||
|
exit (EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
92
src/od65/error.h
Normal file
92
src/od65/error.h
Normal file
@@ -0,0 +1,92 @@
|
|||||||
|
/*****************************************************************************/
|
||||||
|
/* */
|
||||||
|
/* global.h */
|
||||||
|
/* */
|
||||||
|
/* Error handling for the od65 object file dump utility */
|
||||||
|
/* */
|
||||||
|
/* */
|
||||||
|
/* */
|
||||||
|
/* (C) 1998-2000 Ullrich von Bassewitz */
|
||||||
|
/* Wacholderweg 14 */
|
||||||
|
/* D-70597 Stuttgart */
|
||||||
|
/* EMail: uz@musoftware.de */
|
||||||
|
/* */
|
||||||
|
/* */
|
||||||
|
/* This software is provided 'as-is', without any expressed or implied */
|
||||||
|
/* warranty. In no event will the authors be held liable for any damages */
|
||||||
|
/* arising from the use of this software. */
|
||||||
|
/* */
|
||||||
|
/* Permission is granted to anyone to use this software for any purpose, */
|
||||||
|
/* including commercial applications, and to alter it and redistribute it */
|
||||||
|
/* freely, subject to the following restrictions: */
|
||||||
|
/* */
|
||||||
|
/* 1. The origin of this software must not be misrepresented; you must not */
|
||||||
|
/* claim that you wrote the original software. If you use this software */
|
||||||
|
/* in a product, an acknowledgment in the product documentation would be */
|
||||||
|
/* appreciated but is not required. */
|
||||||
|
/* 2. Altered source versions must be plainly marked as such, and must not */
|
||||||
|
/* be misrepresented as being the original software. */
|
||||||
|
/* 3. This notice may not be removed or altered from any source */
|
||||||
|
/* distribution. */
|
||||||
|
/* */
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef ERROR_H
|
||||||
|
#define ERROR_H
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* common */
|
||||||
|
#include "attrib.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/* Data */
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* Messages for internal compiler errors */
|
||||||
|
extern const char _MsgCheckFailed [];
|
||||||
|
extern const char _MsgPrecondition [];
|
||||||
|
extern const char _MsgFail [];
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/* Code */
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void Warning (const char* Format, ...) attribute((format(printf,1,2)));
|
||||||
|
/* Print a warning message */
|
||||||
|
|
||||||
|
void Error (const char* Format, ...) attribute((format(printf,1,2)));
|
||||||
|
/* Print an error message and die */
|
||||||
|
|
||||||
|
void Internal (const char* Format, ...) attribute((format(printf,1,2)));
|
||||||
|
/* Print an internal error message and die */
|
||||||
|
|
||||||
|
#define CHECK(c) \
|
||||||
|
if (!(c)) \
|
||||||
|
Internal (_MsgCheckFailed, #c, c, __FILE__, __LINE__)
|
||||||
|
|
||||||
|
#define PRECONDITION(c) \
|
||||||
|
if (!(c)) \
|
||||||
|
Internal (_MsgPrecondition, #c, c, __FILE__, __LINE__)
|
||||||
|
|
||||||
|
#define FAIL(s) \
|
||||||
|
Internal (_MsgFail, s, __FILE__, __LINE__)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* End of error.h */
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
193
src/od65/fileio.c
Normal file
193
src/od65/fileio.c
Normal file
@@ -0,0 +1,193 @@
|
|||||||
|
/*****************************************************************************/
|
||||||
|
/* */
|
||||||
|
/* fileio.c */
|
||||||
|
/* */
|
||||||
|
/* File I/O for the od65 object file dump utility */
|
||||||
|
/* */
|
||||||
|
/* */
|
||||||
|
/* */
|
||||||
|
/* (C) 1998-2000 Ullrich von Bassewitz */
|
||||||
|
/* Wacholderweg 14 */
|
||||||
|
/* D-70597 Stuttgart */
|
||||||
|
/* EMail: uz@musoftware.de */
|
||||||
|
/* */
|
||||||
|
/* */
|
||||||
|
/* This software is provided 'as-is', without any expressed or implied */
|
||||||
|
/* warranty. In no event will the authors be held liable for any damages */
|
||||||
|
/* arising from the use of this software. */
|
||||||
|
/* */
|
||||||
|
/* Permission is granted to anyone to use this software for any purpose, */
|
||||||
|
/* including commercial applications, and to alter it and redistribute it */
|
||||||
|
/* freely, subject to the following restrictions: */
|
||||||
|
/* */
|
||||||
|
/* 1. The origin of this software must not be misrepresented; you must not */
|
||||||
|
/* claim that you wrote the original software. If you use this software */
|
||||||
|
/* in a product, an acknowledgment in the product documentation would be */
|
||||||
|
/* appreciated but is not required. */
|
||||||
|
/* 2. Altered source versions must be plainly marked as such, and must not */
|
||||||
|
/* be misrepresented as being the original software. */
|
||||||
|
/* 3. This notice may not be removed or altered from any source */
|
||||||
|
/* distribution. */
|
||||||
|
/* */
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
/* common */
|
||||||
|
#include "xmalloc.h"
|
||||||
|
|
||||||
|
/* od65 */
|
||||||
|
#include "error.h"
|
||||||
|
#include "fileio.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/* Code */
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
unsigned Read8 (FILE* F)
|
||||||
|
/* Read an 8 bit value from the file */
|
||||||
|
{
|
||||||
|
int C = getc (F);
|
||||||
|
if (C == EOF) {
|
||||||
|
Error ("Read error (file corrupt?)");
|
||||||
|
}
|
||||||
|
return C;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
unsigned Read16 (FILE* F)
|
||||||
|
/* Read a 16 bit value from the file */
|
||||||
|
{
|
||||||
|
unsigned Lo = Read8 (F);
|
||||||
|
unsigned Hi = Read8 (F);
|
||||||
|
return (Hi << 8) | Lo;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
unsigned long Read24 (FILE* F)
|
||||||
|
/* Read a 24 bit value from the file */
|
||||||
|
{
|
||||||
|
unsigned long Lo = Read16 (F);
|
||||||
|
unsigned long Hi = Read8 (F);
|
||||||
|
return (Hi << 16) | Lo;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
unsigned long Read32 (FILE* F)
|
||||||
|
/* Read a 32 bit value from the file */
|
||||||
|
{
|
||||||
|
unsigned long Lo = Read16 (F);
|
||||||
|
unsigned long Hi = Read16 (F);
|
||||||
|
return (Hi << 16) | Lo;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
long Read32Signed (FILE* F)
|
||||||
|
/* Read a 32 bit value from the file. Sign extend the value. */
|
||||||
|
{
|
||||||
|
/* Read a 32 bit value */
|
||||||
|
unsigned long V = Read32 (F);
|
||||||
|
|
||||||
|
/* Sign extend the value */
|
||||||
|
if (V & 0x80000000UL) {
|
||||||
|
/* Signed value */
|
||||||
|
V |= ~0xFFFFFFFFUL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Return it as a long */
|
||||||
|
return (long) V;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
char* ReadStr (FILE* F, char* Str)
|
||||||
|
/* Read a string from the file. Str must hold 256 chars at max */
|
||||||
|
{
|
||||||
|
/* Read the length byte */
|
||||||
|
unsigned Len = Read8 (F);
|
||||||
|
|
||||||
|
/* Read the string itself */
|
||||||
|
ReadData (F, Str, Len);
|
||||||
|
|
||||||
|
/* Terminate the string and return it */
|
||||||
|
Str [Len] = '\0';
|
||||||
|
return Str;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
char* ReadMallocedStr (FILE* F)
|
||||||
|
/* Read a string from the file into a malloced area */
|
||||||
|
{
|
||||||
|
/* Read the length byte */
|
||||||
|
unsigned Len = Read8 (F);
|
||||||
|
|
||||||
|
/* Allocate memory */
|
||||||
|
char* Str = xmalloc (Len + 1);
|
||||||
|
|
||||||
|
/* Read the string itself */
|
||||||
|
ReadData (F, Str, Len);
|
||||||
|
|
||||||
|
/* Terminate the string and return it */
|
||||||
|
Str [Len] = '\0';
|
||||||
|
return Str;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
FilePos* ReadFilePos (FILE* F, FilePos* Pos)
|
||||||
|
/* Read a file position from the file */
|
||||||
|
{
|
||||||
|
/* The line number is encoded as 24 bit value to save some space */
|
||||||
|
Pos->Line = Read24 (F);
|
||||||
|
Pos->Col = Read8 (F);
|
||||||
|
Pos->Name = Read8 (F);
|
||||||
|
return Pos;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void* ReadData (FILE* F, void* Data, unsigned Size)
|
||||||
|
/* Read data from the file */
|
||||||
|
{
|
||||||
|
if (fread (Data, 1, Size, F) != Size) {
|
||||||
|
Error ("Read error (file corrupt?)");
|
||||||
|
}
|
||||||
|
return Data;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void ReadObjHeader (FILE* F, ObjHeader* H)
|
||||||
|
/* Read an object file header from the file */
|
||||||
|
{
|
||||||
|
/* Read all fields */
|
||||||
|
H->Magic = Read32 (F);
|
||||||
|
H->Version = Read16 (F);
|
||||||
|
H->Flags = Read16 (F);
|
||||||
|
H->OptionOffs = Read32 (F);
|
||||||
|
H->OptionSize = Read32 (F);
|
||||||
|
H->FileOffs = Read32 (F);
|
||||||
|
H->FileSize = Read32 (F);
|
||||||
|
H->SegOffs = Read32 (F);
|
||||||
|
H->SegSize = Read32 (F);
|
||||||
|
H->ImportOffs = Read32 (F);
|
||||||
|
H->ImportSize = Read32 (F);
|
||||||
|
H->ExportOffs = Read32 (F);
|
||||||
|
H->ExportSize = Read32 (F);
|
||||||
|
H->DbgSymOffs = Read32 (F);
|
||||||
|
H->DbgSymSize = Read32 (F);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
92
src/od65/fileio.h
Normal file
92
src/od65/fileio.h
Normal file
@@ -0,0 +1,92 @@
|
|||||||
|
/*****************************************************************************/
|
||||||
|
/* */
|
||||||
|
/* fileio.h */
|
||||||
|
/* */
|
||||||
|
/* File I/O for the od65 object file dump utility */
|
||||||
|
/* */
|
||||||
|
/* */
|
||||||
|
/* */
|
||||||
|
/* (C) 1998-2000 Ullrich von Bassewitz */
|
||||||
|
/* Wacholderweg 14 */
|
||||||
|
/* D-70597 Stuttgart */
|
||||||
|
/* EMail: uz@musoftware.de */
|
||||||
|
/* */
|
||||||
|
/* */
|
||||||
|
/* This software is provided 'as-is', without any expressed or implied */
|
||||||
|
/* warranty. In no event will the authors be held liable for any damages */
|
||||||
|
/* arising from the use of this software. */
|
||||||
|
/* */
|
||||||
|
/* Permission is granted to anyone to use this software for any purpose, */
|
||||||
|
/* including commercial applications, and to alter it and redistribute it */
|
||||||
|
/* freely, subject to the following restrictions: */
|
||||||
|
/* */
|
||||||
|
/* 1. The origin of this software must not be misrepresented; you must not */
|
||||||
|
/* claim that you wrote the original software. If you use this software */
|
||||||
|
/* in a product, an acknowledgment in the product documentation would be */
|
||||||
|
/* appreciated but is not required. */
|
||||||
|
/* 2. Altered source versions must be plainly marked as such, and must not */
|
||||||
|
/* be misrepresented as being the original software. */
|
||||||
|
/* 3. This notice may not be removed or altered from any source */
|
||||||
|
/* distribution. */
|
||||||
|
/* */
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef FILEIO_H
|
||||||
|
#define FILEIO_H
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
/* common */
|
||||||
|
#include "filepos.h"
|
||||||
|
#include "objdefs.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/* Code */
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
unsigned Read8 (FILE* F);
|
||||||
|
/* Read an 8 bit value from the file */
|
||||||
|
|
||||||
|
unsigned Read16 (FILE* F);
|
||||||
|
/* Read a 16 bit value from the file */
|
||||||
|
|
||||||
|
unsigned long Read24 (FILE* F);
|
||||||
|
/* Read a 24 bit value from the file */
|
||||||
|
|
||||||
|
unsigned long Read32 (FILE* F);
|
||||||
|
/* Read a 32 bit value from the file */
|
||||||
|
|
||||||
|
long Read32Signed (FILE* F);
|
||||||
|
/* Read a 32 bit value from the file. Sign extend the value. */
|
||||||
|
|
||||||
|
char* ReadStr (FILE* F, char* Str);
|
||||||
|
/* Read a string from the file. Str must hold 256 chars at max */
|
||||||
|
|
||||||
|
char* ReadMallocedStr (FILE* F);
|
||||||
|
/* Read a string from the file into a malloced area */
|
||||||
|
|
||||||
|
FilePos* ReadFilePos (FILE* F, FilePos* Pos);
|
||||||
|
/* Read a file position from the file */
|
||||||
|
|
||||||
|
void* ReadData (FILE* F, void* Data, unsigned Size);
|
||||||
|
/* Read data from the file */
|
||||||
|
|
||||||
|
void ReadObjHeader (FILE* F, ObjHeader* Header);
|
||||||
|
/* Read an object file header from the file */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* End of fileio.h */
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
49
src/od65/global.c
Normal file
49
src/od65/global.c
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
/*****************************************************************************/
|
||||||
|
/* */
|
||||||
|
/* global.c */
|
||||||
|
/* */
|
||||||
|
/* Global variables for the od65 object file dump utility */
|
||||||
|
/* */
|
||||||
|
/* */
|
||||||
|
/* */
|
||||||
|
/* (C) 2000 Ullrich von Bassewitz */
|
||||||
|
/* Wacholderweg 14 */
|
||||||
|
/* D-70597 Stuttgart */
|
||||||
|
/* EMail: uz@musoftware.de */
|
||||||
|
/* */
|
||||||
|
/* */
|
||||||
|
/* This software is provided 'as-is', without any expressed or implied */
|
||||||
|
/* warranty. In no event will the authors be held liable for any damages */
|
||||||
|
/* arising from the use of this software. */
|
||||||
|
/* */
|
||||||
|
/* Permission is granted to anyone to use this software for any purpose, */
|
||||||
|
/* including commercial applications, and to alter it and redistribute it */
|
||||||
|
/* freely, subject to the following restrictions: */
|
||||||
|
/* */
|
||||||
|
/* 1. The origin of this software must not be misrepresented; you must not */
|
||||||
|
/* claim that you wrote the original software. If you use this software */
|
||||||
|
/* in a product, an acknowledgment in the product documentation would be */
|
||||||
|
/* appreciated but is not required. */
|
||||||
|
/* 2. Altered source versions must be plainly marked as such, and must not */
|
||||||
|
/* be misrepresented as being the original software. */
|
||||||
|
/* 3. This notice may not be removed or altered from any source */
|
||||||
|
/* distribution. */
|
||||||
|
/* */
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#include "global.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/* Data */
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
unsigned long What = 0; /* What should get dumped? */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
61
src/od65/global.h
Normal file
61
src/od65/global.h
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
/*****************************************************************************/
|
||||||
|
/* */
|
||||||
|
/* global.h */
|
||||||
|
/* */
|
||||||
|
/* Global variables for the od65 object file dump utility */
|
||||||
|
/* */
|
||||||
|
/* */
|
||||||
|
/* */
|
||||||
|
/* (C) 2000 Ullrich von Bassewitz */
|
||||||
|
/* Wacholderweg 14 */
|
||||||
|
/* D-70597 Stuttgart */
|
||||||
|
/* EMail: uz@musoftware.de */
|
||||||
|
/* */
|
||||||
|
/* */
|
||||||
|
/* This software is provided 'as-is', without any expressed or implied */
|
||||||
|
/* warranty. In no event will the authors be held liable for any damages */
|
||||||
|
/* arising from the use of this software. */
|
||||||
|
/* */
|
||||||
|
/* Permission is granted to anyone to use this software for any purpose, */
|
||||||
|
/* including commercial applications, and to alter it and redistribute it */
|
||||||
|
/* freely, subject to the following restrictions: */
|
||||||
|
/* */
|
||||||
|
/* 1. The origin of this software must not be misrepresented; you must not */
|
||||||
|
/* claim that you wrote the original software. If you use this software */
|
||||||
|
/* in a product, an acknowledgment in the product documentation would be */
|
||||||
|
/* appreciated but is not required. */
|
||||||
|
/* 2. Altered source versions must be plainly marked as such, and must not */
|
||||||
|
/* be misrepresented as being the original software. */
|
||||||
|
/* 3. This notice may not be removed or altered from any source */
|
||||||
|
/* distribution. */
|
||||||
|
/* */
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef GLOBAL_H
|
||||||
|
#define GLOBAL_H
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/* Data */
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#define D_HEADER 0x00000001UL /* Dump the header */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
extern unsigned long What; /* What should get dumped? */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* End of global.h */
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
216
src/od65/main.c
Normal file
216
src/od65/main.c
Normal file
@@ -0,0 +1,216 @@
|
|||||||
|
/*****************************************************************************/
|
||||||
|
/* */
|
||||||
|
/* main.c */
|
||||||
|
/* */
|
||||||
|
/* Main program of the od65 object file dump utility */
|
||||||
|
/* */
|
||||||
|
/* */
|
||||||
|
/* */
|
||||||
|
/* (C) 2000 Ullrich von Bassewitz */
|
||||||
|
/* Wacholderweg 14 */
|
||||||
|
/* D-70597 Stuttgart */
|
||||||
|
/* EMail: uz@musoftware.de */
|
||||||
|
/* */
|
||||||
|
/* */
|
||||||
|
/* This software is provided 'as-is', without any expressed or implied */
|
||||||
|
/* warranty. In no event will the authors be held liable for any damages */
|
||||||
|
/* arising from the use of this software. */
|
||||||
|
/* */
|
||||||
|
/* Permission is granted to anyone to use this software for any purpose, */
|
||||||
|
/* including commercial applications, and to alter it and redistribute it */
|
||||||
|
/* freely, subject to the following restrictions: */
|
||||||
|
/* */
|
||||||
|
/* 1. The origin of this software must not be misrepresented; you must not */
|
||||||
|
/* claim that you wrote the original software. If you use this software */
|
||||||
|
/* in a product, an acknowledgment in the product documentation would be */
|
||||||
|
/* appreciated but is not required. */
|
||||||
|
/* 2. Altered source versions must be plainly marked as such, and must not */
|
||||||
|
/* be misrepresented as being the original software. */
|
||||||
|
/* 3. This notice may not be removed or altered from any source */
|
||||||
|
/* distribution. */
|
||||||
|
/* */
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
|
/* common */
|
||||||
|
#include "cmdline.h"
|
||||||
|
#include "objdefs.h"
|
||||||
|
#include "version.h"
|
||||||
|
|
||||||
|
/* od65 */
|
||||||
|
#include "dump.h"
|
||||||
|
#include "error.h"
|
||||||
|
#include "fileio.h"
|
||||||
|
#include "global.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/* Data */
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static unsigned FilesProcessed = 0;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/* Code */
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static void Usage (void)
|
||||||
|
/* Print usage information and exit */
|
||||||
|
{
|
||||||
|
fprintf (stderr,
|
||||||
|
"Usage: %s [options] file\n"
|
||||||
|
"Short options:\n"
|
||||||
|
" -h\t\t\tHelp (this text)\n"
|
||||||
|
" -V\t\t\tPrint the version number and exit\n"
|
||||||
|
"\n"
|
||||||
|
"Long options:\n"
|
||||||
|
" --dump-header\t\tDump the object file header\n"
|
||||||
|
" --help\t\tHelp (this text)\n"
|
||||||
|
" --version\t\tPrint the version number and exit\n",
|
||||||
|
ProgName);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static void OptDumpHeader (const char* Opt, const char* Arg)
|
||||||
|
/* Dump the object file header */
|
||||||
|
{
|
||||||
|
What |= D_HEADER;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static void OptHelp (const char* Opt, const char* Arg)
|
||||||
|
/* Print usage information and exit */
|
||||||
|
{
|
||||||
|
Usage ();
|
||||||
|
exit (EXIT_SUCCESS);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static void OptVersion (const char* Opt, const char* Arg)
|
||||||
|
/* Print the assembler version */
|
||||||
|
{
|
||||||
|
fprintf (stderr,
|
||||||
|
"%s V%u.%u.%u - (C) Copyright 2000 Ullrich von Bassewitz\n",
|
||||||
|
ProgName, VER_MAJOR, VER_MINOR, VER_PATCH);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static void DumpFile (const char* Name)
|
||||||
|
/* Dump information from the named file */
|
||||||
|
{
|
||||||
|
unsigned long Magic;
|
||||||
|
|
||||||
|
/* Try to open the file */
|
||||||
|
FILE* F = fopen (Name, "rb");
|
||||||
|
if (F == 0) {
|
||||||
|
Warning ("Cannot open `%s': %s", Name, strerror (errno));
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Read the magic word */
|
||||||
|
Magic = Read32 (F);
|
||||||
|
|
||||||
|
/* Do we know this type of file? */
|
||||||
|
if (Magic != OBJ_MAGIC) {
|
||||||
|
fclose (F);
|
||||||
|
Warning ("File `%s' is not an xo65 object file", Name);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Print the filename */
|
||||||
|
printf ("%s:\n", Name);
|
||||||
|
|
||||||
|
/* Check what to dump */
|
||||||
|
if (What & D_HEADER) {
|
||||||
|
DumpHeader (F, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Close the file */
|
||||||
|
fclose (F);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int main (int argc, char* argv [])
|
||||||
|
/* Assembler main program */
|
||||||
|
{
|
||||||
|
/* Program long options */
|
||||||
|
static const LongOpt OptTab[] = {
|
||||||
|
{ "--dump-header", 0, OptDumpHeader },
|
||||||
|
{ "--help", 0, OptHelp },
|
||||||
|
{ "--version", 0, OptVersion },
|
||||||
|
};
|
||||||
|
|
||||||
|
int I;
|
||||||
|
|
||||||
|
/* Initialize the cmdline module */
|
||||||
|
InitCmdLine (argc, argv, "od65");
|
||||||
|
|
||||||
|
/* Check the parameters */
|
||||||
|
I = 1;
|
||||||
|
while (I < argc) {
|
||||||
|
|
||||||
|
/* Get the argument */
|
||||||
|
const char* Arg = argv [I];
|
||||||
|
|
||||||
|
/* Check for an option */
|
||||||
|
if (Arg [0] == '-') {
|
||||||
|
switch (Arg [1]) {
|
||||||
|
|
||||||
|
case '-':
|
||||||
|
LongOption (&I, OptTab, sizeof(OptTab)/sizeof(OptTab[0]));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'h':
|
||||||
|
OptHelp (Arg, 0);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'H':
|
||||||
|
OptDumpHeader (Arg, 0);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'V':
|
||||||
|
OptVersion (Arg, 0);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
UnknownOption (Arg);
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
/* Filename. Dump it. */
|
||||||
|
DumpFile (Arg);
|
||||||
|
++FilesProcessed;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Next argument */
|
||||||
|
++I;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Print a message if we did not process any files */
|
||||||
|
if (FilesProcessed == 0) {
|
||||||
|
fprintf (stderr, "%s: No input files\n", ProgName);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Success */
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
52
src/od65/make/gcc.mak
Normal file
52
src/od65/make/gcc.mak
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
#
|
||||||
|
# Makefile for the od65 object file dump utility
|
||||||
|
#
|
||||||
|
|
||||||
|
|
||||||
|
# Library dir
|
||||||
|
COMMON = ../common
|
||||||
|
|
||||||
|
CFLAGS = -O2 -g -Wall -I$(COMMON)
|
||||||
|
CC=gcc
|
||||||
|
LDFLAGS=
|
||||||
|
|
||||||
|
OBJS = dump.o \
|
||||||
|
error.o \
|
||||||
|
fileio.o \
|
||||||
|
global.o \
|
||||||
|
main.o
|
||||||
|
|
||||||
|
LIBS = $(COMMON)/common.a
|
||||||
|
|
||||||
|
EXE = od65
|
||||||
|
|
||||||
|
|
||||||
|
.PHONY: all
|
||||||
|
ifeq (.depend,$(wildcard .depend))
|
||||||
|
all: $(EXE)
|
||||||
|
include .depend
|
||||||
|
else
|
||||||
|
all: depend
|
||||||
|
@$(MAKE) -f make/gcc.mak all
|
||||||
|
endif
|
||||||
|
|
||||||
|
|
||||||
|
$(EXE): $(OBJS)
|
||||||
|
$(CC) $(LDFLAGS) -o $(EXE) $(CFLAGS) $(OBJS) $(LIBS)
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -f *~ core *.map
|
||||||
|
|
||||||
|
zap: clean
|
||||||
|
rm -f *.o $(EXE) .depend
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
# Make the dependencies
|
||||||
|
|
||||||
|
.PHONY: depend dep
|
||||||
|
depend dep: $(OBJS:.o=.c)
|
||||||
|
@echo "Creating dependency information"
|
||||||
|
$(CC) -I$(COMMON) -MM $^ > .depend
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user