First working example!

stm8/main.c: 0x8000 must contain the entry point aka "_start" for GNU as.

Some work on supporting debugging symbols with --gas. Not finished yet.
This commit is contained in:
Xavier ASUS 2019-10-22 02:10:51 +02:00
parent 958912f928
commit 5a0c2910df
9 changed files with 60 additions and 50 deletions

View File

@ -34,7 +34,7 @@ OBJECTS = SDCCy.o SDCChasht.o SDCCmain.o \
SDCCBBlock.o SDCCloop.o SDCCcse.o SDCCcflow.o SDCCdflow.o \
SDCClrange.o SDCCptropt.o SDCCpeeph.o SDCCglue.o \
SDCCasm.o SDCCmacro.o SDCCutil.o SDCCdebug.o cdbFile.o SDCCdwarf2.o\
SDCCerr.o SDCCsystem.o SDCCgen.o SDCCgas.o
SDCCerr.o SDCCsystem.o SDCCgen.o
SPECIAL = SDCCy.h
ifeq ($(USE_ALT_LEX), 1)

View File

@ -197,12 +197,6 @@ SDCCgen.o: SDCCgen.c common.h SDCCglobl.h SDCCset.h ../sdccconf.h \
SDCCbitv.h SDCCset.h SDCCast.h SDCCdebug.h SDCCutil.h SDCCasm.h \
SDCCsystem.h port.h SDCCargs.h ../support/util/newalloc.h \
../support/util/dbuf_string.h ../support/util/dbuf.h
SDCCgas.o: SDCCgas.c SDCCgas.h SDCCglobl.h SDCCset.h ../sdccconf.h \
SDCCerr.h SDCCmem.h ../support/util/dbuf.h SDCCsymt.h SDCChasht.h \
SDCCval.h SDCCicode.h SDCCbitv.h SDCCast.h port.h SDCCargs.h SDCCpeeph.h \
SDCCgen.h SDCCicode.h SDCCbitv.h SDCCset.h SDCCast.h \
../support/util/newalloc.h ../support/util/dbuf_string.h \
../support/util/dbuf.h
SDCClex.o: SDCClex.c common.h SDCCglobl.h SDCCset.h ../sdccconf.h \
SDCCerr.h SDCCmem.h ../support/util/dbuf.h SDCCsymt.h SDCChasht.h \
SDCCval.h SDCCast.h SDCCy.h SDCCbitv.h SDCCicode.h SDCClabel.h \

View File

@ -34,7 +34,7 @@ OBJECTS = SDCCy.o SDCChasht.o SDCCmain.o \
SDCCBBlock.o SDCCloop.o SDCCcse.o SDCCcflow.o SDCCdflow.o \
SDCClrange.o SDCCptropt.o SDCCpeeph.o SDCCglue.o \
SDCCasm.o SDCCmacro.o SDCCutil.o SDCCdebug.o cdbFile.o SDCCdwarf2.o\
SDCCerr.o SDCCsystem.o SDCCgen.o SDCCgas.o
SDCCerr.o SDCCsystem.o SDCCgen.o
SPECIAL = SDCCy.h
ifeq ($(USE_ALT_LEX), 1)

View File

@ -100,7 +100,11 @@ dwNewDebugSymbol (void)
{
char debugSym[SDCC_NAME_MAX];
sprintf (debugSym, "S%s$%s$%d", dwModuleName, currFunc->name, dwDebugSymbol);
if (options.gasOutput)
sprintf (debugSym, "%s_%s_%d$", dwModuleName, currFunc->name, dwDebugSymbol);
else
sprintf (debugSym, "S%s$%s$%d", dwModuleName, currFunc->name, dwDebugSymbol);
dwDebugSymbol++;
return Safe_strdup (debugSym);
}

View File

@ -124,19 +124,22 @@ aopLiteral (value *val, int offset)
static void
emitDebugSym (struct dbuf_s *oBuf, symbol * sym)
{
if (sym->level && sym->localof) /* symbol scope is local */
{
dbuf_printf (oBuf, "L%s.%s$", moduleName, sym->localof->name);
if (sym->level && sym->localof) /* symbol scope is local */
{
dbuf_printf (oBuf, "L%s.%s$", moduleName, sym->localof->name);
}
else if (IS_STATIC (sym->etype)) /* symbol scope is file */
{
dbuf_printf (oBuf, "F%s$", moduleName);
}
else /* symbol scope is global */
{
dbuf_printf (oBuf, "G$");
}
dbuf_printf (oBuf, "%s$%ld_%ld$%d", sym->name, sym->level / LEVEL_UNIT, sym->level % LEVEL_UNIT, sym->block);
}
else if (IS_STATIC (sym->etype)) /* symbol scope is file */
{
dbuf_printf (oBuf, "F%s$", moduleName);
}
else /* symbol scope is global */
{
dbuf_printf (oBuf, "G$");
}
dbuf_printf (oBuf, "%s$%ld_%ld$%d", sym->name, sym->level / LEVEL_UNIT, sym->level % LEVEL_UNIT, sym->block);
}
/*-----------------------------------------------------------------*/
@ -151,9 +154,6 @@ emitRegularMap (memmap *map, bool addPublics, bool arFlag)
if (!map)
return;
if (options.gasOutput && !map->syms)
return;
if (addPublics && !options.gasOutput)
{
/* PENDING: special case here - should remove */
@ -380,7 +380,11 @@ emitRegularMap (memmap *map, bool addPublics, bool arFlag)
if (options.debug)
{
emitDebugSym (&map->oBuf, sym);
dbuf_printf (&map->oBuf, "==.\n");
if (options.gasOutput)
dbuf_printf (&map->oBuf, ":\n");
else
dbuf_printf (&map->oBuf, "==.\n");
}
if (IS_STATIC (sym->etype) || sym->level)
if (options.gasOutput)
@ -2252,11 +2256,15 @@ emitOverlay (struct dbuf_s *aBuf)
{
werrorfl (sym->fileDef, sym->lineDef, E_UNKNOWN_SIZE, sym->name);
}
/* print extra debug info if required. GNU as does not need this. */
if (options.debug && !options.gasOutput)
/* print extra debug info if required. */
if (options.debug)
{
emitDebugSym (aBuf, sym);
dbuf_printf (aBuf, "==.\n");
if (options.gasOutput)
dbuf_printf (aBuf, ":\n");
else
dbuf_printf (aBuf, "==.\n");
}
/* allocate space */
@ -2648,13 +2656,14 @@ glue (void)
/* STM8 / PDK14 note: there are no such instructions supported.
Also, we don't need this logic as well. */
if (port->general.glue_up_main && mainf && IFFUNC_HASBODY (mainf->type))
if (port->general.glue_up_main && mainf && IFFUNC_HASBODY (mainf->type) && !options.gasOutput)
{
/* This code is generated in the post-static area.
* This area is guaranteed to follow the static area
* by the ugly shucking and jiving about 20 lines ago.
*/
* This area is guaranteed to follow the static area
* by the ugly shucking and jiving about 20 lines ago.
*/
tfprintf (asmFile, "\t!area\n", port->mem.post_static_name);
if(TARGET_IS_STM8)
fprintf (asmFile, "\tjp\t__sdcc_program_startup\n");
else if(TARGET_PDK_LIKE)

View File

@ -1592,21 +1592,22 @@ parseCmdLine (int argc, char **argv)
}
/* if debug option is set then open the cdbFile */
if (options.debug && fullSrcFileName && !options.gasOutput)
if (options.debug && fullSrcFileName)
{
struct dbuf_s adbFile;
struct dbuf_s adbFile;
dbuf_init (&adbFile, PATH_MAX);
dbuf_append_str (&adbFile, dstFileName);
dbuf_append_str (&adbFile, ".adb");
dbuf_init (&adbFile, PATH_MAX);
dbuf_append_str (&adbFile, dstFileName);
dbuf_append_str (&adbFile, ".adb");
if (debugFile->openFile (dbuf_c_str (&adbFile)))
debugFile->writeModule (moduleName);
else
werror (E_FILE_OPEN_ERR, dbuf_c_str (&adbFile));
if (debugFile->openFile (dbuf_c_str (&adbFile)))
debugFile->writeModule (moduleName);
else
werror (E_FILE_OPEN_ERR, dbuf_c_str (&adbFile));
dbuf_destroy (&adbFile);
dbuf_destroy (&adbFile);
}
MSVC_style (options.vc_err_style);
return 0;

View File

@ -119,10 +119,6 @@ typedef struct
/** return the model string, used as library destination;
port->target is used as model string if get_model is NULL */
const char *(*get_model) (void);
/** Pointer to GAS (GNU assembler) glue function.
* If none is available, it means there is no support
* for this port yet. */
void (*gas_glue)(void);
}
general;

View File

@ -2339,7 +2339,12 @@ void
stm8_emitDebuggerSymbol (const char *debugSym)
{
G.debugLine = 1;
emit2 ("", "%s ==.", debugSym);
if (options.gasOutput)
emit2 ("", "%s:", debugSym);
else
emit2 ("", "%s ==.", debugSym);
G.debugLine = 0;
}
@ -3358,6 +3363,8 @@ genFunction (iCode *ic)
emit2 (";", " function %s", sym->name);
emit2 (";", "-----------------------------------------");
/* Place each new function into its own section so GNU ld
* can perform dead code elimination via --gc-sections. */
if (options.function_sections && options.gasOutput)
{
char name[256];

View File

@ -29,7 +29,6 @@
#include "gen.h"
#include "dbuf_string.h"
#include "peep.h"
#include "SDCCgas.h"
#include "SDCCglobl.h"
#define OPTION_MEDIUM_MODEL "--model-medium"
@ -277,7 +276,7 @@ stm8_genInitStartup (FILE *of)
else
{
fprintf(of,
".global _start\n"
"\t.global _start\n"
"_start:\n"
"\t; Zeroing .bss\n"
"\tldw x, __bss_start\n"
@ -308,7 +307,8 @@ stm8_genIVT(struct dbuf_s * oBuf, symbol ** intTable, int intCount)
int i;
if (options.gasOutput)
dbuf_tprintf(oBuf, "\tint __interrupt_vect ; reset\n");
/* Set entry point address. */
dbuf_tprintf(oBuf, "\tint _start ; reset\n");
else
dbuf_tprintf(oBuf, "\tint s_GSINIT ; reset\n");
@ -441,7 +441,6 @@ PORT stm8_port =
MODEL_MEDIUM | MODEL_LARGE,
MODEL_MEDIUM,
&get_model, /* model string used as library destination */
gas_glue
},
{ /* Assembler */
stm8AsmCmd,