Linux Kernel Learning -4kernal directory (Follow Sina Weibo: Lonely Years of erosion (more than 4,000 technology sharing))

Source: Internet
Author: User
Tags string format

The code file under this directory can be divided into three categories, one is the hardware (exception) interrupt handler file, and the other is the system
The service handler file is called, and the other is a common function file such as process scheduling. See figure 1.5. We are now based on this classification method,
A more detailed description of the functionality that is implemented.
5.1.1.1 Hardware Interrupt Handling class program
It consists of two code files: ASM.S and traps.c files. ASM.S for the interruption caused by most hardware exceptions.
Process of language processing. The TRAPS.C program implements the C function that is called during ASM.S interrupt processing. Several other hardware interrupts
Handlers are implemented in Files System_call.s and MM/PAGE.S.
More e-book tutorials download Please login Http://down.zzbaike.com/ebook
This site provides e-book tutorials are online collection, if the tutorial involves or infringes on your copyright, please contact us.
5th Chapter Kernel Code linux/kernel/
72
Interrupt signals can usually be divided into two categories: hardware interrupts and software interrupts (exceptions). Each interrupt is made up of a number between 0-255
Identity. For interrupt int0--int31 (0x00--0x1f), the function of each interrupt is set or reserved by Intel, which belongs to the soft
Interrupt, but Intel calls it an exception. This is caused by an exception being detected by the CPU when the instruction is executed. Usually can also be divided into faults (Fault)
and traps (traps) in two categories. Interrupt int32--int255 (0X20--0XFF) can be set by the user himself. In a Linux system, the
The int32--int47 (0x20--0x2f) corresponds to the hardware interrupt request signal irq0-irq15 emitted by the 8259A interrupt control chip and the program
Programmed system call (System_call) interrupts are set to int128 (0x80).
The ASM.S code file mainly deals with the processing of the Intel reserved interrupt int0--int16, and the rest of the reserved interrupts int17-int31 by
Intel Corporation is reserved for future expansion. The 16 handlers that correspond to the int32-int47 that are emitted by each IRQ of the interrupt controller chip are divided
Do not process in initialization programs for various hardware such as clocks, keyboards, floppy disks, math coprocessors, hard disks, and so on. In Linux system calls
The processing of int128 (0x80) will be given in KERNEL/SYSTEM_CALL.S. The specific definitions for each interrupt are shown in the code comment after the other
Information section.
The process of processing interrupts caused by a hardware exception is shown below (Figure 5.1).
Figure 5.1 Interrupt processing process due to hardware anomalies (faults, traps)
Because some exceptions cause interrupts, internal CPU generates an error code on the stack (exception interrupt int 8 and Int10-int
14), while the other interrupts do not have this error code (for example, 0 errors and boundary check errors, etc.), so the ASM.S program
The processing of all interrupts is handled separately depending on whether the error code is carried. But the process is still the same.
The error code will be generated.
5.1.1.2 system call processing related programs
The functionality of the application invocation kernel in Linux is done by interrupting the call to int 0x80, and the register EAX the call number. So
The interrupt call is called a system call. Related files that implement system calls include System_call.s, FORK.C, SIGNAL.C, SYS.C
and exit.c files.
The SYSTEM_CALL.S program acts like a ASM.S program in hardware interrupt processing, in addition to clock interrupts and hard drives,
The floppy disk is interrupted for processing. A function in FORK.C and SIGNAL.C is similar to the function of the TRAPS.C program, for system interrupt tuning
Provides a c processing function. The FORK.C program provides two C processing functions: Find_empty_process () and copy_process ().
All registers into the stack.
Error code-in stack
Interrupt return address--into the stack
All segment registers are built into the kernel
Selector values for code snippets
Call the relevant C handler function
The error code and back of the stack
The interrupt return address that comes in the stack
Eject all stack Registers
Interrupt return
Note 1: Selection of kernel code
The character value is 0x10;
Note 2: When there is no error code,
Use 0;
Note 3: The called C function is
Implemented in TRAPS.C. Press in
The stack error code and the
The return address is used as a C-letter
Number of parameters.
More e-book tutorials download Please login Http://down.zzbaike.com/ebook
This site provides e-book tutorials are online collection, if the tutorial involves or infringes on your copyright, please contact us.
5th Chapter Kernel Code linux/kernel/
73
The SIGNAL.C program also provides a function do_signal () that processes signals about the process, which is called during system call interrupt processing.
There are also 4 system call SYS_XXX () functions.
The SYS.C and EXIT.C programs implement some other sys_xxx () system call functions. These sys_xxx () functions are the corresponding systems
Calls are called processing functions, some are implemented using assembly language, such as SYS_EXECVE (), while others are implemented in C
(for example, 4 system call functions in SIGNAL.C).
We can understand this based on the simple naming conventions of these functions: the C that is called during interrupt processing that usually begins with ' Do_ '
function, either a function that is common to the system call processing or a system call, and a system that starts with ' Sys_ '
The function is a dedicated handler for the specified system call. For example, the do_signal () function is basically what all system calls do
function, while DO_HD (), Do_execve () is a special C-processing function that is called by a system.
5.1.1.3 Other general class programs
These procedures include schedule.c, mktime.c, PANIC.C, Printk.c and VSPRINTF.C.
The SCHEDULE.C program includes the most frequently called schedule (), sleep_on (), and Wakeup () functions of the kernel, which are core
A scheduler that toggles the execution of a process or alters the execution state of a process. The MKTIME.C program contains only one kernel used by the
The time function mktime () is called only once in INIT/MAIN.C. The PANIC.C contains a panic () function that is used in the kernel
An error message is displayed and is down when a run occurs. PRINTK.C and VSPRINTF.C are support programs for the kernel display information, which implements the internal
The kernel-specific display function PRINTK () and the string format output function vsprintf ().

Linux Kernel Learning -4kernal directory (Follow Sina Weibo: Lonely Years of erosion (more than 4,000 technology sharing))

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.