linux社区爱心援助Linux认证系列教程业界动态站务新闻公司招聘建议留言网址大全LPI专题CISCO专题
设为首页
加入收藏
管理团队
JSP  
JAVA  
PERL  
 您的位置:首页 > article > unix > unix提高 >
栏目导栏
资料搜索
热门文章
·20%的SOLARIS知识解决80%的问题
·Solaris启动过程详解 zt
·查看Solaris系统硬件配置的命令
·STRUTS 源码学习笔记
·Unix系列shell程序编写(中)
·SOLARIS技巧篇
·snort源码分析
·Unix系列shell程序编写(下)
·在solaris 10/x86下安装oracle
·Apache源代码分析——关于模块
·solaris 10 硬盘安装
·Solaris安全配置手册
·HP-UX基本指令快速参考
· Tomcat Server源码启动分析
·Solaris8 双网卡配置(路由器用
最新文章
·solaris系统安全配置
·RHEL5.0操作系统下NFS服务的配
·Solaris Linux 9下Vsftpd的配置
·在HP-UX下建立只归属于某个目录
·SolarWinds2002使用说明
·从外部存储划盘并加入vg,为fs扩
·因带库问题导致系统光纤卡报错
·Unix下多线程中条件变量的使用
·UNIX和Linux中信号的个数
·不同的类UNIX操作系统密码破解
·AIX系统下Domino邮件服务器安装
·限制ROOT用户远程登陆UNIX系统
·Unix操作系统入侵追踪反击战
·AIX CDE不能启动的故障一般性解
·CentOS4.4用VSFTPD架设FTP服务
Google
 
FreeBSD核心入门
[ 作者:Linux联盟收集  加入时间:2006-06-14 00:46:28  来自:Linux联盟收集 ]
FreeBSD核心入门UVTLinux联盟
1.1概述 UVTLinux联盟
FreeBSD可以在PC/AT兼容机器上运行。CPU是i386,i486,Pentium, UVTLinux联盟
Pentium Pro以及其兼容芯片等。 UVTLinux联盟
1.1.1(略) UVTLinux联盟
1,理论地址: 2个13 bit 长+32 bit 长 UVTLinux联盟
2,线形地址:32 bit 长的空间 UVTLinux联盟
3,物理地址:32 bit 长的空间 UVTLinux联盟
1.1.2进程的虚拟空间 UVTLinux联盟
1,text部分 UVTLinux联盟
这部分是执行文件的的text领域,也就是机器语言部分,对于这个 UVTLinux联盟
部分的空间在机器上的物理内存页是共有的,还有,这部分最后的变量 UVTLinux联盟
地址是etext。 UVTLinux联盟
2,data和bss部分 UVTLinux联盟
执行文件的data部分,也就是初始化的数据段和执行文件指定的内 UVTLinux联盟
存变量。内存变量在开始的时候以0填充。这一段空间可以读写。它的 UVTLinux联盟
边界也是以edata和end的地址做结尾。进程的malloc()等内存分配的 UVTLinux联盟
操作的时候,地址的增加方向向bss空间进行。 UVTLinux联盟
3,stack部分 UVTLinux联盟
也就是进程执行的时候的stack空间,这部分空间(从地址的最高位 UVTLinux联盟
开始可以伸缩),其对于物理内存,伸缩程度由核心自动执行。 UVTLinux联盟
1.2 kernel的configure UVTLinux联盟
freebsd的kernel构成文件在/usr/src/sys的目录下面。下面的子目录做一个 UVTLinux联盟
介绍。 UVTLinux联盟
compile 编译核心的目录。 UVTLinux联盟
conf configure的目录。 UVTLinux联盟
ddb 核心调试的sounre code的目录。 UVTLinux联盟
dev 一部分的drivers的source code的目录。 UVTLinux联盟
gnu 浮点运算的仿真以及ex2fs文件系统的source code目录。 UVTLinux联盟
i386 依赖于pc/at机器的目录,以下介绍它的字目录。 UVTLinux联盟
apm suspend一些节电程序。 UVTLinux联盟
boot 不是kernel本身的东西,只是一些怎么从开机到读入kernel UVTLinux联盟
的boot program的source code。 UVTLinux联盟
conf config的一些依赖data。 UVTLinux联盟
isa isa bus的驱动程序类的source code。 UVTLinux联盟
eisa eisa bus的驱动程序类的source code。 UVTLinux联盟
include 对pc/at的一些include files UVTLinux联盟
i386 对pc/at的一些核心code UVTLinux联盟
ibcs2,linux 使各类的os的执行文件在freebsd上执行的code UVTLinux联盟
isofs/cd9660 UVTLinux联盟
cd-rom在unix文件系统上操作的的有关code UVTLinux联盟
kern 核心code UVTLinux联盟
libkern 核心库的source code UVTLinux联盟
miscfs 实现unix文件系统的code UVTLinux联盟
msdosfs 在unix上操作ms-dos文件系统的有关code UVTLinux联盟
net 实现network功能的基本部分code UVTLinux联盟
netatalk UVTLinux联盟
实现appletalk network功能code UVTLinux联盟
netinet 实现internet network功能的code UVTLinux联盟
netipx 实现ipx功能的code UVTLinux联盟
netns 实现ns network的code UVTLinux联盟
netkey 实现网络加密部分的功能的code UVTLinux联盟
nfs 实现nfs服务 UVTLinux联盟
pc98 对于pc98的支持 UVTLinux联盟
pccard 对pcmcia的支持 UVTLinux联盟
pci 对pci bus的驱动程序的source code UVTLinux联盟
scsi 对cd-rom,hard disk,tape 等的scsi驱动程序的source code UVTLinux联盟
sys 独立于机器体系结构的一部分code UVTLinux联盟
ufs unix file system 的支持code UVTLinux联盟
vm 虚拟内存管理的部分 UVTLinux联盟
1.2.1配置的操作----config command UVTLinux联盟
在root权限下,config,make实行后,可以得到简单的kernel。 UVTLinux联盟
*configure file UVTLinux联盟
移动到/usr/src/sys/i386/config看看。 UVTLinux联盟
GENERIC 从cd-rom等安装freebsd的时候对应于defaule kernel UVTLinux联盟
的配置file UVTLinux联盟
LINT kernel组合功能的网罗的的配置file UVTLinux联盟
下面4个是对配置很有必要的的依赖data file UVTLinux联盟
Makefile.386 config生成的Makefile file的template. UVTLinux联盟
devices.i386 对于unix filesystem可能的block型的device UVTLinux联盟
名字和major号的对照表 UVTLinux联盟
files.i386 记录kernel功能组合的基础上,依赖于pc/at UVTLinux联盟
机器的功能名称和各种功能实现的source code UVTLinux联盟
file的名字表。 UVTLinux联盟
options.i386 记录配置项目的表。 UVTLinux联盟
还有,majors.i386是记录对应驱动器的I/O表和major号的一个文件。 UVTLinux联盟
于核心配置没关系。 UVTLinux联盟
对于新的i/o设备,如果要做device driver,对pc/at,要在files.i386(没 UVTLinux联盟
有的话在/usr/src/sys/conf/files)追加相应的行,不然就不能把它加入 UVTLinux联盟
到核心里面。 UVTLinux联盟
追加的格式为 UVTLinux联盟
相对path名 optional device-name device-driver UVTLinux联盟
UVTLinux联盟
对于配置文件,首先,要设置cpu,bus,i/o设备,多少用户等。例如对于GENERIC UVTLinux联盟
machine "i386" UVTLinux联盟
cpu "I386_CPU" UVTLinux联盟
cpu "I486_CPU" UVTLinux联盟
cpu "I586_CPU" UVTLinux联盟
cpu "I686_COU" UVTLinux联盟
ident GENERIC UVTLinux联盟
maxusers 10 UVTLinux联盟
当作为server时候,应该把最大user设置大一点,以提高系统性能。 UVTLinux联盟
下一步,指定options,对于GENERIC UVTLinux联盟
options MATH_EMULATE #support for x87 emulation UVTLinux联盟
options INET #interNETworing UVTLinux联盟
options FFS #Berkeley Fast Filesystem UVTLinux联盟
options NFS #Network Filesystem UVTLinux联盟
...... UVTLinux联盟
options指定的名字xxx等,如果在/usr/src/sys/conf/options或者在 UVTLinux联盟
/usr/src/sys/i386/conf/options.i386中记载的时候,应在对应的opt_XXX.h中写入 UVTLinux联盟
。没有的话,作为cc命令行的参数定义"-D"在Makefile里面追加。对于XXX的格式应该 UVTLinux联盟
UVTLinux联盟
相对path名 optional xxx UVTLinux联盟
下一步,对于config UVTLinux联盟
config kernel root on wd0 UVTLinux联盟
(略) UVTLinux联盟
配置文件剩下的部分应该是bus,i/o等一些硬件配置,一般有controller,device, UVTLinux联盟
disk,tape四类。例如 UVTLinux联盟
controller isa0 UVTLinux联盟
controller eisa0 UVTLinux联盟
controller pci0 UVTLinux联盟
等。 UVTLinux联盟
第二层的device和controller,记录了一些bus设备的连接。ISA的情况是 UVTLinux联盟
device device_name at isa? 参数 UVTLinux联盟
controller controller_name at isa? 参数 UVTLinux联盟
EISA和PCI就相对简单一点: UVTLinux联盟
device device_name UVTLinux联盟
controller controller_name UVTLinux联盟
device_name里指定的设备名是,串口,并口,网络等装置。 UVTLinux联盟
第三层的disk和tape为 UVTLinux联盟
disk disk_name at 控制设备名 drive 号 UVTLinux联盟
tape tape_name at 控制设备名 drive 号 UVTLinux联盟
SCSI接口卡作为第二层的控制装置记录的同时 UVTLinux联盟
controller scbus0 UVTLinux联盟
作为通用的scsi控制设备。因此,对于它的hard disk,tape,cd-rom,mo设备,有 UVTLinux联盟
device sd0 UVTLinux联盟
device st0 UVTLinux联盟
device cd0 UVTLinux联盟
device od0 UVTLinux联盟
等,它可以自动识别和分配号码。 UVTLinux联盟
对于其他的scsi设备,有 UVTLinux联盟
device pt0 at scbus? UVTLinux联盟
这些东西(bus,scsi,i/o),在生成的ioconf.c以及相应的include中有反映。 UVTLinux联盟
configure的最后,不是一些物理设备,而是kernel内部的一些软设置 UVTLinux联盟
pseudo-device 理论设备名 UVTLinux联盟
首先,要考虑以下两个设备: UVTLinux联盟
pseudo-device pty 16 #ttys - can go as high as 256 UVTLinux联盟
pseudo-device log #syslog interface (/dev/klog) UVTLinux联盟
network使用的场合,应该有下面两个 UVTLinux联盟
pseudo-device loop UVTLinux联盟
pseudo-device ether UVTLinux联盟
这种情况下,最好有 UVTLinux联盟
pseudo-device bpfilter 4 #berkeley packet filter UVTLinux联盟
pseudo-device tun 1 #Tunnel driver ( PPP) UVTLinux联盟
想做floppy的时候,要 UVTLinux联盟
pseudo-device vn #Vnode driver ( turns a file into a device)
1.3 FreeBSD boot之前的工作 UVTLinux联盟
1.3.1pc/at机器的boot顺序 UVTLinux联盟
hard disk的最前面的一个block(512byte),叫做master boot recorder(MBR).这 UVTLinux联盟
里有启动限定的program和分区的信息。分区信息是指对于一个区是16byte长,最多 UVTLinux联盟
只能有4个区。16byte的内容是,分区哪里开始,哪里结束。哪种os,能否启动等。对 UVTLinux联盟
于freebsd,安装的时候向MBR写入了boot easy. UVTLinux联盟
磁盘的结构如下图表示: UVTLinux联盟
block Number UVTLinux联盟
#0 #1 #2 ... #14 #15 #16 #17 UVTLinux联盟
------------------------------------------------------------- UVTLinux联盟
disk no used UVTLinux联盟
label UVTLinux联盟
------------------------------------------------------------- UVTLinux联盟
<-boot->|<---------boot2-------------->| |<--unix file system-- UVTLinux联盟
UVTLinux联盟
FreeBSD用的block#0--#14的15个block里面,含有读入freebsd的程序,bootease UVTLinux联盟
只在block#0里面,在15个block中并没有。它的作用 UVTLinux联盟
。读入mbr,找freebsd的分区 UVTLinux联盟
。读入最初的15个block,到物理内存中0x0001000 UVTLinux联盟
。跳转到相当于block#2的内存位置 UVTLinux联盟
然后,屏幕表示为: UVTLinux联盟
。。。 UVTLinux联盟
。。。 UVTLinux联盟
boot: UVTLinux联盟
(参数说明略) UVTLinux联盟
它的source是/usr/src/sys/i386/boot/biosboot,make之后,生成两个文件: UVTLinux联盟
boot1,boot2分别写入block#1,block#2--#14中。 UVTLinux联盟
一般,一个物理的unix分区理论上可以有8个,比如swap,unix system等。 UVTLinux联盟
boot2部分是boot program,它读入kernel的文件名和option。然后 UVTLinux联盟
。找boot label指定的分区。 UVTLinux联盟
。构造unix filesystem,找指定的kernel UVTLinux联盟
。从开始执行文件,text,data的顺序向物理内存读入。对bss清零。 UVTLinux联盟
。以option的选择,向开始位置跳转。 UVTLinux联盟
1.3.2 kernel的初始化动作 UVTLinux联盟
boot program执行之后,转向kernel的text段开始进行初始化,即先执行 UVTLinux联盟
locore.s的text段。因此是虚拟内存还没有发生作用,locore.s的开始部分必 UVTLinux联盟
须对offset进行补正。locore.s的作用是 UVTLinux联盟
。保存从boot program过来的option UVTLinux联盟
。设定虚拟的stacker UVTLinux联盟
。检测cpu的module UVTLinux联盟
。对自己的bss空间进行0初始化 UVTLinux联盟
。为使虚拟内存工作,要保证最少的管理信息。然后是虚拟空间动作。 UVTLinux联盟
也就是,调用cpu有强的依赖关系的过程init386()(@i386/i386/machdep.c), UVTLinux联盟
然后进行kernel内的管理信息初始化,i/o设备的登记,生成4个kernel process UVTLinux联盟
,再调用main()(@kern/init_main.c)。当main()返回locore.s时,应该有如下 UVTLinux联盟
5个进程: UVTLinux联盟
PID TT STAT TIME COMMAND UVTLinux联盟
0 ?? DLs 0:00.17 (swapper) UVTLinux联盟
1 ?? Is 0:00.19 /sbin/init -- UVTLinux联盟
2 ?? DL 0:56.60 (pagedaemon) UVTLinux联盟
3 ?? DL 0:00.06 (vmdaemon) UVTLinux联盟
4 ?? DL 6:07.65 (updata) UVTLinux联盟
从locore.s返回到process #1,/sbin/init开始动作,然后转向freebsd的普通 UVTLinux联盟
动作。 UVTLinux联盟
init386()和main()的处理大致如下: UVTLinux联盟
。init386() UVTLinux联盟
GDT和LDT,IDT,task stages处理的初始化,例外处理等locore.s没做的 UVTLinux联盟
事情,虚拟内存初始化。然后,根据boot program的参数,增加物理内 UVTLinux联盟
存page数。然后,作成process #0的雏形。 UVTLinux联盟
。main() UVTLinux联盟
逐步调用构成kernel模块的的初始化部分。 UVTLinux联盟
UVTLinux联盟
UVTLinux联盟
FreeBSD核心探讨(翻译)3 UVTLinux联盟
UVTLinux联盟
(续上,liangvy.icewolf.leon翻译) UVTLinux联盟
UVTLinux联盟
但是,kernel构成的各个模块的初始化子程序一个个的列举出来运行很显然是 UVTLinux联盟
不行的。通常是利用时间连表的技能来运行它(ld command)。也就是,程序 UVTLinux联盟
是以很多个source分开编译和联结。相同的模块名字就对应于相同的地址来进 UVTLinux联盟
行调用。它在时间链表里面自动调节执行。 UVTLinux联盟
初始化时候,main()函数要call的模块利用在sys/kernel.h里面定义的宏 UVTLinux联盟
SYSINIT()和SYSINIT_KT()进行登记。这样,kernel在link的时候,ld命令就 UVTLinux联盟
能够得到那些信息和进行配置列表。这个列表就是kernel的组成模块的初始化 UVTLinux联盟
routine的登记。检查source, UVTLinux联盟
就可以找到初始化routine的部分。 UVTLinux联盟
如表: UVTLinux联盟
print_caddr_t(copyright) kern/init_main.c UVTLinux联盟
vm_men_init(NULL) vm/vm_init.c UVTLinux联盟
syctl_order(&sysctl_) kern/kern_sysctl.c UVTLinux联盟
kmemnit(NULL) kern/kern_malloc.c UVTLinux联盟
fpu_init(NULL) i386/i386/math_emulate.c UVTLinux联盟
cpu_startup(NULL) i386/i386/machdep.c UVTLinux联盟
gnufpu_init(NULL) miscfs/devfs/devfs_tree.c UVTLinux联盟
... UVTLinux联盟
各个device的major号与处理routine的登记 (major循序号) UVTLinux联盟
... UVTLinux联盟
configure(NULL) i386/i386/autoconf.c UVTLinux联盟
proc0_init(NULL) kern/init_main.c UVTLinux联盟
rqinit(NULL) kern/kern_synch.c UVTLinux联盟
vm_init_limits(&proc0) vm/vm_glue.c UVTLinux联盟
vfsinit(NULL) kern/vfs_init. Linux联盟收集整理 ,转贴请标明原始链接,如有任何疑问欢迎来本站Linux论坛讨论
分页:[1] 2 3 4 5
评论】【加入收藏夹】【 】【打印】【关闭
※ 相关链接
无相关信息