|
View:
New views
1 Messages
—
Rating Filter:
Alert me
|
|
|
pull-requestHi Peter, please consider pulling from my repo the commits
mentioned below. For easier review I've appended a partial diff for this request (since style cleanup actually doesn't add any value on binary level but big enough to not include it here). Comments are appreciated. --- The following changes since commit 8d2c4edd229da337c6514df9854b9a9e27a7c9d9: H. Peter Anvin (1): assemble: when looking for a REGISTER operand, do an exclusive test are available in the git repository at: git://repo.or.cz/nasm-cyr.git master Cyrill Gorcunov (8): style cleanup use opflags_t type for operands introduce is_class macros use is_REGISTER helper introduce "overflow" helpers assemble.c: check constants for overflow nasmlib: introduce string helpers nasm.c: getkw -- use string helpers assemble.c | 52 ++++--- float.c | 542 ++++++++++++++++++++++++++++++------------------------------ hashtbl.c | 122 +++++++------- nasm.c | 63 +++---- nasm.h | 9 +- nasmlib.c | 36 ++++ nasmlib.h | 238 +++++++++++++++------------ 7 files changed, 569 insertions(+), 493 deletions(-) -- Cyrill --- From: Cyrill Gorcunov <gorcunov@...> Date: Sun, 11 Oct 2009 13:40:44 +0400 Subject: [PATCH 2/8] use opflags_t type for operands Signed-off-by: Cyrill Gorcunov <gorcunov@...> --- assemble.c | 2 +- nasm.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/assemble.c b/assemble.c index 8f13793..e948ee3 100644 --- a/assemble.c +++ b/assemble.c @@ -2141,7 +2141,7 @@ static enum match_result matches(const struct itemplate *itemp, * Check that the operand flags all match up */ for (i = 0; i < itemp->operands; i++) { - int32_t type = instruction->oprs[i].type; + opflags_t type = instruction->oprs[i].type; if (!(type & SIZE_MASK)) type |= size[i]; diff --git a/nasm.h b/nasm.h index 9e233fc..00cbddc 100644 --- a/nasm.h +++ b/nasm.h @@ -682,7 +682,7 @@ enum eval_hint { /* values for `hinttype' */ }; typedef struct operand { /* operand to an instruction */ - int32_t type; /* type of operand */ + opflags_t type; /* type of operand */ int disp_size; /* 0 means default; 16; 32; 64 */ enum reg_enum basereg, indexreg; /* address registers */ int scale; /* index scale */ -- From: Cyrill Gorcunov <gorcunov@...> Date: Sun, 11 Oct 2009 14:05:35 +0400 Subject: [PATCH 3/8] introduce is_class macros Signed-off-by: Cyrill Gorcunov <gorcunov@...> --- nasm.h | 7 +++++++ 1 files changed, 7 insertions(+), 0 deletions(-) diff --git a/nasm.h b/nasm.h index 00cbddc..269b2ea 100644 --- a/nasm.h +++ b/nasm.h @@ -539,6 +539,13 @@ typedef uint32_t opflags_t; #define MEMORY 0x0000c000U #define REGMEM 0x00008000U /* for r/m, ie EA, operands */ +#define is_class(class, op) (((opflags_t)(class) & (opflags_t)(op)) == (opflags_t)(class)) +#define is_class_any(class, op) (((opflags_t)(class) & (opflags_t)(op)) != (opflags_t)0) +#define is_REGISTER(op) is_class(REGISTER, op) +#define is_IMMEDIATE(op) is_class(IMMEDIATE, op) +#define is_MEMORY(op) is_class(MEMORY, op) +#define is_REGMEM(op) is_class(REGMEM, op) + /* Register classes */ #define REG_EA 0x00009000U /* 'normal' reg, qualifies as EA */ #define RM_GPR 0x00208000U /* integer operand */ -- From: Cyrill Gorcunov <gorcunov@...> Date: Sun, 11 Oct 2009 14:45:47 +0400 Subject: [PATCH 4/8] use is_REGISTER helper Signed-off-by: Cyrill Gorcunov <gorcunov@...> --- assemble.c | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-) diff --git a/assemble.c b/assemble.c index e948ee3..5e42bfe 100644 --- a/assemble.c +++ b/assemble.c @@ -2027,7 +2027,7 @@ static enum match_result find_match(const struct itemplate **tempp, * never try to fuzzy-match on them. This also resolves the case * when we have e.g. "xmmrm128" in two different positions. */ - if ((REGISTER & ~instruction->oprs[i].type) == 0) + if (is_REGISTER(instruction->oprs[i].type)) continue; /* This tests if xsizeflags[i] has more than one bit set */ @@ -2155,7 +2155,7 @@ static enum match_result matches(const struct itemplate *itemp, ((itemp->opd[i] ^ type) & SIZE_MASK))) { if ((itemp->opd[i] & ~type & ~SIZE_MASK) || (type & SIZE_MASK)) { return MERR_INVALOP; - } else if ((REGISTER & type) != REGISTER) { + } else if (!is_REGISTER(type)) { /* * Note: we don't honor extrinsic operand sizes for registers, * so "missing operand size" for a register should be @@ -2224,7 +2224,7 @@ static ea *process_ea(operand * input, ea * output, int bits, /* REX flags for the rfield operand */ output->rex |= rexflags(rfield, rflags, REX_R|REX_P|REX_W|REX_H); - if (!(REGISTER & ~input->type)) { /* register direct */ + if (is_REGISTER(input->type)) { /* register direct */ int i; int32_t f; -- From: Cyrill Gorcunov <gorcunov@...> Date: Sun, 11 Oct 2009 15:01:39 +0400 Subject: [PATCH 5/8] introduce "overflow" helpers Suggested-by: H. Peter Anvin <hpa@...> Signed-off-by: Cyrill Gorcunov <gorcunov@...> --- nasmlib.h | 27 +++++++++++++++++++++++++++ 1 files changed, 27 insertions(+), 0 deletions(-) diff --git a/nasmlib.h b/nasmlib.h index 689485b..441ea20 100644 --- a/nasmlib.h +++ b/nasmlib.h @@ -383,4 +383,31 @@ const char *prefix_name(int); extern const uint8_t zero_buffer[ZERO_BUF_SIZE]; size_t fwritezero(size_t bytes, FILE *fp); +static inline bool overflow_general(int64_t value, int bytes) +{ + int sbit = (bytes << 3) - 1; + int64_t vmax = ((int64_t)2 << sbit) - 1; + int64_t vmin = -((int64_t)1 << sbit); + + return value < vmin || value > vmax; +} + +static inline bool overflow_signed(int64_t value, int bytes) +{ + int sbit = (bytes << 3) - 1; + int64_t vmax = ((int64_t)1 << sbit) - 1; + int64_t vmin = -((int64_t)1 << sbit); + + return value < vmin || value > vmax; +} + +static inline bool overflow_unsigned(int64_t value, int bytes) +{ + int sbit = (bytes << 3) - 1; + int64_t vmax = ((int64_t)2 << sbit) - 1; + int64_t vmin = 0; + + return value < vmin || value > vmax; +} + #endif -- From: Cyrill Gorcunov <gorcunov@...> Date: Mon, 21 Sep 2009 00:56:20 +0400 Subject: [PATCH 6/8] assemble.c: check constants for overflow Lets check if a constant supplied to DB and etc does not overflow storage size and emit warning if needed. [ Bug #2857628 http://sourceforge.net/tracker/?func=detail&aid=2857628&group_id=6208&atid=106208 ] Signed-off-by: Cyrill Gorcunov <gorcunov@...> --- assemble.c | 44 +++++++++++++++++++++++++++----------------- 1 files changed, 27 insertions(+), 17 deletions(-) diff --git a/assemble.c b/assemble.c index 5e42bfe..e1f3f9d 100644 --- a/assemble.c +++ b/assemble.c @@ -240,17 +240,26 @@ static const char *size_name(int size) } } -static void warn_overflow(int size, const struct operand *o) +static void warn_overflow(int pass, int size) { - if (size < 8 && o->wrt == NO_SEG && o->segment == NO_SEG) { - int64_t lim = ((int64_t)1 << (size*8))-1; - int64_t data = o->offset; + errfunc(ERR_WARNING | pass | ERR_WARN_NOV, + "%s data exceeds bounds", size_name(size)); +} + +static void warn_overflow_const(int64_t data, int size) +{ + if (overflow_general(data, size)) + warn_overflow(ERR_PASS1, size); +} - if (data < ~lim || data > lim) - errfunc(ERR_WARNING | ERR_PASS2 | ERR_WARN_NOV, - "%s data exceeds bounds", size_name(size)); +static void warn_overflow_opd(const struct operand *o, int size) +{ + if (size < 8 && o->wrt == NO_SEG && o->segment == NO_SEG) { + if (overflow_general(o->offset, size)) + warn_overflow(ERR_PASS2, size); } } + /* * This routine wrappers the real output format's output routine, * in order to pass a copy of the data off to the listing file @@ -708,10 +717,11 @@ int64_t insn_size(int32_t segment, int64_t offset, int bits, uint32_t cp, int32_t align; osize = 0; - if (e->type == EOT_DB_NUMBER) + if (e->type == EOT_DB_NUMBER) { osize = 1; - else if (e->type == EOT_DB_STRING || - e->type == EOT_DB_STRING_FREE) + warn_overflow_const(e->offset, wsize); + } else if (e->type == EOT_DB_STRING || + e->type == EOT_DB_STRING_FREE) osize = e->stringlen; align = (-osize) % wsize; @@ -1343,7 +1353,7 @@ static void gencode(int32_t segment, int64_t offset, int bits, break; case4(030): - warn_overflow(2, opx); + warn_overflow_opd(opx, 2); data = opx->offset; out(offset, segment, &data, OUT_ADDRESS, 2, opx->segment, opx->wrt); @@ -1355,7 +1365,7 @@ static void gencode(int32_t segment, int64_t offset, int bits, size = (opx->type & BITS16) ? 2 : 4; else size = (bits == 16) ? 2 : 4; - warn_overflow(size, opx); + warn_overflow_opd(opx, size); data = opx->offset; out(offset, segment, &data, OUT_ADDRESS, size, opx->segment, opx->wrt); @@ -1363,7 +1373,7 @@ static void gencode(int32_t segment, int64_t offset, int bits, break; case4(040): - warn_overflow(4, opx); + warn_overflow_opd(opx, 4); data = opx->offset; out(offset, segment, &data, OUT_ADDRESS, 4, opx->segment, opx->wrt); @@ -1373,7 +1383,7 @@ static void gencode(int32_t segment, int64_t offset, int bits, case4(044): data = opx->offset; size = ins->addr_size >> 3; - warn_overflow(size, opx); + warn_overflow_opd(opx, size); out(offset, segment, &data, OUT_ADDRESS, size, opx->segment, opx->wrt); offset += size; @@ -1457,7 +1467,7 @@ static void gencode(int32_t segment, int64_t offset, int bits, case4(0140): data = opx->offset; - warn_overflow(2, opx); + warn_overflow_opd(opx, 2); if (is_sbyte16(opx)) { bytes[0] = data; out(offset, segment, bytes, OUT_RAWDATA, 1, NO_SEG, @@ -1481,7 +1491,7 @@ static void gencode(int32_t segment, int64_t offset, int bits, case4(0150): data = opx->offset; - warn_overflow(4, opx); + warn_overflow_opd(opx, 4); if (is_sbyte32(opx)) { bytes[0] = data; out(offset, segment, bytes, OUT_RAWDATA, 1, NO_SEG, @@ -1894,7 +1904,7 @@ static void gencode(int32_t segment, int64_t offset, int bits, case 4: case 8: data = opy->offset; - warn_overflow(ea_data.bytes, opy); + warn_overflow_opd(opy, ea_data.bytes); s += ea_data.bytes; if (ea_data.rip) { if (opy->segment == segment) { -- From: Cyrill Gorcunov <gorcunov@...> Date: Sun, 11 Oct 2009 16:51:31 +0400 Subject: [PATCH 7/8] nasmlib: introduce string helpers To make code more compact we introduce the following string helpers: 1) nasm_get_word - skip leading spaces 2) nasm_skip_word - skip leading non-spaces 3) nasm_zap_spaces - zap leading spaces with zero 4) nasm_zap_spaces_rev - zap spaces in reverse order Signed-off-by: Cyrill Gorcunov <gorcunov@...> --- nasmlib.c | 36 ++++++++++++++++++++++++++++++++++++ nasmlib.h | 5 +++++ 2 files changed, 41 insertions(+), 0 deletions(-) diff --git a/nasmlib.c b/nasmlib.c index 35aa505..2cdd61e 100644 --- a/nasmlib.c +++ b/nasmlib.c @@ -653,3 +653,39 @@ char *nasm_strcat(const char *one, const char *two) strcpy(rslt + l1, two); return rslt; } + +/* skip leading spaces */ +char *nasm_get_word(const char *p) +{ + if (p) + while (*p && nasm_isspace(*p)) + p++; + return (char *)p; +} + +/* skip leading non-spaces */ +char *nasm_skip_word(const char *p) +{ + if (p) + while (*p && !nasm_isspace(*p)) + p++; + return (char *)p; +} + +/* zap leading spaces with zero */ +char *nasm_zap_spaces(char *p) +{ + if (p) + while (*p && nasm_isspace(*p)) + *p++ = 0x0; + return p; +} + +/* zap spaces with zero in reverse order */ +char *nasm_zap_spaces_rev(char *p) +{ + if (p) + while (*p && nasm_isspace(*p)) + *p-- = 0x0; + return p; +} diff --git a/nasmlib.h b/nasmlib.h index 441ea20..6afa75b 100644 --- a/nasmlib.h +++ b/nasmlib.h @@ -377,6 +377,11 @@ int src_get(int32_t *xline, char **xname); char *nasm_strcat(const char *one, const char *two); +char *nasm_get_word(const char *p); +char *nasm_skip_word(const char *p); +char *nasm_zap_spaces(char *p); +char *nasm_zap_spaces_rev(char *p); + const char *prefix_name(int); #define ZERO_BUF_SIZE 4096 -- From: Cyrill Gorcunov <gorcunov@...> Date: Fri, 18 Sep 2009 19:23:53 +0400 Subject: [PATCH 8/8] nasm.c: getkw -- use string helpers This allow us to shrink code a bit and make it easy to read. Signed-off-by: Cyrill Gorcunov <gorcunov@...> --- nasm.c | 63 +++++++++++++++++++++++++++------------------------------------ 1 files changed, 27 insertions(+), 36 deletions(-) diff --git a/nasm.c b/nasm.c index 7bf7c57..d8dee68 100644 --- a/nasm.c +++ b/nasm.c @@ -1772,47 +1772,38 @@ static enum directives getkw(char **directive, char **value) { char *p, *q, *buf; - buf = *directive; - - /* allow leading spaces or tabs */ - while (*buf == ' ' || *buf == '\t') - buf++; + buf = nasm_get_word(*directive); + /* it should be enclosed in [ ] */ if (*buf != '[') - return 0; - - p = buf; - - while (*p && *p != ']') - p++; + return D_NONE; + q = strchr(buf, ']'); + if (!q) + return D_NONE; + + /* stip off the comments */ + p = strchr(buf, ';'); + if (p) { + if (p < q) /* ouch! somwhere inside */ + return D_NONE; + *p = '\0'; + } - if (!*p) - return 0; + /* no brace, no trailing spaces */ + *q = '\0'; + nasm_zap_spaces_rev(--q); - q = p++; + /* directive */ + p = nasm_get_word(++buf); + q = nasm_skip_word(p); + if (!q) + return D_NONE; /* sigh... no value there */ + *q = '\0'; + *directive = p; - while (*p && *p != ';') { - if (!nasm_isspace(*p)) - return 0; - p++; - } - q[1] = '\0'; - - *directive = p = buf + 1; - while (*buf && *buf != ' ' && *buf != ']' && *buf != '\t') - buf++; - if (*buf == ']') { - *buf = '\0'; - *value = buf; - } else { - *buf++ = '\0'; - while (nasm_isspace(*buf)) - buf++; /* beppu - skip leading whitespace */ - *value = buf; - while (*buf != ']') - buf++; - *buf++ = '\0'; - } + /* and value finally */ + p = nasm_get_word(++q); + *value = p; return find_directive(*directive); } -- ------------------------------------------------------------------------------ Come build with us! The BlackBerry(R) Developer Conference in SF, CA is the only developer event you need to attend this year. Jumpstart your developing skills, take BlackBerry mobile applications to market and stay ahead of the curve. Join us from November 9 - 12, 2009. Register now! http://p.sf.net/sfu/devconference _______________________________________________ Nasm-devel mailing list Nasm-devel@... https://lists.sourceforge.net/lists/listinfo/nasm-devel |
| Free embeddable forum powered by Nabble | Forum Help |