ICOM Noack Linux kernel structure Kernel code structure How it boots itself All the system calls are available System is configured Process handling is available
ICOM Noack The kernel code Obtaining it Information at ftp ftp.pr.kernel.orgftp.pr.kernel.org Usually it is in/usr/src – various directories Most recent stable version is What it contains The source code that compiles and links into a bootable system The compressed version is vmlinuz It contains all the openly available device drivers Future drivers appear in future versions or can be compiled in the current version Makefiles for automated configuration
ICOM Noack structure Major directories Arch – architecture-dependent Documentation – read these Drivers – all except network Fs – the file system Include – includes of multiple use Init – from boot to running kernel Ipc – IPC Kernel – the kernel structures Lib – libraries for the kernel Mm – memory management Net – the network code
ICOM Noack More structure The auxiliary files Makefile and rules These explain quite a bit about kernel structure Note – this makefile activates the others in each subdirectory README How to compile Others Casual reading – how Linux gets developed
ICOM Noack Linux is ported to these architectures
ICOM Noack View of the i386 arch area
ICOM Noack Contents of lib for the i386 Comments The.S are assembly language – GNU, not Microsoft Note the individual makefile General utilities, as you would expect
ICOM Noack The makefile for lib Notes The CONFIG shell variables come from the make config step Rules.make is used The.S.o: rule does assembly instead of compilation because of the $(AFLAGS) argument # # Makefile for i386-specific library files.. #.S.o: $(CC) $(AFLAGS) -c $< -o $*.o L_TARGET = lib.a obj-y = checksum.o old-checksum.o delay.o \ usercopy.o getuser.o \ memcpy.o strstr.o obj-$(CONFIG_X86_USE_3DNOW) += mmx.o obj-$(CONFIG_HAVE_DEC_LOCK) += dec_and_lock.o obj-$(CONFIG_DEBUG_IOVIRT) += iodebug.o include $(TOPDIR)/Rules.make
ICOM Noack A sample of GNU assembler /* unsigned int csum_partial(const unsigned char * buff, int len, unsigned int sum) */.text.align 4.globl csum_partial pushl %esi pushl %ebx movl 20(%esp),%eax# Function arg: unsigned int sum movl 16(%esp),%ecx# Function arg: int len movl 12(%esp),%esi# Function arg: unsigned char *buff testl $2, %esi# Check alignment. jz 2f# Jump if alignment is ok. subl $2, %ecx# Alignment uses up two bytes. jae 1f# Jump if we had at least two bytes. addl $2, %ecx# ecx was < 2. Deal with it. jmp 4f
ICOM Noack Some recognizable parts of kernel Notes This is the i386- specific part of kernel Note semaphore.c smp.c signal.c Some of these files will show up in the arch-independent part also
ICOM Noack Tiny piece of kernel code from mm #if CONFIG_HIGHMEM pte_t *kmap_pte; pgprot_t kmap_prot; #define kmap_get_fixmap_pte(vaddr)\ pte_offset(pmd_offset(pgd_offset_k(vaddr), (vaddr)), (vaddr)) void __init kmap_init(void) { unsigned long kmap_vstart; /* cache the first kmap pte */ kmap_vstart = __fix_to_virt(FIX_KMAP_BEGIN); kmap_pte = kmap_get_fixmap_pte(kmap_vstart); kmap_prot = PAGE_KERNEL; } #endif /* CONFIG_HIGHMEM */
ICOM Noack The contents of fs This shows all the file systems supported by Linux
ICOM Noack The non-architecture-dependent routines of the kernel
ICOM Noack The driver repertoire in general
ICOM Noack The block device drivers note: paride contains the IDE drivers
ICOM Noack A few of the char drivers
ICOM Noack Comments - drivers Block device drivers All the common block devices – these include disks and anything else that is block-oriented Character device drivers These include the character-by-character devices – also some pseudo-devices Note – these are architecture-independent
ICOM Noack Some things that aren’t in the kernel Anything that isn’t in vmlinuz Examples: Init – it reads /etc/inittab and starts all those processes Startup scripts – these are called up by init using inittab Libraries and most network daemons The kernel and the distribution are different The distribution contains utilities and libraries for users It contains the system installation utilities Typical distributions are RedHat, Slackware, Suse X-windows is part of the distribution or separately downloadable
ICOM Noack Some techniques for viewing the kernel This is W2K and WXP – Obviously the kernel won’t compile here, but it makes nice slides Open with permits viewing makefiles, etc. Documentation directory contains.txt files Set the.txt association to word, not notepad Viewing in Linux is a little easier The usual gui lets you view the filesystem treewise Clicking on individual.c,.h,.s, etc immediately displays the file in editor (emacs) Learn to use grep and fgrep to find out where structures, etc. are defined Learn to use du (disk usage) to get an idea of the size of the kernel