From f908f39d0fd91ed6d93aa878781d4fa26d33b23e Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Fri, 24 Feb 2006 04:29:39 +0000 Subject: [PATCH] Fix #69 by making the NASM preproc and parser use the yasm built-in alignment bytecode rather than just times'ing a NOP. This generates better NOP code. The new align only triggers when the NASM align directive is used unadorned or with nop as the parameter (e.g. "align 16" or "align 16, nop"). Other uses, including all uses of balign, maintain their old NASM behavior. This is somewhat useful if you still want a string of NOPs rather than more optimized instruction patterns: just use "balign X, nop" rather than "align X". The new align also follows the GAS behavior of increasing the section's alignment to be the specified alignment (if not already larger). While I was in here, I found and fixed a bug in 16-bit alignment generation (typo). I also changed the x86 32-bit code alignment fill pattern per suggestions in the AMD x86 code optimization manual. * nasm-bison.y: Implement a new [align] directive that can take a single parameter (the alignment) and generate a nop-generating align bytecode. * standard.mac: Change align macro to generate [align] if the second macro parameter is nonexistent or "nop". * x86arch.c (x86_get_fill): Update 32-bit fill pattern and fix bug in 16-bit fill pattern. svn path=/trunk/yasm/; revision=1389 --- modules/arch/x86/tests/gas32/align32.hex | 138 ++-- modules/arch/x86/x86arch.c | 19 +- modules/objfmts/coff/tests/x86id.hex | 572 ++++++++--------- modules/objfmts/elf/tests/elf-x86id.hex | 588 +++++++++--------- modules/parsers/nasm/nasm-bison.y | 39 ++ modules/parsers/nasm/tests/Makefile.inc | 6 + modules/parsers/nasm/tests/alignnop16.asm | 4 + modules/parsers/nasm/tests/alignnop16.errwarn | 0 modules/parsers/nasm/tests/alignnop16.hex | 17 + modules/parsers/nasm/tests/alignnop32.asm | 4 + modules/parsers/nasm/tests/alignnop32.errwarn | 0 modules/parsers/nasm/tests/alignnop32.hex | 17 + modules/preprocs/nasm/standard.mac | 4 + 13 files changed, 758 insertions(+), 650 deletions(-) create mode 100644 modules/parsers/nasm/tests/alignnop16.asm create mode 100644 modules/parsers/nasm/tests/alignnop16.errwarn create mode 100644 modules/parsers/nasm/tests/alignnop16.hex create mode 100644 modules/parsers/nasm/tests/alignnop32.asm create mode 100644 modules/parsers/nasm/tests/alignnop32.errwarn create mode 100644 modules/parsers/nasm/tests/alignnop32.hex diff --git a/modules/arch/x86/tests/gas32/align32.hex b/modules/arch/x86/tests/gas32/align32.hex index 66b48bb9..77181969 100644 --- a/modules/arch/x86/tests/gas32/align32.hex +++ b/modules/arch/x86/tests/gas32/align32.hex @@ -80,84 +80,84 @@ eb 90 ff ff -8d -b4 -26 -00 -00 -00 -00 -8d -bc -27 -00 -00 -00 -00 +eb +0c +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 ff ff ff -8d -b6 -00 -00 -00 -00 -8d -bc -27 -00 -00 -00 -00 +eb +0b +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 ff ff ff ff -8d -b6 -00 -00 -00 -00 -8d -bf -00 -00 -00 -00 +eb +0a +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 ff ff ff ff ff -8d -74 -26 -00 -8d -bc -27 -00 -00 -00 -00 +eb +09 +90 +90 +90 +90 +90 +90 +90 +90 +90 ff ff ff ff ff ff -8d -76 -00 -8d -bc -27 -00 -00 -00 -00 +eb +08 +90 +90 +90 +90 +90 +90 +90 +90 ff ff ff @@ -165,15 +165,15 @@ ff ff ff ff -89 -f6 -8d -bc -27 -00 -00 -00 -00 +eb +07 +90 +90 +90 +90 +90 +90 +90 ff ff ff diff --git a/modules/arch/x86/x86arch.c b/modules/arch/x86/x86arch.c index 02be78e1..825709b2 100644 --- a/modules/arch/x86/x86arch.c +++ b/modules/arch/x86/x86arch.c @@ -159,7 +159,7 @@ x86_get_fill(const yasm_arch *arch) "\x8d\x74\x00" /* 7 - lea si, [si+byte 0] */ "\x8d\xbd\x00\x00", /* lea di, [di+word 0] */ "\x8d\xb4\x00\x00" /* 8 - lea si, [si+word 0] */ - "\x8d\xbd\x00\x00" /* lea di, [di+word 0] */ + "\x8d\xbd\x00\x00", /* lea di, [di+word 0] */ "\xeb\x07\x90\x90\x90\x90\x90" /* 9 - jmp $+9; nop fill */ "\x90\x90", "\xeb\x08\x90\x90\x90\x90\x90" /* 10 - jmp $+10; nop fill */ @@ -187,6 +187,8 @@ x86_get_fill(const yasm_arch *arch) "\x8d\xb4\x26\x00\x00\x00\x00", /* 7 - lea esi, [esi*1+dword 0] */ "\x90" /* 8 - nop */ "\x8d\xb4\x26\x00\x00\x00\x00", /* lea esi, [esi*1+dword 0] */ +#if 0 + /* GAS uses these */ "\x89\xf6" /* 9 - mov esi, esi */ "\x8d\xbc\x27\x00\x00\x00\x00", /* lea edi, [edi*1+dword 0] */ "\x8d\x76\x00" /* 10 - lea esi, [esi+byte 0] */ @@ -199,6 +201,21 @@ x86_get_fill(const yasm_arch *arch) "\x8d\xbc\x27\x00\x00\x00\x00", /* lea edi, [edi*1+dword 0]*/ "\x8d\xb4\x26\x00\x00\x00\x00" /* 14 - lea esi, [esi*1+dword 0]*/ "\x8d\xbc\x27\x00\x00\x00\x00", /* lea edi, [edi*1+dword 0]*/ +#else + /* But on newer processors, these are recommended */ + "\xeb\x07\x90\x90\x90\x90\x90" /* 9 - jmp $+9; nop fill */ + "\x90\x90", + "\xeb\x08\x90\x90\x90\x90\x90" /* 10 - jmp $+10; nop fill */ + "\x90\x90\x90", + "\xeb\x09\x90\x90\x90\x90\x90" /* 11 - jmp $+11; nop fill */ + "\x90\x90\x90\x90", + "\xeb\x0a\x90\x90\x90\x90\x90" /* 12 - jmp $+12; nop fill */ + "\x90\x90\x90\x90\x90", + "\xeb\x0b\x90\x90\x90\x90\x90" /* 13 - jmp $+13; nop fill */ + "\x90\x90\x90\x90\x90\x90", + "\xeb\x0c\x90\x90\x90\x90\x90" /* 14 - jmp $+14; nop fill */ + "\x90\x90\x90\x90\x90\x90\x90", +#endif "\xeb\x0d\x90\x90\x90\x90\x90" /* 15 - jmp $+15; nop fill */ "\x90\x90\x90\x90\x90\x90\x90\x90" }; diff --git a/modules/objfmts/coff/tests/x86id.hex b/modules/objfmts/coff/tests/x86id.hex index 5f1ed61f..7339666a 100644 --- a/modules/objfmts/coff/tests/x86id.hex +++ b/modules/objfmts/coff/tests/x86id.hex @@ -96,7 +96,7 @@ f2 00 40 00 -00 +30 00 2e 72 @@ -136,7 +136,7 @@ da 00 20 00 -00 +60 00 55 89 @@ -70630,6 +70630,8 @@ ff 00 00 00 +eb +0d 90 90 90 @@ -70643,10 +70645,8 @@ ff 90 90 90 -90 -90 -90 -90 +eb +07 90 90 90 @@ -71914,6 +71914,8 @@ c7 00 00 00 +eb +0d 90 90 90 @@ -71928,12 +71930,10 @@ c7 90 90 90 -90 -90 -90 -90 -90 -90 +8d +74 +26 +00 04 00 00 @@ -72102,6 +72102,8 @@ c7 00 00 00 +eb +0d 90 90 90 @@ -72115,10 +72117,8 @@ c7 90 90 90 -90 -90 -90 -90 +eb +07 90 90 90 @@ -72910,8 +72910,8 @@ a8 00 00 00 -90 -90 +eb +0d 90 90 90 @@ -73514,6 +73514,8 @@ a9 00 00 00 +eb +0d 90 90 90 @@ -73528,12 +73530,10 @@ a9 90 90 90 -90 -90 -90 -90 -90 -90 +8d +74 +26 +00 00 00 00 @@ -73926,6 +73926,8 @@ a9 00 00 00 +eb +0d 90 90 90 @@ -73939,10 +73941,8 @@ a9 90 90 90 -90 -90 -90 -90 +eb +07 90 90 90 @@ -74118,6 +74118,8 @@ ed 00 00 00 +eb +0d 90 90 90 @@ -74131,10 +74133,8 @@ ed 90 90 90 -90 -90 -90 -90 +eb +07 90 90 90 @@ -74310,6 +74310,8 @@ ef 00 00 00 +eb +0d 90 90 90 @@ -74323,10 +74325,8 @@ ef 90 90 90 -90 -90 -90 -90 +eb +07 90 90 90 @@ -74418,8 +74418,8 @@ ef 00 00 00 -90 -90 +eb +0a 90 90 90 @@ -74487,13 +74487,13 @@ ef 00 00 90 -90 -90 -90 -90 -90 -90 -90 +8d +b4 +26 +00 +00 +00 +00 04 00 00 @@ -74551,13 +74551,13 @@ ef 00 00 90 -90 -90 -90 -90 -90 -90 -90 +8d +b4 +26 +00 +00 +00 +00 00 00 00 @@ -75202,6 +75202,8 @@ ef 00 00 00 +eb +0d 90 90 90 @@ -75215,10 +75217,8 @@ ef 90 90 90 -90 -90 -90 -90 +eb +0b 90 90 90 @@ -75398,6 +75398,8 @@ ff 00 00 00 +eb +0d 90 90 90 @@ -75411,10 +75413,8 @@ ff 90 90 90 -90 -90 -90 -90 +eb +07 90 90 90 @@ -75534,8 +75534,8 @@ f7 00 00 00 -90 -90 +eb +0d 90 90 90 @@ -76110,8 +76110,8 @@ f7 00 00 00 -90 -90 +eb +0d 90 90 90 @@ -76183,13 +76183,13 @@ d4 00 00 90 -90 -90 -90 -90 -90 -90 -90 +8d +b4 +26 +00 +00 +00 +00 00 00 00 @@ -76722,8 +76722,8 @@ af 00 00 00 -90 -90 +eb +0a 90 90 90 @@ -77126,6 +77126,8 @@ d1 00 00 00 +eb +0d 90 90 90 @@ -77139,10 +77141,8 @@ d1 90 90 90 -90 -90 -90 -90 +eb +07 90 90 90 @@ -77710,8 +77710,8 @@ ff 00 00 00 -90 -90 +eb +0d 90 90 90 @@ -78314,6 +78314,8 @@ ff 00 00 00 +eb +0d 90 90 90 @@ -78328,12 +78330,10 @@ ff 90 90 90 -90 -90 -90 -90 -90 -90 +8d +74 +26 +00 00 00 00 @@ -78418,8 +78418,8 @@ c8 00 00 00 -90 -90 +eb +0a 90 90 90 @@ -78626,6 +78626,8 @@ c8 00 00 00 +eb +0d 90 90 90 @@ -78639,10 +78641,8 @@ c8 90 90 90 -90 -90 -90 -90 +eb +0b 90 90 90 @@ -78711,13 +78711,13 @@ e3 00 00 90 -90 -90 -90 -90 -90 -90 -90 +8d +b4 +26 +00 +00 +00 +00 00 00 00 @@ -78970,10 +78970,10 @@ e0 00 00 00 -90 -90 -90 -90 +8d +74 +26 +00 04 00 00 @@ -79142,6 +79142,8 @@ ba 00 00 00 +eb +0d 90 90 90 @@ -79155,10 +79157,8 @@ ba 90 90 90 -90 -90 -90 -90 +eb +07 90 90 90 @@ -79278,8 +79278,8 @@ cd 00 00 00 -90 -90 +eb +0d 90 90 90 @@ -79378,8 +79378,8 @@ cd 00 00 00 -90 -90 +eb +0a 90 90 90 @@ -79530,6 +79530,8 @@ cd 00 00 00 +eb +0d 90 90 90 @@ -79544,12 +79546,10 @@ cd 90 90 90 -90 -90 -90 -90 -90 -90 +8d +74 +26 +00 02 00 00 @@ -79718,6 +79718,8 @@ cd 00 00 00 +eb +0d 90 90 90 @@ -79731,10 +79733,8 @@ cd 90 90 90 -90 -90 -90 -90 +eb +07 90 90 90 @@ -79854,8 +79854,8 @@ a1 00 00 00 -90 -90 +eb +0d 90 90 90 @@ -79982,8 +79982,8 @@ a2 00 00 00 -90 -90 +eb +0d 90 90 90 @@ -80082,8 +80082,8 @@ a1 00 00 00 -90 -90 +eb +0a 90 90 90 @@ -80206,8 +80206,8 @@ c9 00 00 00 -90 -90 +eb +0d 90 90 90 @@ -80334,8 +80334,8 @@ a1 00 00 00 -90 -90 +eb +0d 90 90 90 @@ -80407,13 +80407,13 @@ a1 00 00 90 -90 -90 -90 -90 -90 -90 -90 +8d +b4 +26 +00 +00 +00 +00 00 10 00 @@ -80582,6 +80582,8 @@ aa 00 00 00 +eb +0d 90 90 90 @@ -80595,10 +80597,8 @@ aa 90 90 90 -90 -90 -90 -90 +eb +07 90 90 90 @@ -80690,8 +80690,8 @@ aa 00 00 00 -90 -90 +eb +0a 90 90 90 @@ -80814,8 +80814,8 @@ d9 00 00 00 -90 -90 +eb +0d 90 90 90 @@ -80887,13 +80887,13 @@ e0 00 00 90 -90 -90 -90 -90 -90 -90 -90 +8d +b4 +26 +00 +00 +00 +00 00 10 00 @@ -80978,8 +80978,8 @@ a1 00 00 00 -90 -90 +eb +0a 90 90 90 @@ -81047,13 +81047,13 @@ c8 00 00 90 -90 -90 -90 -90 -90 -90 -90 +8d +b4 +26 +00 +00 +00 +00 08 00 00 @@ -81194,6 +81194,8 @@ c7 00 00 00 +eb +0d 90 90 90 @@ -81208,12 +81210,10 @@ c7 90 90 90 -90 -90 -90 -90 -90 -90 +8d +74 +26 +00 20 00 00 @@ -81326,8 +81326,8 @@ a1 00 00 00 -90 -90 +eb +0d 90 90 90 @@ -81426,8 +81426,8 @@ ae 00 00 00 -90 -90 +eb +0a 90 90 90 @@ -81802,6 +81802,8 @@ c4 00 00 00 +eb +0d 90 90 90 @@ -81816,12 +81818,10 @@ c4 90 90 90 -90 -90 -90 -90 -90 -90 +8d +74 +26 +00 00 20 00 @@ -81879,13 +81879,13 @@ c5 00 00 90 -90 -90 -90 -90 -90 -90 -90 +8d +b4 +26 +00 +00 +00 +00 00 20 00 @@ -82222,8 +82222,8 @@ f7 00 00 00 -90 -90 +eb +0d 90 90 90 @@ -82322,8 +82322,8 @@ c4 00 00 00 -90 -90 +eb +0a 90 90 90 @@ -82474,6 +82474,8 @@ c4 00 00 00 +eb +0d 90 90 90 @@ -82488,12 +82490,10 @@ c4 90 90 90 -90 -90 -90 -90 -90 -90 +8d +74 +26 +00 00 40 00 @@ -82578,8 +82578,8 @@ c4 00 00 00 -90 -90 +eb +0a 90 90 90 @@ -82647,13 +82647,13 @@ c4 00 00 90 -90 -90 -90 -90 -90 -90 -90 +8d +b4 +26 +00 +00 +00 +00 40 20 00 @@ -82766,8 +82766,8 @@ c4 21 00 00 -90 -90 +eb +0d 90 90 90 @@ -82866,8 +82866,8 @@ c4 21 00 00 -90 -90 +eb +0a 90 90 90 @@ -82935,13 +82935,13 @@ c5 00 00 90 -90 -90 -90 -90 -90 -90 -90 +8d +b4 +26 +00 +00 +00 +00 00 80 00 @@ -82999,13 +82999,13 @@ c4 00 00 90 -90 -90 -90 -90 -90 -90 -90 +8d +b4 +26 +00 +00 +00 +00 00 80 00 @@ -83118,8 +83118,8 @@ c4 00 00 00 -90 -90 +eb +0d 90 90 90 @@ -83274,6 +83274,8 @@ c4 00 00 00 +eb +0d 90 90 90 @@ -83288,12 +83290,10 @@ c4 90 90 90 -90 -90 -90 -90 -90 -90 +8d +74 +26 +00 00 80 00 @@ -83602,8 +83602,8 @@ a2 00 00 00 -90 -90 +eb +0a 90 90 90 @@ -83671,13 +83671,13 @@ a7 00 00 90 -90 -90 -90 -90 -90 -90 -90 +8d +b4 +26 +00 +00 +00 +00 04 00 20 @@ -83846,6 +83846,8 @@ a7 00 00 00 +eb +0d 90 90 90 @@ -83859,10 +83861,8 @@ a7 90 90 90 -90 -90 -90 -90 +eb +07 90 90 90 @@ -83991,13 +83991,13 @@ a6 00 24 00 -90 -90 -90 -90 -90 -90 -90 +8d +b4 +26 +00 +00 +00 +00 00 00 00 @@ -84133,6 +84133,8 @@ a6 65 64 00 +eb +0d 90 90 90 @@ -84146,10 +84148,8 @@ a6 90 90 90 -90 -90 -90 -90 +eb +08 90 90 90 @@ -84225,6 +84225,8 @@ a6 65 72 00 +eb +0d 90 90 90 @@ -84238,10 +84240,8 @@ a6 90 90 90 -90 -90 -90 -90 +eb +0c 90 90 90 @@ -84320,6 +84320,8 @@ a6 6f 6e 00 +eb +0d 90 90 90 @@ -84333,10 +84335,8 @@ a6 90 90 90 -90 -90 -90 -90 +eb +0d 90 90 90 @@ -84383,9 +84383,9 @@ a6 6f 6e 00 -90 -90 -90 +8d +76 +00 af 03 00 @@ -84474,10 +84474,10 @@ ef 06 00 00 -90 -90 -90 -90 +8d +74 +26 +00 75 6e 72 @@ -85258,6 +85258,8 @@ fc 15 00 00 +eb +0d 90 90 90 @@ -85272,12 +85274,10 @@ fc 90 90 90 -90 -90 -90 -90 -90 -90 +8d +74 +26 +00 60 73 27 @@ -85322,6 +85322,8 @@ fc 64 65 00 +eb +0d 90 90 90 @@ -85336,12 +85338,10 @@ fc 90 90 90 -90 -90 -90 -90 -90 -90 +8d +74 +26 +00 43 61 6e @@ -85397,8 +85397,8 @@ fc 64 65 00 -90 -90 +eb +07 90 90 90 @@ -85471,6 +85471,8 @@ fc 64 65 00 +eb +0d 90 90 90 @@ -85484,10 +85486,8 @@ fc 90 90 90 -90 -90 -90 -90 +eb +0d 90 90 90 diff --git a/modules/objfmts/elf/tests/elf-x86id.hex b/modules/objfmts/elf/tests/elf-x86id.hex index 1a61d6ed..5f3bb4c1 100644 --- a/modules/objfmts/elf/tests/elf-x86id.hex +++ b/modules/objfmts/elf/tests/elf-x86id.hex @@ -68765,6 +68765,10 @@ ff 00 00 00 +00 +00 +00 +00 02 00 00 @@ -68930,6 +68934,8 @@ ff 00 00 00 +eb +0d 90 90 90 @@ -68943,10 +68949,8 @@ ff 90 90 90 -90 -90 -90 -90 +eb +07 90 90 90 @@ -70214,6 +70218,8 @@ c7 00 00 00 +eb +0d 90 90 90 @@ -70228,12 +70234,10 @@ c7 90 90 90 -90 -90 -90 -90 -90 -90 +8d +74 +26 +00 04 00 00 @@ -70402,6 +70406,8 @@ c7 00 00 00 +eb +0d 90 90 90 @@ -70415,10 +70421,8 @@ c7 90 90 90 -90 -90 -90 -90 +eb +07 90 90 90 @@ -71210,8 +71214,8 @@ a8 00 00 00 -90 -90 +eb +0d 90 90 90 @@ -71814,6 +71818,8 @@ a9 00 00 00 +eb +0d 90 90 90 @@ -71828,12 +71834,10 @@ a9 90 90 90 -90 -90 -90 -90 -90 -90 +8d +74 +26 +00 00 00 00 @@ -72226,6 +72230,8 @@ a9 00 00 00 +eb +0d 90 90 90 @@ -72239,10 +72245,8 @@ a9 90 90 90 -90 -90 -90 -90 +eb +07 90 90 90 @@ -72418,6 +72422,8 @@ ed 00 00 00 +eb +0d 90 90 90 @@ -72431,10 +72437,8 @@ ed 90 90 90 -90 -90 -90 -90 +eb +07 90 90 90 @@ -72610,6 +72614,8 @@ ef 00 00 00 +eb +0d 90 90 90 @@ -72623,10 +72629,8 @@ ef 90 90 90 -90 -90 -90 -90 +eb +07 90 90 90 @@ -72718,8 +72722,8 @@ ef 00 00 00 -90 -90 +eb +0a 90 90 90 @@ -72787,13 +72791,13 @@ ef 00 00 90 -90 -90 -90 -90 -90 -90 -90 +8d +b4 +26 +00 +00 +00 +00 04 00 00 @@ -72851,13 +72855,13 @@ ef 00 00 90 -90 -90 -90 -90 -90 -90 -90 +8d +b4 +26 +00 +00 +00 +00 00 00 00 @@ -73502,6 +73506,8 @@ ef 00 00 00 +eb +0d 90 90 90 @@ -73515,10 +73521,8 @@ ef 90 90 90 -90 -90 -90 -90 +eb +0b 90 90 90 @@ -73698,6 +73702,8 @@ ff 00 00 00 +eb +0d 90 90 90 @@ -73711,10 +73717,8 @@ ff 90 90 90 -90 -90 -90 -90 +eb +07 90 90 90 @@ -73834,8 +73838,8 @@ f7 00 00 00 -90 -90 +eb +0d 90 90 90 @@ -74410,8 +74414,8 @@ f7 00 00 00 -90 -90 +eb +0d 90 90 90 @@ -74483,13 +74487,13 @@ d4 00 00 90 -90 -90 -90 -90 -90 -90 -90 +8d +b4 +26 +00 +00 +00 +00 00 00 00 @@ -75022,8 +75026,8 @@ af 00 00 00 -90 -90 +eb +0a 90 90 90 @@ -75426,6 +75430,8 @@ d1 00 00 00 +eb +0d 90 90 90 @@ -75439,10 +75445,8 @@ d1 90 90 90 -90 -90 -90 -90 +eb +07 90 90 90 @@ -76010,8 +76014,8 @@ ff 00 00 00 -90 -90 +eb +0d 90 90 90 @@ -76614,6 +76618,8 @@ ff 00 00 00 +eb +0d 90 90 90 @@ -76628,12 +76634,10 @@ ff 90 90 90 -90 -90 -90 -90 -90 -90 +8d +74 +26 +00 00 00 00 @@ -76718,8 +76722,8 @@ c8 00 00 00 -90 -90 +eb +0a 90 90 90 @@ -76926,6 +76930,8 @@ c8 00 00 00 +eb +0d 90 90 90 @@ -76939,10 +76945,8 @@ c8 90 90 90 -90 -90 -90 -90 +eb +0b 90 90 90 @@ -77011,13 +77015,13 @@ e3 00 00 90 -90 -90 -90 -90 -90 -90 -90 +8d +b4 +26 +00 +00 +00 +00 00 00 00 @@ -77270,10 +77274,10 @@ e0 00 00 00 -90 -90 -90 -90 +8d +74 +26 +00 04 00 00 @@ -77442,6 +77446,8 @@ ba 00 00 00 +eb +0d 90 90 90 @@ -77455,10 +77461,8 @@ ba 90 90 90 -90 -90 -90 -90 +eb +07 90 90 90 @@ -77578,8 +77582,8 @@ cd 00 00 00 -90 -90 +eb +0d 90 90 90 @@ -77678,8 +77682,8 @@ cd 00 00 00 -90 -90 +eb +0a 90 90 90 @@ -77830,6 +77834,8 @@ cd 00 00 00 +eb +0d 90 90 90 @@ -77844,12 +77850,10 @@ cd 90 90 90 -90 -90 -90 -90 -90 -90 +8d +74 +26 +00 02 00 00 @@ -78018,6 +78022,8 @@ cd 00 00 00 +eb +0d 90 90 90 @@ -78031,10 +78037,8 @@ cd 90 90 90 -90 -90 -90 -90 +eb +07 90 90 90 @@ -78154,8 +78158,8 @@ a1 00 00 00 -90 -90 +eb +0d 90 90 90 @@ -78282,8 +78286,8 @@ a2 00 00 00 -90 -90 +eb +0d 90 90 90 @@ -78382,8 +78386,8 @@ a1 00 00 00 -90 -90 +eb +0a 90 90 90 @@ -78506,8 +78510,8 @@ c9 00 00 00 -90 -90 +eb +0d 90 90 90 @@ -78634,8 +78638,8 @@ a1 00 00 00 -90 -90 +eb +0d 90 90 90 @@ -78707,13 +78711,13 @@ a1 00 00 90 -90 -90 -90 -90 -90 -90 -90 +8d +b4 +26 +00 +00 +00 +00 00 10 00 @@ -78882,6 +78886,8 @@ aa 00 00 00 +eb +0d 90 90 90 @@ -78895,10 +78901,8 @@ aa 90 90 90 -90 -90 -90 -90 +eb +07 90 90 90 @@ -78990,8 +78994,8 @@ aa 00 00 00 -90 -90 +eb +0a 90 90 90 @@ -79114,8 +79118,8 @@ d9 00 00 00 -90 -90 +eb +0d 90 90 90 @@ -79187,13 +79191,13 @@ e0 00 00 90 -90 -90 -90 -90 -90 -90 -90 +8d +b4 +26 +00 +00 +00 +00 00 10 00 @@ -79278,8 +79282,8 @@ a1 00 00 00 -90 -90 +eb +0a 90 90 90 @@ -79347,13 +79351,13 @@ c8 00 00 90 -90 -90 -90 -90 -90 -90 -90 +8d +b4 +26 +00 +00 +00 +00 08 00 00 @@ -79494,6 +79498,8 @@ c7 00 00 00 +eb +0d 90 90 90 @@ -79508,12 +79514,10 @@ c7 90 90 90 -90 -90 -90 -90 -90 -90 +8d +74 +26 +00 20 00 00 @@ -79626,8 +79630,8 @@ a1 00 00 00 -90 -90 +eb +0d 90 90 90 @@ -79726,8 +79730,8 @@ ae 00 00 00 -90 -90 +eb +0a 90 90 90 @@ -80102,6 +80106,8 @@ c4 00 00 00 +eb +0d 90 90 90 @@ -80116,12 +80122,10 @@ c4 90 90 90 -90 -90 -90 -90 -90 -90 +8d +74 +26 +00 00 20 00 @@ -80179,13 +80183,13 @@ c5 00 00 90 -90 -90 -90 -90 -90 -90 -90 +8d +b4 +26 +00 +00 +00 +00 00 20 00 @@ -80522,8 +80526,8 @@ f7 00 00 00 -90 -90 +eb +0d 90 90 90 @@ -80622,8 +80626,8 @@ c4 00 00 00 -90 -90 +eb +0a 90 90 90 @@ -80774,6 +80778,8 @@ c4 00 00 00 +eb +0d 90 90 90 @@ -80788,12 +80794,10 @@ c4 90 90 90 -90 -90 -90 -90 -90 -90 +8d +74 +26 +00 00 40 00 @@ -80878,8 +80882,8 @@ c4 00 00 00 -90 -90 +eb +0a 90 90 90 @@ -80947,13 +80951,13 @@ c4 00 00 90 -90 -90 -90 -90 -90 -90 -90 +8d +b4 +26 +00 +00 +00 +00 40 20 00 @@ -81066,8 +81070,8 @@ c4 21 00 00 -90 -90 +eb +0d 90 90 90 @@ -81166,8 +81170,8 @@ c4 21 00 00 -90 -90 +eb +0a 90 90 90 @@ -81235,13 +81239,13 @@ c5 00 00 90 -90 -90 -90 -90 -90 -90 -90 +8d +b4 +26 +00 +00 +00 +00 00 80 00 @@ -81299,13 +81303,13 @@ c4 00 00 90 -90 -90 -90 -90 -90 -90 -90 +8d +b4 +26 +00 +00 +00 +00 00 80 00 @@ -81418,8 +81422,8 @@ c4 00 00 00 -90 -90 +eb +0d 90 90 90 @@ -81574,6 +81578,8 @@ c4 00 00 00 +eb +0d 90 90 90 @@ -81588,12 +81594,10 @@ c4 90 90 90 -90 -90 -90 -90 -90 -90 +8d +74 +26 +00 00 80 00 @@ -81902,8 +81906,8 @@ a2 00 00 00 -90 -90 +eb +0a 90 90 90 @@ -81971,13 +81975,13 @@ a7 00 00 90 -90 -90 -90 -90 -90 -90 -90 +8d +b4 +26 +00 +00 +00 +00 04 00 20 @@ -82146,6 +82150,8 @@ a7 00 00 00 +eb +0d 90 90 90 @@ -82159,10 +82165,8 @@ a7 90 90 90 -90 -90 -90 -90 +eb +07 90 90 90 @@ -82291,13 +82295,13 @@ a6 00 24 00 -90 -90 -90 -90 -90 -90 -90 +8d +b4 +26 +00 +00 +00 +00 00 00 00 @@ -82433,6 +82437,8 @@ a6 65 64 00 +eb +0d 90 90 90 @@ -82446,10 +82452,8 @@ a6 90 90 90 -90 -90 -90 -90 +eb +08 90 90 90 @@ -82525,6 +82529,8 @@ a6 65 72 00 +eb +0d 90 90 90 @@ -82538,10 +82544,8 @@ a6 90 90 90 -90 -90 -90 -90 +eb +0c 90 90 90 @@ -82620,6 +82624,8 @@ a6 6f 6e 00 +eb +0d 90 90 90 @@ -82633,10 +82639,8 @@ a6 90 90 90 -90 -90 -90 -90 +eb +0d 90 90 90 @@ -82683,9 +82687,9 @@ a6 6f 6e 00 -90 -90 -90 +8d +76 +00 af 03 00 @@ -82774,10 +82778,10 @@ ef 06 00 00 -90 -90 -90 -90 +8d +74 +26 +00 75 6e 72 @@ -83558,6 +83562,8 @@ fc 15 00 00 +eb +0d 90 90 90 @@ -83572,12 +83578,10 @@ fc 90 90 90 -90 -90 -90 -90 -90 -90 +8d +74 +26 +00 60 73 27 @@ -83622,6 +83626,8 @@ fc 64 65 00 +eb +0d 90 90 90 @@ -83636,12 +83642,10 @@ fc 90 90 90 -90 -90 -90 -90 -90 -90 +8d +74 +26 +00 43 61 6e @@ -83697,8 +83701,8 @@ fc 64 65 00 -90 -90 +eb +07 90 90 90 @@ -83771,6 +83775,8 @@ fc 64 65 00 +eb +0d 90 90 90 @@ -83784,10 +83790,8 @@ fc 90 90 90 -90 -90 -90 -90 +eb +0d 90 90 90 @@ -153410,10 +153414,6 @@ cb 00 00 00 -00 -00 -00 -00 3b 00 00 @@ -153430,7 +153430,7 @@ cb 00 00 00 -90 +94 a2 01 00 @@ -153470,7 +153470,7 @@ a2 00 00 00 -d8 +dc a2 01 00 @@ -153510,7 +153510,7 @@ e4 00 00 00 -bc +c0 a4 01 00 @@ -153670,7 +153670,7 @@ f3 00 00 00 -9c +a0 0c 01 00 @@ -153686,7 +153686,7 @@ f3 00 00 00 -04 +20 00 00 00 @@ -153710,7 +153710,7 @@ f3 00 00 00 -c0 +c4 63 01 00 diff --git a/modules/parsers/nasm/nasm-bison.y b/modules/parsers/nasm/nasm-bison.y index 853f68c8..a56bc658 100644 --- a/modules/parsers/nasm/nasm-bison.y +++ b/modules/parsers/nasm/nasm-bison.y @@ -596,6 +596,45 @@ nasm_parser_directive(yasm_parser_nasm *parser_nasm, const char *name, vp->param = NULL; } parser_nasm->prev_bc = yasm_section_bcs_last(parser_nasm->cur_section); + } else if (yasm__strcasecmp(name, "align") == 0) { + /*@only@*/ yasm_expr *boundval; + /*@depedent@*/ yasm_intnum *boundintn; + + /* it can be just an ID or a complete expression, so handle both. */ + vp = yasm_vps_first(valparams); + if (vp->val) + boundval = p_expr_new_ident(yasm_expr_sym( + yasm_symtab_use(p_symtab, vp->val, line))); + else if (vp->param) { + boundval = vp->param; + vp->param = NULL; + } + + /* Largest .align in the section specifies section alignment. + * Note: this doesn't match NASM behavior, but is a lot more + * intelligent! + */ + boundintn = yasm_expr_get_intnum(&boundval, NULL); + if (boundintn) { + unsigned long boundint = yasm_intnum_get_uint(boundintn); + + /* Alignments must be a power of two. */ + if ((boundint & (boundint - 1)) == 0) { + if (boundint > yasm_section_get_align(parser_nasm->cur_section)) + yasm_section_set_align(parser_nasm->cur_section, boundint, + cur_line); + } + } + + /* As this directive is called only when nop is used as fill, always + * use arch (nop) fill. + */ + parser_nasm->prev_bc = + yasm_section_bcs_append(parser_nasm->cur_section, + yasm_bc_create_align(boundval, NULL, NULL, + /*yasm_section_is_code(parser_nasm->cur_section) ?*/ + yasm_arch_get_fill(parser_nasm->arch)/* : NULL*/, + cur_line)); } else if (yasm__strcasecmp(name, "cpu") == 0) { yasm_vps_foreach(vp, valparams) { if (vp->val) diff --git a/modules/parsers/nasm/tests/Makefile.inc b/modules/parsers/nasm/tests/Makefile.inc index 3e7e1cdc..a4351798 100644 --- a/modules/parsers/nasm/tests/Makefile.inc +++ b/modules/parsers/nasm/tests/Makefile.inc @@ -3,6 +3,12 @@ TESTS += modules/parsers/nasm/tests/nasm_test.sh EXTRA_DIST += modules/parsers/nasm/tests/nasm_test.sh +EXTRA_DIST += modules/parsers/nasm/tests/alignnop16.asm +EXTRA_DIST += modules/parsers/nasm/tests/alignnop16.errwarn +EXTRA_DIST += modules/parsers/nasm/tests/alignnop16.hex +EXTRA_DIST += modules/parsers/nasm/tests/alignnop32.asm +EXTRA_DIST += modules/parsers/nasm/tests/alignnop32.errwarn +EXTRA_DIST += modules/parsers/nasm/tests/alignnop32.hex EXTRA_DIST += modules/parsers/nasm/tests/endcomma.asm EXTRA_DIST += modules/parsers/nasm/tests/endcomma.errwarn EXTRA_DIST += modules/parsers/nasm/tests/endcomma.hex diff --git a/modules/parsers/nasm/tests/alignnop16.asm b/modules/parsers/nasm/tests/alignnop16.asm new file mode 100644 index 00000000..dd413619 --- /dev/null +++ b/modules/parsers/nasm/tests/alignnop16.asm @@ -0,0 +1,4 @@ +bits 16 +mov eax,32 +align 16 +ret diff --git a/modules/parsers/nasm/tests/alignnop16.errwarn b/modules/parsers/nasm/tests/alignnop16.errwarn new file mode 100644 index 00000000..e69de29b diff --git a/modules/parsers/nasm/tests/alignnop16.hex b/modules/parsers/nasm/tests/alignnop16.hex new file mode 100644 index 00000000..de32de77 --- /dev/null +++ b/modules/parsers/nasm/tests/alignnop16.hex @@ -0,0 +1,17 @@ +66 +b8 +20 +00 +00 +00 +eb +08 +90 +90 +90 +90 +90 +90 +90 +90 +c3 diff --git a/modules/parsers/nasm/tests/alignnop32.asm b/modules/parsers/nasm/tests/alignnop32.asm new file mode 100644 index 00000000..13410d06 --- /dev/null +++ b/modules/parsers/nasm/tests/alignnop32.asm @@ -0,0 +1,4 @@ +bits 32 +mov eax,32 +align 16 +ret diff --git a/modules/parsers/nasm/tests/alignnop32.errwarn b/modules/parsers/nasm/tests/alignnop32.errwarn new file mode 100644 index 00000000..e69de29b diff --git a/modules/parsers/nasm/tests/alignnop32.hex b/modules/parsers/nasm/tests/alignnop32.hex new file mode 100644 index 00000000..4af43b8c --- /dev/null +++ b/modules/parsers/nasm/tests/alignnop32.hex @@ -0,0 +1,17 @@ +b8 +20 +00 +00 +00 +eb +09 +90 +90 +90 +90 +90 +90 +90 +90 +90 +c3 diff --git a/modules/preprocs/nasm/standard.mac b/modules/preprocs/nasm/standard.mac index fe6a49b1..85170cb2 100644 --- a/modules/preprocs/nasm/standard.mac +++ b/modules/preprocs/nasm/standard.mac @@ -65,7 +65,11 @@ __SECT__ %endmacro %imacro align 1-2+.nolist nop +%ifidni %2,nop + [align %1] +%else times ($$-$) & ((%1)-1) %2 +%endif %endmacro %imacro alignb 1-2+.nolist resb 1 times ($$-$) & ((%1)-1) %2