Kernel bug. h and GCC inline assembly learning, kernel bug. hgcc inline

Source: Internet
Author: User

Kernel bug. h and GCC inline assembly learning, kernel bug. hgcc inline

All the learning content is in the annotations. In my learning process, after seeing this code segment, all I need is to learn it roughly. Strive to understand the entire part.
The following shows my learning code:

# Ifndef _ i1__bug_h # define _ i1__bug_h/** Tell the user there is some problem. * Tell The user that there are some problems * the offending file and line are encoded after the "officially * undefined" opcode for parsing in The trap handler. ** problematic files and lines are encoded after the "officially undefined" operation code to be resolved in a trap * Handler. * // *** 1 :__ asm __: gcc inline assembly method * Common gcc inline assembly method: * Embedded Assembly Syntax: _ asm _ (Assembly statement template: Output part: input part: Damage description part) * consists of four parts: Assembly statement template, output part, input part, damage description section. * use the ":" format for each part. The Assembly statement template is required. The other three parts are optional. * if the latter part is used, and the former part is empty, you also need to use the ":" format. The corresponding part of the content is blank ** 2: ud2 command is a software instruction that allows the CPU to generate invalid opcode exception, * If the kernel finds this exception on the CPU, it immediately stops running. * 3 :__ volatile _ tells the compiler that none of the commands currently written are immutable, including the order, * If _ volatile _ is not included, the optimized Type Selection-O is used during gcc compilation, * The compiler will optimize the code according to its own optimization rules. * 4: The following may not be clear after inline is added. In this way, the Assembly command is used only: * ud2 ;*. word % c0 ;*. long % c1; *: "I" (_ LINE _), "I" (_ FILE _); ** as shown in the code above: * ud2; command to stop CPU running *. word % c0; The placeholder % c0 is a word *. long % c1; The placeholder % c1 is a long integer * ::; the output part in the middle is omitted * "I" (_ LINE __), "I" (_ FILE _) Replace the placeholder % c0, % c1, with (_ LINE _) and (_ FILE _) * respectively, "I" indicates the number of integers ** 5: the abbreviation of some register constraints * r: I/O, indicating that a general register is used, selected by GCC in % eax/% ax/% al, % ebx/% bx/% bl, % ecx/% cx/% cl, % edx/% dx/% dl a gcc considers it appropriate; * q: I/O indicates that a general register is used, which has the same meaning as r. * g: I/O indicates that registers or memory addresses are used. * m: I/O, memory Address used; * a: I/O, % eax/% ax/% al; * B: I/O, % ebx/% bx/% bl; * c: I/O, % ecx/% cx/% cl; * d: I/O, % edx/% dx/% dl; * D: I/O, % edi/% di; * S: I/O, % esi/% si is used; * f: I/O indicates that floating point registers are used; * t: I/O indicates that the first floating point register is used; * u: i/O indicates that the second floating point register is used. * A: I/O indicates that % eax and % edx are combined into A 64-bit integer. * o: i/O, which indicates the offset of one memory location; * V: I/O, which indicates that only one direct memory location is used; * I: I/O, indicates the immediate number of an integer; * n: I/O indicates the immediate number with a known integer; * F: I/O, indicates the immediate Number of floating point types; *****/# ifdef CONFIG_BUG # define HAVE_ARCH_BUG # ifdef CONFIG_DEBUG_BUGVERBOSE # define BUG () \ _ asm _ volatile _ ("ud2 \ n" \ "\ t. word % c0 \ n "\" \ t. long % c1 \ n "\:" I "(_ LINE _)," I "(_ FILE _) # else # define BUG () _ asm _ volatile _ ("ud2 \ n") // directly stop the CPU running # endif # include <asm-generic/bug. h> # endif

In the process of GCC inline assembly, we can see that GCC only supports AT&T assembly language, and we know some features about AT&T assembly language. I have studied X86 assembly before and found many differences. By reading an article, I made a general summary of it, which is more valuable.
Comparison between AT&T and intel

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.