parser.
Add testcase for both local labels and .org fill.
Noticed by: Jung Lee <moorang@gmail.com>
Testcase from: Xiaoming Mo <xiaoming.mo@skelix.org>
svn path=/trunk/yasm/; revision=1899
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);
}
len = org->start - bc->offset;
for (i=0; i<len; i++)
- YASM_WRITE_8(*bufp, 0);
+ YASM_WRITE_8(*bufp, org->fill); /* 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);
}
/** 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
(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 */
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
--- /dev/null
+# 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
+
--- /dev/null
+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
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