This file is vital and MUST be included into program code to do anything else; without this file you'll have to write in usual boring way.
CODESEG
, DATASEG
, UDATASEG
, END
, I_STRUC
, I_END
macros are here, some other will be added.
Also it contains optimizing macros _mov
(former __setreg32
),
_add
, _sub
, that perform register assignment, addition and subtraction.
You can use these macros instead of mov, add, sub instructions;
if you take care of size, this will produce quite good results
(do not try to understand how they work :).
This file includes two others: includes.inc and syscall.inc, you do need to include them manually.
This file stores generic constant definitions and structures (from libc headers), that are OS independent. If you add some defined constant, please do not forget to mention header file it was taken from.
File holds system call macros, here are general things to know them: (warning: from asmutils 0.11 syscall macros will change seriously!)
sys_write EMPTY,EMPTY,1
will expand to:
_mov edx,1
__syscall write...
sys_write eax, ebx, ecx
;
it will expand to:
mov edx,ecx
mov ecx,ebx
mov ebx,eax
__syscall write...
WARNING: *never* use __syscall
macro in your program directly
(of course the same applies to int 0x80 !!).
This is a VERY BAD thing to do.
This will MAKE YOUR CODE UNPORTABLE!
So please use only sys_xxx
macros!
If some system call is missing, you can add it to this file; it's simple, just look how others are done there; use sys_syscallname as macro name.
This file applies only to Linux. ELF macros are defined here.
These macros can be (and are, by default) used to reduce final size of executable.
Brian Raiter wrote README.elf and comments in elf.inc containing
all you need to know about what they do and how they work.
But here are another good news: almost all of them (except ELF_BSTRUC and ELF_AT)
are integrated into existing program structure.
To enable them you just need to have ELF_MACROS = y
line in Makefile (enabled by default),
this turns on automatic usage of these macros (and you do not have to include elf.inc).
And if you will follow simple rules when writing a program,
then you will not have to carry out two different definitions for sections and structures;
so, you can compile the same source with and without usage of these macros,
getting correct code in both cases.
This is experimental thing, however it seems to work well.
Rules are simple: use following section order: CODESEG, DATASEG, UDATASEG, END,
and use I_STRUC and I_END to define structures in UDATASEG
instead of istruc
and iend
(take any asmutils source as an example).
Alternatively, you can use macros from elf.inc directly if you want,
but then you can't compile your source using usual nasm/ld procedure.
If you want to go this way, take the time and read REAME.elf carefully
(also do read it if you want to understand how they work).
Personally I think that first way is simpler.