Liu Chang Original works reproduced please indicate the source "Linux kernel Analysis" MOOC course http://mooc.study.163.com/course/USTC-1000029000OverviewThis article mainly analyzes the process of Linux, process scheduling and context switching, it will involve the timing of schedule scheduling and process switching execution process, and through the GDB tracking Linu
function with a macro, added the recognition of VMware and KVM, and then compiled it with GCC to run:
The code is as follows:
/** Check if a Linux system running on a virtual machine (Vmware/xen HVM/KVM)*/#include stdio.h#include string.h
#define HYPERVISOR_INFO 0x40000000
#define CPUID (idx, eax, ebx, ecx, edx) \ASM volatile (\"Test%1,%1; JZ 1f; ud2a;. ASCII \ "Xen\"; 1:cpuid "\: "=b" (*EBX), "=a" (*eax),
. The code is as follows:ENTRY (RET_FROM_INTR) get_current (%EBX) //Place a pointer to the TASK_STRUCT structure of the current process into the Register EBXMOVL eflags (%ESP),%eax# mix eflags and Csmovb CS (%ESP),%altestl $ (vm_mask | 3),%eax//see if the interrupt is in User state jne Ret_with_reschedule //assumed to be in user state, then run Ret_with_ RESCHEDULEJMP Restore_allRet_with_reschedule:cmpl $0,need_resched (%EBX)//View the contents of the TASK_STRUCT structure at need_resched jne
. First, because the size of a hard disk is 512 bytes, it is exactly the factor of 64 K. Second, when the kernel bootsect reads data, it is necessary to determine whether it is approaching 64 K. If it exceeds the 64 K, it will calculate how many pieces can be read and then read.13. What is the relationship between page tables and page Directory items in Linux memory and the storage of kernel internal codes ?? Does it cause a conflict, overwrite it, or
table entry, and the table entry should be an interrupt gate.First, the SS of the user-state stack, the esp,eflags of the user stack, and the cs,eip of the user space are deposited into the system stack (obtained from TSS).(2), the CPU according to the setting of the interrupt gate reached the entrance of the total service program of the channel. asmlinkage void Irq0x00_interrupt (); __asm__ ("\ n" "Irq0x00_interrupt: \n\t" "Pushl $0x00-256 \n\t" "JMP common_interrupt ");Press the interrupt
I. Course notesgcc -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%2Call: 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
external function, press the parameter (msg address) into the stack, and the Call function outputs the result.
Let's look at a program:
Section. text
Global main
Main:
Mov eax, 4; called on 4
Mov ebx, 1; ebx returns 1 to indicate stdout
Mov ecx, msg; the first address of the string is sent to ecx
Mov edx, 14; the length of the string is sent to edx
Int 80 h; output string
Mov eax, 1; 1 call
Int
=0x123Direct addressing MOVL 0x123,%eax-----edx=* (int32_t*) 0x123;Addressing MOVL 4 (%EBX),%edx---edx = * (INET_32 *) (EBX+4), (the value of EBX is added after 4 as an address and the data it points to is assigned to%edxMost directives have direct access to memory addresses)AT assembly format is slightly different from Intel assemblerThe
, Vpsee rewrites the code, replaces the function with macros, increases the recognition of VMware and KVM, and then compiles it with GCC to run:
Copy Code code as follows:
/*
* Check if a Linux system running on a virtual machine (Vmware/xen HVM/KVM)
*/
#include stdio.h
#include string.h
#define HYPERVISOR_INFO 0x40000000
#define CPUID (idx, eax, ebx, ecx, edx) \ASM volatile (\"Test%1,%
Linux Kernel Design and Implementation of Reading Notes, Linux Kernel
Chapter 3 Process Management
1. fork system calls are returned twice from the kernel: one is returned to the sub-process and one is returned to the parent process. the task_struct structure is allocated by the slab distributor. 2.6 was previously placed at the bottom of the stack of the kernel stack. The task_struct of all processes are c
First, the Linux Summary of kernel analysis(a) How the computer works1. Stored program Computer working model2. X86CPU Register: General Register, segment register, flag register, etc.3. Assembly Instructions for Computers(1) MOVL directive:
Register addressing, register mode, register identifier beginning with%. Do not deal with memory, eax assignment to edx;
Immediate addressing, placing the
Ask you about a piece of code in the Linux Kernel assembly! -- Linux general technology-Linux programming and kernel information. The following is a detailed description. # Include in C language in entry. S
And # What does the define statement mean?
Why can I use this syntax in assembly? I don't seem to have found this syntax in assembly? Please advise
# Inc
Thread_infoSysret_check:lockdep_sys_exit disable_interrupts (clbr_none) Trace_irqs_off movl ti_flags+thread_info (%RSP, Rip-argoffset),%edxAndl%edi,%edxJNZ sysret_careful//If there is thread_info flags to deal with, such as Need_resched ////Direct returnCfi_remember_state/* * Sysretq'll re-enable interrupts: */trace_irqs_on movq Rip-argoffset (%RSP),%RCXCfi_register RIP,RCX Restore_args1,-arg_skip,0 /*cfi_register rflags,r11*/ //Restore the top address (RSP) in the PERCPU variable before sav
Author: wztEMail: wzt@xsec.orgSite: http://www.xsec.orgDate: 2008-6-13 nbsp;. introduction 2. x86 hardware addressing method 3. kernel settings for page tables 4. instance analysis ing mechanism 1. introduction we often see some places like 0x32118965 in the program disassembly code.
Author: wztEMail: wzt@xsec.orgSite: http://www.xsec.orgDate: 2008-6-13
I. thread theoryII. X86 hardware addressing method3. kernel page table settingsIV. instance analysis ing mechanism
I. thread theoryWe often se
Chen Chaojan Original WorksReprint please indicate the source "Linux kernel Analysis" MOOC course http://mooc.study.163.com/course/USTC-1000029000
Blog Directory1. First week: How Computers work2. Second week: How the operating system works3. Third week: Construct a simple Linux kernel menuos4. Fourth week: Three layers of flap system call (top)5. Fifth week: Three layers of flap operating syst
The process in Linux is the most basic concept, the process from the run queue to the beginning of the run there are two places, one is the SWITCH_TO macro in the label 1: "1:/t", the other is ret_form_fork, as long as not the newly created process, Almost all started with the label 1 above, and the SWITCH_TO macro is the place where all processes want to run, except for the kernel itself, so that although the Lin
Article Title: linux memory management initialization. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
ENTRY (startup_32)
/*
* Set segments to known values.
*/
Cld
Lgdt boot_gdt_descr-_ PAGE_OFFSET/* set the segment register *
small functions with frequently called parameters. Therefore, parameters can be passed through registers. Take GCC as an example. When GCC uses fastcall, the first two parameters from left to right are passed through the ECX and EDX registers by default. Other parameters are passed through the stack, however, you can use _ attribute _ (regparm (N) to control the number of registers that can be used. For example, regparm (3) indicates that the first t
memory.
Direct addressing, which accesses data directly from a specified memory address. No $ is the address, and the memory data pointed to by the memory address 0x123 into the edx register.
Indirect addressing, the value of the Register as a memory address to access memory, register EBX stored value as memory address, the memory address store data into edx.
Variable addressing, which alters t
the GNU debugging ignores the start breakpoint, a null instruction NOP is required at the Start tab. when the program contains the necessary debugging information, we can run it in GDB: $gdb Hello GNU gdb (gdb) Red Hat Enterprise Linux (7.2-60.EL6)Copyright (C) Free Software Foundation, Inc.License gplv3+: GNU GPL version 3 or later This was free software:you was free to change and redistribute it.There is NO WARRANTY, to the extent permitted by law.
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.