Click here to load reader
Upload
gambhiri-naveen
View
108
Download
0
Embed Size (px)
DESCRIPTION
Linux 内核分析入门. 西安交通大学 李思 2004 年 8 月 26 日. 主要内容. 有关 Linux 内核的基础知识 实模式与保护模式 用户空间与内核空间 Linux 内核源代码导读 工具与策略 内核源码目录结构 实例分析 Linux 启动代码分析 Linux 进程调度代码分析 Linux 设备驱动程序设计概述. 1. Linux 内核的发展. 内核源代码的行数. 2. 有关 Linux 内核的基础知识. (左移四位). 16 位段地址. 软件地址:. 16 位段地址. :. 16 位段内偏移. 物理地址:. 16 位段内偏移. - PowerPoint PPT Presentation
Citation preview
Linux
2004826
LinuxLinuxLinuxLinuxLinux
1. Linux
2.Linux
BIOS Dos1M
Linux4G32(+)()()32 = +
1/procnetlink
LKMLKM = Loadable Kernel Module, LKMLKM/LKMLKMLKM:
Linux
Source InsightWindowsLinuxwineSource NavigatorLinuxLXRLinux Cross ReferenceHTMLhttp://lxr.linux.no
Linux
Linux/usr/src/linuxDocumentationarchfsinitkernelincludeipcdriversnetmmlibscriptsalphaarmi386ia64m68kmipsmips64ppcs390shsparcsparc64acornatmblockcdromchardiofc4i2ci2oideieee1394isdnmacintoshmiscnetadfsaffsautofsautofs4bfscodecramfsdevfsdevptsefsext2fathfshpfsasm-alphaasm-armasm-genericasm-i386asm-ia64asm-m68kasm-mipsasm-mips64linuxmath-emunetpcmciascsivideoadfsaffsautofsautofs4bfscodecramfsdevfsdevptsefsext2fathfshpfs802appletalkatmax25bridgecoredecneteconetethernetipv4ipv6ipxirdakhttpdlapb
DocumentationLinuxOpenDocjavadochttp://kernelbook.sourceforge.netkernel-docs.txt (Linux)
archLinuxkernel, lib, mm, boot lib2.4:alpha, arm, i386, ia64, m68k, mips, mips64ppc, s390, sh, sparc, sparc64
driversLinux(100M): cdrom, ide, isdn, parport, pcmcia, pnp, sound, telephony, videofc4, i2c, nubus, pci, sbus, tc, usbacorn, macintosh, s390, sgidrivers/charn_tty.cttydrivers/blockfloppy.cdrivers/net
fs:(VFS)Vfs:exec.c, binfmt_*.c devices.c, blk_dev.csuper.c, filesystems.cinode.c, dcache.c, namei.c, buffer.c, file_table.copen.c, read_write.c, select.c, pipe.c, fifo.cI/Ofcntl.c, ioctl.c, locks.c, dquot.c, stat.c
includeinclude/asm-*include/linux#ifdef#ifdef __KERNEL__ /* kernel stuff */#endif:math-emu
initdo_mounts.cmain.cversion.cdo_mounts.cversion.cLinuxmain.cstart_kernel
ipcSystem V:sem.cshm.cmsg.cutil.cLinuxSystem V IPCutil.c
kernelLinuxsched.cfork.c, exec.c, signal.c, exit.cacct.c, capability.c, exec_domain.c kmod.c, ksyms.c, module.ctime.c, resource.c, dma.c, softirq.c, timer.cprintk.c, info.c, panic.c, sysctl.c, sys.c
libC:brlock.c Big Readercmdline.c errno.c inflate.c string.c arch/libarch/libvsprintf.c printk
mmswap.c, swapfile.c (), swap_state.c ()vmscan.c , kwapdpage_io.c slab.c slabpage_alloc.c vmalloc.c memory.c filemap.c mmap.c, mremap.c, mlock.c, mprotect.c
netCoreBridge: khttpdwebSched: Sunrpc: RPCUnix: unix socketipv4/ipv6ethernet802802.xBluetooth
scriptsscript:
FAQ(1)printfmallocvolatileI/Odo{...}while(0) Red HatLinuxhttp://www.kernel.orgLinux?find/usr/src/linux-2.x.x-name"*.[chS]" \ |xargscat|wc-l
FAQ(2) structfoo { unsignedchara:4, b:4; unsignedintc; unsigned chardata[0]; }__attribute__((packed)); a:4b:44__attribute__((packed))sizeof(struct foo)8data[0]
1:
bootsect.s(BootLoader)setup.s (BootLoader)arch/i386/boot/compressed/head.S arch/i386/boot/compressed/misc.carch/i386/init/main.c, start_kernel()init init
BIOSPOST0x7C000x7C00
bootsect.s0x7C000x90000ljmp0x94000-12122.88MLoadingsetup0x90200 setupsyssize0x10000bootsectrootljmpsetup.s
setup.ssetupsetupsetup(BIOS)(vedio.s)APM0x90000-0x901FFbootsectNMIsystem0x10000x1000compressed/head.ssystem04K
setup.s
head.sarch/i386/boot/compressed/head.Smisc.cdecompress_kernel()0x1000000x100000head.Sarch/i386/boot/head.SBSSinit/main.cstart_kernel()
start_kernel(1)Linux printk(linux_banner) setup_arch() parse_options()"arch/alpha/kernel/entry.S"trap_init() init_IRQ() sched_init() softirq_init()CMOS time_init()console_init() init_modules() profile_init()
start_kernel(2)Cache(CacheCache) kmem_cache_init()CPU calibrate_delay() mem_init()cachekmem_cache_sizes_init() pgtable_cache_init()fork fork_init()proc proc_caches_init() vfs_caches_init() page_cache_init() signals_init()/proc proc_root_init() ipc_init()CPUbug check_bugs()init()idlerest_init()
init() do_basic_setup() free_initmem()/dev/consolestdinstdoutstderrinit=xxx/sbin/init/etc/init/bin/init/bin/sh
do_basic_setup() pci_init()keventd start_context_thread()do_initcalls() __initcallmodule_initkflushdkupdateinodekswapd SCSI
5.2:
SCHED_FIFO: SCHED_RRSCHED_OTHERnicerenicenice(-20190)21-nicenice
schedule()prevprevSCHED_RRcounterpriorityprev goodnessgoodnessgoodnesscc0goodness0schedulecounterpriorityprevswitch_to
goodness()weightweightCPUcounter
policy
weight
SCHED_RR
weight =1000 + rt_priority
SCHED_FIFO
weight =1000 + rt_priority
SCHED_OTHER
if ( counter == 0 ) weight = 0;
else weight = counter + 20 - nice;
if (p->mm == this_mm || !p->mm) weight++;
6.Linux
OSOSOSint (* read)(char *buf, int length);int dev_read(char *buf, int length) { }send=&dev_read;OSrc=(*read)(buffer, 500);(*read)dev_read
Linuxskeletonskeleton
LinuxLinuxLinuxhttp://www.oldlinux.orgLinux()Linux Device Driver, 2nd EditionUnderstanding The Linux Kernel, 2nd Edition
Linux