Got hi8/lo8 asm instructions working

GNU as does not support the #</#> notation asxxx uses to determine
address LSB and MSB. Instead, two instructions have been created on
GNU as and ld (see my stm8-binutils-gdb fork) for this purpose.

On the other hand, I'm upset to see gen.c does not provide an
assembler-agnostic implementation when SDCCasm.c already provides
tools already meant for this.

OTOH, support for the "-C" has been added for --gas.
This commit is contained in:
Xavier ASUS 2019-10-24 06:19:28 +02:00
parent 8eeb5d5444
commit d5577a84aa
4 changed files with 42 additions and 9 deletions

View File

@ -424,8 +424,8 @@ static const ASM_MAPPING _gas_mapping[] = {
{"immedword", "0x%04x"},
{"immedbyte", "0x%02x"},
{"hashedstr", "#%s"},
{"lsbimmeds", "#<(%s)"},
{"msbimmeds", "#>(%s)"},
{"lsbimmeds", "lo8(%s)"},
{"msbimmeds", "hi8(%s)"},
{"module", ".file \"%s\""},
{"global", ".global %s"},
{"fileprelude", ""},

View File

@ -1499,8 +1499,8 @@ printIvalFuncPtr (sym_link * type, initList * ilist, struct dbuf_s *oBuf)
{
if (TARGET_PDK_LIKE)
{
dbuf_printf (oBuf, "\tret #<%s\n", name);
dbuf_printf (oBuf, "\tret #>%s\n", name);
dbuf_tprintf (oBuf, "\tret !lsbimmeds\n", name);
dbuf_tprintf (oBuf, "\tret !msbimmeds\n", name);
}
else if (TARGET_IS_STM8 && FUNCPTRSIZE == 3)
{
@ -1560,7 +1560,7 @@ printIvalCharPtr (symbol * sym, sym_link * type, value * val, struct dbuf_s *oBu
{
if (TARGET_PDK_LIKE && !TARGET_IS_PDK16)
{
dbuf_printf (oBuf, "\tret #<%s\n", val->name);
dbuf_tprintf (oBuf, "\t!lsbimmeds", val->name);
dbuf_printf (oBuf, IN_CODESPACE (SPEC_OCLS (val->etype)) ? "\tret #>(%s + 0x8000)\n" : "\tret #0\n", val->name);
}
else if (port->use_dw_for_init)
@ -2130,7 +2130,14 @@ createInterruptVect (struct dbuf_s *vBuf)
return;
}
dbuf_tprintf (vBuf, "\t!areacode\n", HOME_NAME);
dbuf_tprintf (vBuf, "\t!areacode", HOME_NAME);
if (options.gasOutput)
/* Read-executable flags must be defined so ld can
* place the interrupt vectors into a separate section.*/
dbuf_tprintf (vBuf, ",\t\"ax\"");
dbuf_printf(vBuf, "\n");
dbuf_printf (vBuf, "__interrupt_vect:\n");

View File

@ -139,6 +139,8 @@ typedef struct
const char *file_ext;
/** If non-null will be used to execute the assembler. */
void (*do_assemble) (set *);
/** Command to run the GNU assembler. */
const char **binutils_cmd;
}
assembler;
@ -157,6 +159,8 @@ typedef struct
const int needLinkerScript;
const char *const *crt;
const char *const *libs;
/** Extension for ELF object files generated using GNU binutils (.o) */
const char *o_ext;
}
linker;

View File

@ -20,6 +20,7 @@
#include "ralloc.h"
#include "gen.h"
#include "dbuf.h"
/* Use the D macro for basic (unobtrusive) debugging messages */
#define D(x) do if (options.verboseAsm) { x; } while (0)
@ -435,10 +436,31 @@ aopGet(const asmop *aop, int offset)
{
wassertl_bt (offset < (2 + (options.model == MODEL_LARGE)), "Immediate operand out of range");
if (offset == 0)
SNPRINTF (buffer, sizeof(buffer), "#<(%s + %d)", aop->aopu.immd, aop->aopu.immd_off);
{
struct dbuf_s temp;
dbuf_init(&temp, sizeof buffer);
/* SNPRINTF (buffer, sizeof(buffer), "#<(%s + %d)", aop->aopu.immd, aop->aopu.immd_off); */
SNPRINTF(buffer, sizeof buffer, "%s + %d", aop->aopu.immd, aop->aopu.immd_off);
dbuf_tprintf(&temp, "!lsbimmeds", buffer);
SNPRINTF(buffer, sizeof buffer, "%s", dbuf_c_str(&temp));
dbuf_destroy(&temp);
return buffer;
}
else
SNPRINTF (buffer, sizeof(buffer), "#((%s + %d) >> %d)", aop->aopu.immd, aop->aopu.immd_off, offset * 8);
return (buffer);
{
struct dbuf_s temp;
dbuf_init(&temp, sizeof buffer);
/* SNPRINTF (buffer, sizeof(buffer), "#((%s + %d) >> %d)", aop->aopu.immd, aop->aopu.immd_off, offset * 8); */
SNPRINTF(buffer, sizeof buffer, "%s + %d", aop->aopu.immd, aop->aopu.immd_off);
dbuf_tprintf(&temp, "!msbimmeds", buffer);
SNPRINTF(buffer, sizeof buffer, "%s", dbuf_c_str(&temp));
dbuf_destroy(&temp);
return buffer;
}
}
if (aop->type == AOP_DIR)