2017-2018-1 20179219 "Linux kernel Fundamentals and analysis" third week job

Source: Internet
Author: User
Tags volatile

I. Course notes

gcc -g xxx    -s xxx    get the disassembly file of the executable program just generated three magic weapon: Stored program computer, program call stack, interrupt %1    Represents the following output and input parts, the first is expressed as%0, the second is expressed as%1, and the third is expressed as%2

Call: Pushes the value of the current CS:EIP to the top of the stack, Cs:eip points to the entry address of the called function
{Program Call procedure: Step1. When you do a CS:EIP, the original value points to the next instruction on the message, which is saved to the top of the stack, and then the value of CS:EIP points to the entry address of XXX
Step2. After entering xxx, the first instruction PUSHL%EBP; the second instruction Movl%ESP,%EBP; The general operation in the function body may be pressed, stacked
Step3. Exit Xxx,movl%EBP,%ESP;POPL%ebp;ret}


C language inline assembler commonly used modifiers:"a "Put the input variable into the EAX"b"put input variables in ebx"C"put input variables in ecx"D"put the input variable into edx"s"Placing input variables in ESI"D"put input variables in EDI"Q"put the input variable into one of the eax ebx ecx edx"R"put the input variable into the general register, which is a eax ebx ecx edx EDI"A"add eax and edx. To synthesize a 64-bit register of EAX and edx"m"Memory Variables"o"The operand is a memory variable, but it is addressed as an offset type"V"The operand is a memory variable, but its address is not an offset type"."The operand is a memory variable, but it is addressed in an AutoIncrement way"P"operand is a valid memory address (pointer)"g"put the input variable into one of the eax ebx ecx edx or as a memory variable"X"operands can be of any type"I" 0-immediate number between 31 (for 32-bit shift instructions)"J" 0-immediate number between 63 (for 64-bit shift instructions)"N" 0-immediate number between 255 (for out instruction)"I"Immediate number"N"Immediately, some systems do not support immediate numbers other than digits, and these systems should use"a" "="The operating system is only written in the instruction (output operand)"+"operating system is read/write type in instruction (input/output operand)"F"floating point number"T"first floating-point register"u"second floating-point register"G"Standard 80387"%"the operand can be swapped with the next operand in the position of"#"A partial comment, from which all letters are ignored between the character and the comma thereafter"*"If the register is selected, the subsequent letters are ignored Eg.start process0by task[0]asm volatile ("MOVL%1,%%esp\n\t" //set TASK_[PID].THREAD.SP to ESP "PUSHL%1\n\t" //Push EBP "PUSHL%0\n\t" //Push Task_[pid].thread.ip "ret\n\t" //pop task_[pai].thread.ip to Eip "popl%%EBP \n\t" : :"C"(Task_[pid].thread.ip,"D"(TASK[PID].THREAD.SP))) Process Context Switch: ASM volatile ("PUSHL%%ebp\n\t" //Save EBP "MOVL%%esp,%0\n\t" //Save ESP "MOVL%2,%%esp\n\t" //Restore ESP "MOVL $1f,%1\n\t" //save Eip $1f refers to the position of the next label 1:The entry into the EIP when the process is called again, that is, the process will continue to run again. The $1f book here is interpreted as 24 Line 1: The address, very confusing. Actually this is this is just at&t A syntax: Local labels can be numeric, and can be repeated. On the transfer instruction for these markings, the label is marked with a suffix, b means forward, and f is backwards. "PUSHL%3\n\t" "ret\n\t" //Restore EIP "1:\t" //Next process start here "popl%%ebp\n\t" :"=m"(PREV->THREAD.SP),"=m"(prev->thread.ip):"m"(NEXT->THREAD.SP),"m"(next->thread.ip));

Second, the experiment

Error found: line 6th comment should be/*val3=%eax*/

2017-2018-1 20179219 "Linux kernel Fundamentals and analysis" third week job

Related Article

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.