2011-08-04 12:31:37 +00:00
|
|
|
/*****************************************************************************/
|
|
|
|
/* */
|
|
|
|
/* span.c */
|
|
|
|
/* */
|
|
|
|
/* A span of data within a segment */
|
|
|
|
/* */
|
|
|
|
/* */
|
|
|
|
/* */
|
|
|
|
/* (C) 2011, Ullrich von Bassewitz */
|
|
|
|
/* Roemerstrasse 52 */
|
|
|
|
/* D-70794 Filderstadt */
|
|
|
|
/* EMail: uz@cc65.org */
|
|
|
|
/* */
|
|
|
|
/* */
|
|
|
|
/* 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 "xmalloc.h"
|
2011-08-04 13:14:26 +00:00
|
|
|
|
2011-08-11 17:11:45 +00:00
|
|
|
/* ld65 */
|
2011-08-04 13:14:26 +00:00
|
|
|
#include "fileio.h"
|
|
|
|
#include "objdata.h"
|
|
|
|
#include "segments.h"
|
2011-08-04 12:31:37 +00:00
|
|
|
#include "span.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2011-08-11 17:11:45 +00:00
|
|
|
/* Data */
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-08-14 19:24:03 +00:00
|
|
|
/* Definition of a span */
|
|
|
|
struct Span {
|
|
|
|
unsigned Id; /* Id of the span */
|
|
|
|
unsigned Sec; /* Section id of this span */
|
|
|
|
unsigned long Offs; /* Offset of span within segment */
|
|
|
|
unsigned long Size; /* Size of span */
|
|
|
|
};
|
2011-08-11 17:11:45 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
/* Code */
|
2011-08-04 12:31:37 +00:00
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-08-18 11:57:17 +00:00
|
|
|
Span* NewSpan (ObjData* Obj, unsigned SecId, unsigned long Offs, unsigned long Size)
|
2011-08-04 13:14:26 +00:00
|
|
|
/* Create and return a new span */
|
2011-08-04 12:31:37 +00:00
|
|
|
{
|
|
|
|
/* Allocate memory */
|
|
|
|
Span* S = xmalloc (sizeof (*S));
|
|
|
|
|
|
|
|
/* Initialize the fields */
|
2011-08-18 11:57:17 +00:00
|
|
|
S->Id = CollCount (&Obj->Spans);
|
2011-08-14 19:24:03 +00:00
|
|
|
S->Sec = SecId;
|
2011-08-04 12:31:37 +00:00
|
|
|
S->Offs = Offs;
|
|
|
|
S->Size = Size;
|
|
|
|
|
2011-08-18 11:57:17 +00:00
|
|
|
/* Insert it into the collection of all spans of this object file */
|
|
|
|
CollAppend (&Obj->Spans, S);
|
|
|
|
|
2011-08-04 12:31:37 +00:00
|
|
|
/* Return the result */
|
2011-08-11 17:11:45 +00:00
|
|
|
return S;
|
2011-08-04 12:31:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-08-04 13:14:26 +00:00
|
|
|
Span* ReadSpan (FILE* F, ObjData* O)
|
|
|
|
/* Read a Span from a file and return it */
|
|
|
|
{
|
2011-08-18 11:57:17 +00:00
|
|
|
/* Create a new Span and return it */
|
2011-08-14 19:24:03 +00:00
|
|
|
unsigned SecId = ReadVar (F);
|
|
|
|
unsigned long Offs = ReadVar (F);
|
|
|
|
unsigned Size = ReadVar (F);
|
2011-08-18 11:57:17 +00:00
|
|
|
return NewSpan (O, SecId, Offs, Size);
|
2011-08-04 13:14:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void ReadSpans (Collection* Spans, FILE* F, ObjData* O)
|
|
|
|
/* Read a list of Spans from a file and return it */
|
|
|
|
{
|
|
|
|
/* First is number of Spans */
|
|
|
|
unsigned Count = ReadVar (F);
|
|
|
|
|
|
|
|
/* Preallocate enough entries in the collection */
|
|
|
|
CollGrow (Spans, Count);
|
|
|
|
|
|
|
|
/* Read the spans and add them */
|
|
|
|
while (Count--) {
|
|
|
|
CollAppend (Spans, ReadSpan (F, O));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-08-04 12:31:37 +00:00
|
|
|
void FreeSpan (Span* S)
|
|
|
|
/* Free a span structure */
|
|
|
|
{
|
|
|
|
/* Just free the structure */
|
|
|
|
xfree (S);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-08-14 19:24:03 +00:00
|
|
|
unsigned SpanId (const struct ObjData* O, const Span* S)
|
|
|
|
/* Return the global id of a span */
|
2011-08-04 12:31:37 +00:00
|
|
|
{
|
2011-08-14 19:24:03 +00:00
|
|
|
return O->SpanBaseId + S->Id;
|
|
|
|
}
|
2011-08-04 12:31:37 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2011-08-14 19:24:03 +00:00
|
|
|
unsigned SpanCount (void)
|
|
|
|
/* Return the total number of spans */
|
|
|
|
{
|
|
|
|
/* Walk over all object files */
|
|
|
|
unsigned I;
|
|
|
|
unsigned Count = 0;
|
|
|
|
for (I = 0; I < CollCount (&ObjDataList); ++I) {
|
2011-08-04 12:31:37 +00:00
|
|
|
|
2011-08-14 19:24:03 +00:00
|
|
|
/* Get this object file */
|
|
|
|
const ObjData* O = CollAtUnchecked (&ObjDataList, I);
|
2011-08-04 12:31:37 +00:00
|
|
|
|
2011-08-14 19:24:03 +00:00
|
|
|
/* Count spans */
|
|
|
|
Count += CollCount (&O->Spans);
|
2011-08-04 12:31:37 +00:00
|
|
|
}
|
|
|
|
|
2011-08-14 19:24:03 +00:00
|
|
|
return Count;
|
2011-08-04 12:31:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-08-14 19:24:03 +00:00
|
|
|
void PrintDbgSpans (FILE* F)
|
|
|
|
/* Output the spans to a debug info file */
|
2011-08-11 17:11:45 +00:00
|
|
|
{
|
2011-08-14 19:24:03 +00:00
|
|
|
unsigned I, J;
|
2011-08-11 17:11:45 +00:00
|
|
|
|
2011-08-14 19:24:03 +00:00
|
|
|
/* Walk over all object files */
|
|
|
|
for (I = 0; I < CollCount (&ObjDataList); ++I) {
|
2011-08-11 17:11:45 +00:00
|
|
|
|
2011-08-14 19:24:03 +00:00
|
|
|
/* Get this object file */
|
|
|
|
ObjData* O = CollAtUnchecked (&ObjDataList, I);
|
2011-08-11 17:11:45 +00:00
|
|
|
|
2011-08-14 19:24:03 +00:00
|
|
|
/* Walk over all spans in this object file */
|
|
|
|
for (J = 0; J < CollCount (&O->Spans); ++J) {
|
|
|
|
|
|
|
|
/* Get this span */
|
|
|
|
Span* S = CollAtUnchecked (&O->Spans, J);
|
2011-08-11 17:11:45 +00:00
|
|
|
|
2011-08-14 19:24:03 +00:00
|
|
|
/* Get the section for this span */
|
|
|
|
const Section* Sec = GetObjSection (O, S->Sec);
|
2011-08-11 17:11:45 +00:00
|
|
|
|
2011-08-14 19:24:03 +00:00
|
|
|
/* Output the data */
|
|
|
|
fprintf (F, "span\tid=%u,seg=%u,start=%lu,size=%lu\n",
|
2011-08-18 11:57:17 +00:00
|
|
|
O->SpanBaseId + S->Id,
|
|
|
|
Sec->Seg->Id,
|
|
|
|
Sec->Offs + S->Offs,
|
2011-08-14 19:24:03 +00:00
|
|
|
S->Size);
|
|
|
|
}
|
2011-08-11 17:11:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|