Commit graph

66 commits

Author SHA1 Message Date
Peter Johnson
24e01c833f Add missing YASM_LIB_DECL declarations. 2014-08-10 12:33:52 -07:00
Peter Johnson
94ab1135a3 Remove $Id$ and RCSID() usage.
These are useless now that we're using git.
2011-08-19 10:43:16 -07:00
Peter Johnson
1e77ce6c40 Add core TASM syntax support.
Contributed by: Samuel Thibault <samuel.thibault@ens-lyon.org>

It is built on top of the NASM parser and preproc, with the following
notable extensions for TASM syntax:
 - case insensitive symbols and filenames,
 - support for segment and size of labels, which permits to avoid giving
   them on each memory dereference,
 - support for data reservation (i.e. e.g. "var dd ?"),
 - support for multiples (i.e. e.g. "var dd 1 dup 10"),
 - little endian string integer constants,
 - additional expression operators: shl, shr, and, or, low, high,
 - additional offset keyword,
 - additional fword and df,
 - support for doubled quotes within quotes,
 - support for array-like and structure-like notations: t[eax] and
   [var].field,
 - support for tasm directives: macro, rept, irp, locals, proc, struc,
   segment, assume.

Notes:

 - Almost all extensions are only effective when tasm_compatible_mode is
   set, so we should have very reduced possible breakage.

 - Because the "and" keyword can be an expression operator and an
   instruction name, the data pseudo-instructions explicitly switch the
   lexer state to INSTRUCTION state to fix the ambiguity.

 - In gen_x86_insn.py, several instructions (namely lds and lea) now take
   relaxed memory sizes.  The reason is that in the case of tasm, the size
   of the actual pointed data is passed up to there, and thus any type of
   data should be accepted.

With all of this, loadlin can be compiled by yasm with quite reduced
modifications.

A new TASM-like frontend is also included.

svn path=/trunk/yasm/; revision=2130
2008-10-07 05:38:11 +00:00
Peter Johnson
eb7b1adb30 Enable DLL/plugin builds with cmake on Windows.
Add proper declspec dllimport/dllexport to all libyasm functions.
Use macros to make these do nothing on non-cmake and Unix builds.

svn path=/trunk/yasm/; revision=2101
2008-05-23 06:46:51 +00:00
Peter Johnson
1afb23f689 Fix a couple of Doxygen nits.
svn path=/trunk/yasm/; revision=1931
2007-09-08 01:34:51 +00:00
Peter Johnson
a310410911 Doxygen documentation fixes.
svn path=/trunk/yasm/; revision=1897
2007-07-16 04:42:02 +00:00
Peter Johnson
2bb74148c1 Merge expr-int.h into expr.h, removing YASM_EXPR_INTERNAL in the process.
svn path=/trunk/yasm/; revision=1895
2007-07-14 05:31:08 +00:00
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
9d5e81b920 expr.h: Fix comment to match [1655].
svn path=/trunk/yasm/; revision=1656
2006-10-19 03:08:44 +00:00
Peter Johnson
fd04b1aef6 Don't mix EQU expansion with other expr leveling; we could get confused
with certain combinations.
(2nd half of #83)

This also hides some internals of yasm_expr_level_tree.

svn path=/trunk/yasm/; revision=1655
2006-10-18 05:36:51 +00:00
Peter Johnson
3e8d2c2e7a - Fix much brokenness in absolute value handling, particularly in regards to
PC-relative relocations (jumps and calls).
- Allow SEG:OFF to be used as just an offset portion (like NASM does).
- Labels in absolute sections that are declared global are given the correct
  absolute value in the symbol table.

One difference from NASM:
  label equ 0040h:001eh
  jmp label
in NASM means the same as:
  jmp 001eh  (a near jump)
but yasm will treat this the same as:
  jmp 0040h:001eh  (a far jump)

I'm still not completely happy with this implementation, but it's workable
and fixes all the bugs I've found so far in absolute handling.

svn path=/trunk/yasm/; revision=1634
2006-09-29 07:18:45 +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
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
36ff44b3ac Fix ELF64 relocations for common, global, and common+global symbols to match
GAS output.  The way we were generating relocations before would make
common+global symbol usage generate a relocation against the symbol but
figure in the symbol's value into the relocation addend.

* expr.h (yasm_symrec_relocate_action): New enum, so that:
(yasm_expr_extract_symrec): can conditionalize replacing the symbol with its
value based on whether the symbol is only local (e.g. not declared global,
etc).
* expr.c (yasm_expr_extract_symrec): Update implementation.

* xdf-objfmt.c, coff-objfmt.c: Update to use new enum constants.

* elf-objfmt.c (elf_objfmt_output_expr): Only relocate against section if
symbol is only local, and change call to yasm_expr_extract_symrec to only
add in symbol value if symbol is only local.

* stabs-elf.hex, elftest.hex: Update for changes.

* elf_gas64_reloc.asm: New test.

svn path=/trunk/yasm/; revision=1311
2005-11-06 20:07:15 +00:00
Michael Urman
8b38ea65cb Deconst yasm_expr_get_intnum's return, allowing inplace modifications to
be made. The specific instigator for this is the ability to modify the
value in a relocation stored in a .rela.section so that listings are
"correct".

svn path=/trunk/yasm/; revision=1159
2004-10-11 03:42:08 +00:00
Peter Johnson
713ab6d384 * expr.h (yasm_expr_extract_seg): Comment change: remove documentation for
nonexistent "simplify" argument.

svn path=/trunk/yasm/; revision=1150
2004-09-27 05:34:40 +00:00
Peter Johnson
2ac9e732f2 * expr.c (yasm_expr_extract_symrec): Add "relocate" parameter. Use it to
control whether the symbol is replaced with the symbol's value (old
behavior), or just replace it with 0 (new optional behavior).  The old
behavior is enabled by setting relocate=1.
* expr.h (yasm_expr_extract_symrec): Likewise (and document new behavior).
* elf-objfmt.c (elf_objfmt_output_expr): Use new function (with relocate=1).
* coff-objfmt.c (coff_objfmt_output_expr): Likewise.

* expr.c (yasm_expr_extract_segment): Renamed to yasm_expr_extract_segoff, a
more approprate name given what operator it looks at.
* expr.h (yasm_expr_extract_segment): Likewise.
* x86bc.c (x86_bc_jmp_tobytes): Use new function name.

* expr.c (yasm_expr_extract_seg): New function to remove SEG unary operator.
* expr.h (yasm_expr_extract_seg): Likewise.

* expr.c (yasm_expr_extract_shr): New function to split SHR operator into
left and right halves.
* expr.h (yasm_expr_extract_shr): Likewise.

* xdf.h: New header file describing the newly added Extended Dynamic Object
Format (XDF).  Note: GCC-only code.
* xdfdump.c: New utility that uses the format described in xdf.h to
completely dump an XDF file.  Note: non-portable code (runs correctly on
little endian machines only).
Neither of these files are currently included in the distribution.

* xdf-objfmt.c: New YASM objfmt module to output XDF format object files.
* modules/objfmts/xdf/Makefile.inc: Add to build.
* modules/objfmts/Makefile.inc: Likewise.

The XDF object format is a blend between COFF and OMF.  It is a very simple
object format intended for use by operating system loaders or similar types
of targets.  It allows shifted relocations (useful for static interrupt or
page tables), both flat and segment-relative, and the use of the SEG, WRT,
and x86 JMP FAR notations.

Test cases will be committed soon.


svn path=/trunk/yasm/; revision=1149
2004-09-27 04:15:12 +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
Peter Johnson
616be0ba09 Add yasm_expr_extract_wrt() to separate portions of WRT expression.
svn path=/trunk/yasm/; revision=1031
2003-08-03 21:06:15 +00:00
Peter Johnson
3de47f7b4d Add \rcs, \endrcs, \license, and \endlicense wrappers around $IdPath$ and
copyright/license portions to shorten Doxygen output.  Comment only change.

svn path=/trunk/yasm/; revision=985
2003-06-28 17:38:08 +00:00
Peter Johnson
c3d042d742 Change parameter name for yasm_expr_extract_segment declaration to ep to
match documentation and function definition.
No functional change.

svn path=/trunk/yasm/; revision=961
2003-06-02 00:11:14 +00:00
Peter Johnson
13cbbfcb4a Add support for FAR call/jmp. Because of the jmp label, label equ seg:off
problem, adding this required adding some fields to x86_jmprel (now a
misnomer, as FAR jumps are absolute) to save the far opcode, and additional
support in libyasm's yasm_expr_* to properly handle the YASM_EXPR_SEGOFF
operator.

svn path=/trunk/yasm/; revision=954
2003-05-27 04:13:16 +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
d710166b48 Comment for Doxygen documentation generation. Comment-only changes.
svn path=/trunk/yasm/; revision=939
2003-05-04 20:28:28 +00:00
Peter Johnson
0786a76895 Make libyasm a "real" library, including installing header files.
Start separating modules and frontends from libyasm internals.

svn path=/trunk/yasm/; revision=849
2003-03-15 05:07:49 +00:00
Peter Johnson
d9f68d6d4b Unmodularize errwarn, while making key errwarn functions replaceable.
Also removes dependency of libyasm on libintl (gettext), so it can be linked
-no-undefined now!

svn path=/trunk/yasm/; revision=842
2003-03-10 08:55:41 +00:00
Peter Johnson
a2e07e1e10 The Great Renaming (prefixing with yasm_), Part 1.
svn path=/trunk/yasm/; revision=838
2003-03-08 19:15:40 +00:00
Peter Johnson
b1faf6329c Relicense under 2-clause BSD license.
svn path=/trunk/yasm/; revision=835
2003-02-21 03:50:29 +00:00
Peter Johnson
9f6cb6783f Modularize errwarn. gettext()-ize in errwarn, not in every module, eliminating
libintl dependency in modules.
Also standardize initialize() and cleanup() functions.
Move replace_extension() from file.c to main.c.
Clean up some extern variable declarations in various places (particularly
nasm-compatible parser).

svn path=/trunk/yasm/; revision=792
2002-11-01 10:05:03 +00:00
Peter Johnson
2f19ce4ecd Delete last of global variables by making a line manager and passing around
the line index.  Fixes some minor line number/error message nits due to
incorrect usage of line_index in old global variable method.

svn path=/trunk/yasm/; revision=787
2002-10-27 09:21:39 +00:00
Peter Johnson
d6f22c3fce Dynamically load all modules (preloading some of the default ones).
Start reducing global variables for cleaner module separation.
Add rudimentary debug format module interface and "null" debug format.

svn path=/trunk/yasm/; revision=784
2002-10-26 08:25:39 +00:00
Peter Johnson
4c3bb4a7cc Get rid of expr_xform_neg_tree(), integrating its functionality into
expr_level_tree().  This fixes negative equ's and probably other issues.
This also makes expr_simplify() a macro pointing to expr_level_tree().

svn path=/trunk/yasm/; revision=778
2002-10-22 08:42:16 +00:00
Peter Johnson
fab557b414 Add expr_extract_symrec() to assist in performing relocation output.
svn path=/trunk/yasm/; revision=768
2002-10-21 04:14:01 +00:00
Peter Johnson
a3a9fd2aa0 Completely revamp how label resolution is done (part of Bug#6). Now calculates
/distances/ between bytecodes in a section using bc_calc_dist() functions (a
"typical" one is provided for most occasions).  expr_expand_labelequ() is gone,
as its functionality is integrated into expr_simplify().  Currently these
changes break most bin objfmt output, as it doesn't know how to resolve
absolute labels yet.  Also, very preliminary expr support for :, SEG, and WRT
operators has been added (part of Bug#2).  Several other minor bug fixes.

svn path=/trunk/yasm/; revision=718
2002-10-01 18:56:28 +00:00
Peter Johnson
c5ef1bf2dc Eliminate duplicate code for callbacks from expr_expand_labelequ() by moving
code and adding a resolve_precall function parameter (which caused cascading
changes in bytecode-related sources).

svn path=/trunk/yasm/; revision=701
2002-08-18 03:48:17 +00:00
Peter Johnson
3320945f95 Massive restructuring of lexing and parsing (NASM-compatible parser).
Bugzilla Bug#3.  Not all instructions are parsed yet, so this is actually a
minor feature regression from the user side, but this commit lays the framework
for much easier additions of new assembler syntaxes and architectures.  The
re2c tool is now used to generate the lexers, as it's much more flexibly
function-oriented than lex.
 - nasm-bison.y is a repocopy+modify of nasm/bison.y.in.
 - x86arch.h now includes all of x86-int.h

svn path=/trunk/yasm/; revision=670
2002-08-09 05:43:03 +00:00
Peter Johnson
f8bfa83597 Make expr_print() take a const expr.
svn path=/trunk/yasm/; revision=601
2002-04-22 07:49:47 +00:00
Peter Johnson
a6f0bff972 Splint cleanups: expr_copy_* don't take a NULL, so they can't return NULL.
svn path=/trunk/yasm/; revision=599
2002-04-22 06:17:11 +00:00
Peter Johnson
adfc2e10c9 Add expr_get_floatnum().
svn path=/trunk/yasm/; revision=529
2002-03-18 08:00:39 +00:00
Peter Johnson
d85e7014a8 Binary object format output! Lots of structural changes needed, particularly
with regards to resolve_label().
MAJOR FIXME: The tobytes() pass acts like a final optimization pass.  This
causes internal errors because of length mismatches (optimized to shorter len).

svn path=/trunk/yasm/; revision=521
2002-03-17 21:58:36 +00:00
Peter Johnson
e23d88b957 Make resolve_label() take a symrec * instead of a section * and bytecode *.
Extend expr_expand_equ() into expr_expand_labelequ() and call resolve_label()
here.

svn path=/trunk/yasm/; revision=440
2002-01-09 07:23:00 +00:00
Peter Johnson
fbf87da90a Comment fix.
svn path=/trunk/yasm/; revision=437
2002-01-09 07:03:47 +00:00
Peter Johnson
825eaa5823 Massive cleanup of debugging output (via _print() functions). All now take
FILE *'s to print to somewhere other than stdout, and the formatting is
improved through the use of a global indent_level.

Changes to main() include the ability to specify an output file.

svn path=/trunk/yasm/; revision=357
2001-11-21 08:25:09 +00:00
Peter Johnson
29f7d9a917 New function: expr_get_symrec().
svn path=/trunk/yasm/; revision=338
2001-11-18 15:51:47 +00:00
Peter Johnson
8178f883a5 Modify so that almost everything passes LCLint with the options in lclint.sh.
This is actually worthwhile; I found and fixed a few bugs/edge cases while
doing this.
For more information on LCLint, see <http://lclint.cs.virginia.edu/>.

svn path=/trunk/yasm/; revision=335
2001-11-17 08:33:23 +00:00
Peter Johnson
d7fe402fb9 Split away x86-specific parts of expression handling (eg, effective address ->
ModRM+SIB).

svn path=/trunk/yasm/; revision=328
2001-11-15 23:44:41 +00:00