diff options
Diffstat (limited to 'README.1st')
-rw-r--r-- | README.1st | 257 |
1 files changed, 85 insertions, 172 deletions
@@ -1,187 +1,100 @@ -This is a specially patched version of NASM. It can be used to supplement -building of Crystal Space, the Open Source 3D Engine project. You can find -Crystal Space at the following locations: - -http://crystal.linuxgames.com/ -http://crystal.sourceforge.net/ - -Details of changes in this version of NASM follow. - --*- A new keyword %xdefine and its case-insensitive counterpart %ixdefine. - They work almost the same way as %define and %idefine but expand - the definition immediately, not on the invocation. Something like a cross - between %define and %assign. The "x" suffix stands for "eXpand", so - "xdefine" can be deciphered as "expand-and-define". Thus you can do - things like this: - - %assign ofs 0 +PROLOGUE + +One day someone wrote that nasm needs: + +> - A good ALIGN mechanism, similar to GAS's. GAS pads out space by +> means of the following (32-bit) instructions: +> 8DB42600000000 lea esi,[esi+0x0] +> 8DB600000000 lea esi,[esi+0x0] +> 8D742600 lea esi,[esi+0x0] +> 8D7600 lea esi,[esi+0x0] +> 8D36 lea esi,[esi] +> 90 nop +> It uses up to two of these instructions to do up to 14-byte pads; +> when more than 14 bytes are needed, it issues a (short) jump to +> the end of the padded section and then NOPs the rest. Come up with +> a similar scheme for 16 bit mode, and also come up with a way to +> use it - internal to the assembler, so that programs using ALIGN +> don't knock over preprocess-only mode. +> Also re-work the macro form so that when given one argument in a +> code section it calls this feature. + +Well palign is your friend. + + + This is a modified version of nasm-0.98.24 that can accept +two new directives.The two new directives that control +the align mechanism are 'palign' and 'p2align'.They are nasm directives +that don't depend on preprocessor but rather align the code while assembling +in a gas-like style. + The syntax of these directives is + +[palign n] where '0 <= n <= 6' and +[p2align n] where '0 <= n <=6' + + The use of these directives is + +[palign n] + + Pad the location counter to a particular storage boundary. +The n is a number between 0 and 6 of low-order zero bits the location counter +must have after advancement. +For example `palign 3' advances the location counter until +it a multiple of 8.If the location counter is already a multiple of 8, +no change is needed. +If n=0 then nothing is done +if n => 6 then palign advances the location counter until it a multiple +of 64.For now the maximum is 64 bytes,if you want more use the ALIGN macro. + +[p2align n] + + This directive do almost the same thing with a little exception. +It will continue aligning until a directive [p2align 0] meet or until +the current section changes.So this piece of code + + BITS 32 + SECTION .text + [p2align 5] - %macro arg 1 - %xdefine %1 dword [esp+ofs] - %assign ofs ofs+4 - %endmacro - --*- Changed the place where the expansion of %$name macros are expanded. - Now they are converted into ..@ctxnum.name form when detokenizing, so - there are no quirks as before when using %$name arguments to macros, - in macros etc. For example: - - %macro abc 1 - %define %1 hello - %endm - - abc %$here - %$here - - Now last line will be expanded to "hello" as expected. This also allows - for lots of goodies, a good example are extended "proc" macros included - in this archive. - --*- Added a check for "cstk" in smacro_defined() before calling get_ctx() - - this allows for things like: - - %ifdef %$abc - %endif - - to work without warnings even in no context. - --*- Added a check for "cstk" in %if*ctx and %elif*ctx directives - - this allows to use %ifctx without excessive warnings. If there is - no active context, %ifctx goes through "false" branch. - --*- Removed "user error: " prefix with %error directive: it just clobbers the - output and has absolutely no functionality. Besides, this allows to write - macros that does not differ from build-in functions in any way. - --*- Added expansion of string that is output by %error directive. Now you - can do things like: - - %define hello(x) Hello, x! - - %define %$name andy - %error "hello(%$name)" - - Same happened with %include directive. - --*- Now all directives that expect an identifier will try to expand and - concatenate everything without whitespaces in between before usage. - For example, with "unfixed" nasm the commands - - %define %$abc hello - %define __%$abc goodbye - __%$abc - - would produce "incorrect" output: last line will expand to - - hello goodbyehello - - Not quite what you expected, eh? :-) The answer is that preprocessor - treats the %define construct as if it would be - - %define __ %$abc goodbye - - (note the white space between __ and %$abc). After my "fix" it - will "correctly" expand into - - goodbye - - as expected. Note that I use quotes around words "correct", "incorrect" - etc because this is rather a feature not a bug; however current behaviour - is more logical (and allows more advanced macro usage :-). - - Same change was applied to: - %push,%macro,%imacro,%define,%idefine,%xdefine,%ixdefine, - %assign,%iassign,%undef - --*- A new directive [WARNING {+|-}warning-id] have been added. It works only - if the assembly phase is enabled (i.e. it doesn't work with nasm -e). - --*- A new warning type: macro-selfref. By default this warning is disabled; - when enabled NASM warns when a macro self-references itself; for example - the following source: - - [WARNING macro-selfref] - - %macro push 1-* - %rep %0 - push %1 - %rotate 1 - %endrep - %endmacro - - push eax,ebx,ecx - - will produce a warning, but if we remove the first line we won't see it - anymore (which is The Right Thing To Do {tm} IMHO since C preprocessor - eats such constructs without warnings at all). - --*- Added a "error" routine to preprocessor which always will set ERR_PASS1 - bit in severity_code. This removes annoying repeated errors on first - and second passes from preprocessor. - --*- Added the %+ operator in single-line macros for concatenating two - identifiers. Usage example: - - %define _myfunc _otherfunc - %define cextern(x) _ %+ x - cextern (myfunc) - - After first expansion, third line will become "_myfunc". After this - expansion is performed again so it becomes "_otherunc". - --*- Now if preprocessor is in a non-emmitting state, no warning or error - will be emmitted. Example: - - %if 1 - mov eax,ebx - %else - put anything you want between these two brackets, - even macro-parameter references %1 or local labels %$zz - or macro-local labels %%zz - no warning will be emmitted. - %endif + ;some code here --*- Context-local variables on expansion as a last resort are looked up - in outer contexts. For example, the following piece: - %push outer - %define %$a [esp] + SECTION .data - %push inner - %$a - %pop - %pop + ;some data here - will expand correctly the fourth line to [esp]; if we'll define another - %$a inside the "inner" context, it will take precedence over outer - definition. However, this modification has been applied only to - expand_smacro and not to smacro_define: as a consequence expansion - looks in outer contexts, but %ifdef won't look in outer contexts. +guarantee that all the instructions in the code segment will be aligned +in a 32 byte boundary so than no instruction break the cache line on a +pentium processor. - This behaviour is needed because we don't want nested contexts to - act on already defined local macros. Example: +BUGS - %define %$arg1 [esp+4] - test eax,eax - if nz - mov eax,%$arg1 - endif +Well my english are very very bad. +This optimization will not work +for now for 16-bit code. +Also there may be a problem with the prefixes like ds,es,rep,lock etc - In this example the "if" mmacro enters into the "if" context, so %$arg1 - is not valid anymore inside "if". Of course it could be worked around - by using explicitely %$$arg1 but this is ugly IMHO. +so this code will work --------------------------------// fixes for 0.98 //----------------------------- + 'rep movsd' --*- Fixed memory leak in %undef. The origline wasn't freed before - exiting on success. +but this may not work ------------------------------// Fixes for 0.98.01 //---------------------------- + 'rep' + 'movsd' --*- Fixed trap in preprocessor when line expanded to empty set of tokens. - This happens, for example, in the following case: +if you want to be sure put the prefix in the same line +with the instruction. - #define SOMETHING - SOMETHING +Also don't try this in a data or a bss segment.Use the ALIGN macro better +FEEDBACK -Andrew Zabolotny <bit@eltech.ru> +If you have any suggestion, comment or found a bug please email me +and i will try to reply immediately. +From your feedback it depends this project to get better as i intend +to implement more things and improve the code in the next version of nasm. + +AUTHOR +Panos Minos 03-04-2002 +email: <panosminos@mycosmos.gr> , <panosminos1@mycosmos.gr> |