From 5797fbacd30318a12b6251f0455616e951531817 Mon Sep 17 00:00:00 2001 From: gferg <> Date: Sun, 21 Jan 2001 20:35:02 +0000 Subject: [PATCH] updated --- LDP/howto/docbook/Assembly-HOWTO.sgml | 127 +++++++++++- LDP/howto/linuxdoc/Kernel-HOWTO.sgml | 276 +++++++++++++++++++++----- 2 files changed, 345 insertions(+), 58 deletions(-) diff --git a/LDP/howto/docbook/Assembly-HOWTO.sgml b/LDP/howto/docbook/Assembly-HOWTO.sgml index 62177e5a..9e453e6d 100644 --- a/LDP/howto/docbook/Assembly-HOWTO.sgml +++ b/LDP/howto/docbook/Assembly-HOWTO.sgml @@ -1,6 +1,6 @@ + Introduction"> Do you need assembly?"> @@ -52,7 +52,7 @@ -1999-2000Konstantin Boldyshev +1999-2001Konstantin Boldyshev 1996-1999Francois-Rene Rideau @@ -70,7 +70,7 @@ with no Invariant Sections, with no Front-Cover Texts, and no Back-Cover texts. -This is the Linux Assembly HOWTO. +This is the Linux Assembly HOWTO, version &version;. This document describes how to program in assembly language using free programming tools, focusing on development for or from the Linux Operating System, @@ -1938,7 +1938,7 @@ only 5 parameters in registers. Linux Kernel Internals, and especially - + How System Calls Are Implemented on i386 Architecture? chapter will give you more robust overview. @@ -2574,7 +2574,9 @@ It is already functional and should be the right choice, check it out! You can also try gdb ;). Although it is source-level debugger, it can be used to debug pure assembly code, and with some trickery you can make -gdb to do what you need. +gdb to do what you need +(unfortunately, nasm '-g' switch does not generate +proper debug info for gdb; this is nasm bug, I think). Here's an answer from Dmitry Bakhvalov: @@ -2738,6 +2740,114 @@ Now you can play with it using insmod/rmmod/lsmod + + + +How do I allocate memory dynamically? + + + + +An answer from H-Peter Recktenwald: + + + + ebx := 0 (in fact, any value below .bss seems to do) + sys_brk + eax := current top (of .bss section) + + ebx := [ current top < ebx < (esp - 16K) ] + sys_brk + eax := new top of .bss + + + + + + +I can't understand how to use select system call! + + + + +An answer from Patrick Mochel: + + + +When you call sys_open, you get back a file descriptor, which is simply an +index into a table of all the open file descriptors that your process has. +stdin, stdout, and stderr are always 0, 1, and 2, respectively, because +that is the order in which they are always open for your process from there. +Also, notice that the first file descriptor that you open yourself (w/o first +closing any of those magic three descriptors) is always 3, and they increment +from there. + +Understanding the index scheme will explain what select does. When you +call select, you are saying that you are waiting certain file descriptors +to read from, certain ones to write from, and certain ones to watch from +exceptions from. Your process can have up to 1024 file descriptors open, +so an fd_set is just a bit mask describing which file descriptors are valid +for each operation. Make sense? + +Since each fd that you have open is just an index, and it only needs to be +on or off for each fd_set, you need only 1024 bits for an fd_set structure. +1024 / 32 = 32 longs needed to represent the structure. + +Now, for the loose example. +Suppose you want to read from a file descriptor (w/o timeout). + +- Allocate the equivalent to an fd_set. + +.data + +my_fds: times 32 dd 0 + +- open the file descriptor that you want to read from. + +- set that bit in the fd_set structure. + + First, you need to figure out which of the 32 dwords the bit is in. + + Then, use bts to set the bit in that dword. bts will do a modulo 32 + when setting the bit. That's why you need to first figure out which + dword to start with. + + mov edx, 0 + mov ebx, 32 + div ebx + + lea ebx, my_fds + bts ebx[eax * 4], edx + +- repeat the last step for any file descriptors you want to read from. + +- repeat the entire exercise for either of the other two fd_sets if you want action from them. + +That leaves two other parts of the equation - the n paramter and the timeout +parameter. I'll leave the timeout parameter as an exercise for the reader +(yes, I'm lazy), but I'll briefly talk about the n parameter. + +It is the value of the largest file descriptor you are selecting from (from +any of the fd_sets), plus one. Why plus one? Well, because it's easy to +determine a mask from that value. Suppose that there is data available on +x file descriptors, but the highest one you care about is (n - 1). Since +an fd_set is just a bitmask, the kernel needs some efficient way for +determining whether to return or not from select. So, it masks off the bits +that you care about, checks if anything is available from the bits that are +still set, and returns if there is (pause as I rummage through kernel source). +Well, it's not as easy as I fantasized it would be. To see how the kernel +determines that mask, look in fs/select.c in the kernel source tree. + +Anyway, you need to know that number, and the easiest way to do it is to save +the value of the last file descriptor open somewhere so you don't lose it. + +Ok, that's what I know. A warning about the code above (as always) is that +it is not tested. I think it should work, but if it doesn't let me know. +But, if it starts a global nuclear meltdown, don't call me. ;-) + + + + @@ -2761,6 +2871,13 @@ that need not to be repeatedly mentioned every time. + +0.6b21 Jan 2001konst + +new questions in FAQ, corrected few URLs + + + 0.6a10 Dec 2000konst diff --git a/LDP/howto/linuxdoc/Kernel-HOWTO.sgml b/LDP/howto/linuxdoc/Kernel-HOWTO.sgml index ba55bbbc..4a77797f 100644 --- a/LDP/howto/linuxdoc/Kernel-HOWTO.sgml +++ b/LDP/howto/linuxdoc/Kernel-HOWTO.sgml @@ -6,7 +6,7 @@ The Linux Kernel HOWTO <author>Brian Ward, <tt>bri@cs.uchicago.edu</tt> -<date>v3.0, 16 Jan 2001 +<date>v2.1, 21 Jan 2001 <abstract> This is a detailed guide to kernel configuration, compilation, upgrades, @@ -94,98 +94,119 @@ This section is written by name="Al Dev"> The latest version of this section is at <url url="http://www.aldev.8m.com"> and click on -"Quick Steps to recompile linux kernel". Mirror site is at <url url="http://aldev.webjump.com">. +"Quick Steps to recompile linux kernel". Mirror sites are at - +<url url="http://aldev.webjump.com">, +<url name="angelfire" url="http://www.angelfire.com/nv/aldev">, +<url name="geocities" url="http://www.geocities.com/alavoor/index.html">, +<url name="virtualave" url="http://aldev.virtualave.net">, +<url name="bizland" url="http://aldev.bizland.com">, +<url name="theglobe" url="http://members.theglobe.com/aldev/index.html">, +<url name="spree" url="http://members.spree.com/technology/aldev">, +<url name="infoseek" url="http://homepages.infoseek.com/~aldev1/index.html">, +<url name="bcity" url="http://www3.bcity.com/aldev">, +<url name="50megs" url="http://aldev.50megs.com">. +These sites have <bf>lots of linux goodies</bf> and tips. A copy of the above web-site is reproduced here - Kernel re-compile is required in order to make the kernel very lean and which will result in FASTER operating system . It is also required to support any new devices. +<bf>Note: </bf> Below 'bash#' denotes the bash prompt, you should type +the commands that appear after the 'bash#' prompt. <enum> <item> Login in as 'root' throughout all these steps. Mount Redhat linux cdrom and install the linux kernel source rpm <code> -cd /mnt/cdrom/RedHat/RPMS -rpm -i kernel-headers*.rpm -rpm -i kernel-sources*.rpm -rpm -i bin86*.rpm +bash$ su - root +bash# cd /mnt/cdrom/RedHat/RPMS +bash# rpm -i kernel-headers*.rpm +bash# rpm -i kernel-sources*.rpm +bash# rpm -i dev86*.rpm +bash# rpm -i bin86*.rpm </code> -(The bin86*.rpm is required only for OLDER Linux systems like redhat 5.x. -Install the Intel assembler 'as86' command. Get from -<url url="http://rpmfind.net/linux/RPM/mandrake/7.1/Mandrake/RPMS/bin86-0.4-12mdk.i586.html">) -or at <url url="http://rpmfind.net/linux/RPM/kondara/jirai/i586/bin86-0.4-8k.i586.html"> +(The bin86*.rpm and 'as86' is required only for <bf>OLDER Linux</bf> systems like redhat 5.x. +Get Intel assembler 'as86' command from +dev86*.rpm on cdrom or from +<url url="http://rpmfind.net/linux/RPM/mandrake/7.1/Mandrake/RPMS/bin86-0.4-12mdk.i586.html"> +, <url url="http://rpmfind.net/linux/RPM/kondara/jirai/i586/bin86-0.4-8k.i586.html"> +). <p> <item> Start X-windows with 'startx'. <code> -cd /usr/src/linux -make xconfig +bash# man startx +bash# startx +bash# cd /usr/src/linux +bash# make xconfig </code> -The <bf>"make xconfig"</bf> brings up a user friendly GUI interface! DO NOT +The <bf>"make xconfig"</bf> brings up a user friendly GUI interface! <bf>DO NOT</bf> use 'make config' which is a command-line option ( -use this only if you CANNOT bring up X-window). You load +use this only if you <bf>CANNOT</bf> bring up X-window). You load the configuration file from <it>/usr/src/linux/arch/i386/config.in </it> <p> -<item> Enable the Loadable kernel modules support! See these man pages -<code> -man lsmod -man insmod -man rmmod -man depmod -</code> +<item> Enable the Loadable kernel modules support! With this option you can load/unload the device drivers dynamically on running linux system on the fly. +See these man pages +<code> +bash# man lsmod +bash# man insmod +bash# man rmmod +bash# man depmod +</code> <p> <item> Save and Exit "make xconfig". And now, do - <code> -make dep -make clean +bash# make dep +bash# make clean </code> <p> <item> Read the following file (to gain some knowledge about kernel building...) - <code> -man less -less /usr/src/linux/arch/i386/config.in -</code> +bash# man less +bash# less /usr/src/linux/arch/i386/config.in Type 'h' for help and to navigate press i, j, k, l, h or arrow, page up/down keys. +</code> <p> <item> Now, give the make command - <code> - cd /usr/src/linux - man nohup - nohup make bzImage & - tail nohup.out (.... to monitor the progress) + bash# cd /usr/src/linux + bash# man nohup + bash# nohup make bzImage & + bash# tail nohup.out (.... to monitor the progress) This will put the kernel in /usr/src/linux/arch/i386/boot/bzImage - man tail + bash# man tail </code> <p> -<item> After bzImage is successful, copy the kernel image to /boot directory - +<item> After bzImage is successful, copy the kernel image to /boot directory. +You must copy the new kernel image to /boot directory, otherwise the +new kernel <bf>may not</bf> boot. +And then read the manual page on lilo +(see also <url url="http://www.linuxdoc.org/HOWTO/LILO-crash-rescue-HOWTO.html">) - <code> -cp /usr/src/linux/arch/i386/boot/bzImage /boot/bzImage.myker -</code> -You must copy the new kernel image to /boot directory, otherwise the new kernel may not boot. And then read the manual page on lilo - -<code> -man lilo -man lilo.conf +bash# cp /usr/src/linux/arch/i386/boot/bzImage /boot/bzImage.myker +bash# man lilo +bash# man lilo.conf And edit /etc/lilo.conf file and put these lines - image=/boot/bzImage.myker label=myker root=/dev/hda1 read-only You can check device name for 'root=' with the command - - df /boot + bash# df /boot </code> <p> <item> Now give <code> -lilo ; -lilo -q ; +bash# lilo +bash# lilo -q </code> You must re-run lilo even if entry 'myker' exists, everytime you create a new bzImage. <p> @@ -193,32 +214,36 @@ You must re-run lilo even if entry 'myker' exists, everytime you create a new bz <item> Reboot the machine and at lilo press tab key and type 'myker' If it boots then you did a good job! Otherwise at lilo select your old kernel, boot and re-try all over again. Your old kernel -is still intact at say <it>/boot/vmlinuz-2.0.34-0.6</it> +<bf>is still INTACT and SAFE</bf> at say <it>/boot/vmlinuz-2.0.34-0.6</it> <p> <item> Loadable Modules: Boot new kernel and install the loadable modules from RedHat Linux cdrom <code> -rpm -i /mnt/cdrom/contrib/kernel-modules*.rpm ....(For old linux systems which do not have -insmod pre-installed) -man insmod -insmod +bash# rpm -i /mnt/cdrom/contrib/kernel-modules*.rpm +....(For old linux systems which do not have insmod pre-installed) +bash# man insmod +bash# insmod </code> <p> <item> If your linux is already had loadable module enabled, then check -for files in /lib/modules. The step given below may not be +for files in /lib/modules. The step given below <bf>may not</bf> be needed. Build modules by installing kernel-source*.rpm and kernel-headers*.rpm. <code> -cd /usr/src/linux -make modules -make install_modules +bash# cd /usr/src/linux +bash# make modules +bash# make install_modules </code> <p> -<item> Since the new kernel 'myker' boots, you can create the boot disk. Insert a blank floppy into floppy drive and - +<item> If your new kernel 'myker' boots and works properly, you can create the +boot disk. Insert a blank floppy into floppy drive and - <code> -cd /usr/src/linux -make bzdisk +bash# cd /usr/src/linux +bash# make bzdisk +See also mkbootdisk - +bash# rpm -i mkbootdisk*.rpm +bash# man mkbootdisk </code> </enum> <!-- @@ -1426,5 +1451,150 @@ redistribution, in the interest of keeping things up-to-date (you could send me a copy of the thing you're making while you're at it). Translators are also advised to contact the author before translating. The printed version looks nicer. Recycle.<p> +<!-- + ******************************************* + ************ End of Section *************** + ******************************************* + + + +<chapt change> Other Formats of this Document +--> +<sect> Other Formats of this Document +<p> +This section is written by + <htmlurl url="mailto:alavoor@yahoo.com" + name="Al Dev"> +(at site <url url="http://www.aldev.8m.com"> +mirrors at +<url url="http://aldev.webjump.com">, +<url name="angelfire" url="http://www.angelfire.com/nv/aldev">, +<url name="geocities" url="http://www.geocities.com/alavoor/index.html">, +<url name="virtualave" url="http://aldev.virtualave.net">, +<url name="bizland" url="http://aldev.bizland.com">, +<url name="theglobe" url="http://members.theglobe.com/aldev/index.html">, +<url name="spree" url="http://members.spree.com/technology/aldev">, +<url name="infoseek" url="http://homepages.infoseek.com/~aldev1/index.html">, +<url name="bcity" url="http://www3.bcity.com/aldev">, +<url name="50megs" url="http://aldev.50megs.com">) + +This document is published in 12 different formats namely - DVI, Postscript, +Latex, Adobe Acrobat PDF, +LyX, GNU-info, HTML, RTF(Rich Text Format), Plain-text, Unix man pages, +single HTML file and SGML. +<itemize> +<item> +You can get this HOWTO document as a single file tar ball in HTML, DVI, +Postscript or SGML formats from - +<url url="ftp://sunsite.unc.edu/pub/Linux/docs/HOWTO/other-formats/"> +and <url url="http://www.linuxdoc.org/docs.html#howto"> + +<item>Plain text format is in: +<url url="ftp://sunsite.unc.edu/pub/Linux/docs/HOWTO"> +and <url url="http://www.linuxdoc.org/docs.html#howto"> +<item>Single HTML file format is in: +<url url="http://www.linuxdoc.org/docs.html#howto"> + +<item>Translations to other languages like French, German, Spanish, +Chinese, Japanese are in +<url url="ftp://sunsite.unc.edu/pub/Linux/docs/HOWTO"> +and <url url="http://www.linuxdoc.org/docs.html#howto"> +Any help from you to translate to other languages is welcome. +</itemize> +The document is written using a tool called "SGML-Tools" which can be got from - +<url url="http://www.sgmltools.org"> +Compiling the source you will get the following commands like +<itemize> +<item>sgml2html Kernel-HOWTO.sgml (to generate html file) +<item>sgml2rtf Kernel-HOWTO.sgml (to generate RTF file) +<item>sgml2latex Kernel-HOWTO.sgml (to generate latex file) +</itemize> + +LaTeX documents may be converted into PDF files simply by +producing a Postscript output using <bf>sgml2latex</bf> ( and dvips) and running the +output through the Acrobat <bf>distill</bf> (<url url="http://www.adobe.com">) command as follows: +<code> +bash$ man sgml2latex +bash$ sgml2latex filename.sgml +bash$ man dvips +bash$ dvips -o filename.ps filename.dvi +bash$ distill filename.ps +bash$ man ghostscript +bash$ man ps2pdf +bash$ ps2pdf input.ps output.pdf +bash$ acroread output.pdf & +</code> +Or you can use Ghostscript command <bf>ps2pdf</bf>. +ps2pdf is a work-alike for nearly all the functionality of +Adobe's Acrobat Distiller product: it +converts PostScript files to Portable Document Format (PDF) files. +<bf>ps2pdf</bf> is implemented as a very small command script (batch file) that invokes Ghostscript, selecting a special "output device" +called <bf>pdfwrite</bf>. In order to use ps2pdf, the pdfwrite device must be included in the makefile when Ghostscript was compiled; +see the documentation on building Ghostscript for details. + +This howto document is located at - +<itemize> +<item> <url url="http://sunsite.unc.edu/LDP/HOWTO/Kernel-HOWTO.html"> +</itemize> + +Also you can find this document at the following mirrors sites - +<itemize> +<item> <url url="http://www.caldera.com/LDP/HOWTO/Kernel-HOWTO.html"> +<item> <url url="http://www.WGS.com/LDP/HOWTO/Kernel-HOWTO.html"> +<item> <url url="http://www.cc.gatech.edu/linux/LDP/HOWTO/Kernel-HOWTO.html"> +<item> <url url="http://www.redhat.com/linux-info/ldp/HOWTO/Kernel-HOWTO.html"> + +<item> Other mirror sites near you (network-address-wise) can be found at +<url url="http://sunsite.unc.edu/LDP/hmirrors.html"> +select a site and go to directory /LDP/HOWTO/Kernel-HOWTO.html +</itemize> + + +In order to view the document in dvi format, use the xdvi program. The xdvi +program is located in tetex-xdvi*.rpm package in Redhat Linux which can be +located through ControlPanel | Applications | Publishing | TeX menu buttons. + To read dvi document give the command - +<tscreen><verb> + xdvi -geometry 80x90 howto.dvi + man xdvi +</verb></tscreen> + And resize the window with mouse. + To navigate use Arrow keys, Page Up, Page Down keys, also + you can use 'f', 'd', 'u', 'c', 'l', 'r', 'p', 'n' letter + keys to move up, down, center, next page, previous page etc. + To turn off expert menu press 'x'. + +You can read postscript file using the program 'gv' (ghostview) or +'ghostscript'. +The ghostscript program is in ghostscript*.rpm package and gv +program is in gv*.rpm package in Redhat Linux +which can be located through ControlPanel | Applications | Graphics menu +buttons. The gv program is much more user friendly than ghostscript. +Also ghostscript and gv are available on other platforms like OS/2, +Windows 95 and NT, you view this document even on those platforms. + +<itemize> +<item>Get ghostscript for Windows 95, OS/2, and for all OSes from <url url="http://www.cs.wisc.edu/~ghost"> +</itemize> + +To read postscript document give the command - +<tscreen><verb> + gv howto.ps + ghostscript howto.ps +</verb></tscreen> + +You can read HTML format document using Netscape Navigator, Microsoft Internet +explorer, Redhat Baron Web browser or any of the 10 other web browsers. + +You can read the latex, LyX output using LyX a X-Windows front end to latex. +<!-- +******************************************* +************ End of Section *************** +******************************************* + + + + +--> </article>