GNU as now assembles successfully

A new (untested) startup routine has been written for GNU as.
Section names have been considered from stm8-binutils linker script.
This commit is contained in:
Xavier ASUS 2019-10-21 03:04:31 +02:00
parent 3fcc2d265f
commit 41e45c2e8d
2 changed files with 72 additions and 41 deletions

View File

@ -154,7 +154,7 @@ emitRegularMap (memmap *map, bool addPublics, bool arFlag)
if (options.gasOutput && !map->syms)
return;
if (addPublics)
if (addPublics && !options.gasOutput)
{
/* PENDING: special case here - should remove */
if (!strcmp (map->sname, CODE_NAME))
@ -162,8 +162,7 @@ emitRegularMap (memmap *map, bool addPublics, bool arFlag)
else if (!strcmp (map->sname, DATA_NAME))
{
dbuf_tprintf (&map->oBuf, "\t!areadata\n", map->sname);
if (options.data_seg && strcmp (DATA_NAME, options.data_seg) && !options.gasOutput)
/* GNU as only needs .bss. */
if (options.data_seg && strcmp (DATA_NAME, options.data_seg))
dbuf_tprintf (&map->oBuf, "\t!area\n", options.data_seg);
}
else if (!strcmp (map->sname, HOME_NAME))
@ -174,6 +173,15 @@ emitRegularMap (memmap *map, bool addPublics, bool arFlag)
if (map->regsp)
dbuf_tprintf (&map->oBuf, "\t!org\n", 0);
}
else if (options.gasOutput)
if (map == code)
dbuf_tprintf (&map->oBuf, "\t!area\n", ".text");
else if (map == data)
dbuf_tprintf (&map->oBuf, "\t!area\n", DATA_NAME);
else if (map == initialized)
dbuf_tprintf (&map->oBuf, "\t!area\n", INITIALIZED_NAME);
else if (map == initializer)
dbuf_tprintf (&map->oBuf, "\t!area\n", INITIALIZER_NAME);
for (sym = setFirstItem (map->syms); sym; sym = setNextItem (map->syms))
{
@ -2497,7 +2505,7 @@ glue (void)
snprintf( section_name, sizeof section_name / sizeof *section_name,
".%s", start_stack);
/* Set alloc/write flags. */
tfprintf(asmFile, "\t!area , \"aw\", @progbits\n", section_name);
tfprintf(asmFile, "\t!area , \"aw\"\n", section_name);
tfprintf(asmFile, "\t!local\n", start_stack);
tfprintf(asmFile, "\t!comm\n\n", start_stack, size, 1);
}
@ -2686,7 +2694,7 @@ glue (void)
fprintf (asmFile, "%s", iComments2);
fprintf (asmFile, "; code\n");
fprintf (asmFile, "%s", iComments2);
tfprintf (asmFile, "\t!areacode\n", options.code_seg);
tfprintf (asmFile, "\t!areacode\n", CODE_NAME);
dbuf_write_and_destroy (&code->oBuf, asmFile);
if (port->genAssemblerEnd)

View File

@ -240,41 +240,64 @@ stm8_genExtraArea (FILE *of, bool hasMain)
static void
stm8_genInitStartup (FILE *of)
{
const char *const startup = options.gasOutput ?
"_start"
: "__sdcc_gs_init_startup";
tfprintf (of, "!labeldef\n", startup);
if (options.stack_loc >= 0)
if (!options.gasOutput)
{
fprintf (of, "\tldw\tx, #0x%04x\n", options.stack_loc);
fprintf (of, "\tldw\tsp, x\n");
tfprintf (of, "!labeldef\n", "__sdcc_gs_init_startup");
if (options.stack_loc >= 0)
{
fprintf (of, "\tldw\tx, #0x%04x\n", options.stack_loc);
fprintf (of, "\tldw\tsp, x\n");
}
/* Init static & global variables */
tfprintf (of, "!labeldef\n", "__sdcc_init_data");
fprintf (of, "; stm8_genXINIT() start\n");
/* Zeroing memory (required by standard for static & global variables) */
fprintf (of, "\tldw x, #l_DATA\n");
fprintf (of, "\tjreq\t00002$\n");
fprintf (of, "00001$:\n");
fprintf (of, "\tclr (s_DATA - 1, x)\n");
fprintf (of, "\tdecw x\n");
fprintf (of, "\tjrne\t00001$\n");
fprintf (of, "00002$:\n");
/* Copy l_INITIALIZER bytes from s_INITIALIZER to s_INITIALIZED */
fprintf (of, "\tldw\tx, #l_INITIALIZER\n");
fprintf (of, "\tjreq\t00004$\n");
fprintf (of, "00003$:\n");
fprintf (of, "\tld\ta, (s_INITIALIZER - 1, x)\n");
fprintf (of, "\tld\t(s_INITIALIZED - 1, x), a\n");
fprintf (of, "\tdecw\tx\n");
fprintf (of, "\tjrne\t00003$\n");
fprintf (of, "00004$:\n");
fprintf (of, "; stm8_genXINIT() end\n");
}
else
{
fprintf(of,
".global _start\n"
"_start:\n"
"\t; Zeroing .bss\n"
"\tldw x, __bss_start\n"
"\t$0:\n"
"\tclr (x)\n"
"\tincw x\n"
"\tcpw x, __bss_end\n"
"\tjrne $0\n"
"\t; Copying .data from ROM to RAM\n"
"\t; Calculate .data section size\n"
"\tldw x, __data_load_start\n"
"\tldw y, __data_start\n"
"\t$1:\n"
"\tld a, (x)\n"
"\tld (y), a\n"
"\tincw x\n"
"\tincw y\n"
"\tcpw y, _edata\n"
"\tjrne $1\n");
}
/* Init static & global variables */
tfprintf (of, "!labeldef\n", "__sdcc_init_data");
fprintf (of, "; stm8_genXINIT() start\n");
/* Zeroing memory (required by standard for static & global variables) */
fprintf (of, "\tldw x, #l_DATA\n");
fprintf (of, "\tjreq\t00002$\n");
fprintf (of, "00001$:\n");
fprintf (of, "\tclr (s_DATA - 1, x)\n");
fprintf (of, "\tdecw x\n");
fprintf (of, "\tjrne\t00001$\n");
fprintf (of, "00002$:\n");
/* Copy l_INITIALIZER bytes from s_INITIALIZER to s_INITIALIZED */
fprintf (of, "\tldw\tx, #l_INITIALIZER\n");
fprintf (of, "\tjreq\t00004$\n");
fprintf (of, "00003$:\n");
fprintf (of, "\tld\ta, (s_INITIALIZER - 1, x)\n");
fprintf (of, "\tld\t(s_INITIALIZED - 1, x), a\n");
fprintf (of, "\tdecw\tx\n");
fprintf (of, "\tjrne\t00003$\n");
fprintf (of, "00004$:\n");
fprintf (of, "; stm8_genXINIT() end\n");
}
#define STM8_INTERRUPTS_COUNT 30
@ -286,10 +309,10 @@ stm8_genIVT(struct dbuf_s * oBuf, symbol ** intTable, int intCount)
if (options.gasOutput)
{
dbuf_tprintf(oBuf, "!area , \"ax\", @progbits\n", ".text.__interrupt");
dbuf_tprintf(oBuf, "!area\n", ".vectors");
}
dbuf_tprintf(oBuf, "\tint s_GSINIT ; reset\n");
else
dbuf_tprintf(oBuf, "\tint s_GSINIT ; reset\n");
if(intCount > STM8_INTERRUPTS_COUNT)
{