Commit graph

139 commits

Author SHA1 Message Date
Peter Johnson
469e54fa4a Update all copyright dates.
svn path=/trunk/yasm/; revision=1827
2007-04-22 05:09:49 +00:00
Peter Johnson
00473ca981 Bite the bullet and convert tabs to spaces. Previously yasm's source has
been using a mix of tabs and 4 spaces to indent; this looks horrible if
tab size is ever not 8.  While I debated converting to tab-only indentation
that would have been a far higher impact to the source.

svn path=/trunk/yasm/; revision=1825
2007-04-22 03:32:46 +00:00
Peter Johnson
a770e511c1 Move libyasm-stdint.h include out of util.h, as util.h is included from
build platform files.

While here, fix a few warnings by pushing uintptr_t to a few more register
usages.

Noticed by: rugxulo@gmail.com

svn path=/trunk/yasm/; revision=1786
2007-02-24 04:16:05 +00:00
Peter Johnson
d260877b31 Allow multiples to become temporarily negative during optimization.
Negative multiples are still checked for during output.

svn path=/trunk/yasm/; revision=1752
2007-02-04 00:34:28 +00:00
Peter Johnson
95e57a41e4 Fix handling of times 0 <...>.
svn path=/trunk/yasm/; revision=1750
2007-02-03 23:52:44 +00:00
Peter Johnson
9ab89fdfe6 Take [1423] to the next logical step by supporting the general case of
(sym in other section)-(sym in this section) rather than just
(sym in other section)-(curpos) (e.g. sym-$).  Unfortunately supporting
this required precbc to be flowed down to the value_finalize functions,
but it's relatively reasonable to do so, as all of the _finalize() routines
have access to precbc.

Reported by: Peter Tanski <peter_tanski@cox.net>

svn path=/trunk/yasm/; revision=1705
2006-12-10 07:05:06 +00:00
Peter Johnson
bc85eba4f5 Support optimization of multiple.
svn path=/branches/new-optimizer/; revision=1589
2006-06-21 06:25:52 +00:00
Peter Johnson
9445734d22 In preparation for further work on optimizing multiple, break multiple apart
from bytecode.len into bytecode.mult_int.  Add new function
yasm_bc_next_offset() to handle the most common use case of bytecode.len,
figuring out the following bytecode's offset.

svn path=/branches/new-optimizer/; revision=1586
2006-06-20 06:23:07 +00:00
Peter Johnson
c2de3a1667 Start implementing support for multiples.
svn path=/branches/new-optimizer/; revision=1585
2006-06-19 06:18:11 +00:00
Peter Johnson
114cee8b06 Implement first phase of align and org.
svn path=/branches/new-optimizer/; revision=1567
2006-06-11 06:57:03 +00:00
Peter Johnson
ad687bb34a Get rid of origin_prevbc; it's no longer needed due to yasm_value handling
of PC-relative values.

Add new yasm_value_get_intnum(); this is a simplified variant of
yasm_value_output_basic().

svn path=/branches/new-optimizer/; revision=1560
2006-06-10 04:01:12 +00:00
Peter Johnson
a7b6526ea4 Get rid of calc_bc_dist_func, the only times this was used was when
yasm_common_calc_bc_dist was used.  Rename yasm_common_calc_bc_dist to
yasm_calc_bc_dist, call it directly from the expr functions, and change
higher-level callers to boolean flags of whether to calculate bc distance
or not.

svn path=/branches/new-optimizer/; revision=1550
2006-06-07 04:01:33 +00:00
Peter Johnson
eca4d7c5c2 Merge [1333]-[1543] (inclusive) into new-optimizer branch. This results in
a temporary regression of functionality but will yield some benefits later
on (chief among them is easier eventual merging back to the mainline!).

svn path=/branches/new-optimizer/; revision=1545
2006-05-31 06:13:01 +00:00
Peter Johnson
26e2ac882f Change calc_len to call back to add_span function so that multiple spans can
be added by a single calc_len.

svn path=/branches/new-optimizer/; revision=1544
2006-05-28 04:54:44 +00:00
Peter Johnson
fe09480565 Fix major bug related to multiple handling. Unfortunately this slows down
bytecode multiple output significantly, but this way handles generating
relocations correctly (otherwise extern foo; times 5 dd foo doesn't work!).

* bytecode.h (yasm_bc_tobytes): Remove multiple output parameter.
(yasm_bc_get_multiple): New.
* bytecode.c (yasm_bc_tobytes): Update to iterate through multiple here.
(yasm_bc_get_multiple): New.
* xdf-objfmt.c, elf-objfmt.c, bin-objfmt.c, coff-objfmt.c: Don't iterate
through multiple here.
* nasm-listfmt.c: Use yasm_bc_get_multiple() to get multiple instead of
yasm_bc_tobytes().

* bytecode.pxi: Update.

* tests/win32-relocovfl.asm: Tests both this and [1534] but generates too
huge of a file (3MB) to be put into the automated tests.

svn path=/trunk/yasm/; revision=1536
2006-05-11 07:00:33 +00:00
Peter Johnson
83c0ecaaec * coretype.h (yasm_value): Add size field (specified in bits).
(yasm_value_output_func): Remove valsize and shift parameters.
* bytecode.h (yasm_effaddr): Remove disp_len, replacing with
need_nonzero_len.
(yasm_immval): Remove len.
* value.h (yasm_value_initialize): Add size parameter.
(yasm_value_finalize_expr): Likewise.
(yasm_value_output_basic): Remove valsize and shift parameters.

Update all implementations and users for the above.

* intnum.c (yasm_intnum_calc): Fix bug in shift right (was doing a logical
instead of arithmetic shift).

* lc3b-basic.asm, lc3b-basic.errwarn, lc3b-basic.hex: Update based on
fixed warnings.

svn path=/trunk/yasm/; revision=1534
2006-05-10 08:54:52 +00:00
Peter Johnson
ad54f1bf5c * bc-int.h (yasm_bytecode_callback): Add reserve flag to indicate if the
bytecode outputs just space and not data.
* bytecode.pxi: Update to match.
* bytecode.c (yasm_bc_tobytes): Use reserve flag instead of checking
against bytecode_reserve as special case.
* dwarf2-info.c, dwarf2-line.c, dwarf2-dbgfmt.c, cv-symline.c, cv-type.c,
* stabs-dbgfmt.c, lc3bbc.c, x86bc.c: Update to set reserve=0.

* bc-align.c, bc-insn.c, bc-reserve.c, bc-org.c, bc-incbin.c, bc-data.c,
* bytecode.c: Split out bytecodes into separate files.  While we're here,
merge LEB128 into general data bytecode.


svn path=/trunk/yasm/; revision=1532
2006-05-10 04:18:23 +00:00
Peter Johnson
d5a77fddaf Try to combine as much data as possible into single raw (used to be string)
dataval data bytecode blocks.  This drastically cuts down on dataval
overhead for large sets of constant data (savings of 30% or more on peak
memory usage in some cases).  We may try to improve this even more down the
road by doing things like combining across multiple data bytecodes and
converting constant instructions into raw bytes.

* bytecode.c (yasm_bc_create_data): Add (optional) yasm_arch operand so that
bytes can be generated from constant values of >1 byte size.  Do as much
simplification to constant raw bytes here as possible.
(bytecode_data): No longer a need to remember append_zero.
(bc_data_resolve, bc_data_output): Update to not handle append_zero.
(yasm_dataval): Rename string to raw.
(yasm_dv_create_string): Rename to:
(yasm_dv_create_raw): Here.

* bytecode.h (yasm_dv_create_string): Change into macro that casts parameters
into yasm_dv_create_raw().
(yasm_dv_create_raw): New.

modules: Update for new yasm_bc_create_data() parameter.

svn path=/trunk/yasm/; revision=1530
2006-05-08 08:08:15 +00:00
Peter Johnson
4c33af41ec Revamp error/warning handling, using a model similar to Python's internal
exception handling.  There are now two layers an error or warning goes
through before it hits the user: first an error is logged via
yasm_error_set() (or yasm_warn_set() for a warning).  Only one error may
be set, whereas multiple warnings can be set (yasm_warn_set maintains a
linked list).  Then, calling yasm_errwarn_propagate() propagates any error
and/or warning(s) to an errwarns structure and associates the
errors/warnings with a line number at that time; this call also clears the
pending errors/warnings and allows new ones to be set.  The propagate
function can safely be called when there are no pending error/warnings.

In addition, there are some helper errwarn functions that allow clearing of
an error/warning without propagating, getting it separately, etc.

Still yet to be done: changing most/all uses of yasm_internal_error() into
yasm_error_set(YASM_ERROR_ASSERTION).

The main advantage this change has is making libyasm functions feel much
more library like, and separating the user code line numbers from the inner
function error handling (e.g. intnum create functions only needed the line
number to trigger errors; this is no longer required).

The set/propagate/etc functions use global data structures to avoid passing
around a pointer to every function.  This would need to be made thread-local
data in a threaded app.  Errwarns containers (that keep associated line
numbers) are no longer global, so multiple source streams can be processed
separately with no conflict (at least if there's only a single thread of
execution).

svn path=/trunk/yasm/; revision=1521
2006-05-04 07:55:32 +00:00
Peter Johnson
9fa87cdae1 Massive cleanup of relocation and WRT handling. Closes #49 and lays the
groundwork for further features and possible cleanups.

Note: this commit changes the way in which relocations in the
COFF/Win32/Win64 target can be forced to reference a different symbol than
is being pointed to; instead of the ambiguous "trap+(trap.end-trap)" to get
the reloc to point at trap.end but reference the trap symbol, after this
commit "trap.end wrt trap" is the way to say this.  This also reads a lot
more clearly and is not ambiguous.  This should really only affect people
who write .pdata sections for Win64.  See the
objfmts/win64/tests/win64-dataref.asm testcase for an example of usage.

This cleanup adds a new data structure, yasm_value, which is used for all
expressions that can be potentially relocatable.  This data structure
splits the absolute portion of the expression away from the relative
portion and any modifications to the relative portion (SEG, WRT,
PC-relative, etc).  A large amount of code in the new value module breaks
a general expression into its absolute and relative parts
(yasm_value_finalize_expr) and provides a common set of code for writing
out non-relocated values (yasm_value_output_basic).

All bytecode handling in both libyasm and the architecture modules was
rewritten to use yasm_values when appropriate (e.g. data values,
immediates, and effective addresses).  The yasm_output_expr_func is now
yasm_output_value_func and all users and implementors (mainly in object
formats) have been updated to handle yasm_values.

Simultaneously with this change, yasm_effaddr and yasm_immval full
structure definitions have been moved from bc-int.h to bytecode.h.
The data hiding provided by bc-int.h was relatively minimal and probably
overkill.  Also, great simplifications have been made to x86 effective
address expression handling.

svn path=/trunk/yasm/; revision=1419
2006-03-19 04:18:10 +00:00
Peter Johnson
a8871be674 * bytecode.c (yasm_bc_destroy): Only xfree symrecs if non-NULL.
(bc_align_destroy): Free boundary and maxskip (closing memory leaks).
* gas-bison.y (gas_get_section): Don't strdup name, it's always passed
in already strdup'ed/allocated (closes memory leak).

svn path=/trunk/yasm/; revision=1403
2006-03-05 09:29:52 +00:00
Peter Johnson
43308cd122 * bytecode.c (yasm_bc_create_insn): Use yasm_ops_initialize() instead of
STAILQ_INIT().
(yasm_bc_create_empty_insn): Initialize operands member.

svn path=/trunk/yasm/; revision=1400
2006-03-05 08:02:35 +00:00
Peter Johnson
48720ff6a6 Fix a few things found by valgrind. There will be more of these.
* bytecode.c (yasm_bc_create_insn): Initialize operands list if none were
given.
* section.c (yasm_object_destroy): Free filenames.
* gas-token.c (fill): Use memmove instead of memcpy on overlapping memory
copy.
* nasm-token.c (fill): Likewise.
* elf.c (elf_secthead_destroy): Free size member.

svn path=/trunk/yasm/; revision=1399
2006-03-05 07:50:16 +00:00
Peter Johnson
96be946565 * bytecode.c (yasm_bc_tobytes): *really* fix handling of bytecodes larger than provided buffer.
The only way to cause this to happen is with incbin, and while we do have a test intended for this,
it doesn't actually check this functionality due to a change made to unbreak distcheck; next up is
figuring out a good test that will work for different source/build directories.

svn path=/trunk/yasm/; revision=1362
2006-02-05 02:47:56 +00:00
Peter Johnson
309ee78ee4 Merge [1270] - [1332] (inclusive) into new-optimizer branch. It's going
to need some of these changes during implementation and testing.

svn path=/branches/new-optimizer/; revision=1335
2006-01-17 07:54:30 +00:00
Peter Johnson
7f72306ed5 Make negative times value an error case.
* bytecode.c (yasm_bc_resolve, yasm_bc_tobytes): Look for negative multiple.

* timesover-err.asm: New testcase for this.

Reported by: Stefan <SMarF@gmx.de>

svn path=/trunk/yasm/; revision=1296
2005-10-30 06:15:15 +00:00
Peter Johnson
1abcdbfc01 Enhance builtin bytecode_data to support embedded NULs in character strings.
While NASM doesn't allow this, GAS does.

While we're here, greatly clean up GAS data bytecode creation by no longer
building intermediate valparam list.

* bytecode.h (yasm_dv_create_string): Add length parameter.
(yasm_bc_create_data): Add append_zero parameter for new ability to append
a single ero byte after each data value.  This is used by the GAS .asciz
directive.
* bytecode.c (bytecode_data, ...): Implement the above.

* gas-bison.y (gas_define_strings, gas_define_data)
(gas_define_leb128): Remove; replace in usage with direct calls to bytecode
functions.  Add str, dataval, and datavalhead to parser union.  Add new
dirvals, which has valparams type, and change strvals and datavals to
datavals type.
* gas-token.re: Use new str type where STRING token is generated.

* nasm-bison.y: Add str type to union, and use for STRING token.
* nasm-token.re: Use new str type where STRING token is generated.

* coff-objfmt.c (win32_objfmt_directive): Adjust for updates to
bytecode_data.

* strzero.asm: Simple test for NUL in GAS string.


svn path=/trunk/yasm/; revision=1293
2005-10-26 03:22:44 +00:00
Peter Johnson
4024e3b87e Support standalone, segment, and REX prefixes in GAS mode.
* bytecode.c (yasm_bc_create_empty_insn): New function to create empty
instruction that can have prefixes applied to it, for standalone prefixes.
* bytecode.h (yasm_bc_create_empty_insn): Prototype.

* x86arch.h (x86_parse_insn_prefix): Add prefix types for segment registers
(X86_SEGREG) and REX bytes (X86_REX).
(yasm_x86__bc_apply_prefixes): Adjust prototype to include REX pointer (as
this isn't in the x86_common structure).
* x86bc.c (yasm_x86__bc_apply_prefixes): Support the new prefix types.

* x86id.re (x86_finalize_*): Use const x86_insn_info; all insn_infos are
const so these pointers should be as well.
(yasm_x86__finalize_insn): Handle empty instruction case by pointing to new
empty_insn info.
(empty_insn): New.
(yasm_x86__parse_check_prefix): Support GAS prefix naming, and REX and jump
hint prefixes (only in GAS mode at the moment).

* gas-bison.y: Add rules to handle segreg prefixes as well as standalone
prefixes (both segreg and others).

* gas-prefix.asm: New testcase that also hits the warning cases in
yasm_x86__bc_apply_prefixes X86_REX case.

svn path=/trunk/yasm/; revision=1292
2005-10-24 04:48:37 +00:00
Peter Johnson
1ddc1272d2 Add support for LEB128 encoded integers (both signed and unsigned). This
is needed for the GAS .uleb128 and .sleb128 directives.

* intnum.c (yasm_intnum_sign): New signedness discovery function.
* intnum.h (yasm_intnum_sign): Prototype.

* intnum.c (yasm_intnum_get_leb128, yasm_intnum_size_leb128): New.
* intnum.h (yasm_intnum_get_leb128, yasm_intnum_size_leb128): Prototype.
* leb128_test.c: New test for intnum-level LEB128 functions.

* bytecode.c (bytecode_leb128): New bytecode and supporting functions.
(yasm_bc_create_leb128): New creation function.
* bytecode.h (yasm_bc_create_leb128): Prototype.

* gas-token.re: Recognize .uleb128 and .sleb128.
* gas-bison.y: Ditto.
(gas_define_leb128): New.
* leb128.asm: New test for GAS .uleb128 and .sleb128 directives.

svn path=/trunk/yasm/; revision=1287
2005-10-17 07:43:16 +00:00
Peter Johnson
77a535f673 Create new working branch for new (Robertson 1977) optimizer.
This doesn't really work yet, which is why it's on a branch!

svn path=/branches/new-optimizer/; revision=1269
2005-10-08 05:45:29 +00:00
Peter Johnson
8cecb5b2a1 * bytecode.c (bc_align_tobytes): Handle cases where some code fills don't
exist (this happens in LC3b).
* lc3barch.c (lc3b_get_fill): NOP pattern is actually all 0's.

svn path=/trunk/yasm/; revision=1264
2005-10-03 06:49:15 +00:00
Peter Johnson
d660906db5 Implement align and org bytecodes. While we're here, implement .zero
directive for GAS (it's generated by GCC).

* bytecode.c (bytecode_align): Update for full align implementation.
(yasm_bc_create_align): Likewise.
(bc_align_finalize): New.
(bc_align_resolve, bc_align_tobytes): Real implementation.
* bytecode.h (yasm_bc_create_align): Update to match.
* arch.h (get_fill, yasm_arch_get_fill): New, to get NOP fill patterns.
* x86arch.c (x86_get_fill): Implement.
* lc3barch.c (lc3b_get_fill): Likewise (probably buggy, there's no real NOP).

* bytecode.c (bytecode_org): New org bytecode.
(bc_org_callback, bc_org_destroy, bc_org_print, bc_org_resolve)
(bc_org_tobytes, yasm_bc_create_org): Implement.

* gas-parser.h (yasm_parser_gas): Add code_section flag to indicate when to
use code fill vs. data fill.
* gas-parser.c: Initialize flag.
* gas-bison.y: Update flag in various places.  Generate org bytecode.
Call gas_parser_align to generate align bytecode.
(gas_parser_align): Generate align bytecode.

* gas-bison.y: Implement .zero directive.
* gas-token.re: Likewise.

* align32, align64: New tests to test align directive NOP generation.

svn path=/trunk/yasm/; revision=1263
2005-10-03 05:52:04 +00:00
Peter Johnson
a43f40ebf3 Revert [1251]. From further investigation, ML64's generation of REL32 in
these cases seems to be a bug.  If you get a linker error about ADDR32, it
means you aren't using RIP-relative instructions.  Note this means to access
an array you need to do:
  lea rax, [var wrt rip] ; generates RIP-relative insn and REL32 reloc
  mov rcx, [rax+rbx]     ; rbx is index
and not:
  mov rcx, [var+rbx]     ; generates ADDR32 reloc
At least when trying to build a DLL (the ADDR32 reloc fails the DLL link).
When building statically, ADDR32 should work okay and thus the latter form
can be used.

svn path=/trunk/yasm/; revision=1257
2005-10-01 05:47:54 +00:00
Peter Johnson
253056c994 * coff-objfmt.c (coff_objfmt_output_expr): Change relocations output for
instructions in Win64 to always be REL32 regardless of whether they're
RIP relative or not.  I don't understand this behavior, but it matches how
ML64 generates relocs and unbreaks linking.  The handling of this case must
be handled at a higher level somehow (either at the linker or the compiler).
Note that this REL32 generation behavior of ML64 happens only with the
latest version (VC8); the 2003 SP1 SDK ML64 doesn't do this.

* bytecode.c (yasm_bc_is_data): New supporting function.
* bytecode.h (yasm_bc_is_data): Prototype.

Testcase pending.

Reported by and much debugging support contributed by:
  Brian Gladman <brg@gladman.plus.com>. Thanks!

svn path=/trunk/yasm/; revision=1251
2005-09-28 03:23:24 +00:00
Peter Johnson
aa2571e22b Preliminary GAS parser. Only a few instructions are supported at present.
This work is being done under contract with a company that has requested
to remain unnamed at the present time.

* bc-int.h (yasm_effaddr): Add strong flag to indicate if the effective
address is definitely an effective address; GAS does not use [] to designate
effective addresses so it's otherwise impossible to tell the difference
between "expr(,1)" and just "expr" (important for the relative jump
instructions).
* bytecode.h (yasm_ea_set_strong): New function to set the strong flag.
* bytecode.c (yasm_ea_set_strong): Implementation.
* x86bc.c (yasm_x86__ea_create_reg): Initialize strong flag.

* arch.h (yasm_insn_operand): Add deref flag to indicate use of "*foo" in
GAS syntax.
* arch.c (yasm_operand_create_reg, yasm_operand_create_segreg)
(yasm_operand_create_mem, yasm_operand_create_imm): Set deref flag to 0.

* gas: GAS syntax lexer and parser.  Not all directives are implemented yet
(some will require additional core bytecodes).

* elf-objfmt.c (elf_objfmt_section_switch): Add support for GAS-style
section flags.

* x86arch.h (yasm_arch_x86): Add parser setting.
* x86arch.c (x86_create): Check for gas parser and initialize setting.

* x86bc.c (yasm_x86__ea_create_expr): Transform val+RIP to val wrt RIP when
using the GAS parser (this is how GAS interprets "expr(%rip)").

* x86id.re: Too many changes to enumerate in detail.  Add new modifiers for
GAS suffixes.  Start using them in a couple instructions.  Split check_id
into subfunctions (still one entry point at present).
(yasm_x86__finalize_insn): Support new modifiers, reverse operands, derefs.

* yasm.c (main): Change all undef to extern when using GAS parser (this is
default GAS behavior).


svn path=/trunk/yasm/; revision=1239
2005-09-25 04:25:26 +00:00
Peter Johnson
ca1f865343 * bytecode.c (bc_incbin_tobytes): Fix fread call so that return value check
works (was broken for >1 byte files).
(yasm_bc_tobytes): Fix handling of bytecodes that are larger than provided
buffer.

Patch by: Stephen Polkowski <stephen@centtech.com>

svn path=/trunk/yasm/; revision=1219
2005-08-27 02:05:36 +00:00
Peter Johnson
35304f5427 Refactor some the x86 bytecode handling now that we parse the entire file
before finalizing instructions.

* x86arch.h (yasm_x86__bc_apply_prefixes): Don't take num_segregs and
prefixes parameters.
* x86bc.c (yasm_x86__bc_apply_prefixes): Move segreg code to...
* x86id.re (yasm_x86__finalize_insn): Here (only user of this code).
(x86_finalize_jmp): Don't pass num_segregs and prefixes.

* x86arch.h (x86_common): New; refactored common bytecode parameters.
(x86_opcode): New; refactored opcode parameters.
(x86_insn): Refactor with x86_common and x86_opcode.
(x86_jmp): Likewise.
* x86id.re (x86_finalize_common, x86_finalize_opcode): New.
(yasm_x86__finalize_insn, x86_finalize_jmp): Use and update substruct refs.
* x86bc.c (x86_common_print, x86_opcode_print): New.
(x86_bc_insn_print, x86_bc_jmp_print): Use and update substruct refs.
(x86_common_resolve): New.
(x86_bc_insn_resolve, x86_bc_jmp_resolve): Use and update substruct refs.
(x86_common_tobytes, x86_opcode_tobytes): New.
(x86_bc_insn_tobytes, x86_bc_jmp_tobytes): Use and update substruct refs.
(yasm_x86__bc_apply_prefixes): Utilize refactor to simplify.

* bytecode.c (bc_insn_finalize): Simplify (or at least level) immediates
and memory operands before passing them off to yasm_arch_finalize_insn().
This may result in some minor performance improvement on complex static
expressions.

* x86arch.h (x86_parse_targetmod): Add X86_FAR_SEGOFF; this is only
generated due to a SEG:OFF immediate being detected during finalize.
(x86_jmp_opcode_sel): Remove JMP_FAR; this is now a separate bytecode.
(x86_jmp): Remove far opcode.
(x86_jmpfar): New bytecode for far jumps.
(yasm_x86__bc_transform_jmpfar): New.
* x86bc.c (x86_bc_callback_jmpfar): New.
(yasm_x86__bc_transform_jmpfar, x86_bc_jmpfar_destroy): New.
(x86_bc_jmp_print): Move far jump code to..
(x86_bc_jmpfar_print): Here (new).
(x86_bc_jmp_resolve, x86_bc_jmpfar_resolve): Likewise (latter new).
(x86_bc_jmp_tobytes, x86_bc_jmpfar_tobytes): Likewise (latter new).
* x86id.re (OPAP_JmpFar): Remove (detected immediately now).
(jmp_insn, call_insn): Update.
(x86_finalize_jmpfar): New.
(x86_finalize_jmp): Remove far jump-related code.
(yasm_x86__finalize_insn): Add check for SEG:OFF immediate operand, and
apply X86_FAR_SEGOFF if necessary.  Match OPTM_Far against both X86_FAR
and X86_FAR_SEGOFF.  Add shortcut to x86_finalize_jmpfar().


svn path=/trunk/yasm/; revision=1182
2004-11-18 06:17:35 +00:00
Peter Johnson
a44fb7746c Move generation of arch instruction bytecodes from on-the-fly during the
initial parse stage to a new pass between parse and optimization.  This
should allow for more accurate generation of arch bytecodes and other future
code simplifications in arch.

This change necessitated changing how bytecodes are extended from the base
yasm_bytecode structure; the original method did not allow for bytecodes to
be reliably changed from one type to another, as reallocation of the base
structure to fit the new type could result in the entire structure being
relocated on the heap, and thus all the pointer references to the original
bytecode being lost.  After this commit, the yasm_bytecode base structure
has a void pointer to any extension data.  This change rippled across all
bytecode-creating source files, and comprises the majority of this commit.

* bc-int.h (yasm_bytecode): Add contents pointer.
(yasm_bytecode_callback): Make destroy() and print() take void *contents
instead of bytecode pointer.
(yasm_bc_create_common): Take a pointer to contents instead of datasize.
(yasm_bc_transform): New; transforms a bytecode of any type into a
different type.
* bytecode.c (bytecode_data, bytecode_reserve, bytecode_incbin)
(bytecode_align): Remove bc base structure.
(bc_data_destroy, bc_data_print): Update to match yasm_bytecode_callback.
(bc_reserve_destroy, bc_reserve_print): Likewise.
(bc_incbin_destroy, bc_incbin_print): Likewise.
(bc_align_destroy, bc_align_print): Likewise.
(yasm_bc_create_common): Take a pointer to contents instead of datasize.
(bc_data_resolve, bc_data_tobytes, yasm_bc_create_data): Update to use
contents pointer.
(bc_reserve_resolve, bc_reserve_tobytes, yasm_bc_create_reserve): Likewise.
(bc_incbin_resolve, bc_incbin_tobytes, yasm_bc_create_incbin): Likewise.
(yasm_bc_create_align): Likewise.
(yasm_bc_destroy, yasm_bc_print): Update to match yasm_bytecode_callback.

* section.c (yasm_object_get_general, yasm_object_create_absolute): Pass
a NULL pointer instead of yasm_bytecode size to yasm_bc_create_common().

* stabs-dbgfmt.c (stabs_bc_str, stabs_bc_stab): Remove.
(stabs_bc_str_destroy, stabs_bc_str_print): Update.
(stabs_bc_stab_destroy, stabs_bc_stab_print): Likewise.
(stabs_bc_str_callback, stabs_bc_stab_callback): Add common finalize().
(stabs_dbgfmt_append_bcstr): Update to use contents pointer.
(stabs_dbgfmt_append_stab, stabs_dbgfmt_generate): Likewise.
(stabs_bc_stab_tobytes, stabs_bc_str_tobytes): Likewise.

* lc3barch.h (lc3b_insn): Move here from lc3bbc.c.
(lc3b_new_insn_data, yasm_lc3b__bc_create_insn): Remove.
(yasm_lc3b__bc_transform_insn): New.
* lc3bbc.c (lc3b_insn): Remove (moved).
(lc3b_bc_insn_destroy, lc3b_bc_insn_print): Update.
(lc3b_bc_callback_insn): Add common finalize().
(lc3b_bc_insn_resolve, lc3b_insn_tobytes): Use contents pointer.
(yasm_lc3b__bc_create_insn): Remove.
(yasm_lc3b__bc_transform_insn): New.
* lc3bid.re (yasm_lc3b__parse_insn): Directly create lc3b_insn.

* x86arch.h (x86_insn, x86_jmp): Move here from x86bc.c
(x86_new_insn_data, x86_new_jmp_data): Remove.
(yasm_x86__bc_create_insn, yasm_x86__bc_create_jmp): Remove.
(yasm_x86__bc_transform_insn, yasm_x86__bc_transform_jmp): New.
* x86bc.c (x86_insn, x86_jmp): Remove (moved).
(x86_bc_insn_destroy, x86_bc_insn_print): Update.
(x86_bc_jmp_destroy, x86_bc_jmp_print): Likewise.
(x86_bc_callback_insn, x86_bc_callback_jmp): Add common finalize().
(x86_bc_insn_resolve, x86_insn_tobytes): Use contents pointer.
(x86_bc_jmp_resolve, x86_jmp_tobytes): Likewise.
(yasm_x86__bc_create_insn, yasm_x86__bc_create_jmp): Remove.
(yasm_x86__bc_transform_insn, yasm_x86__bc_transform_jmp): New.
* x86id.re (yasm_x86__parse_insn, x86_parse_jmp): Directly create bytecode
contents.

* bc-int.h (yasm_bytecode_callback): Add new finalize() that will finalize
a bytecode after the parse stage.
(yasm_bc_finalize_common): New; common version of bytecode callback
finalize function.
* bytecode.h (yasm_bc_finalize): New wrapper around callback finalize().
* bytecode.c (yasm_bc_finalize): Implementation.
(yasm_bc_finalize_common): Likewise.
(bc_data_callback, bc_data_reserve_callback, bc_incbin_callback)
(bc_align_callback): Add yasm_bc_finalize_common() as finalize() function.

* section.h (yasm_object_finalize): New; finalizes an entire object.
* section.c (yasm_object_finalize): Implementation.

* yasm.c (main): Call yasm_object_finalize() after parse.

* bc-int.h (yasm_effaddr): Add segreg.
* bytecode.h (yasm_ea_set_segreg): New function to set segreg.
* bytecode.c (yasm_ea_set_segreg): Implement.

* x86bc.c (yasm_x86__ea_create_reg, x86_ea_print, x86_bc_insn_resolve)
(x86_bc_insn_tobytes): Use new EA segreg location.

* coretype.h: Move yasm_insn_operands definition from arch.h to here, as it
is now used in prototypes in bytecode.h.

* bytecode.c (bytecode_insn): New instruction bytecode.
(bc_insn_destroy, bc_insn_print, bc_insn_finalize, bc_insn_resolve)
(bc_insn_tobytes): New callback support functions.
(bc_insn_callback): New.
(yasm_bc_create_insn, yasm_bc_insn_add_prefix, yasm_bc_insn_add_seg_prefix):
New parser-callable functions.
* bytecode.h (yasm_bc_create_insn, yasm_bc_insn_add_prefix)
(yasm_bc_insn_add_seg_prefix): Likewise.

* nasm-bison.y: Call new insn bytecode functions rather than arch functions.

* arch.h (YASM_ARCH_VERSION): Bump version.
(yasm_arch): Rename and extend parse_insn to finalize_insn.  Remove
parse_prefix, parse_seg_prefix, and parse_seg_override.
(yasm_arch_parse_insn): Rename to yasm_arch_finalize_insn.
(yasm_arch_parse_prefix, yasm_arch_parse_seg_prefix)
(yasm_arch_parse_seg_override): Remove.

* lc3barch.c (yasm_lc3b_LTX_arch): Update to match new yasm_arch.
* lc3barch.h (yasm_lc3b__parse_insn): Rename to yasm_lc3b__finalize_insn.
* lc3bid.re (yasm_lc3b__parse_insn): Likewise.

* x86arch.c (x86_parse_prefix, x86_parse_seg_prefix)
(x86_parse_seg_override): Remove.
(yasm_x86_LTX_arch): Update to match new yasm_arch.
* x86arch.h (yasm_x86__parse_insn): Rename to yasm_x86__finalize_insn.
* x86id.re (yasm_x86__parse_insn): Likewise.
(x86_new_jmp): Rename to x86_finalize_jmp.

* x86arch.h (yasm_x86__bc_apply_prefixes, yasm_x86__ea_init): New.
* x86bc.c (yasm_x86__bc_apply_prefixes, yasm_x86__ea_init): Likewise.


svn path=/trunk/yasm/; revision=1177
2004-11-14 23:17:17 +00:00
Peter Johnson
ad2c7b3e3f * bc-int.h (yasm_bytecode): Add new pointer to array symrecs. This is a
NULL-terminated array of labels that point to this bytecode (as the bytecode
previous to the label).  NULL if no labels point to this bytecode.

* bytecode.c (yasm_bc_create_common): Initialize symrecs variable to NULL.
* bytecode.c (yasm_bc_destroy): Delete symrecs variable.

* bytecode.h (yasm_bc__add_symrec): Declare new function.
* bytecode.c (yasm_bc__add_symrec): New.

* symrec.c (yasm_symtab_define_label): Call yasm_bc__add_symrec().

This new functionality is needed to make writing certain dbgfmt routines
easier.

svn path=/trunk/yasm/; revision=1147
2004-09-13 02:44:00 +00:00
Peter Johnson
1a86c34026 * On most files: re-enable $IdPath$ as $Id$, and enable Id keyword expansion.
svn path=/trunk/yasm/; revision=1137
2004-09-04 01:24:57 +00:00
Peter Johnson
55438b7229 Massive libyasm / module interface update - Phase 1
As yasm has evolved, various minor additions have been made to libyasm to
support the new features.  These minor additions have accumulated, and
some contain significant redundancies.  In addition, the core focus of
yasm has begun to move away from the front-end commandline program "yasm"
to focusing on libyasm, a collection of reusable routines for use in all
sorts of programs dealing with code at the assembly level, and the modules
that provide specific features for parsing such code.

This libyasm/module update focuses on cleaning up much of the cruft that
has accumulated in libyasm, standardizing function names, eliminating
redundancies, making many of the core objects more reusable for future
extensions, and starting to make libyasm and the modules thread-safe by
eliminating static variables.

Specific changes include:
 - Making a symbol table data structure (no longer global).  It follows a
   factory model for creating symrecs.
 - Label symbols now refer only to bytecodes; bytecodes have a pointer to
   their containing section.
 - Standardizing on *_create() and *_destroy() for allocation/deallocation.
 - Adding a standardized callback mechanism for all data structures that
   allow associated data.  Allowed the removal of objfmt and
   dbgfmt-specific data callbacks in their interfaces.
 - Unmodularizing linemgr, but allowing multiple linemap instances (linemgr
   is now renamed linemap).
 - Remove references to lindex; all virtual lines (from linemap) are now
   just "line"s.
 - Eliminating the bytecode "type" enum, instead adding a standardized
   callback mechanism for custom (and standard internal) bytecode types.
   This will make it much easier to add new bytecodes, and eliminate the
   possibility of type collisions.  This also allowed the removal of the
   of_data and df_data bytecodes, as objfmts and dbgfmts can now easily
   implement their own bytecodes, and the cleanup of arch's bytecode usage.
 - Remove the bytecodehead and sectionhead pseudo-containers, instead
   making true containers: section now implements all the functions of
   bytecodehead, and the new object data structure implements all the
   functions of sectionhead.
 - Add object data structure: it's a container that contains sections, a
   symbol table, and a line mapping for a single object.  Every former use
   of sectionhead now takes an object.
 - Make arch interface and all standard architectures thread-safe:
   yasm_arch_module is the module interface; it contains a create()
   function that returns a yasm_arch * to store local yasm_arch data; all
   yasm_arch_module functions take the yasm_arch *.
 - Make nasm parser thread-safe.

To be done in phase 2: making other module interfaces thread-safe.  Note
that while the module interface may be thread-safe, not all modules may be
written in such a fashion (hopefully all the "standard" ones will be, but
this is yet to be determined).

svn path=/trunk/yasm/; revision=1058
2003-10-02 05:03:50 +00:00
Michael Urman
47576797ad STABS debugging information. This includes, naturally, several draft
changes to the dbgfmt interface, and other assorted updates, including:
* yasm.c now calls df->initialize() and df->generate()
* a dbgfmt bytecode type with associated handling
* yasm_output_reloc_func type for use particularly by dbgfmts
* df: initialize updated; generate, bc_dbgfmt_data_{output|delete|print} added
* null-dbgfmt structure brought in line with these additions
* elf-objfmt made aware of stabs sections, and what to do with them

The bad news:
* just enough stabs output to support line number information in GDB
* GDB identifies function labels off by 3 bytes in my test, but line
  numbers remain correct, somehow.  Unknown whether stabs-dbgfmt or GDB
  at fault.

svn path=/trunk/yasm/; revision=1037
2003-08-15 03:43:55 +00:00
Peter Johnson
bfb1ee5b0c Fixed some conversion warnings caused by intnum commit. Missed these due to
use of configure.ac's --enable-warnerror, which was set up to disable
conversion errors due to flex's warning-prone generated code.  As we no
longer use flex, fix configure.ac to not disable conversion errors.

svn path=/trunk/yasm/; revision=1018
2003-07-26 02:32:04 +00:00
Peter Johnson
d151392af8 Big output_expr(), intnum_tobytes(), and floatnum_tobytes() changes:
- Switch to bit-based output, including shift capability
 - This means the standard intnum output functions can be used for non-byte
   oriented archs like LC-3b (implemented)
 - Default out of range (overflow) warnings for intnum (bugzilla bug 14)
 - Change floating point overflow/underflow errors to warnings
To do (hooks but not implemented):
 - Shifting floatnums into destination
 - Floatnum destinations larger than floatnum value
 - Big endian support for intnum and floatnum
Related simultaneous changes:
 - Use bc instead of ep in objfmt output_expr() functions; while bc->line
   should == (*ep)->line, in case they differ, we want to use the bc->line
   so as not to confuse users.
 - lc3b-mp22NC test was not properly offsetting the accessed variables, but
   since the variable "sections" started at an aligned offset, the output
   was actually correct.  The new intnum warnings uncovered this issue, so
   fix code to be correct (and not generate warnings).

svn path=/trunk/yasm/; revision=1017
2003-07-25 03:27:21 +00:00
Peter Johnson
16c09e4b41 Add lindex parameter to yasm_intnum_calc(), and add error messages for SEG,
WRT, and ':' (SEGOFF) usage.  This change also brings the yasm_intnum_calc()
interface in line with the yasm_floatnum_calc() interface.

Note: This may not be the final place we want these error messages to reside,
but the lindex addition should remain for the sake of consistency.

svn path=/trunk/yasm/; revision=953
2003-05-26 19:16:44 +00:00
Peter Johnson
cfc6bf0ded Clean up and simplify libyasm.h options and symbol visibility:
- Move config.h and util.h from libyasm (and installed libyasm) to top level.
- Move yasm_* functions from util.h to coretype.h.
- Remove a number of autoconf-related YASM_*_INTERNAL options from libyasm.h.
- Rename YASM_INTERNAL to YASM_LIB_INTERNAL; it now actually means what the
  comment describes: enables definitions that violate the yasm_* namespace.

While we're at it, no longer define YASM_LIB_INTERNAL from yasm frontend, so
it's closer to what a real typical libyasm-using application would look like.

svn path=/trunk/yasm/; revision=944
2003-05-05 03:42:12 +00:00
Peter Johnson
8f91cd9d24 Change how bytecode and section lists are allocated. When YASM_INTERNAL is not
defined, the structures for the list heads are not defined, so the existing
yasm_bcs_initialize() and yasm_sections_initialize() were impossible to use.
Instead, rename these functions to yasm_bcs_new() and yasm_sections_new() and
make them allocate the space internally.  Update yasm_bcs_delete() and
yasm_sections_delete() to free the internally-allocated space.

svn path=/trunk/yasm/; revision=942
2003-05-04 22:15:09 +00:00
Peter Johnson
0ab3ae5153 Flatten arch interface, changing some parse function names in the process.
No functional changes.

svn path=/trunk/yasm/; revision=903
2003-03-31 05:36:30 +00:00
Peter Johnson
dd1d356936 De-constify yasm_bytecode parameter to yasm_output_expr_func.
svn path=/trunk/yasm/; revision=883
2003-03-24 06:46:22 +00:00
Peter Johnson
0caa11ff3b Enable more warnings and perform code cleanups to avoid them.
When -Werror is used, disable -Wconversion, because flex-generated code causes
warnings when calling fwrite() and fread().

svn path=/trunk/yasm/; revision=873
2003-03-17 00:03:02 +00:00