1K地址: 1 0000000000(10个0)
1M地址:1 0000000000(10个0)0000000000(10个0)
1G地址:1 0000000000(10个0)0000000000(10个0)0000000000(10个0)
3G地址:11 0000000000 0000000000 0000000000
3G地址:0xcfffffff
3G – 4G地址范围:0xcfffffff– 0xffffffff
设计文件内容如下:
show.c内容:
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/module.h>
static int a = 1;
int show_hellotest(void)
{
printk("aadrr = %p, show_test addr = %p !\n",&a,show_hellotest);
return 0;
}
hello.c内容:
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/module.h>
extern int show_hellotest(void);
static int __init hello_init(void)
{
printk("helloworld init!\n");
show_hellotest();
return 0;
}
static void __exit hello_exit(void)
{
printk("helloworld exit!\n");
}
MODULE_LICENSE("GPL");
module_init(hello_init);
module_exit(hello_exit);
Makefile内容
ifeq ($(KERNELRELEASE),)
all:
make -C/lib/modules/$(shell uname -r)/build M=$(shell pwd)
clean:
rm *.o *.ko*.mod.c modules.order
else
obj-m:=helloshow.o
helloshow-y+=hello.o
helloshow-y+=show.o
endif
执行完make,然后输入sudoinsmod helloshow.ko,再输入dmesg,得到打印如下:
[17946.600413] hello world init!
[17946.600415] a adrr = f9c15000, show_test addr =f9c13000 !