aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCyrill Gorcunov <gorcunov@gmail.com>2018-12-01 21:32:15 +0300
committerCyrill Gorcunov <gorcunov@gmail.com>2018-12-01 21:32:15 +0300
commit20029a586cd519be717cc06b24485ce7365c8ed3 (patch)
treef3e0e6e48fe760a5824aec2c2ce06955037cee3e
parentba499c2ac77fd0293fed8809c921ee64b2987e10 (diff)
downloadnasm-20029a586cd519be717cc06b24485ce7365c8ed3.tar.gz
nasm-20029a586cd519be717cc06b24485ce7365c8ed3.tar.xz
nasm-20029a586cd519be717cc06b24485ce7365c8ed3.zip
output: bin -- Use nasm_error helpers
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
-rw-r--r--output/outbin.c145
1 files changed, 64 insertions, 81 deletions
diff --git a/output/outbin.c b/output/outbin.c
index ea49abb5..a3220e86 100644
--- a/output/outbin.c
+++ b/output/outbin.c
@@ -232,8 +232,7 @@ static void bin_cleanup(void)
int h;
#ifdef DEBUG
- nasm_error(ERR_DEBUG,
- "bin_cleanup: Sections were initially referenced in this order:\n");
+ nasm_debug("bin_cleanup: Sections were initially referenced in this order:\n");
for (h = 0, s = sections; s; h++, s = s->next)
fprintf(stdout, "%i. %s\n", h, s->name);
#endif
@@ -508,8 +507,7 @@ static void bin_cleanup(void)
for (h = 0, s = sections; s; s = s->next) {
if (!(s->flags & VSTART_DEFINED)) { /* Non-fatal errors after assembly has completed are generally a
* no-no, but we'll throw a fatal one eventually so it's ok. */
- nasm_error(ERR_NONFATAL, "cannot compute vstart for section %s",
- s->name);
+ nasm_nonfatal("cannot compute vstart for section %s", s->name);
h++;
}
}
@@ -517,8 +515,7 @@ static void bin_cleanup(void)
nasm_fatal("circular vfollows path detected");
#ifdef DEBUG
- nasm_error(ERR_DEBUG,
- "bin_cleanup: Confirm final section order for output file:\n");
+ nasm_debug("bin_cleanup: Confirm final section order for output file:\n");
for (h = 0, s = sections; s && (s->flags & TYPE_PROGBITS);
h++, s = s->next)
fprintf(stdout, "%i. %s\n", h, s->name);
@@ -732,7 +729,7 @@ static void bin_out(int32_t segto, const void *data,
if (wrt != NO_SEG) {
wrt = NO_SEG; /* continue to do _something_ */
- nasm_error(ERR_NONFATAL, "WRT not supported by binary output format");
+ nasm_nonfatal("WRT not supported by binary output format");
}
/* Find the segment we are targeting. */
@@ -749,8 +746,8 @@ static void bin_out(int32_t segto, const void *data,
}
if ((s->flags & TYPE_NOBITS) && (type != OUT_RESERVE))
- nasm_error(ERR_WARNING, "attempt to initialize memory in a"
- " nobits section: ignored");
+ nasm_warn("attempt to initialize memory in a"
+ " nobits section: ignored");
switch (type) {
case OUT_ADDRESS:
@@ -759,11 +756,11 @@ static void bin_out(int32_t segto, const void *data,
if (segment != NO_SEG && !find_section_by_index(segment)) {
if (segment % 2)
- nasm_error(ERR_NONFATAL, "binary output format does not support"
- " segment base references");
+ nasm_nonfatal("binary output format does not support"
+ " segment base references");
else
- nasm_error(ERR_NONFATAL, "binary output format does not support"
- " external references");
+ nasm_nonfatal("binary output format does not support"
+ " external references");
segment = NO_SEG;
}
if (s->flags & TYPE_PROGBITS) {
@@ -789,8 +786,8 @@ static void bin_out(int32_t segto, const void *data,
case OUT_RESERVE:
if (s->flags & TYPE_PROGBITS) {
- nasm_error(ERR_WARNING, "uninitialized space declared in"
- " %s section: zeroing", s->name);
+ nasm_warn("uninitialized space declared in"
+ " %s section: zeroing", s->name);
saa_wbytes(s->contents, NULL, size);
}
break;
@@ -804,11 +801,11 @@ static void bin_out(int32_t segto, const void *data,
size = realsize(type, size);
if (segment != NO_SEG && !find_section_by_index(segment)) {
if (segment % 2)
- nasm_error(ERR_NONFATAL, "binary output format does not support"
- " segment base references");
+ nasm_nonfatal("binary output format does not support"
+ " segment base references");
else
- nasm_error(ERR_NONFATAL, "binary output format does not support"
- " external references");
+ nasm_nonfatal("binary output format does not support"
+ " external references");
segment = NO_SEG;
}
if (s->flags & TYPE_PROGBITS) {
@@ -821,7 +818,7 @@ static void bin_out(int32_t segto, const void *data,
}
default:
- nasm_error(ERR_NONFATAL, "unsupported relocation type %d\n", type);
+ nasm_nonfatal("unsupported relocation type %d\n", type);
break;
}
@@ -835,13 +832,13 @@ static void bin_deflabel(char *name, int32_t segment, int64_t offset,
(void)offset; /* Don't warn that this parameter is unused */
if (special)
- nasm_error(ERR_NONFATAL, "binary format does not support any"
- " special symbol types");
+ nasm_nonfatal("binary format does not support any"
+ " special symbol types");
else if (name[0] == '.' && name[1] == '.' && name[2] != '@')
- nasm_error(ERR_NONFATAL, "unrecognised special symbol `%s'", name);
+ nasm_nonfatal("unrecognised special symbol `%s'", name);
else if (is_global == 2)
- nasm_error(ERR_NONFATAL, "binary output format does not support common"
- " variables");
+ nasm_nonfatal("binary output format does not support common"
+ " variables");
else {
struct Section *s;
struct bin_label ***ltp;
@@ -955,14 +952,13 @@ static int bin_read_attribute(char **line, int *attribute,
break;
}
if (!**line) {
- nasm_error(ERR_NONFATAL,
- "invalid syntax in `section' directive");
+ nasm_nonfatal("invalid syntax in `section' directive");
return -1;
}
++(*line);
}
if (!**line) {
- nasm_error(ERR_NONFATAL, "expecting `)'");
+ nasm_nonfatal("expecting `)'");
return -1;
}
}
@@ -971,8 +967,8 @@ static int bin_read_attribute(char **line, int *attribute,
/* Check for no value given. */
if (!*exp) {
- nasm_error(ERR_WARNING, "No value given to attribute in"
- " `section' directive");
+ nasm_warn("No value given to attribute in"
+ " `section' directive");
return -1;
}
@@ -983,13 +979,13 @@ static int bin_read_attribute(char **line, int *attribute,
e = evaluate(stdscan, NULL, &tokval, NULL, 1, NULL);
if (e) {
if (!is_really_simple(e)) {
- nasm_error(ERR_NONFATAL, "section attribute value must be"
- " a critical expression");
+ nasm_nonfatal("section attribute value must be"
+ " a critical expression");
return -1;
}
} else {
- nasm_error(ERR_NONFATAL, "Invalid attribute value"
- " specified in `section' directive.");
+ nasm_nonfatal("Invalid attribute value"
+ " specified in `section' directive.");
return -1;
}
*value = (uint64_t)reloc_value(e);
@@ -1033,8 +1029,7 @@ static void bin_assign_attributes(struct Section *sec, char *astring)
*astring = '\0';
astring++;
}
- nasm_error(ERR_WARNING, "ignoring unknown section attribute:"
- " \"%s\"", p);
+ nasm_warn("ignoring unknown section attribute: \"%s\"", p);
}
continue;
}
@@ -1043,9 +1038,8 @@ static void bin_assign_attributes(struct Section *sec, char *astring)
case ATTRIB_NOBITS:
if ((sec->flags & TYPE_DEFINED)
&& (sec->flags & TYPE_PROGBITS))
- nasm_error(ERR_NONFATAL,
- "attempt to change section type"
- " from progbits to nobits");
+ nasm_nonfatal("attempt to change section type"
+ " from progbits to nobits");
else
sec->flags |= TYPE_DEFINED | TYPE_NOBITS;
continue;
@@ -1053,8 +1047,8 @@ static void bin_assign_attributes(struct Section *sec, char *astring)
/* Handle progbits attribute. */
case ATTRIB_PROGBITS:
if ((sec->flags & TYPE_DEFINED) && (sec->flags & TYPE_NOBITS))
- nasm_error(ERR_NONFATAL, "attempt to change section type"
- " from nobits to progbits");
+ nasm_nonfatal("attempt to change section type"
+ " from nobits to progbits");
else
sec->flags |= TYPE_DEFINED | TYPE_PROGBITS;
continue;
@@ -1062,8 +1056,7 @@ static void bin_assign_attributes(struct Section *sec, char *astring)
/* Handle align attribute. */
case ATTRIB_ALIGN:
if (!value || ((value - 1) & value)) {
- nasm_error(ERR_NONFATAL,
- "argument to `align' is not a power of two");
+ nasm_nonfatal("argument to `align' is not a power of two");
} else {
/*
* Alignment is already satisfied if
@@ -1074,8 +1067,7 @@ static void bin_assign_attributes(struct Section *sec, char *astring)
/* Don't allow a conflicting align value. */
if ((sec->flags & START_DEFINED) && (sec->start & (value - 1))) {
- nasm_error(ERR_NONFATAL,
- "`align' value conflicts with section start address");
+ nasm_nonfatal("`align' value conflicts with section start address");
} else {
sec->align = value;
sec->flags |= ALIGN_DEFINED;
@@ -1086,8 +1078,7 @@ static void bin_assign_attributes(struct Section *sec, char *astring)
/* Handle valign attribute. */
case ATTRIB_VALIGN:
if (!value || ((value - 1) & value))
- nasm_error(ERR_NONFATAL, "argument to `valign' is not a"
- " power of two");
+ nasm_nonfatal("argument to `valign' is not a power of two");
else { /* Alignment is already satisfied if the previous
* align value is greater. */
if ((sec->flags & VALIGN_DEFINED) && (value < sec->valign))
@@ -1096,9 +1087,7 @@ static void bin_assign_attributes(struct Section *sec, char *astring)
/* Don't allow a conflicting valign value. */
if ((sec->flags & VSTART_DEFINED)
&& (sec->vstart & (value - 1)))
- nasm_error(ERR_NONFATAL,
- "`valign' value conflicts "
- "with `vstart' address");
+ nasm_nonfatal("`valign' value conflicts with `vstart' address");
else {
sec->valign = value;
sec->flags |= VALIGN_DEFINED;
@@ -1109,17 +1098,17 @@ static void bin_assign_attributes(struct Section *sec, char *astring)
/* Handle start attribute. */
case ATTRIB_START:
if (sec->flags & FOLLOWS_DEFINED)
- nasm_error(ERR_NONFATAL, "cannot combine `start' and `follows'"
- " section attributes");
+ nasm_nonfatal("cannot combine `start' and `follows'"
+ " section attributes");
else if ((sec->flags & START_DEFINED) && (value != sec->start))
- nasm_error(ERR_NONFATAL, "section start address redefined");
+ nasm_nonfatal("section start address redefined");
else {
sec->start = value;
sec->flags |= START_DEFINED;
if (sec->flags & ALIGN_DEFINED) {
if (sec->start & (sec->align - 1))
- nasm_error(ERR_NONFATAL, "`start' address conflicts"
- " with section alignment");
+ nasm_nonfatal("`start' address conflicts"
+ " with section alignment");
sec->flags ^= ALIGN_DEFINED;
}
}
@@ -1128,21 +1117,19 @@ static void bin_assign_attributes(struct Section *sec, char *astring)
/* Handle vstart attribute. */
case ATTRIB_VSTART:
if (sec->flags & VFOLLOWS_DEFINED)
- nasm_error(ERR_NONFATAL,
- "cannot combine `vstart' and `vfollows'"
- " section attributes");
+ nasm_nonfatal("cannot combine `vstart' and `vfollows'"
+ " section attributes");
else if ((sec->flags & VSTART_DEFINED)
&& (value != sec->vstart))
- nasm_error(ERR_NONFATAL,
- "section virtual start address"
- " (vstart) redefined");
+ nasm_nonfatal("section virtual start address"
+ " (vstart) redefined");
else {
sec->vstart = value;
sec->flags |= VSTART_DEFINED;
if (sec->flags & VALIGN_DEFINED) {
if (sec->vstart & (sec->valign - 1))
- nasm_error(ERR_NONFATAL, "`vstart' address conflicts"
- " with `valign' value");
+ nasm_nonfatal("`vstart' address conflicts"
+ " with `valign' value");
sec->flags ^= VALIGN_DEFINED;
}
}
@@ -1153,14 +1140,13 @@ static void bin_assign_attributes(struct Section *sec, char *astring)
p = astring;
astring += strcspn(astring, " \t");
if (astring == p)
- nasm_error(ERR_NONFATAL, "expecting section name for `follows'"
- " attribute");
+ nasm_nonfatal("expecting section name for `follows'"
+ " attribute");
else {
*(astring++) = '\0';
if (sec->flags & START_DEFINED)
- nasm_error(ERR_NONFATAL,
- "cannot combine `start' and `follows'"
- " section attributes");
+ nasm_nonfatal("cannot combine `start' and `follows'"
+ " section attributes");
sec->follows = nasm_strdup(p);
sec->flags |= FOLLOWS_DEFINED;
}
@@ -1169,16 +1155,14 @@ static void bin_assign_attributes(struct Section *sec, char *astring)
/* Handle vfollows attribute. */
case ATTRIB_VFOLLOWS:
if (sec->flags & VSTART_DEFINED)
- nasm_error(ERR_NONFATAL,
- "cannot combine `vstart' and `vfollows'"
- " section attributes");
+ nasm_nonfatal("cannot combine `vstart' and `vfollows'"
+ " section attributes");
else {
p = astring;
astring += strcspn(astring, " \t");
if (astring == p)
- nasm_error(ERR_NONFATAL,
- "expecting section name for `vfollows'"
- " attribute");
+ nasm_nonfatal("expecting section name for `vfollows'"
+ " attribute");
else {
*(astring++) = '\0';
sec->vfollows = nasm_strdup(p);
@@ -1293,21 +1277,21 @@ bin_directive(enum directive directive, char *args, int pass)
e = evaluate(stdscan, NULL, &tokval, NULL, 1, NULL);
if (e) {
if (!is_really_simple(e))
- nasm_error(ERR_NONFATAL, "org value must be a critical"
+ nasm_nonfatal("org value must be a critical"
" expression");
else {
value = reloc_value(e);
/* Check for ORG redefinition. */
if (origin_defined && (value != origin))
- nasm_error(ERR_NONFATAL, "program origin redefined");
+ nasm_nonfatal("program origin redefined");
else {
origin = value;
origin_defined = 1;
}
}
} else
- nasm_error(ERR_NONFATAL, "No or invalid offset specified"
- " in ORG directive.");
+ nasm_nonfatal("No or invalid offset specified"
+ " in ORG directive.");
return DIRR_OK;
}
case D_MAP:
@@ -1343,14 +1327,13 @@ bin_directive(enum directive directive, char *args, int pass)
else { /* Must be a filename. */
rf = nasm_open_write(p, NF_TEXT);
if (!rf) {
- nasm_error(ERR_WARNING, "unable to open map file `%s'",
- p);
+ nasm_warn("unable to open map file `%s'", p);
map_control = 0;
return DIRR_OK;
}
}
} else
- nasm_error(ERR_WARNING, "map file already specified");
+ nasm_warn("map file already specified");
}
if (map_control == 0)
map_control |= MAP_ORIGIN | MAP_SUMMARY;