2019-2020-1 20199312 "Linux kernel principle and Analysis" in the third week of work

  • Three magic weapons computer: stored-program computer, function calls, interrupts
  • Stack effects: frame recorded as a function call, passing function parameters, return value address, it provides functions inside the local amount of storage space.
  • Stack registers associated ESP: Stack pointer stack stack EBP: base address pointer to the stack stack bottom
  • The stack grows down the cause of
    this problem with the virtual address space allocation rules about every executable C programs, from low to higher addresses followed: text, data, bss, stack, stack, variable environmental parameters; the pile and there are a lot of address space free between the stack, when the need to allocate space, up to heap up, down stack

  • Eip function call by call instruction in the address A scare an instruction stored in the stack, called code point provided eip
    CS: eip always point to the address of the next instruction
    sequentially performed: always point to the address of the next instruction of jump and link testing branch: eip will be modified according to program needs.
    call: the current CS: value of eip onto stack, CS: eip called function points to the entry address
    RET: pop cd previously saved here from the stack: the value of eip placed SC: eip in

xxx call
before executing the call
, when executed call, cs: eip original value points to the next instruction call, this value is saved to the stack, and then cs: ei value xx entry address pointing
into the xxx
first instruction: pushl% ebp
The second instruction: movl% esp,% ebp
proposed xxx
movl% ebp,% ESP
popl $ ebp
-ret

  • experiment

$ cd ~/LinuxKernel/linux-3.9.4
$ rm -rf mykernel
$ patch -p1 < ../mykernel_for_linux3.9.4sc.patch
$ make allnoconfig
$ make
$ qemu -kernel arch/x86/boot/bzImage

  • Renderings

  • View Files

View mymain.c file:

   vi mymain.c


void __init my_start_kernel(void)
{
    int i = 0;
    while(1)
    {
        i++;
        if(i%100000 == 0)
            printk(KERN_NOTICE "my_start_kernel here  %d \n",i);
            
    }
}

to sum up:

Guess you like

Origin www.cnblogs.com/banpingcu/p/11604003.html