《Linux内核完全注释》《完全剖析》 » 阅读本书所需的基础

转贴网址:http://www.oldlinux.org/oldlinux/viewthread.php?tid=2551&extra=page%3D1

[这个贴子最后由redgrid在 2006/08/09 00:45pm 第 17 次编辑]Linux 0.11虽然不是什么“珠穆朗玛峰”,但它肯定还是“华山”或“泰山”。虽然有路但你还是需要最基本的努力和花费一定的代价才能“攀登”上去。1. PC兼容机硬件工作原理(比如8259A,8253, 8042,UART等硬件);2. Intel 32位 运行模式工作原理,寻址方式;3. 传统C语言;4. 一些Intel asm基础。5. 会使用Linux操作系统,懂得Linux系统的基本操作。推荐参考书籍:============《UNIX操作系统设计》http://www.china-pub.com/computers/common/info.asp?id=34*《UNIX环境高级编程》http://www.china-pub.com/computers/common/info.asp?id=30《操作系统:设计与实现》(MINIX)http://www.china-pub.com/computers/common/info.asp?id=2033《IBM PC 汇编语言程序设计》http://www.china-pub.com/computers/common/info.asp?id=7721*《深入理解计算机系统》http://www.china-pub.com/computers/common/info.asp?id=18133《Linux权威指南》http://www.china-pub.com/computers/common/info.asp?id=1174《Linux Assembly Language Programming》ftp://plinux.org/pub/linux/docs/ … age_Programming.pdf*《Intel 80386 Programmer’;s Reference Manual》ftp://plinux.org/pub/linux/docs/Intel_80386_Manual.pdf*《The C Programming Language》ftp://plinux.org/pub/linux/docs/The_C_programming_Language.rar加星号“*”者为重点推荐读物!============================================如果有些忘了,就请先花哪怕一天时间将这些基础知识先浏览一遍,在看本书。硬件方面可参考教科书。Intel 32 mode 可见Intel 386 manual;内核代码中用到的汇编程序(as86和AT&T语法)可参照以下一些文档。————————————————————-MINIX 汇编手册:http://www.oldlinux.org/oldlinux/viewthread.php?tid=291NASM 汇编手册:http://www.oldlinux.org/oldlinux/viewthread.php?tid=877as86 在线手册:http://www.oldlinux.org/oldlinux/viewthread.php?tid=1895ld86 在线手册:http://www.oldlinux.org/oldlinux/viewthread.php?tid=1428/*****************************************//* 本站资源: *//*http://oldlinux.org/Linux.old/ *//*****************************************/===============================================如果你具有大学计算机本科或以上学历,那么你可以在适当复习以上知识后就能顺利看懂本书。如果你是在读本科计算机系的学生,那么在学习过操作系统课程或者正在学习时,只要复习一些有关Intel PC机组成原理,就应该很顺利地理解本书,并能很好地帮助你理解操作系统的基本原理。如果你是其它专业在读本科学生,那么你可以首先自学一些有关操作系统的理论知识和计算机微机原理课程(如果没有学过的话),了解一些操作系统的基本术语,再继续学习本书。如果你是一个专科学生,那么你首先需要准备的知识与一个非计算机本科生所要做的一样。如果你是一个中学毕业的学生,那么你可以先自学一些《计算机原理》、《微机原理》、《C语言》、《英语》等基本课程,然后再继续阅读本书。当然也可以把摊子铺开,同时阅读:)注意: 无论你现在的学位或学历怎样,这都不是主要问题。关键在于努力和刻苦。而兴趣是学习的最好动力之一。即使你没有任何学位,只要识字能上网,那么你面前的道路还是宽广的。“世上无难事,只要肯登攀”。———————————————————————————————源代码浏览工具介绍http://www.oldlinux.org/oldlinux/viewthread.php?tid=1470============================  在本机上阅读源代码,可以使用redhat 的snavigator或Source Dynamics的Source Insight软件。snavigator是免费的,source Insight可以去www.sourceInsight.com去下载。或者在此处下载:http://oldlinux.org/download/tools/si350.rar(3.2MB)http://oldlinux.org/download/tools/Release-SN51E-win32.zip(7.8MB)http://oldlinux.org/download/tools/src2html/Source Insight的使用方法可参见文章:http://www-900.ibm.com/developer … t/tip17/index.shtml  也可以使用本站网页上提供的再线交叉引用阅读程序:http://oldlinux.org/lxr/http/source/在阅读本书时,最好在计算机中安装这两个软件之一,边阅读书中注释边浏览代码。————————————————————————————————lxr设置方法介绍(1)======================How to make your own Cross ReferenceBy qhshang at 163.comIt is a long long time to gen xref for it, a not so long time to glimpse-index it.If you are lucky enough to make lxr.conf done like it on this host in half an hour, do NOT drop me a mail:-)—————————————-Install lxrModify Makefile to customize the PERLBIN and INSTALLPREFIX, to indicate the perl program and where you install lxr.then$ make installTo generate your reference for files in Your_dir:$ genxref Your_dirwhile genxref is in lxr/binIn my practice using genxref, locale should be set to C, en_US.utf-8 is not ok.I don’;t know why, because I don’;t read the perl script throughly.—————————————-Install glimpse:First makeglimpse, then cp bin/{glimpse,glimpseindex} to /bin or /usr/binGenerate index using glimpse:$ glimpseindex -H . Your_dirhere -H means where to put the generated index files.Test your index:$ glimpse Your_string—————————————-Web server configurationTo make lxr viewable in web pages, add lines for xrefs in apache conf 文件:<Directory /Your_path_to_lxr>Options AllAllowOverride Allorder allow,denyallow from all</Directory>To make sure perl script can be executed:make a file .htaccess inyour lxr perl script dir:Options Indexes<Files ~ (search|source|ident|diff|find)$> SetHandler cgi-script Options ExecCGI</Files>NOTE: some said only one line is OK: SetHandler cgi-scriptI don’;t know if it works.—————————————-Make your files browsable from browsers:First you should make sure the lxr dir can be accessed via web server.then$ chmod 755 xref fileidx$ chmod 755 .glimpse_*$ chmod 755 Your_Dir_To_WWWROOT -R$ chmod 755 Your_Dir_To_LXR -R—————————————-Configuration 文件: xrefs.confMy file is only for example use.Your can modify your conf file according to your own condition.# Define typed variable “v”, read valueset from file.variable: v, Version, [/Your_web_server_root/xrefs/src/versions], [/Your_web_server_root/xrefs/src/defversion]# here variable v is for Version, read from file, and defversion is for# default version, which will be shown to you by default.# Define typed variable “a”.First value is default.variable: a, Architecture, [/Your_web_server_root/xrefs/src/archs]# and a is for Arch, the first one will be shown by default.# Define the base url for the LXR files.baseurl: http://Your_web_server_root/xrefs/# this url variable can be refered in template-head# These are the templates for the HTML heading, directory listing and# footer, respectively.htmlhead: /Your_web_server_root/xrefs/template-headhtmltail: /Your_web_server_root/xrefs/template-tailhtmldir:/Your_web_server_root/xrefs/template-dir# The source is here.sourceroot: /Your_web_server_root/xrefs/src/linux-$v/linuxsrcrootname: Linux-$v# because I have more then one Linux kernel version, so I put them like the# above for clear reference# I make a linux subdir to hold the original kernel source here# “#include <foo.h>” is mapped to this directory (in the LXR source# tree)incprefix: /usr/include# I don’;t know what is this mean, who can tell qhshang?# The database files go here.dbdir: /Your_web_server_root/xrefs/src/linux-$v# here is where you put the fileidx and xref file db.# the location can be various according to your operation.# Glimpse can be found here.glimpsebin: /usr/local/bin/glimpse# for freetext search# The power of regexps.This is pretty Linux-specific, but quite# useful.Tinker with it and see what it does.(How’;s that for# documentation?)map: /include/asm[^//]*/ /include/asm-$a/map: /arch/[^//]+/ /arch/$a/—————————————-To provide the cross reference with Green-colored comments for C/C++,there is a patch for lxr.(I am sorry that I forgot the url of this patch.)It should be put to lxr/lib/LXR.— Common.pmWed Mar7 15:34:24 2001+++ Common.pmSat Jan 27 12:42:41 2001@@ -18,8 +18,8 @@@cterm = (‘;atom’;,’;////.’;,’;’;,-‘;comment’;,’;//*’;,’;/*/’;,-‘;comment’;,’;//’;,”/n”,+’;comment1′;,’;//’;,”/n”,+’;comment2′;,’;//*’;,’;/*/’;,’;string’;,’;”‘;,’;”‘;,’;string’;,”‘;”,”‘;”,’;include’;,’;#include’;,”/n”);@@ -179,12 +179,17 @@while (defined($frag)) { &markspecials($frag);- if ($btype eq ‘;comment’;) {-# Comment+ if ($btype eq ‘;comment1’;) {+# C++-style comment ‘;//’;# Convert mail adresses to mailto:&freetextmarkup($frag);-$frag = “<b><i>$frag</i></b>”;-$frag =~ s#/n#</i></b>/n<b><i>#g;+$frag = “<font color=/”#00AA00/”><i>$frag”;+$frag =~ s#/n#</i></font>/n#g;+ } elsif ($btype eq ‘;comment2’;) {+# C-style comment ‘;/* … */’;+&freetextmarkup($frag);+$frag = “<font color=/”#00AA00/”><i>$frag</i></font>”;+$frag =~ s#/n#</i></font>/n<font color=/”/#00AA00/”><i>#g; } elsif ($btype eq ‘;string’;) {# String$frag = “<i>$frag</i>”;—————————————-Some misc questions:开始lxr作perl查询的时候出错,有时侯能工作,但是有警告: /** Warning: Use of uninitialized value in subroutine entry at /usr/lib/perl5/5.8.0/i386-linux-thread-multi/DB_File.pm line 259./于是找到这个文件中的相应行,不知是错什么了:DoTie_($tieHASH, @arg) ;觉得是mod_perl问题。下载一个mod_perl-1.99_10,照别人曾经写的作:解压到/root:$ perl Makefile.PL EVERYTHING=1 APACHE_SRC=../httpd.x.x.x /srcUSE_APACI=1 PREP_HTTPD=1 DO_HTTPD=1结果是:[root@secteam mod_perl-1.99_10]# perl Makefile.PL EVERYTHING=1APACHE_SRC=../httpd-2.0.47/ USE_APACI=1 PREP_HTTPD=1 DO_HTTPD=1Reading Makefile.PL args from @ARGV!!! Unable to determine server version, aborting.!!! Please specify MP_APXS or MP_AP_PREFIX.不行,我猜测是版本不同导致的问题于是按照mod_perl 的INSTALL 文件作:% perl Makefile.PL MP_APXS=/usr/local/apache2/bin/apxsmake没有问题,make test 有很多错:/usr/bin/perl -Iblib/arch -Iblib/lib /t/TEST -clean*** setting ulimit to allow core filesulimit -c unlimited; t/TEST -cleanAPACHE_USER= APACHE_GROUP= APACHE_PORT= APACHE= APXS= //usr/bin/perl -Iblib/arch -Iblib/lib /t/TEST -verbose=0*** setting ulimit to allow core filesulimit -c unlimited; t/TEST -verbose=0*** root mode: changing the files ownership to ‘;nobody’; (99:99)*** sudo -u ‘;#99’; /usr/bin/perl -e ‘;print -r “/root/mod_perl-1.99_10/t”&& -w _ && -x _ ? “OK” : “NOK”‘;*** result: NOK!!! You are running the test suite under user ‘;root’;.Apache cannot spawn child processes as ‘;root’;, thereforewe attempt to run the test suite with user ‘;nobody’; (99:99).The problem is that the path:/root/mod_perl-1.99_10/tmust be ‘;rwx’; by user ‘;nobody’;, so Apache can read and write under thatpath.There several ways to resolve this issue. For example move’;/root/mod_perl-1.99_10/t’; to ‘;/tmp/’; and repeat the ‘;make test’; phase.You can test whether the location is good by running the following test:% sudo -u ‘;#99’; /usr/bin/perl -e ‘;print -r “/root/mod_perl-1.99_10/t” &&-w _ && -x _ ? “OK” : “NOK”‘;make: *** [run_tests] Error 29原来是解tar gz包到root路径的原因,先不理会,make install也可以安装,重启apache,查询警告依旧。于是重新解到tmp下,% perl Makefile.PL MP_APXS=/usr/local/apache2/bin/apxs% make && make test还是同样的错,突然看到错误中还有: /root/mod_perl-1.99_10/t,可是我已经解到/tmp下作的呀,很不解,(:-)没有深究)只有删掉/root下的,重新解到/tmp,make test的时候巨多的OK。。。然后就一路顺风成功install。于是启动apache:[root@secteam apache2]# ./bin/apachectl startSyntax error on line 235 of /usr/local/apache2/conf/httpd.conf:Invalid command ‘;AddModule’;, perhaps mis-spelled or defined by a modulenot included in the server configuration现在注释掉下面的[root@secteam apache2]# vi /usr/local/apache2/conf/httpd.conf#AddModule mod_perl.c启动[root@secteam apache2]# ./bin/apachectl start[Thu Oct 09 10:00:34 2003] [error] Can’;t locate Apache.pm in @INC (@INCcontains: /usr/lib/perl5/5.8.0/i386-linux-thread-multi/usr/lib/perl5/5.8.0/usr/lib/perl5/site_perl/5.8.0/i386-linux-thread-multi/usr/lib/perl5/site_perl/5.8.0 /usr/lib/perl5/site_perl/5.6.1/usr/lib/perl5/site_perl/usr/lib/perl5/vendor_perl/5.8.0/i386-linux-thread-multi/usr/lib/perl5/vendor_perl/5.8.0 /usr/lib/perl5/vendor_perl ./usr/local/apache2/ /usr/local/apache2/lib/perl) at (eval 1) line 3.[Thu Oct 09 10:00:34 2003] [error] Can’;t load Perl module Apache forserver 192.9.200.102:80, exiting…奇怪,怎么没有Apache.pm呢,locate Apache.pm出来好几个,因为不知道哪里修改@INC,所以我找到一个Apache.pm拷贝到@INC中的一个位置。启动[root@secteam apache2]# ./bin/apachectl start,可以,但是查询的时候警告仍然如初这样认为是pm问题,需要perl5.8.1,于是make,make install启动apachectl,发现libperl.so找不到,连vim都不能用了:vim: error while loading shared libraries: libperl.so: cannot openshared object 文件: No such file or directory于是从别的地方找了一个拷贝到/usr/lib,可以了。然后去掉perl5.8.0的内容,这次启动apache,发现又有很多pm找不到,觉的是mod_perl的配置决定了perl相关程序的位置。于是重新把mod_perl make,make install,此时执行lxr发现错误:The server encountered an internal error or misconfiguration and wasunable to complete your request.分析了一下,觉的是perl的路径问题,修改lxr的以下文件的perl路径:diff,find,ident,search,source,OK(或者把perl链接到/usr/bin因为大多perl脚本都是)这样lxr的标识符索引也没有警告了,但是freetext搜索还不可以,认为是glimpse的问题。(freetext有glimpse支持)然后把glimpse的属性搞定,freetext搜索就好了现在默认是Linux-2.5.72-lsm1/其他问题apachectl的问题:我是ssh到server上的,执行/usr/local/apache2/bin/apachectl restart每次都使得我的ssh链接关闭,不得其解,到server本机终端执行/usr/local/apache2/bin/apachectl restart每次都退出一层shell,奇怪。(没有仔细读apachectl script)只好到apache 所在路径下执行。各位可否给点指点? 而且apachectl不给出成功与否,[root@secteam apache2]# ./bin/apachectl stophttpd (pid 20453?) not running————————————————————————————————Lxr设置方法介绍(2)==========================0. 假设你把lxr安装在你的web主目录中(也即,例如,http://oldlinux.org/lxr/),那么:1. web目录下建立文件“.htaccess”,其内容如下:—————–开始(不包括本行)# Web Access script permission<Files ~ (search|ident|diff|find|source|ident1)$>SetHandler cgi-script</Files>——————结束2. 编辑配置文件: lxr/http/lxr.conf 例如oldlinux.org的配置文件内容为:——————–开始# Configuration file.# Define typed variable “v”, read valueset from file.variable: v, 版本, [/var/www/oldlinux.org/lxr/source/versions], [/var/www/oldlinux.org/lxr/source/defversion]# Define typed variable “a”.First value is default.variable: a, 体系结构, (i386)# Define the base url for the LXR files.baseurl:http://oldlinux.org/lxr/http/# These are the templates for the HTML heading, directory listing and# footer, respectively.htmlhead: /var/www/oldlinux.org/lxr/http/template-headhtmltail: /var/www/oldlinux.org/lxr/http/template-tailhtmldir:/var/www/oldlinux.org/lxr/http/template-dir# The source is here.sourceroot: /var/www/oldlinux.org/lxr/source/$v/linux/srcrootname: Linux# “#include <foo.h>” is mapped to this directory (in the LXR source# tree)incprefix: /include# The database files go here.dbdir: /var/www/oldlinux.org/lxr/source/$v# Glimpse can be found here.glimpsebin: /usr/local/bin/glimpse# The power of regexps.This is pretty Linux-specific, but quite# useful.Tinker with it and see what it does.(How’;s that for# documentation?)map: /include/asm[^//]*/ /include/asm-$a/map: /arch/[^//]+/ /arch/$a/—————————-结束。3. 建立源文件内容。对每一个想要浏览的内核版本,按以下步骤进行(若要使用第5,6选项步骤,你要首先安装glimpse软件):# Source install procedures1. mkdir a subdirectory with the code version number;2. chdir into the subdirectory;3. tar -zxvf the compressed soucecode(this will generate a ‘;linux’; subdir);4. /var/www/html/lxr/bin/genxref linux5. [ Optional ] glimpseindex -H . linux6. [ Optional ] chmod 644 .glim*7. Edit the ‘;versions’; file to contain this new code version number;8. done!Example: To Install the linux kernel code version 2.1.33:The compressed code packet is : linux-2.1.33.tar.gz———————————————————-1. mkdir /var/www/html/lxr/source/2.1.332. chdir /var/www/html/lxr/source/2.1.333. tar -zxvf linux-2.1.33.tar.gz4. /var/www/html/lxr/bin/genxref linux5. [ Optional ] glimpseindex -H . linux6. [ Optional ] chmod 644 .glim*7. Insert the line ‘;2.1.33’; into the ‘;versions’; file.8. Done!==============================================================================================================================================最后提醒一下,从我们讨论的内核版本号(0.11)可以知道,这个内核版本并不是一个没有错误的完善版本(当然这也不存在),其中有些代码必然不可能都是最好或是最有效率的,但是作为了解内核工作实现原理来讲肯定已经做够了。****** 这里是终点,更是一个新的起点 ******

也有伤心的,既有令人兴奋的,也有令人灰心的,

《Linux内核完全注释》《完全剖析》 » 阅读本书所需的基础

相关文章:

你感兴趣的文章:

标签云: