20169217 "Linux kernel Fundamentals and Analysis" Seventh week work

Source: Internet
Author: User
Tags volatile

First of all to improve the last week's homework, last week's embedded assembly did not compile successfully, the reason, or I do not understand the communication parameters, the write function of the 3 parameters are to be passed, not only the string of rumors printed on the line.

Under the guidance of the teacher and refer to the code of Mao Weihua classmate, finally compiled successfully!

#include <stdio.h>#include<string.h>#include<stdlib.h>#include<unistd.h>intMain () {Char* msg ="liuhongyi20169217"; intLen = -; intresult =0; ASMvolatile (                 "mov%2,%%edx;\n\r" /*incoming parameters: the length of the string to display*/                 "mov%1,%%ecx;\n\r" /*Incoming Entry: File descriptor (STDOUT)*/                 "mov $ $,%%ebx;\n\r" /*Incoming parameters: the string to display*/                 "mov $4,%%eax;\n\r" /*system call Number: 4 Sys_write*/                 "int $0x80" /*triggering system call interruption*/                 :"=m"(Result)/*Output section: This example does not use*/                 :"m"(msg),"R"(LEN)/*Input part: binding string and string length variable*/                 :"%eax"); return 0;}

Let's complete this week's experiment based on the embedded assembler code that was completed last week.

First part of the experiment is performed according to the requirements of MOOC's curriculum:

1. Update the menu code to the latest version.

-Rfgit clone https://github.com/mengning/menu.gitCD menu

2. Add Menuconfig to the main function.

3. Add the corresponding time and TIMEASM functions.

Based on the code that called the function in the previous lesson, write the following code:

#include <stdio.h>#include<string.h>#include<stdlib.h>#include<unistd.h>intWriteText () {Write (1,"liuhongyi20169217", -); return 0;}intwriteasm () {Char* msg ="liuhongyi20169217"; intLen = -; intresult =0; ASMvolatile (                 "mov%2,%%edx;\n\r" /*incoming parameters: the length of the string to display*/                 "mov%1,%%ecx;\n\r" /*Incoming Entry: File descriptor (STDOUT)*/                 "mov $ $,%%ebx;\n\r" /*Incoming parameters: the string to display*/                 "mov $4,%%eax;\n\r" /*system call Number: 4 Sys_write*/                 "int $0x80" /*triggering system call interruption*/                 :"=m"(Result)/*Output section: This example does not use*/                 :"m"(msg),"R"(LEN)/*Input part: binding string and string length variable*/                 :"%eax"); return 0;}intMain () {printmenuos (); Setprompt ("menuos>>"); Menuconfig ("version","menuos V1.0 (Based on Linux 3.18.6)", NULL); Menuconfig ("quit","Quit from Menuos", Quit); Menuconfig (" Time","Show System time", time); Menuconfig ("time-asm","Show System Time (ASM)", timeasm); Menuconfig ("WRITETEXT","WRITETEXT", WRITETEXT); Menuconfig ("writeasm","Write (ASM)", writeasm); Executemenu ();}

4. Recompile

$ make Rootfs

The first part of the experiment was completed and now the second part of the experiment.

Using the QEMU command to restart the kernel and use the-s and-s parameters, the command is as follows:

$ cd/home/shiyanlou/-kernel linux-3.18. 6/arch/x86/boot/bzimage-initrd rootfs.img-s-S

At this point, use GDB to debug, reopen a window, and enter the following command:

$ gdb (gdb) file Linux-3.18. 6/vmlinux (GDB) target remote:1234Continue

Problems encountered:

From the very beginning of this experiment, we encountered a difficult problem, that is, the experimental environment can not be built. Whether it is using their own virtual machine or the experimental building of the virtual experiment environment, can not be updated from the experiment to the link to git, so that the subsequent experiments can not be completed successfully, but I based on the content of MOOC, the experimental steps are listed. The solution is not yet, I hope the teacher to give guidance.

Summary of the contents of the book:

9th, Chapter 10 introduces the concept of synchronization and concurrency and Linux solutions for synchronization and concurrency, namely, lock and atomic operations.

1. The simplest method of ensuring synchronization, atomic operation. My understanding is that the reading and writing of the data and the operation of the data are bundled together, and cannot be interrupted during this process, so that synchronization can be ensured.

2. Describes the mechanism for resolving concurrent execution, locks. and discusses a variety of locking mechanisms, the most common lock in the kernel is a spin lock, lightweight individual holders of the lock is a busy time, there are sleep lock mutex. My understanding of the locking mechanism is that when multiple threads of the party preempt the same resource, the thread that needs to enter first locks the resource, and then releases the resource to other threads after the execution completes.

20169217 "Linux kernel Fundamentals and Analysis" Seventh week work

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.