Added/completed/debugged o65 support for Lunix

git-svn-id: svn://svn.cc65.org/cc65/trunk@1126 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
cuz
2001-12-01 13:34:51 +00:00
parent df92f7585f
commit ebbd68673b
14 changed files with 225 additions and 103 deletions

View File

@@ -185,6 +185,10 @@ static void SetSys (const char* Sys)
DefineNumericMacro ("__GEOS__", 1);
break;
case TGT_LUNIX:
DefineNumericMacro ("__LUNIX__", 1);
break;
default:
AbEnd ("Unknown target system type");
}

View File

@@ -6,7 +6,7 @@
/* */
/* */
/* */
/* (C) 2000 Ullrich von Bassewitz */
/* (C) 2000-2001 Ullrich von Bassewitz */
/* Wacholderweg 14 */
/* D-70597 Stuttgart */
/* EMail: uz@musoftware.de */
@@ -64,6 +64,7 @@ const char* TargetNames [TGT_COUNT] = {
"bbc",
"apple2",
"geos",
"lunix"
};

View File

@@ -6,7 +6,7 @@
/* */
/* */
/* */
/* (C) 2000 Ullrich von Bassewitz */
/* (C) 2000-2001 Ullrich von Bassewitz */
/* Wacholderweg 14 */
/* D-70597 Stuttgart */
/* EMail: uz@musoftware.de */
@@ -59,6 +59,7 @@ typedef enum {
TGT_BBC,
TGT_APPLE2,
TGT_GEOS,
TGT_LUNIX,
TGT_COUNT /* Number of target systems */
} target_t;

View File

@@ -112,6 +112,7 @@ void TgtTranslateInit (void)
case TGT_BBC: break;
case TGT_APPLE2: break;
case TGT_GEOS: break;
case TGT_LUNIX: Tab = CTPET; break;
default:
AbEnd ("Internal error: Target system unknown (%d)", Target);
}

View File

@@ -1,13 +1,12 @@
MEMORY {
COMBINED: start = $0000, size = $FFFF, file = %O;
ZEROPAGE: start = $0000, size = $0100, file = %O;
}
SEGMENTS {
ZEROPAGE: load = COMBINED, type = zp;
CODE: load = COMBINED, type = wprot;
RODATA: load = COMBINED, type = wprot;
DATA: load = COMBINED, type = rw, define = yes;
BSS: load = COMBINED, type = bss, define = yes;
ZEROPAGE: load = ZEROPAGE, type = zp;
}
FEATURES {
CONDES: segment = RODATA,
@@ -23,7 +22,7 @@ FILES {
%O: format = o65;
}
FORMATS {
o65: os = lunix, type = small, extsym = "LUNIXKERNAL", extsym = "LIB6502";
o65: os = lunix, type = small, import = LUNIXKERNAL, import = LIB6502;
}
SYMBOLS {
__STACKSIZE__ = $800; # 2K stack

View File

@@ -866,7 +866,7 @@ static void ParseO65 (void)
switch (CfgTok) {
case CFGTOK_SMALL:
/* Default, nothing to do */
O65SetSmallModel (O65FmtDesc);
break;
case CFGTOK_LARGE:

View File

@@ -6,7 +6,7 @@
/* */
/* */
/* */
/* (C) 1999 Ullrich von Bassewitz */
/* (C) 1999-2001 Ullrich von Bassewitz */
/* Wacholderweg 14 */
/* D-70597 Stuttgart */
/* EMail: uz@musoftware.de */
@@ -35,9 +35,11 @@
#include <string.h>
#include "../common/hashstr.h"
#include "../common/xmalloc.h"
/* common */
#include "hashstr.h"
#include "xmalloc.h"
/* ld65 */
#include "error.h"
#include "extsyms.h"
@@ -50,7 +52,7 @@
/* Structure holding an external symbol */
struct ExtSym_ {
struct ExtSym {
ExtSym* List; /* Next entry in list of all symbols */
ExtSym* Next; /* Next entry in hash list */
unsigned Flags; /* Generic flags */
@@ -60,7 +62,7 @@ struct ExtSym_ {
/* External symbol table structure */
#define HASHTAB_SIZE 53
struct ExtSymTab_ {
struct ExtSymTab {
ExtSym* Root; /* List of symbols */
ExtSym* Last; /* Pointer to last symbol */
unsigned Count; /* Number of symbols */
@@ -109,7 +111,7 @@ ExtSym* NewExtSym (ExtSymTab* Tab, const char* Name)
Tab->Last->List = E;
}
Tab->Last = E;
Tab->Count++;
++Tab->Count;
/* Insert the symbol into the hash table */
E->Next = Tab->HashTab [Hash];
@@ -230,7 +232,7 @@ const char* ExtSymName (const ExtSym* E)
const ExtSym* ExtSymNext (const ExtSym* E)
/* Return the next symbol in the list */
{
return E->Next;
return E->List;
}

View File

@@ -6,7 +6,7 @@
/* */
/* */
/* */
/* (C) 1999 Ullrich von Bassewitz */
/* (C) 1999-2001 Ullrich von Bassewitz */
/* Wacholderweg 14 */
/* D-70597 Stuttgart */
/* EMail: uz@musoftware.de */
@@ -45,10 +45,10 @@
/* Forward decl for structure holding an external symbol */
typedef struct ExtSym_ ExtSym;
typedef struct ExtSym ExtSym;
/* External symbol table structure */
typedef struct ExtSymTab_ ExtSymTab;
typedef struct ExtSymTab ExtSymTab;
@@ -97,3 +97,4 @@ const ExtSym* ExtSymNext (const ExtSym* E);

View File

@@ -54,6 +54,7 @@ INCS = apple2.inc \
cbm510.inc \
cbm610.inc \
geos.inc \
lunix.inc \
none.inc \
pet.inc \
plus4.inc
@@ -125,6 +126,9 @@ cbm610.inc: cfg/cbm610.cfg
geos.inc: cfg/geos.cfg
@$(CVT) $< $@ CfgGeos
lunix.inc: cfg/lunix.cfg
@$(CVT) $< $@ CfgLunix
none.inc: cfg/none.cfg
@$(CVT) $< $@ CfgNone

View File

@@ -62,8 +62,19 @@
/* Header mode bits */
#define MF_CPU_65816 0x8000 /* Executable is for 65816 */
#define MF_CPU_6502 0x0000 /* Executable is for the 6502 */
#define MF_CPU_MASK 0x8000 /* Mask to extract CPU type */
#define MF_SIZE_32BIT 0x2000 /* All size words are 32bit */
#define MF_CPU_816 0x8000 /* Executable is for 65816 */
#define MF_SIZE_16BIT 0x0000 /* All size words are 16bit */
#define MF_SIZE_MASK 0x2000 /* Mask to extract size */
#define MF_ALIGN_1 0x0000 /* Bytewise alignment */
#define MF_ALIGN_2 0x0001 /* Align words */
#define MF_ALIGN_4 0x0002 /* Align longwords */
#define MF_ALIGN_256 0x0003 /* Align pages (256 bytes) */
#define MF_ALIGN_MASK 0x0003 /* Mask to extract alignment */
/* The four o65 segment types. Note: These values are identical to the values
* needed for the segmentID in the o65 spec.
@@ -81,6 +92,7 @@
#define O65RELOC_LOW 0x20
#define O65RELOC_SEGADR 0xc0
#define O65RELOC_SEG 0xa0
#define O65RELOC_MASK 0xc0
/* O65 executable file header */
typedef struct O65Header O65Header;
@@ -195,6 +207,50 @@ static unsigned O65SegType (const SegDesc* S)
static const SegDesc* FindSeg (SegDesc** const List, unsigned Count, const Segment* S)
/* Search for a segment in the given list of segment descriptors and return
* the descriptor for a segment if we found it, and NULL if not.
*/
{
unsigned I;
for (I = 0; I < Count; ++I) {
if (List[I]->Seg == S) {
/* Found */
return List[I];
}
}
/* Not found */
return 0;
}
static const SegDesc* O65FindSeg (const O65Desc* D, const Segment* S)
/* Search for a segment in the segment lists and return it's segment descriptor */
{
const SegDesc* SD;
if ((SD = FindSeg (D->TextSeg, D->TextCount, S)) != 0) {
return SD;
}
if ((SD = FindSeg (D->DataSeg, D->DataCount, S)) != 0) {
return SD;
}
if ((SD = FindSeg (D->BssSeg, D->BssCount, S)) != 0) {
return SD;
}
if ((SD = FindSeg (D->ZPSeg, D->ZPCount, S)) != 0) {
return SD;
}
/* Not found */
return 0;
}
/*****************************************************************************/
/* Expression handling */
/*****************************************************************************/
@@ -515,6 +571,8 @@ static unsigned O65WriteExpr (ExprNode* E, int Signed, unsigned Size,
RelocType = O65RELOC_LOW;
} else if (E->Op == EXPR_BYTE1) {
RelocType = O65RELOC_HIGH;
} else if (E->Op == EXPR_BYTE2) {
RelocType = O65RELOC_SEG;
} else {
switch (Size) {
@@ -548,10 +606,28 @@ static unsigned O65WriteExpr (ExprNode* E, int Signed, unsigned Size,
/* Put the number of the imported symbol into the table */
O65RelocPutWord (D->CurReloc, ExtSymNum (ED.ExtRef));
} else {
/* Segment reference */
/* Segment reference. Search for the segment and map it to it's
* o65 segmentID
*/
const SegDesc* Seg = O65FindSeg (D, ED.SegRef->Seg);
if (Seg == 0) {
/* For some reason, we didn't find this segment in the list of
* segments written to the o65 file.
*/
return SEG_EXPR_INVALID;
}
RelocType |= O65SegType (Seg);
O65RelocPutByte (D->CurReloc, RelocType);
/* Output additional data if needed */
switch (RelocType & O65RELOC_MASK) {
case O65RELOC_HIGH:
O65RelocPutByte (D->CurReloc, ED.Val & 0xFF);
break;
case O65RELOC_SEG:
O65RelocPutWord (D->CurReloc, ED.Val & 0xFFFF);
break;
}
}
/* Success */
@@ -592,13 +668,13 @@ static void O65WriteSeg (O65Desc* D, SegDesc** Seg, unsigned Count, int DoWrite)
D->SegSize += S->Seg->Size;
}
/* Terminate the relocation table for the this segment */
/* Terminate the relocation table for this segment */
if (D->CurReloc) {
O65RelocPutByte (D->CurReloc, 0);
}
/* Check the size of the segment for overflow */
if ((D->Header.Mode & MF_SIZE_32BIT) == 0 && D->SegSize > 0xFFFF) {
if ((D->Header.Mode & MF_SIZE_MASK) == MF_SIZE_16BIT && D->SegSize > 0xFFFF) {
Error ("Segment overflow in file `%s'", D->Filename);
}
@@ -711,7 +787,9 @@ static void O65WriteDataReloc (O65Desc* D)
static void O65WriteExports (O65Desc* D)
/* Write the list of exports */
{
/* For now... */
/* Since ld65 creates exectutables, not object files, we do not have
* exports. This may change if we support writing shared libraries...
*/
WriteSize (D, 0);
}
@@ -796,10 +874,26 @@ void FreeO65Desc (O65Desc* D)
void O65Set816 (O65Desc* D)
void O65Set6502 (O65Desc* D)
/* Enable 6502 mode */
{
D->Header.Mode = (D->Header.Mode & ~MF_CPU_MASK) | MF_CPU_6502;
}
void O65Set65816 (O65Desc* D)
/* Enable 816 mode */
{
D->Header.Mode |= MF_CPU_816;
D->Header.Mode = (D->Header.Mode & ~MF_CPU_MASK) | MF_CPU_65816;
}
void O65SetSmallModel (O65Desc* D)
/* Enable a small memory model executable */
{
D->Header.Mode = (D->Header.Mode & ~MF_SIZE_MASK) | MF_SIZE_16BIT;
}
@@ -807,7 +901,7 @@ void O65Set816 (O65Desc* D)
void O65SetLargeModel (O65Desc* D)
/* Enable a large memory model executable */
{
D->Header.Mode |= MF_SIZE_32BIT;
D->Header.Mode = (D->Header.Mode & ~MF_SIZE_MASK) | MF_SIZE_32BIT;
}
@@ -816,14 +910,14 @@ void O65SetAlignment (O65Desc* D, unsigned Align)
/* Set the executable alignment */
{
/* Remove all alignment bits from the mode word */
D->Header.Mode &= ~0x0003;
D->Header.Mode &= ~MF_ALIGN_MASK;
/* Set the alignment bits */
switch (Align) {
case 1: break;
case 2: D->Header.Mode |= 0x01; break;
case 4: D->Header.Mode |= 0x02; break;
case 256: D->Header.Mode |= 0x03; break;
case 1: D->Header.Mode |= MF_ALIGN_1; break;
case 2: D->Header.Mode |= MF_ALIGN_2; break;
case 4: D->Header.Mode |= MF_ALIGN_4; break;
case 256: D->Header.Mode |= MF_ALIGN_256; break;
default: Error ("Invalid alignment for O65 format: %u", Align);
}
}
@@ -917,7 +1011,7 @@ static void O65SetupSegments (O65Desc* D, Memory* M)
D->BssCount = 0;
D->ZPCount = 0;
/* Walk through the memory list and count the segment types */
/* Walk through the segment list and count the segment types */
N = M->SegList;
while (N) {

View File

@@ -79,9 +79,15 @@ O65Desc* NewO65Desc (void);
void FreeO65Desc (O65Desc* D);
/* Delete the descriptor struct with cleanup */
void O65Set816 (O65Desc* D);
void O65Set6502 (O65Desc* D);
/* Enable 6502 mode */
void O65Set65816 (O65Desc* D);
/* Enable 816 mode */
void O65SetSmallModel (O65Desc* D);
/* Enable a small memory model executable */
void O65SetLargeModel (O65Desc* D);
/* Enable a large memory model executable */

View File

@@ -534,6 +534,12 @@ void SegWrite (FILE* Tgt, Segment* S, SegWriteFunc F, void* Data)
Frag->Pos.Line);
break;
case SEG_EXPR_INVALID:
Error ("Invalid expression in module `%s', line %lu",
GetSourceFileName (Frag->Obj, Frag->Pos.Name),
Frag->Pos.Line);
break;
default:
Internal ("Invalid return code from SegWriteFunc");
}

View File

@@ -89,9 +89,10 @@ struct Section {
/* Prototype for a function that is used to write expressions to the target
* file (used in SegWrite). It returns one of the following values:
*/
#define SEG_EXPR_OK 0 /* Ok */
#define SEG_EXPR_RANGE_ERROR 1 /* Range error */
#define SEG_EXPR_TOO_COMPLEX 2 /* Expression too complex */
#define SEG_EXPR_OK 0U /* Ok */
#define SEG_EXPR_RANGE_ERROR 1U /* Range error */
#define SEG_EXPR_TOO_COMPLEX 2U /* Expression too complex */
#define SEG_EXPR_INVALID 3U /* Expression is invalid (e.g. unmapped segment) */
typedef unsigned (*SegWriteFunc) (ExprNode* E, /* The expression to write */
int Signed, /* Signed expression? */

View File

@@ -6,7 +6,7 @@
/* */
/* */
/* */
/* (C) 1998-2000 Ullrich von Bassewitz */
/* (C) 1998-2001 Ullrich von Bassewitz */
/* Wacholderweg 14 */
/* D-70597 Stuttgart */
/* EMail: uz@musoftware.de */
@@ -56,6 +56,7 @@ static const char CfgEmpty[] = "";
#include "cbm510.inc"
#include "cbm610.inc"
#include "geos.inc"
#include "lunix.inc"
#include "none.inc"
#include "pet.inc"
#include "plus4.inc"
@@ -82,6 +83,7 @@ const TargetDesc Targets [TGT_COUNT] = {
{ BINFMT_BINARY, CfgBBC },
{ BINFMT_BINARY, CfgApple2 },
{ BINFMT_BINARY, CfgGeos },
{ BINFMT_O65, CfgLunix },
};