Preparation:
- Come up with a kernel source tree. (The latest stable kernel is 2.6.36.1, you could get it from kernel.org
)
- Build kernel and install it on your system. 具体可以参考在ubuntu10.10上编译安装linux-2.6.36.1 kernel
Hello module coding:
hello.c
#include <linux/init.h>
#include <linux/module.h>
MODULE_LICENSE("Dual BSD/GPL");
static int hello_init(void)
{
printk(KERN_ALERT "Hello, allenpettle\n");
return 0;
}
static void hello_exit(void)
{
printk(KERN_ALERT "Goodbye, allenpettle\n");
}
module_init(hello_init);
module_exit(hello_exit);
linux/module.h and linux/init.h must appear in every loadable modules.
module.h contains many definitions of symbols and functions.
init.h specify initialization and cleanup functions.
module_init and module_exit are mandatory.
MAKEFILE 注意前面不是空格而是tab,不然编译不过
# If KERNELRELEASE is defined, we've been invoked from the
# kernel build system and can use its language.
ifneq ($(KERNELRELEASE),)
obj-m := hello.o
# Otherwise we were called directly from the command
# line; invoke the kernel build system.
else
KERNELDIR ?= /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
default:
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules
endif
obj-m
A makefile symbol used by the kernel build system to determine which modules
should be built in the current directory.
make / insmod / rmmod操作, dmesg看log,如果log太多,dmesg -c 清空
Kernel Space VS. User Space
System memory in Linux can be divided into two distinct regions: kernel space and user space.
Kernel space is where the kernel(i.e., the core of the operating system) executes and provides its services.
User space is that set of memory locations in which user processes run. A process is an excuting instance of a program.
Kernel space can be accessed by user processes only through the use of system calls.
- 大小: 103.1 KB
- 大小: 87.3 KB
分享到:
相关推荐
Robert authored OpenCV2 Computer Vision Application Programming Cookbook in 2011 and co-authored Object Oriented Software Development published by McGraw Hill in 2001. He co-founded Visual Cortek in...
It starts with the installation and basic concepts, then continues with more complex modules available in ROS such as sensors and actuators integration (drivers), navigation and mapping (so you can ...
Chapter 2, "A Peek Inside the Kernel," takes a brisk peek into the innards of the Linux kernel and teaches you some must-know kernel concepts. It first takes you through the boot process and then ...
"Linux Device Driver 3rd Edition" offers a comprehensive guide for developers looking to write device drivers for the Linux system. It not only covers the technical aspects of driver development but ...
Charles.River.Media.Fundamentals.of.SVG.Programming.Concepts.to.Source.Code.eBook-DDU.chm
Beginning Linux Programming, Fourth Edition continues its unique approach to teaching UNIX programming in a simple and structured way on the Linux ... and kernel programming for the latest Linux Kernel.
[操作系统概念.(操作系统恐龙书)].Silberschatz.Galvin.Operating.System.Concepts.7th.ED
Chapter 2, “A Peek Inside the Kernel” , takes a brisk look into the innards of the Linux kernel and teaches you some must-know kernel concepts. It first takes you through the boot process and then ...
Data Mining - Concepts and Techniques (3rd Ed).pdf )
"Coding Interview Questions" is a book that presents interview questions in simple and straightforward manner with a clear-cut explanation. This book will provide an introduction to the basics. It ...
"Data.Mining.Concepts.and.Techniques.2nd.Ed 配套 PPT 9 章"是一个专门针对这一主题的学习资源,包含三个核心部分:图挖掘(Section 9.1. Graph Mining.ppt)、社会网络分析(Section 9.2. Social Network ...
Parallel Programming: Concepts and Practice By 作者: Bertil Schmidt Ph.D. – Jorge Gonzalez-Dominguez Ph.D. – Christian Hundt – Moritz Schlarb ISBN-10 书号: 0128498900 ISBN-13 书号: 9780128498903 ...
《Data Mining: Concepts and Techniques》(数据挖掘:概念与技术)这本书是数据挖掘领域内的一本经典教材,由Jiawei Han,Micheline Kamber和Jian Pei三位专家撰写,目前已经更新到第三版。这本书不仅适合学术研究...
To aid students, the book provides numerous examples and complete program scripts that will help in grasping the key concepts effectively. Table of Contents Chapter 1. Unix: An Introduction Chapter 2...
Kernel development can be a daunting task and is very different from programming traditional user applications. The kernel environment is more volatile and complex. Extraordinary care must be taken to...
Addison.PostgreSQL.Introduction.and.Concepts