From c9fd57f1a17b166490ec29d1f669048dd9c60944 Mon Sep 17 00:00:00 2001 From: Lukas Krickl Date: Sun, 19 Jan 2025 08:00:06 +0100 Subject: [PATCH] mlb: Added support for sections to mlb This still needs testing. It uses the current address at time of using .section as an offset so that mlb files can be formatted correctly. --- man/ulas.5 | 4 +++- src/ulas.c | 7 +++++++ src/ulas.h | 4 +++- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/man/ulas.5 b/man/ulas.5 index 7a85c77..964b881 100644 --- a/man/ulas.5 +++ b/man/ulas.5 @@ -141,7 +141,9 @@ The special value $ will evaluate to the current address. .SH section \.section - Defines a section name. + Defines a section name. + For mlb files .section will use the address (set via .org) present at the time of + invoking .section as an offset address. .SH SEE ALSO diff --git a/src/ulas.c b/src/ulas.c index d0b4a33..b38d4aa 100644 --- a/src/ulas.c +++ b/src/ulas.c @@ -90,6 +90,7 @@ void ulas_nextpass(void) { ulas.chksm = 0; ulas.filename = ulas.initial_filename; ulas.section[0] = '\0'; // reset section + ulas.section_address = 0; for (int i = 0; i < ULAS_CHARCODEMAPLEN; i++) { ulas.charcodemap[i] = (char)i; @@ -366,6 +367,11 @@ int ulas_symbolset(const char *cname, int scope, struct ulas_tok tok, } int ulas_symbolout_mlbloc(FILE *dst, long addr) { + if (ulas.section[0] != '\0') { + fprintf(dst, "%s:", ulas.section); + return (int)ulas.section_address; + } + if (addr == -1) { fprintf(dst, "Unknown:"); return 0; @@ -2440,6 +2446,7 @@ int ulas_asmdirsection(FILE *dst, FILE *src, const char **line, return -1; } strncpy(ulas.section, ulas.tok.buf, ULAS_SECTIONMAX); + ulas.section_address = ulas.address; return 0; } diff --git a/src/ulas.h b/src/ulas.h index fc67478..43deaa7 100644 --- a/src/ulas.h +++ b/src/ulas.h @@ -319,7 +319,9 @@ struct ulas { // but cna be set with a directive char charcodemap[ULAS_CHARCODEMAPLEN]; char section[ULAS_SECTIONMAX]; - + // where was the section defined? + unsigned int section_address; + struct ulas_arch arch; }; -- 2.30.2