From: Peter Johnson Date: Fri, 20 Jul 2007 03:40:59 +0000 (-0000) Subject: Add support for second parameter (fill value) to .org directive in GAS X-Git-Tag: v0.6.2~8^2~13 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=36cdd57be284e60685a03c6016b3268711a21eb8;p=yasm Add support for second parameter (fill value) to .org directive in GAS parser. Add testcase for both local labels and .org fill. Noticed by: Jung Lee Testcase from: Xiaoming Mo svn path=/trunk/yasm/; revision=1899 --- diff --git a/libyasm/bc-org.c b/libyasm/bc-org.c index e354f23e..ae0497a2 100644 --- a/libyasm/bc-org.c +++ b/libyasm/bc-org.c @@ -41,6 +41,7 @@ typedef struct bytecode_org { unsigned long start; /* target starting offset within section */ + unsigned long fill; /* fill value */ } bytecode_org; static void bc_org_destroy(void *contents); @@ -133,16 +134,17 @@ bc_org_tobytes(yasm_bytecode *bc, unsigned char **bufp, void *d, } len = org->start - bc->offset; for (i=0; ifill); /* XXX: handle more than 8 bit? */ return 0; } yasm_bytecode * -yasm_bc_create_org(unsigned long start, unsigned long line) +yasm_bc_create_org(unsigned long start, unsigned long fill, unsigned long line) { bytecode_org *org = yasm_xmalloc(sizeof(bytecode_org)); org->start = start; + org->fill = fill; return yasm_bc_create_common(&bc_org_callback, org, line); } diff --git a/libyasm/bytecode.h b/libyasm/bytecode.h index afe8b147..e53dc542 100644 --- a/libyasm/bytecode.h +++ b/libyasm/bytecode.h @@ -351,11 +351,12 @@ void yasm_bc_set_multiple(yasm_bytecode *bc, /*@keep@*/ yasm_expr *e); /** Create a bytecode that puts the following bytecode at a fixed section * offset. * \param start section offset of following bytecode + * \param fill fill value * \param line virtual line (from yasm_linemap) * \return Newly allocated bytecode. */ /*@only@*/ yasm_bytecode *yasm_bc_create_org - (unsigned long start, unsigned long line); + (unsigned long start, unsigned long fill, unsigned long line); /** Get the section that contains a particular bytecode. * \param bc bytecode diff --git a/modules/parsers/gas/gas-parse.c b/modules/parsers/gas/gas-parse.c index 6f92ebb2..f45b35f8 100644 --- a/modules/parsers/gas/gas-parse.c +++ b/modules/parsers/gas/gas-parse.c @@ -388,14 +388,32 @@ parse_line(yasm_parser_gas *parser_gas) (int)ival); } case DIR_ORG: + { + yasm_intnum *start, *value=NULL; get_next_token(); /* DIR_ORG */ - if (!expect(INTNUM)) return NULL; + /* TODO: support expr instead of intnum */ - bc = yasm_bc_create_org(yasm_intnum_get_uint(INTNUM_val), cur_line); - yasm_intnum_destroy(INTNUM_val); + if (!expect(INTNUM)) return NULL; + start = INTNUM_val; get_next_token(); /* INTNUM */ + + if (curtok == ',') { + get_next_token(); /* ',' */ + /* TODO: support expr instead of intnum */ + if (!expect(INTNUM)) return NULL; + value = INTNUM_val; + get_next_token(); /* INTNUM */ + } + if (value) { + bc = yasm_bc_create_org(yasm_intnum_get_uint(start), + yasm_intnum_get_uint(value), cur_line); + yasm_intnum_destroy(value); + } else + bc = yasm_bc_create_org(yasm_intnum_get_uint(start), 0, + cur_line); + yasm_intnum_destroy(start); return bc; - + } /* Data visibility directives */ case DIR_LOCAL: get_next_token(); /* DIR_LOCAL */ diff --git a/modules/parsers/gas/tests/bin/Makefile.inc b/modules/parsers/gas/tests/bin/Makefile.inc index 8132e69c..196b82aa 100644 --- a/modules/parsers/gas/tests/bin/Makefile.inc +++ b/modules/parsers/gas/tests/bin/Makefile.inc @@ -6,6 +6,8 @@ EXTRA_DIST += modules/parsers/gas/tests/bin/gas_bin_test.sh EXTRA_DIST += modules/parsers/gas/tests/bin/gas-comment.asm EXTRA_DIST += modules/parsers/gas/tests/bin/gas-comment.errwarn EXTRA_DIST += modules/parsers/gas/tests/bin/gas-comment.hex +EXTRA_DIST += modules/parsers/gas/tests/bin/gas-llabel.asm +EXTRA_DIST += modules/parsers/gas/tests/bin/gas-llabel.hex EXTRA_DIST += modules/parsers/gas/tests/bin/gas-set.asm EXTRA_DIST += modules/parsers/gas/tests/bin/gas-set.hex EXTRA_DIST += modules/parsers/gas/tests/bin/rept-err.asm diff --git a/modules/parsers/gas/tests/bin/gas-llabel.asm b/modules/parsers/gas/tests/bin/gas-llabel.asm new file mode 100644 index 00000000..11f3f545 --- /dev/null +++ b/modules/parsers/gas/tests/bin/gas-llabel.asm @@ -0,0 +1,29 @@ +# Skelix by Xiaoming Mo (xiaoming.mo@skelix.org) +# Licence: GPLv2 + .text + #.globl start + .code16 +start: + jmp code +msg: + .string "Hello World!\x0" +code: + movw $0xb800,%ax + movw %ax, %es + xorw %ax, %ax + movw %ax, %ds + + movw $msg, %si + xorw %di, %di + cld + movb $0x07, %al +1: + cmpw $0, (%si) + je 1f + movsb + stosb + jmp 1b +1: jmp 1b +.org 0x1fe, 0x90 +.word 0xaa55 + diff --git a/modules/parsers/gas/tests/bin/gas-llabel.hex b/modules/parsers/gas/tests/bin/gas-llabel.hex new file mode 100644 index 00000000..4bef5c77 --- /dev/null +++ b/modules/parsers/gas/tests/bin/gas-llabel.hex @@ -0,0 +1,512 @@ +eb +0e +48 +65 +6c +6c +6f +20 +57 +6f +72 +6c +64 +21 +00 +00 +b8 +00 +b8 +8e +c0 +31 +c0 +8e +d8 +be +02 +00 +31 +ff +fc +b0 +07 +83 +3c +00 +74 +04 +a4 +aa +eb +f7 +eb +fe +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +55 +aa diff --git a/tools/python-yasm/bytecode.pxi b/tools/python-yasm/bytecode.pxi index 8a077b0d..193e3a6c 100644 --- a/tools/python-yasm/bytecode.pxi +++ b/tools/python-yasm/bytecode.pxi @@ -93,9 +93,9 @@ cdef object __make_bytecode(yasm_bytecode *bc): return bcobj # Org bytecode -def __org__new__(cls, start, line=0): +def __org__new__(cls, start, value=0, line=0): cdef yasm_bytecode *bc - bc = yasm_bc_create_org(start, line) + bc = yasm_bc_create_org(start, line, value) obj = Bytecode.__new__(cls, __pass_voidp(bc, Bytecode)) __bytecode_map[PyCObject_FromVoidPtr(bc, NULL)] = obj return obj