《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=291
NASM 匯編手冊:?http://www.oldlinux.org/oldlinux/viewthread.php?tid=877
as86? ?在線手冊:?http://www.oldlinux.org/oldlinux/viewthread.php?tid=1895
ld86? ?在線手冊: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 Reference
By qhshang at 163.com
It 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 lxr
Modify Makefile to customize the PERLBIN and INSTALLPREFIX, to indicate the perl program and where you install lxr.
then?
$ make install
To generate your reference for files in Your_dir:
$ genxref Your_dir
while genxref is in lxr/bin
In 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 make??glimpse, then cp bin/{glimpse,glimpseindex} to /bin or /usr/bin
Generate index using glimpse:
$ glimpseindex -H . Your_dir
here -H means where to put the generated index files.
Test your index:
$ glimpse Your_string
----------------------------------------
Web server configuration
To make lxr viewable in web pages, add lines for xrefs in apache conf 文件:
<Directory /Your_path_to_lxr>
Options All
AllowOverride All
order allow,deny
allow from all
</Directory>
To make sure perl script can be executed:
make a file .htaccess in??your 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-script
I 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.conf
My 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-head
htmltail: /Your_web_server_root/xrefs/template-tail
htmldir:??/Your_web_server_root/xrefs/template-dir
# The source is here.
sourceroot: /Your_web_server_root/xrefs/src/linux-$v/linux
srcrootname: 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 Mar??7 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 /src
USE_APACI=1 PREP_HTTPD=1 DO_HTTPD=1
結果是:
[root@secteam mod_perl-1.99_10]# perl Makefile.PL EVERYTHING=1
APACHE_SRC=../httpd-2.0.47/ USE_APACI=1 PREP_HTTPD=1 DO_HTTPD=1
Reading 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/apxs
make沒有問題,make test 有很多錯:
/usr/bin/perl -Iblib/arch -Iblib/lib /
t/TEST -clean
*** setting ulimit to allow core files
ulimit -c unlimited; t/TEST -clean
APACHE_USER= APACHE_GROUP= APACHE_PORT= APACHE= APXS= /
/usr/bin/perl -Iblib/arch -Iblib/lib /
t/TEST -verbose=0
*** setting ulimit to allow core files
ulimit -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';, therefore
we attempt to run the test suite with user ';nobody'; (99:99).
The problem is that the path:
/root/mod_perl-1.99_10/t
must be ';rwx'; by user ';nobody';, so Apache can read and write under that
path.
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 start
Syntax error on line 235 of /usr/local/apache2/conf/httpd.conf:
Invalid command ';AddModule';, perhaps mis-spelled or defined by a module
not 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 (@INC
contains: /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 for
server 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 open
shared 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 was
unable 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 stop
httpd (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-head
htmltail: /var/www/oldlinux.org/lxr/http/template-tail
htmldir:??/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 procedures
1. 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 linux
5. [ Optional ] glimpseindex -H . linux
6. [ 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.33
2. chdir /var/www/html/lxr/source/2.1.33
3. tar -zxvf linux-2.1.33.tar.gz
4. /var/www/html/lxr/bin/genxref linux
5. [ Optional ] glimpseindex -H . linux
6. [ Optional ] chmod 644 .glim*
7. Insert the line ';2.1.33'; into the ';versions'; file.
8. Done!?
=======================================================================
=======================================================================
最后提醒一下,從我們討論的內核版本號(0.11)可以知道,這個內核版本并不是
一個沒有錯誤的完善版本(當然這也不存在),其中有些代碼必然不可能都是
最好或是最有效率的,但是作為了解內核工作實現原理來講肯定已經做夠了。
****** 這里是終點,更是一個新的起點 ******
總結
以上是生活随笔為你收集整理的《Linux内核完全注释》《完全剖析》 » 阅读本书所需的基础知识 -- 再次强调。的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Spring SAS 0.2.0 上手教
- 下一篇: SQLServer安装挂起解决方法