Upload
madeline-gray
View
216
Download
0
Embed Size (px)
Citation preview
ICOM 5007 - Noack
Linux kernel structure
Kernel code structureHow it boots itself
All the system calls are availableSystem is configured
Process handling is available
ICOM 5007 - Noack
The kernel code
Obtaining itInformation at www.kernel.org
ftp ftp.pr.kernel.org
Usually it is in/usr/src – various directories
Most recent stable version is 2.4.19
What it containsThe 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 5007 - Noack
structure
Major directoriesArch – 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 5007 - Noack
More structure
The auxiliary filesMakefile and rules
These explain quite a bit about kernel structure
Note – this makefile activates the others in each subdirectory
READMEHow to compile
OthersCasual reading –
how Linux gets developed
ICOM 5007 - Noack
Linux is ported to these architectures
ICOM 5007 - Noack
View of the i386 arch area
ICOM 5007 - Noack
Contents of lib for the i386
CommentsThe .S are assembly language – GNU, not Microsoft
Note the individual makefile
General utilities, as you would expect
ICOM 5007 - Noack
The makefile for lib
NotesThe 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.oobj-$(CONFIG_DEBUG_IOVIRT) += iodebug.o
include $(TOPDIR)/Rules.make
ICOM 5007 - Noack
A sample of GNU assembler
/*unsigned int csum_partial(const unsigned char * buff, int len, unsigned int sum) */
.text
.align 4
.globl csum_partialpushl %esipushl %ebxmovl 20(%esp),%eax # Function arg: unsigned int summovl 16(%esp),%ecx # Function arg: int lenmovl 12(%esp),%esi # Function arg: unsigned char *bufftestl $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 5007 - Noack
Some recognizable parts of kernel
NotesThis 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 5007 - Noack
Tiny piece of kernel code from mm
#if CONFIG_HIGHMEMpte_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 5007 - Noack
The contents of fsThis shows all the file systems supported by
Linux
ICOM 5007 - Noack
The non-architecture-dependentroutines of the kernel
ICOM 5007 - Noack
The driver repertoire in general
ICOM 5007 - Noack
The block device driversnote: paride contains the IDE drivers
ICOM 5007 - Noack
A few of the char drivers
ICOM 5007 - Noack
Comments - drivers
Block device driversAll the common block devices – these include disks and anything else
that is block-oriented
Character device driversThese include the character-by-character devices – also some
pseudo-devices
Note – these are architecture-independent
ICOM 5007 - Noack
Some things that aren’t in the kernel
Anything that isn’t in vmlinuzExamples:
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 differentThe 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 5007 - 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 easierThe 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