<<linux device driver,third edition>> Chapter 2: Building and Running Modules
Kernel Modules Versus Applications
Kernel modules programming is similar to event driven programming.
the task of the module's initialization function is to perpare for later invocation of the module's functions;it's as though the module were saying,"Here I am,and this is what I can do."The module's exit function gets invoked just before the module is unloaded.it should tell the kernel,"I'm not there anymore;don't ask me to do anything else".
A module,is linked only to the kernel,and the only functions it can call are the ones exported by the kernel
Concurrency in the kernel
- interrupt handlers
- symmetric multiprocessor(SMP)
- kernel code has been made preemptible
As a result,Linux kernel code,including driver code,must be reentrant.
A Few Other Details
Kernel code cannot do floating point arithmetic.
Kernel has very small stack.
Often,as you look at the kernel API,you will encounter function name starting with a double undersore(__).Essentially,it says to the programmer:"if you call this function,be sure you know what you are doing"
Compiling Modules
obj-m := hello.o
hello-objs := main.o add.o
all:
make -C /usr/src/XXX/ M=`pwd` modules
clean:
make -C /usr/src/XXX/ M=`pwd` clean
Loading and Unloading Modules
insmod
The program loads the module code and data into the kernel,which,in turn,performs a function similar to the of ld,in that it links any unresolved symbol in the module to the symbol table of the kernel
modprobe
like insmod,load a module into the kernel.It differs in that it will look at the module to be loaded to see whether it references any symbols that are not currently defined in the kernel.If any such references are found,modprobe looks for other modules in the current module search path that define the relevant symbols.When modprobe finds those modules,it loads them into the kernel as well.
The kernel symbol table
EXPORT_SYMBOL(name)
EXPORT_SYMBOL_GPL(name)
Module Parameters
insmod hello.ko howmany=10 whom="Mom"
Parameters are declared with the module_param macro,which is defined in moduleparam.h .module_param takes three parameters: the name of the variable,its type , and a permissions mask to be used for an accompanying sysfs entry.
eg:
static char *whom="world";
static int howmany=1;
module_param(howmany,int,S_IRUGO);
module_param(whom,charp,S_IRUGO);
<<linux device driver,third edition>> Chapter 2: Building and Running Modules的更多相关文章
- <<linux device driver,third edition>> Chapter 4:Debugging Techniques
Debugging by Printing printk lets you classify messages accoring to their severity by associating di ...
- <<linux device driver,third edition>> Chapter 3:Char Drivers
The Internal Representation of Device Numbers Within the kernel,the dev_t type(defined in linux/type ...
- linux device driver —— 环形缓冲区的实现
还是没有接触到怎么控制硬件,但是在书里看到了一个挺巧妙的环形缓冲区实现. 此环形缓冲区实际为一个大小为bufsize的一维数组,有一个rp的读指针,一个wp的写指针. 在数据满时写进程会等待读进程读取 ...
- Linux Device Driver 学习(1)
Linux Device Driver 学习(1) 一.搭建虚拟机开发环境 1.选择虚拟机VirtualBox,官网下载.deb包安装: VirtualBox Linux 5.1.6 下载fedora ...
- how to write your first linux device driver
how to write your first linux device driver 0. environment-ubuntu 1804 64bit 1. apt-get install linu ...
- Linux Device Driver && Device File
catalog . 设备驱动程序简介 . I/O体系结构 . 访问设备 . 与文件系统关联 . 字符设备操作 . 块设备操作 . 资源分配 . 总线系统 1. 设备驱动程序简介 设备驱动程序是内核的关 ...
- How to learn linux device driver
To learn device driver development, like any other new knowledge, the bestapproach for me is to lear ...
- linux device driver —— ioctl
实现了应用程序和设备驱动通过ioctl通信.还是对设备驱动没什么感觉,贴一下代码吧. 在Ubuntu 16.04 64bit中测试通过 ioctldemo.c #include <linux/m ...
- linux device driver —— 字符设备
现在对linux设备驱动还没有什么认识,跟着书上敲了一个字符驱动,这里把代码贴一下. 测试环境是 Ubuntu 16.04 64bit 驱动程序: #include <linux/fs.h> ...
随机推荐
- Jetbrains软件永久破解
说明:该破解到期时间为2099年,基本为永久破解! 1.点击右侧链接下载脚本JetbrainsCrack-3.1-release-enc.jar [JetbrainsCrack-release-enc ...
- Shaping Regions(dfs)
Shaping Regions Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 124 Solved: 39[Submit][Status][Web B ...
- socket、web socket
WEB SOCKET: 说明:为浏览器提供双工异步通信,浏览器可以向服务端发送消息.服务端也可以向浏览器发送消息. SOCKET: 说明:网络上的两个程序通过一个双向的通信连接实现数据的交换,这个连接 ...
- FullCalendar – jQuery Event Calendar in ASP.NET
https://github.com/esausilva/ASP.Net-EventCalendar http://trentrichardson.com/examples/timepicker/ h ...
- √n求单值欧拉函数
基本定理: 首先看一下核心代码: 核心代码 原理解析: 当初我看不懂这段代码,主要有这么几个问题: 1.定理里面不是一开始写了一个n*xxx么?为什么代码里没有*n? 2.ans不是*(prime[i ...
- 【代码笔记】Web-ionic-头部与底部
index代码: <!DOCTYPE html> <html> <head> <meta charset="utf-8"> < ...
- 纯小白入手 vue3.0 CLI - 3.1 - 路由 ( router )
vue3.0 CLI 真小白一步一步入手全教程系列:https://www.cnblogs.com/ndos/category/1295752.html 尽量把纷繁的知识,肢解重组成为可以堆砌的知识. ...
- Spark机器学习——模型选择与参数调优之交叉验证
spark 模型选择与超参调优 机器学习可以简单的归纳为 通过数据训练y = f(x) 的过程,因此定义完训练模型之后,就需要考虑如何选择最终我们认为最优的模型. 如何选择最优的模型,就是本篇的主要内 ...
- GridView的簡單使用
項目GitHub地址:https://github.com/leonInShanghai/IMbobo GridView XML佈局: <?xml version="1.0" ...
- [20170909]为什么是12秒.txt
[20170909]为什么是12秒.txt --//在开发程序时我一般会强调开发尽量不要写一些自定义函数,往往可能导致CPU忙.--//例子很像这样: CREATE OR REPLACE FUNCTI ...