mirror of https://github.com/tLDP/LDP
updated
This commit is contained in:
parent
cb25823664
commit
743a7a04ca
|
@ -1,26 +1,11 @@
|
|||
<!doctype linuxdoc system>
|
||||
|
||||
<!-- $Id$
|
||||
<!-- $Id$ -->
|
||||
|
||||
NOTE TO PUBLISHERS:
|
||||
|
||||
(1) This document uses iso-8859-1 latin encoding,
|
||||
so you must give -l flag to sgmltools 0.99.x,
|
||||
or -c latin to sgmltools 1.x...
|
||||
|
||||
(2) some of the material here can be skipped for a paper print,
|
||||
as much as it is redundant with other material
|
||||
(e.g. how to use the HOWTO, plea for contributions, etc,
|
||||
which should be replaced by a generic explanation at the head
|
||||
of any good HOWTO compendium),
|
||||
or do not worth the paper to print it ("History", "Credits"),
|
||||
considering that HOWTO compendiums must squeeze lot of
|
||||
stuff on a limited place.
|
||||
|
||||
(3) I recommend you not to edit/remove/strip
|
||||
the rest of the document (after the introduction)
|
||||
unless you explicitly state you did it on the same page
|
||||
as the HOWTO appears, and/or you agree with me before.
|
||||
<!--
|
||||
This is (probably) the last release of HOWTO with linuxdoc dtd.
|
||||
Following releases will be in docbook dtd.
|
||||
Translators (if any), get ready.
|
||||
-->
|
||||
|
||||
<article>
|
||||
|
@ -29,9 +14,9 @@
|
|||
|
||||
<author>
|
||||
<url url="mailto:konst@linuxassembly.org" name="Konstantin Boldyshev"> and
|
||||
<url url="mailto:fare@tunes.org" name="François-René Rideau">
|
||||
<url url="mailto:fare@tunes.org" name="Francois-Rene Rideau">
|
||||
|
||||
<date>v0.5i, May 4, 2000
|
||||
<date>v0.5j, June 14, 2000
|
||||
|
||||
<abstract>
|
||||
This is the Linux Assembly HOWTO.
|
||||
|
@ -39,26 +24,29 @@ This is the Linux Assembly HOWTO.
|
|||
This document describes how to program in assembly language
|
||||
using FREE programming tools,
|
||||
focusing on development for or from the Linux Operating System,
|
||||
mostly on IA32 (i386) platform.
|
||||
mostly on IA-32 (i386) platform.
|
||||
|
||||
Included material may or may not be applicable
|
||||
to other hardware and/or software platforms.
|
||||
Contributions about them will be gladly accepted.
|
||||
Contributions about them are gladly accepted.
|
||||
|
||||
<bf/Keywords/:
|
||||
<tt/assembly, assembler, asm, inline asm, macroprocessor, preprocessor,
|
||||
32-bit, IA32, i386, x86, gas, as86, nasm, OS, kernel, system, libc,
|
||||
32-bit, IA-32, i386, x86, gas, as86, nasm, OS, kernel, system, libc,
|
||||
system call, interrupt, small, fast, embedded, hardware, port/
|
||||
</abstract>
|
||||
|
||||
<toc>
|
||||
|
||||
|
||||
<sect>INTRODUCTION
|
||||
<p>
|
||||
|
||||
You can skip this section if you are familiar with HOWTOs,
|
||||
or just hate to read all this assembly-nonrelated crap.
|
||||
|
||||
<sect1>Legal Blurb
|
||||
<p>Copyright © 1999-2000 Konstantin Boldyshev.
|
||||
<p>Copyright © 1996-1999 François-René Rideau.
|
||||
<p>Copyright © 1996-1999 Francois-Rene Rideau.
|
||||
|
||||
This document may be distributed only subject to the terms and conditions set
|
||||
forth in the <url url="http://linuxdoc.org/COPYRIGHT.html" name="LDP License">.
|
||||
|
@ -80,15 +68,26 @@ and partial documents, must meet the following requirements:
|
|||
the original author's (or authors') permission
|
||||
</itemize>
|
||||
|
||||
The most recent official version of this document is available from
|
||||
<url url="http://linuxassembly.org" name="Linux Assembly"> and
|
||||
<url url="http://linuxdoc.org" name="LDP"> sites.
|
||||
If you are reading a few-months-old copy,
|
||||
consider checking urls above for a new version.
|
||||
|
||||
<sect1>Foreword
|
||||
<p>
|
||||
This document aims answering questions of those
|
||||
who program or want to program 32-bit x86 assembly using
|
||||
<em><url url="http://www.gnu.org/philosophy/" name="free software"></em>,
|
||||
particularly under the Linux operating system.
|
||||
It also points to other documents about
|
||||
At many places, Universal Resource Locators (URL) are given for some
|
||||
software or documentation repository.
|
||||
This document also points to other documents about
|
||||
non-free, non-x86, or non-32-bit assemblers,
|
||||
although this is not its primary goal.
|
||||
Also note that there are FAQs and docs about programming
|
||||
on your favorite platform (whatever it is), which you should consult
|
||||
for platform-specific issues, not related directly to assembly programming.
|
||||
|
||||
Because the main interest of assembly programming is to build
|
||||
the guts of operating systems, interpreters, compilers, and games,
|
||||
|
@ -96,7 +95,19 @@ where C compiler fails to provide the needed expressiveness
|
|||
(performance is more and more seldom as issue),
|
||||
we are focusing on development of such kind of software.
|
||||
|
||||
<sect1>Important Note
|
||||
If you don't know what <em/free/ software is,
|
||||
please do read <em/carefully/ the GNU General Public License,
|
||||
which is used in a lot of free software,
|
||||
and is the model for most of their licenses.
|
||||
It generally comes in a file named <tt/COPYING/ (or <tt/COPYING.LIB/).
|
||||
Literature from the <url url="http://www.fsf.org" name="FSF">
|
||||
(free software foundation) might help you, too.
|
||||
Particularly, the interesting feature of free software
|
||||
is that it comes with sources that you can consult and correct,
|
||||
or sometimes even borrow from.
|
||||
Read your particular license carefully and do comply to it.
|
||||
|
||||
<sect1>Contributions
|
||||
<p>
|
||||
This is an interactively evolving document: you are especially invited
|
||||
to ask questions,
|
||||
|
@ -110,58 +121,39 @@ To contribute, please contact the Assembly-HOWTO maintainer.
|
|||
At the time of this writing, it is
|
||||
<url url="mailto:konst@linuxassembly.org" name="Konstantin Boldyshev">
|
||||
and no more
|
||||
<url url="mailto:fare@tunes.org" name="François-René Rideau">.
|
||||
I (Faré) had been looking for some time for a serious hacker
|
||||
<url url="mailto:fare@tunes.org" name="Francois-Rene Rideau">.
|
||||
I (Fare) had been looking for some time for a serious hacker
|
||||
to replace me as maintainer of this document,
|
||||
and am pleased to announce Konstantin as my worthy successor.
|
||||
|
||||
<sect2>How to use this document
|
||||
<sect1>Credits
|
||||
<p>
|
||||
This document contains answers to some frequently asked questions.
|
||||
At many places, Universal Resource Locators (URL) are given for some
|
||||
software or documentation repository.
|
||||
Please see that the most useful repositories are mirrored,
|
||||
and that by accessing a nearer mirror site,
|
||||
you relieve the whole Internet from unneeded network traffic,
|
||||
while saving your own precious time.
|
||||
Particularly, there are large repositories all over the world,
|
||||
that mirror other popular repositories.
|
||||
You should learn and note what are those places near you (networkwise).
|
||||
Sometimes, the list of mirrors is listed in a file,
|
||||
or in a login message. Please heed the advice.
|
||||
Else, you should ask archie about the software you're looking for...
|
||||
|
||||
The most recent official version of this document is available from
|
||||
<url url="http://linuxassembly.org" name="Linux Assembly"> and
|
||||
<url url="http://linuxdoc.org" name="LDP"> sites.
|
||||
If you are reading a few-months-old copy,
|
||||
please check the urls above for a new version.
|
||||
|
||||
|
||||
<sect2>Other related documents
|
||||
<p>
|
||||
|
||||
I would like to thank following persons, by order of appearance:
|
||||
<itemize>
|
||||
<item>If you don't know what <em/free/ software is,
|
||||
please do read <em/carefully/ the GNU General Public License,
|
||||
which is used in a lot of free software,
|
||||
and is a model for most of their licenses.
|
||||
It generally comes in a file named <tt/COPYING/,
|
||||
with a library version in a file named <tt/COPYING.LIB/.
|
||||
Literature from the <url url="http://www.fsf.org" name="FSF">
|
||||
(free software foundation) might help you, too.
|
||||
|
||||
<item>Particularly, the interesting feature of free software
|
||||
is that it comes with sources that you can consult and correct,
|
||||
or sometimes even borrow from.
|
||||
Read your particular license carefully, and do comply to it.
|
||||
|
||||
<item>There are FAQs and docs about programming on your favorite platform,
|
||||
whatever it is, which you should consult for platform-specific issues,
|
||||
not related directly to assembly programming.
|
||||
|
||||
<item>Refer to <ref id="res" name="RESOURCES"> section of this HOWTO
|
||||
for pointers to related documents and projects.
|
||||
<item><url url="mailto:buried.alive@in.mail" name="Linus Torvalds">
|
||||
for Linux
|
||||
<item><url url="mailto:bde@zeta.org.au" name="Bruce Evans">
|
||||
for bcc from which as86 is extracted
|
||||
<item><url url="mailto:anakin@pobox.com" name="Simon Tatham"> and
|
||||
<url url="mailto:jules@earthcorp.com" name="Julian Hall">
|
||||
for NASM
|
||||
<item><url url="mailto:gregh@metalab.unc.edu" name="Greg Hankins">
|
||||
and now
|
||||
<url url="mailto:linux-howto@metalab.unc.edu" name="Tim Bynum">
|
||||
for maintaining HOWTOs
|
||||
<item><url url="mailto:raymoon@moonware.dgsys.com" name="Raymond Moon">
|
||||
for his FAQ
|
||||
<item><url url="mailto:dumas@linux.eu.org" name="Eric Dumas">
|
||||
for his translation of the mini-HOWTO into French
|
||||
(sad thing for the original author to be French and write in English)
|
||||
<item><url url="mailto:paul@geeky1.ebtech.net" name="Paul Anderson">
|
||||
and <url url="mailto:rahim@megsinet.net" name="Rahim Azizarab">
|
||||
for helping me, if not for taking over the HOWTO.
|
||||
<item><url url="mailto:pcg@goof.com" name="Marc Lehman">
|
||||
for his insight on GCC invocation.
|
||||
<item><url url="mailto:ams@wiw.org" name="Abhijit Menon-Sen">
|
||||
for helping me figure out the argument passing convention
|
||||
<item>All the people who have contributed ideas, answers, remarks, and moral support.
|
||||
</itemize>
|
||||
|
||||
<sect1>History
|
||||
|
@ -169,6 +161,11 @@ for pointers to related documents and projects.
|
|||
Each version includes a few fixes and minor corrections,
|
||||
that need not to be repeatedly mentioned every time.
|
||||
<descrip>
|
||||
<tag/Version 0.5j 14 Jun 2000/
|
||||
Complete rearrangement of INTRODUCTION and RESOURCES;
|
||||
FAQ added to RESOURCES, misc cleanups and additions
|
||||
(and more to come)
|
||||
|
||||
<tag/Version 0.5i 04 May 2000/
|
||||
Added HLA, TALC;
|
||||
rearrangements in RESOURCES, QUICK START, ASSEMBLERS;
|
||||
|
@ -212,7 +209,7 @@ that need not to be repeatedly mentioned every time.
|
|||
<tag/Version 0.4q 22 June 1999/
|
||||
process argument passing (argc,argv,environ) in assembly.
|
||||
This is yet another
|
||||
"last release by Faré before new maintainer takes over".
|
||||
"last release by Fare before new maintainer takes over".
|
||||
Nobody knows who might be the new maintainer.
|
||||
|
||||
<tag/Version 0.4p 6 June 1999/
|
||||
|
@ -288,42 +285,13 @@ that need not to be repeatedly mentioned every time.
|
|||
<tag/Version 0.2 04 May 1996/ *
|
||||
|
||||
<tag/Version 0.1 23 Apr 1996/
|
||||
Francois-Rene "Faré" Rideau <fare@tunes.org>
|
||||
Francois-Rene "Fare" Rideau <fare@tunes.org>
|
||||
creates and publishes the first mini-HOWTO,
|
||||
because "I'm sick of answering ever the same questions
|
||||
on comp.lang.asm.x86"
|
||||
</descrip>
|
||||
|
||||
|
||||
<sect1>Credits
|
||||
<p>
|
||||
I would like to thank following persons, by order of appearance:
|
||||
<itemize>
|
||||
<item><url url="mailto:buried.alive@in.mail" name="Linus Torvalds">
|
||||
for Linux
|
||||
<item><url url="mailto:bde@zeta.org.au" name="Bruce Evans">
|
||||
for bcc from which as86 is extracted
|
||||
<item><url url="mailto:anakin@pobox.com" name="Simon Tatham"> and
|
||||
<url url="mailto:jules@earthcorp.com" name="Julian Hall">
|
||||
for NASM
|
||||
<item><url url="mailto:gregh@metalab.unc.edu" name="Greg Hankins">
|
||||
and now
|
||||
<url url="mailto:linux-howto@metalab.unc.edu" name="Tim Bynum">
|
||||
for maintaining HOWTOs
|
||||
<item><url url="mailto:raymoon@moonware.dgsys.com" name="Raymond Moon">
|
||||
for his FAQ
|
||||
<item><url url="mailto:dumas@linux.eu.org" name="Eric Dumas">
|
||||
for his translation of the mini-HOWTO into French
|
||||
(sad thing for the original author to be French and write in English)
|
||||
<item><url url="mailto:paul@geeky1.ebtech.net" name="Paul Anderson">
|
||||
and <url url="mailto:rahim@megsinet.net" name="Rahim Azizarab">
|
||||
for helping me, if not for taking over the HOWTO.
|
||||
<item><url url="mailto:pcg@goof.com" name="Marc Lehman">
|
||||
for his insight on GCC invocation.
|
||||
<item><url url="mailto:ams@wiw.org" name="Abhijit Menon-Sen">
|
||||
for helping me figure out the argument passing convention
|
||||
<item>All the people who have contributed ideas, remarks, and moral support.
|
||||
</itemize>
|
||||
|
||||
|
||||
|
||||
|
@ -358,11 +326,8 @@ Assembly can express very low-level things:
|
|||
<item>you can produce reasonably fast code for tight loops
|
||||
to cope with a bad non-optimizing compiler
|
||||
(but then, there are free optimizing compilers available!)
|
||||
<item>you can produce code where
|
||||
(but only on CPUs with known instruction timings,
|
||||
which generally excludes all current ....
|
||||
<item>you can produce hand-optimized code
|
||||
that's perfectly tuned for your particular hardware setup,
|
||||
perfectly tuned for your particular hardware setup,
|
||||
though not to anyone else's.
|
||||
<item>you can write some code for your new language's
|
||||
optimizing compiler
|
||||
|
@ -378,8 +343,8 @@ Assembly is a very low-level language
|
|||
This means
|
||||
<itemize>
|
||||
<item>it's long and tedious to write initially,
|
||||
<item>it's very bug-prone,
|
||||
<item>your bugs will be very difficult to chase,
|
||||
<item>it's quite bug-prone,
|
||||
<item>your bugs can be very difficult to chase,
|
||||
<item>it's very difficult to understand and modify,
|
||||
i.e. to maintain.
|
||||
<item>the result is very non-portable to other architectures,
|
||||
|
@ -607,47 +572,45 @@ The original GCC site is the GNU FTP site
|
|||
together with all released application software from the GNU project.
|
||||
Linux-configured and precompiled versions can be found in
|
||||
<url url="ftp://metalab.unc.edu/pub/Linux/GCC/">
|
||||
There exists a lot of FTP mirrors of both sites.
|
||||
There are a lot of FTP mirrors of both sites,
|
||||
everywhere around the world, as well as CD-ROM copies.
|
||||
|
||||
GCC development has split into two branches some time ago (GCC 2.8 and EGCS),
|
||||
but they merged back, and current GCC webpage is <url url="http://gcc.cygnus.com">.
|
||||
but they merged back, and current GCC webpage is <url url="http://gcc.gnu.org">.
|
||||
|
||||
Sources adapted to your favorite OS, and binaries precompiled for it,
|
||||
Sources adapted to your favorite OS and precompiled binaries
|
||||
should be found at your usual FTP sites.
|
||||
|
||||
For most popular DOS port of GCC is named DJGPP,
|
||||
and can be found in directories of such name in FTP sites. See:
|
||||
|
||||
<url url="http://www.delorie.com/djgpp/">
|
||||
and can be found in directories of such name in FTP sites.
|
||||
See <url url="http://www.delorie.com/djgpp/">.
|
||||
|
||||
There are two Win32 GCC ports:
|
||||
<url url="http://sourceware.cygnus.com/cygwin/" name="cygwin"> and
|
||||
<url url="http://www.mingw.org" name="mingw">
|
||||
|
||||
There is also a port of GCC to OS/2 named EMX,
|
||||
that also works under DOS,
|
||||
and includes lots of unix-emulation library routines.
|
||||
See around the following site:
|
||||
<url url="ftp://ftp-os2.cdrom.com/pub/os2/emx09c/">.
|
||||
<!-- Other URLs listed in previous versions of this HOWTO
|
||||
seem to be as dead as OS/2. -->
|
||||
|
||||
<!-- broken url url="http://www.leo.org/pub/comp/os/os2/gnu/emx+gcc/"-->
|
||||
<!-- broken url url="http://warp.eecs.berkeley.edu/os2/software/shareware/emx.html"-->
|
||||
|
||||
<sect2>Where to find docs for GCC Inline Asm
|
||||
<p>
|
||||
The documentation of GCC includes documentation files in texinfo format.
|
||||
You can compile them with tex and print then result,
|
||||
The documentation of GCC includes documentation files in TeXinfo format.
|
||||
You can compile them with TeX and print then result,
|
||||
or convert them to .info, and browse them with emacs,
|
||||
or convert them to .html, or nearly whatever you like.
|
||||
or convert them to .html, or nearly whatever you like;
|
||||
convert (with the right tools) to whatever you like,
|
||||
or just read as is.
|
||||
The .info files are generally found on any good installation for GCC.
|
||||
|
||||
The right section to look for is:
|
||||
<tt/C Extensions::Extended Asm::/
|
||||
The right section to look for is <tt/C Extensions::Extended Asm::/
|
||||
|
||||
Section
|
||||
<tt/Invoking GCC::Submodel Options::i386 Options::/
|
||||
might help too.
|
||||
Section <tt/Invoking GCC::Submodel Options::i386 Options::/ might help too.
|
||||
Particularly, it gives the i386 specific constraint names for registers:
|
||||
<tt/abcdSDB/ correspond to
|
||||
<tt/%eax/,
|
||||
|
@ -733,7 +696,7 @@ Note that modern GCC has <tt/-mpentium/ and such flags
|
|||
(and <url url="http://goof.com/pcg/" name="PGCC"> has even more),
|
||||
whereas GCC 2.7.x and older versions do not.
|
||||
A good choice of CPU-specific flags should be in the Linux kernel.
|
||||
Check the texinfo documentation of your current GCC installation for more.
|
||||
Check the TeXinfo documentation of your current GCC installation for more.
|
||||
|
||||
<tt/-m386/ will help optimize for size,
|
||||
hence also for speed on computers whose memory is tight and/or loaded,
|
||||
|
@ -751,7 +714,7 @@ whereas other files will be optimized for size.
|
|||
To optimize even more, option <tt/-mregparm=2/
|
||||
and/or corresponding function attribute might help,
|
||||
but might pose lots of problems when linking to foreign code,
|
||||
<em/including the libc/.
|
||||
<em/including libc/.
|
||||
There are ways to correctly declare foreign functions
|
||||
so the right call sequences be generated,
|
||||
or you might want to recompile the foreign libraries
|
||||
|
@ -908,19 +871,23 @@ The Netwide Assembler project provides cool i386 assembler,
|
|||
written in C, that should be modular enough
|
||||
to eventually support all known syntaxes and object formats.
|
||||
|
||||
<sect2>Where to find NASM
|
||||
<sect2>Where to find NASM<label id="findnasm">
|
||||
<p>
|
||||
<url url="http://www.cryogen.com/Nasm/">
|
||||
|
||||
Binary release on your usual metalab mirror in
|
||||
<tt>devel/lang/asm/</tt>
|
||||
Binary release on your usual metalab mirror in <tt>devel/lang/asm/</tt>.
|
||||
Should also be available as .rpm or .deb in your usual RedHat/Debian
|
||||
distributions' contrib.
|
||||
|
||||
At the time of writing current version of NASM is 0.98.
|
||||
|
||||
Note: there's also an extented NASM version available at
|
||||
<url url="ftp://ftp.linuxgames.com/crystal/nasm/">
|
||||
know as 0.98e. It introduces several serious bugfixes and improvements,
|
||||
so you may want to use it instead of "official" version.
|
||||
|
||||
<sect2>What it does
|
||||
<p>
|
||||
At the time this HOWTO is written, current version of NASM is 0.98.
|
||||
|
||||
The syntax is Intel-style.
|
||||
Fairly good macroprocessing support is integrated.
|
||||
|
||||
|
@ -943,8 +910,8 @@ though of course, it doesn't support three bazillion different architectures.
|
|||
If you like Intel-style syntax, as opposed to GAS syntax,
|
||||
then it should be the assembler of choice...
|
||||
|
||||
Note: There's a <ref id="res-related" name="converter between GAS AT&T and Intel assembler syntax">,
|
||||
which does conversion in both directions.
|
||||
Note: There are <ref id="res" name="converters between GAS AT&T and Intel assembler syntax">,
|
||||
which perform conversion in both directions.
|
||||
|
||||
<sect1>AS86
|
||||
<p>
|
||||
|
@ -1101,48 +1068,48 @@ improvement over many of its successors. -John"
|
|||
|
||||
<sect2>HLA
|
||||
<p>
|
||||
<url url="http://webster.cs.ucr.edu
" name="HLA">
|
||||
<url url="http://webster.cs.ucr.edu" name="HLA">
|
||||
is a <bf/H/igh <bf/L/evel <bf/A/ssembly language.
|
||||
It uses
a high level language like syntax
|
||||
(similar to
Pascal, C/C++, and other HLLs) for variable
declarations,
|
||||
procedure declarations, and
procedure calls. It uses a modified
|
||||
assembly
language syntax for the standard machine
instructions.
|
||||
It also provides several high
level language style control structures
|
||||
(if,
while, repeat..until, etc.) that help you
write much more readable code.
|
||||
It uses a high level language like syntax
|
||||
(similar to Pascal, C/C++, and other HLLs) for variable declarations,
|
||||
procedure declarations, and procedure calls. It uses a modified
|
||||
assembly language syntax for the standard machine instructions.
|
||||
It also provides several high level language style control structures
|
||||
(if, while, repeat..until, etc.) that help you write much more readable code.
|
||||
|
||||
HLA is free, but runs only under Win32.
|
||||
You need MASM and a 32-bit
version of MS-link,
|
||||
HLA is free, but runs only under Win32.
|
||||
You need MASM and a 32-bit version of MS-link,
|
||||
because HLA produces MASM code and uses MASM for final
|
||||
assembling and linking. However it comes with <tt/m2t/ (MASM to TASM)
|
||||
post-processor
program that converts the HLA MASM output to a form
|
||||
that
will compile under TASM.
Unfortunately, NASM is not supported.
|
||||
post-processor program that converts the HLA MASM output to a form
|
||||
that will compile under TASM. Unfortunately, NASM is not supported.
|
||||
|
||||
|
||||
<sect2>TALC
|
||||
<p>
|
||||
<url url="http://www.cs.cornell.edu/talc/
" name="TALC">
|
||||
<url url="http://www.cs.cornell.edu/talc/" name="TALC">
|
||||
is another free MASM/Win32 based compiler
|
||||
(however it supports ELF output, does it?).
|
||||
|
||||
TAL stands for <bf/T/yped <bf/A/ssembly <bf/L/anguage.
|
||||
It extends traditional untyped assembly
languages with typing annotations,
|
||||
memory management primitives, and a sound set of
typing rules, to guarantee
|
||||
the memory safety, control flow safety,
and type safety of TAL programs.
|
||||
Moreover, the typing constructs are expressive
enough to encode
|
||||
most source language programming features including records and
structures,
|
||||
arrays, higher-order and polymorphic functions, exceptions, abstract data
types,
|
||||
It extends traditional untyped assembly languages with typing annotations,
|
||||
memory management primitives, and a sound set of typing rules, to guarantee
|
||||
the memory safety, control flow safety,and type safety of TAL programs.
|
||||
Moreover, the typing constructs are expressive enough to encode
|
||||
most source language programming features including records and structures,
|
||||
arrays, higher-order and polymorphic functions, exceptions, abstract data types,
|
||||
subtyping, and modules.
|
||||
Just as importantly, TAL is flexible enough to admit
many low-level compiler optimizations.
|
||||
Consequently, TAL is an ideal target platform
for type-directed compilers
|
||||
Just as importantly, TAL is flexible enough to admit many low-level compiler optimizations.
|
||||
Consequently, TAL is an ideal target platform for type-directed compilers
|
||||
that want to produce verifiably safe code
|
||||
for use in secure
mobile code applications
|
||||
for use in secure mobile code applications
|
||||
or extensible operating system kernels.
|
||||
|
||||
<sect2>Non-free and/or Non-32bit x86 assemblers.
|
||||
<p>
|
||||
You may find more about them,
|
||||
together with the basics of x86 assembly programming,
|
||||
in <ref id="res-general" name="Raymond Moon's FAQ for comp.lang.asm.x86">.
|
||||
in <ref id="res-general" name="Raymond Moon's x86 assembly FAQ">.
|
||||
|
||||
Note that all DOS-based assemblers should work inside the Linux DOS Emulator,
|
||||
as well as other similar emulators, so that if you already own one,
|
||||
|
@ -1395,7 +1362,7 @@ make it unchallenged as for macroprocessing/metaprogramming.
|
|||
|
||||
<sect2>Linking to GCC
|
||||
<p>
|
||||
That's the preferred way.
|
||||
This is the preferred way if you are developing mixed C-asm project.
|
||||
Check GCC docs and examples from Linux kernel <tt/.S/ files
|
||||
that go through gas (not those that go through as86).
|
||||
|
||||
|
@ -1453,12 +1420,8 @@ More generally, it will do lots of file format conversions.
|
|||
<sect2>Direct Linux syscalls
|
||||
<p>
|
||||
Often you will be told that using libc is the only way,
|
||||
and direct system calls are bad.
|
||||
Believe it, <em/unless/ of course
|
||||
you're specifically writing your own replacement for the libc,
|
||||
adapted to your specific language or memory requirements or whatever.
|
||||
|
||||
But you must know that libc is not sacred, and in <em/most/ cases
|
||||
and direct system calls are bad. This is true. To some extent.
|
||||
So, you must know that libc is not sacred, and in <em/most/ cases
|
||||
libc only does some checks, then calls kernel, and then sets errno.
|
||||
You can easily do this in your program as well (if you need to),
|
||||
and your program will be dozen times smaller, and
|
||||
|
@ -1482,6 +1445,8 @@ Pros:
|
|||
<itemize>
|
||||
<item>smallest possible size; squeezing the last byte out of the system.
|
||||
<item>highest possible speed; squeezing cycles out of your favorite benchmark.
|
||||
<item>full control: you can adapt your program/library
|
||||
to your specific language or memory requirements or whatever
|
||||
<item>no pollution by libc cruft.
|
||||
<item>no pollution by C calling conventions
|
||||
(if you're developing your own language or environment).
|
||||
|
@ -1496,14 +1461,14 @@ Cons:
|
|||
<item>If any other program on your computer uses the libc,
|
||||
then duplicating the libc code will actually
|
||||
waste memory, not save it.
|
||||
<item>Services redundantly implemented in many static binaries
|
||||
are a waste of memory.
|
||||
But you can make your libc replacement a shared library.
|
||||
<item>Size is much better saved by having some kind
|
||||
of bytecode, wordcode, or structure interpreter
|
||||
than by writing everything in assembly.
|
||||
(the interpreter itself could be written either in C or assembly.)
|
||||
<item>Services redundantly implemented in many static binaries
|
||||
are a waste of memory.
|
||||
But you can put your libc replacement in a shared library.
|
||||
<item>The best way to keep multiple binaries small is
|
||||
The best way to keep multiple binaries small is
|
||||
to not have multiple binaries, but instead
|
||||
to have an interpreter process files with <tt/#!/ prefix.
|
||||
This is how OCaml works when used in wordcode mode
|
||||
|
@ -1537,9 +1502,11 @@ Cons:
|
|||
and can be <em/quite/ boring sometimes.
|
||||
Note that some people have already reimplemented "light"
|
||||
replacements for parts of the libc -- check them out!
|
||||
(Rick Hohensee's <url url="ftp://linux01.gwdg.de/pub/cLIeNUX/interim/libsys.tgz" name="libsys">,
|
||||
Christian Fowelin's <ref id="res-projects" name="libASM">,
|
||||
<ref id="res-projects" name="asmutils"> project is working on pure assembly libc)
|
||||
(Redhat's minilibc,
|
||||
Rick Hohensee's <url url="ftp://linux01.gwdg.de/pub/cLIeNUX/interim/libsys.tgz" name="libsys">,
|
||||
Felix von Leitner's <url url="http://www.fefe.de/dietlibc/" name="dietlibc">,
|
||||
Christian Fowelin's <ref id="res" name="libASM">,
|
||||
<ref id="res" name="asmutils"> project is working on pure assembly libc)
|
||||
|
||||
<item>Static libraries prevent your benefitting from libc upgrades
|
||||
as well as from libc add-ons such as the <tt/zlibc/ package,
|
||||
|
@ -1579,7 +1546,7 @@ then here is some advice.
|
|||
(And if you think you can do better,
|
||||
then send feedback to the authors!)
|
||||
<item>As an example of pure assembly code that does everything you want,
|
||||
examine <ref id="res-projects" name="Linux Assembly Projects">.
|
||||
examine <ref id="res" name="Linux Assembly resources">.
|
||||
</itemize>
|
||||
|
||||
Basically, you issue an <tt/int 0x80/,
|
||||
|
@ -1714,10 +1681,10 @@ This HOWTO is not about Windows programming,
|
|||
you can find lots of documents about it everywhere..
|
||||
The thing you should know is that
|
||||
<url url="http://www.cygnus.com" name="Cygnus Solutions">
|
||||
developed the cygwin32.dll library, for GNU programs to run on Win32 platform.
|
||||
Thus, you can use GCC, GAS, all the GNU tools, and many other Unix applications.
|
||||
Take a look on their webpage.
|
||||
|
||||
developed the
|
||||
<url url="http://sourceware.cygnus.com/cygwin/" name="cygwin32.dll library">,
|
||||
for GNU programs to run on Win32 platform; thus, you can use GCC, GAS,
|
||||
all the GNU tools, and many other Unix applications.
|
||||
|
||||
<sect1>Your own OS
|
||||
<p>
|
||||
|
@ -1765,7 +1732,7 @@ it will communicate directly with kernel.
|
|||
I will show the same sample program in two assemblers, <tt/nasm/ and <tt/gas/,
|
||||
thus showing Intel and AT&T syntax.
|
||||
|
||||
You may also want to read <ref id="res-tutorials"
|
||||
You may also want to read <url url="http://linuxassembly.org/intro.html"
|
||||
name="Introduction to UNIX assembly programming"> tutorial,
|
||||
it contains sample code for other UNIX-like OSes.
|
||||
|
||||
|
@ -1775,7 +1742,7 @@ First of all you need assembler (compiler): <tt/nasm/ or <tt/gas/.
|
|||
Second, you need linker: <tt/ld/, assembler produces only object code.
|
||||
Almost all distributions include <tt/gas/ and <tt/ld/, in binutils package.
|
||||
As for <tt/nasm/, you may have to download and install binary packages
|
||||
for Linux and docs from the <ref id="res-related" name="nasm webpage">;
|
||||
for Linux and docs from the <ref id="findnasm" name="nasm webpage">;
|
||||
however, several distributions (Stampede, Debian, SuSe)
|
||||
already include it, check first.
|
||||
<p>
|
||||
|
@ -1858,8 +1825,8 @@ _start:
|
|||
|
||||
<sect1>Producing object code
|
||||
<p>
|
||||
First step of building binary is producing object file from source, by invoking assembler;
|
||||
we must issue the following:
|
||||
First step of building binary is producing object file from source
|
||||
by invoking assembler; we must issue the following:
|
||||
<p>
|
||||
For <tt/nasm/ example:
|
||||
|
||||
|
@ -1874,81 +1841,46 @@ This will produce <tt/hello.o/ object file.
|
|||
|
||||
<sect1>Producing executable
|
||||
<p>
|
||||
Second step is producing executable file itself from object file, by invoking linker:
|
||||
Second step is producing executable file itself from object file
|
||||
by invoking linker:
|
||||
<p>
|
||||
<tt/$ ld -s -o hello hello.o/
|
||||
|
||||
This will finally build <tt/hello/ ELF binary.
|
||||
This will finally build <tt/hello/ executable.
|
||||
<p>
|
||||
Hey, try to run it... Works? That's it. Pretty simple.
|
||||
|
||||
If you get interested and want to proceed further,
|
||||
you may want to look through
|
||||
<ref id="res-projects" name="Linux assembly projects">,
|
||||
they contain PLENTY of source code and examples.
|
||||
|
||||
|
||||
<sect>RESOURCES<label id="res">
|
||||
<p>
|
||||
|
||||
You main resource for Linux/UNIX assembly programming material
|
||||
is <url url="http://linuxassembly.org" name="Linux Assembly"> :).
|
||||
Here are some of resources listed there. This list is cut-down and
|
||||
may be outdated, so please visit the site for detailed up-to-date list.
|
||||
is <bf><url url="http://linuxassembly.org/resources.html"
|
||||
name="Linux Assembly resources page"></bf>
|
||||
Do visit it, and get plenty of pointers to assembly projects,
|
||||
tools, tutorials, documentation, guides, etc,
|
||||
concerning different UNIX operating systems and CPUs.
|
||||
Because it evolves quickly, I will no longer duplicate it in this HOWTO.
|
||||
|
||||
<sect1>Software projects<label id="res-projects">
|
||||
<p>
|
||||
If you are new to assembly in general, here are few starting pointers:
|
||||
|
||||
<label id="res-general">
|
||||
<itemize>
|
||||
<item><url url="http://linuxassembly.org/asmutils.html"
|
||||
name="asmutils"> (miscellaneus utilities, assembly libc)
|
||||
<item><url url="http://www.fowelin.de/christian/computer.linux.assembly.libASM.html"
|
||||
name="libASM"> (assembly library, lots of various routines)
|
||||
<item><url url="http://sax.sax.de/~adlibit/"
|
||||
name="e3"> (cool WordStar-like text editor)
|
||||
<item><url url="http://mars.wiwi.uni-halle.de/ec64/"
|
||||
name="ec64"> (Commodore C64 emulator)
|
||||
<item><url url="http://www.muppetlabs.com/~breadbox/software/elfkickers.html"
|
||||
name="ELF kickers & tiny Linux executables">
|
||||
<item><url url="ftp://www.netstat.ne.jp/pub/Linux/Linux-Alpha-JP/BLAS/"
|
||||
name="Alpha Linux
BLAS"> (basic linear algebra subroutines)
|
||||
<item><url url="http://users.ev1.net/~redelm/"
|
||||
name="cpuburn"> (CPU loading utililties)
|
||||
<item><url url="http://www.lionking.org/~cubbi/serious/asmix.html"
|
||||
name="ASMIX"> (several commandline unix utilities)
|
||||
<item><url url="ftp://ftp.forth.org/pub/Forth/Compilers/native/unix/Linux/linux-eforth-1.0e.tar.gz"
|
||||
name="eforth 1.0e">
|
||||
<item><url url="http://sunsite.unc.edu/pub/Linux/system/misc/"
|
||||
name="smallutils"> (few utils for i386 and Sparc)
|
||||
<item><url url="http://webster.cs.ucr.edu/Page_asm/ArtOfAsm.html"
|
||||
name="The Art Of Assembly">
|
||||
<item><url url="http://www2.dgsys.com/˜raymoon/faq/"
|
||||
name="x86 assembly FAQ">
|
||||
<item><url url="ftp://ftp.luth.se/pub/msdos/"
|
||||
name="ftp.luth.se"> mirrors the hornet and x2ftp
|
||||
former archives of msdos assembly coding stuff
|
||||
<item><url url="http://www.koth.org" name="CoreWars">,
|
||||
a fun way to learn assembly in general
|
||||
<item>Usenet:
|
||||
<url url="news://comp.lang.asm.x86" name="comp.lang.asm.x86">;
|
||||
<url url="news://alt.lang.asm" name="alt.lang.asm">
|
||||
</itemize>
|
||||
|
||||
Note that several projects are not Linux-specific,
|
||||
and run on FreeBSD and other OSes too.
|
||||
|
||||
There are quite a lot of mixed C-assembly projects, like
|
||||
<url url="http://www.kernel.org/" name="Linux kernel">,
|
||||
<url url="http://www.swox.com/gmp/" name="GNU MP Library">,
|
||||
<url url="http://www.gnu.org/glibc/" name="GNU libc">,
|
||||
<url url="http://www.tutok.sk/fastgl/" name="OpenGUI">,
|
||||
<url url="http://www.freeamp.org/" name="FreeAmp">,
|
||||
just to name few.
|
||||
Some of them use <tt/gas/ (sometimes with <tt/m4/), the other use <tt/nasm/.
|
||||
You may want to examine their source code as well for examples
|
||||
of assembly programming on different hardware platforms.
|
||||
|
||||
<sect1>Tutorials<label id="res-tutorials">
|
||||
<p>
|
||||
|
||||
<itemize>
|
||||
<item><url url="http://linuxassembly.org/intro.html"
|
||||
name="Introduction to UNIX Assembly Programming">
|
||||
<item><url url="http://www.cs.pdx.edu/~bjorn/CS200/linux_tutorial/"
|
||||
name="Linux assembly tutorial"> (GAS and GDB related)
|
||||
<item><url url="http://www.muppetlabs.com/~breadbox/software/tiny/teensy.html"
|
||||
name="A Whirlwind Tutorial on Creating Really Teensy ELF Executables for Linux">
|
||||
<item><url url="http://bewoner.dma.be/JanW/"
|
||||
name="Jan's Linux & Assembler HomePage"> (mostly about assembly programming with libc)
|
||||
</itemize>
|
||||
|
||||
<sect1>Mailing list<label id="res-list">
|
||||
<p>
|
||||
|
@ -1966,75 +1898,114 @@ To subscribe send a blank message to <url url="mailto:linux-assembly@egroups.com
|
|||
|
||||
List archives are available at <url url="http://www.egroups.com/list/linux-assembly/">.
|
||||
|
||||
<sect1>Books<label id="res-books">
|
||||
|
||||
<sect1>Frequently asked questions (with asnwers)<label id="faq">
|
||||
<p>
|
||||
Unfortunately there are no ready books I can recommend on the topic.
|
||||
However I'm in the progress of writing a book "Linux Assembly Programming",
|
||||
which /hopefully/ will be published somewhere in 2000-2001.
|
||||
Here are frequently asked questions. Answers are taken
|
||||
from the <ref id="res-list" name="linux-assembly mailing list">.
|
||||
|
||||
<sect1>CPU manuals and assembly programming guides<label id="res-cpu">
|
||||
<sect2>How do I do graphics programming in Linux?
|
||||
<p>
|
||||
An answer from <url url="mailto:paulf@icom.co.za" name="Paul Furber">:
|
||||
|
||||
<itemize>
|
||||
<item>IA32 (x86):
|
||||
<url url="http://sandpile.org" name="sandpile.org">,
|
||||
<url url="http://developer.intel.com" name="Intel">,
|
||||
<url url="http://www.amd.com/support/techdocdir.html" name="AMD">,
|
||||
<url url="http://www.cyrix.com/products/cyrindex.htm" name="Cyrix">,
|
||||
<url url="http://www.xs4all.nl/~feldmann/86bugs.htm" name="x86 bugs">
|
||||
<item>Alpha:
|
||||
<url url="http://www.digital.com/semiconductor/alpha/papers/"
|
||||
name="Digital Alpha papers">,
|
||||
<url url="http://ftp.digital.com/pub/Digital/info/semiconductor/literature/dsc-library.html"
|
||||
name="Digital Documentation Library">,
|
||||
<url url="http://www.unix.digital.com/faqs/publications/base_doc/DOCUMENTATION/V40D_PDF/"
|
||||
name="more manuals">
|
||||
<item>SPARC:
|
||||
<url url="http://www.sparc.com/standards.html"
|
||||
name="SPARC International Standard Documents Repository">
|
||||
<item>MIPS:
|
||||
<url url="http://www.mips.com/publications/"
|
||||
name="MIPS Online Publications Library">
|
||||
<item>PPC:
|
||||
<url url="http://www.lightsoft.co.uk/Fantasm/Beginners/begin1.html"
|
||||
name="Beginners Guide to PowerPC Assembly Language">
|
||||
</itemize>
|
||||
<verb>
|
||||
Ok you have a number of options to graphics in Linux. Which one you use
|
||||
depends on what you want to do. There isn't one Web site with all the
|
||||
information but here are some tips:
|
||||
|
||||
<sect1>Somehow related projects<label id="res-related">
|
||||
SVGALib: This is a C library for console SVGA access.
|
||||
Pros: very easy to learn, good coding examples, not all that different
|
||||
from equivalent gfx libraries for DOS, all the effects you know from DOS
|
||||
can be converted with little difficulty.
|
||||
Cons: programs need superuser rights to run since they write directly to
|
||||
the hardware, doesn't work with all chipsets, can't run under X-Windows.
|
||||
Search for svgalib-1.4.x on http://ftp.is.co.za
|
||||
|
||||
Framebuffer: do it yourself graphics at SVGA res
|
||||
Pros: fast, linear mapped video access, ASM can be used if you want :)
|
||||
Cons: has to be compiled into the kernel, chipset-specific issues, must
|
||||
switch out of X to run, relies on good knowledge of linux system calls
|
||||
and kernel, tough to debug
|
||||
Examples: asmutils (http://www.linuxassembly.org) and the leaves example
|
||||
and my own site for some framebuffer code and tips in asm
|
||||
(http://ma.verick.co.za/linux4k/)
|
||||
|
||||
Xlib: the application and development libraries for XFree86.
|
||||
Pros: Complete control over your X application
|
||||
Cons: Difficult to learn, horrible to work with and requires quite a bit
|
||||
of knowledge as to how X works at the low level.
|
||||
Not recommended but if you're really masochistic go for it. All the
|
||||
include and lib files are probably installed already so you have what
|
||||
you need.
|
||||
|
||||
Low-level APIs: include PTC, SDL, GGI and Clanlib
|
||||
Pros: very flexible, run under X or the console, generally abstract away
|
||||
the video hardware a little so you can draw to a linear surface, lots of
|
||||
good coding examples, can link to other APIs like OpenGL and sound libs,
|
||||
Windows DirectX versions for free
|
||||
Cons: Not as fast as doing it yourself, often in development so versions
|
||||
can (and do) change frequently.
|
||||
Examples: PTC and GGI have excellent demos, SDL is used in sdlQuake,
|
||||
Myth II, Civ CTP and Clanlib has been used for games as well.
|
||||
|
||||
High-level APIs: OpenGL - any others?
|
||||
Pros: clean api, tons of functionality and examples, industry standard
|
||||
so you can learn from SGI demos for example
|
||||
Cons: hardware acceleration is normally a must, some quirks between
|
||||
versions and platforms
|
||||
Examples: loads - check out www.mesa3d.org under the links section.
|
||||
|
||||
To get going try looking at the svgalib examples and also install SDL
|
||||
and get it working. After that, the sky's the limit.
|
||||
</verb>
|
||||
|
||||
<sect2>How do I debug pure assembly code under Linux?
|
||||
<p>
|
||||
An answer from <url url="mailto:dl@gazeta.ru" name="Dmitry Bakhvalov">:
|
||||
|
||||
<itemize>
|
||||
<item><url url="http://www.cryogen.com/Nasm/"
|
||||
name="NASM"> (portable x86 assembler with Intel syntax)
|
||||
<item><url url="http://biew.sourceforge.net"
|
||||
name="BIEW"> (portable console hex viewer/editor with built-in disassembler)
|
||||
<item><url url="http://wildsau.idv.uni-linz.ac.at/mfx/upx.html"
|
||||
name="UPX"> (portable executable packer for several formats)
|
||||
<item><url url="http://hermes.terminal.at/intel2gas/"
|
||||
name="Intel2gas"> (converter between AT&T and Intel assembler syntax)
|
||||
<item><url url="http://www.multimania.com/~placr/"
|
||||
name="A2I"> (converter from AT&T to NASM Intel assembler syntax)
|
||||
<item><url url="http://asmjournal.freeservers.com"
|
||||
name="Assembly Programming Journal"> (has articles on Linux/Unix assembly programming)
|
||||
</itemize>
|
||||
<verb>
|
||||
Personally, I use gdb for debugging asmutils. Try this:
|
||||
|
||||
1) Use the following stuff to compile:
|
||||
$nasm -f elf -g smth.asm
|
||||
$ld -o smth smth.o
|
||||
|
||||
<sect1>General pointers<label id="res-general">
|
||||
2) Fire up gdb:
|
||||
$gdb smth
|
||||
|
||||
3) In gdb:
|
||||
(gdb) disassemble _start
|
||||
Place a breakpoint at <_start+1> (If placed at _start the breakpoint
|
||||
wouldnt work, dunno why)
|
||||
(gdb) b *0x8048075
|
||||
|
||||
To step thru the code I use the following macro:
|
||||
(gdb)define n
|
||||
>ni
|
||||
>printf "eax=%x ebx=%x ...etc...",$eax,$ebx,...etc...
|
||||
>disassemble $pc $pc+15
|
||||
>end
|
||||
|
||||
Then start the program with r command and debug with n.
|
||||
|
||||
Hope this helps.
|
||||
</verb>
|
||||
|
||||
<sect2>Any other useful debugging tools?
|
||||
<p>
|
||||
Definitely <tt/strace/ can help a lot (<tt/ktrace/ and <tt/kdump/ on FreeBSD),
|
||||
it is used to trace system calls and signals. Read <tt/man strace/ for details.
|
||||
|
||||
<itemize>
|
||||
<item><url url="http://webster.cs.ucr.edu/Page_asm/ArtOfAsm.html"
|
||||
name="The Art Of Assembly">
|
||||
<item><url url="http://www2.dgsys.com/˜raymoon/faq/"
|
||||
name="x86 assembly FAQ">
|
||||
<item><url url="ftp://ftp.luth.se/pub/msdos/"
|
||||
name="ftp.luth.se"> mirrors the hornet and x2ftp
|
||||
former archives of msdos assembly coding stuff
|
||||
<item>Fun stuff: <url url="http://www.koth.org"
|
||||
name="CoreWars">, a fun way to learn assembly in general
|
||||
<item>Usenet:
|
||||
<url url="news://comp.lang.asm.x86" name="comp.lang.asm.x86">;
|
||||
<url url="news://alt.lang.asm" name="alt.lang.asm">
|
||||
</itemize>
|
||||
<sect2>How do I access BIOS functions from Linux (BSD, BeOS, etc)?
|
||||
<p>
|
||||
Noway. This is protected mode, use OS services instead.
|
||||
Again, you can't use <tt/int 0x10/, <tt/int 0x13/, etc.
|
||||
Fortunately almost everything can be implemented
|
||||
through system calls or library functions.
|
||||
In the worst case you may go through direct port access,
|
||||
or make a kernel patch to implement needed functionality.
|
||||
|
||||
<em/That's all for now, folks/.
|
||||
|
||||
$Id$
|
||||
|
||||
|
|
Loading…
Reference in New Issue