把下载的内核源码拷贝到 /usr/src/kernels/ 下
make && make modules_install && make install 即可安装新kernel到fedora,并在grub中出现
选项。
修改源码目录
[root@localhost linux-2.6.29.6]# vim ./arch/x86/include/asm/unistd_32.h
[root@localhost linux-2.6.29.6]# vim arch/x86/kernel/syscall_table_32.S
[root@localhost linux-2.6.29.6]# vim kernel/sys.c
三个文件,其中 sys.c用于添加自己的kernel API
unistd_32.h 用于添加系统调用号,(这里一定要定义未使用的)
syscall_table_32.S 中按定义的系统调用号的位置添加新定义的系统API 的名字(即声明)
之后在应用层用syscall(318,100);//318是系统调用号,100是参数
即可实现调用。
但是在执行syscall调用时出现没有打印出希望的信息,原因是printk级别低,
一种是调高printk打印机别,另一种是用dmesg看。
注意:如果自定义的sysycall引用了自己写的并添加到内核中的文件中EXPORT_SYMBOL的函数的话,出现"undefine reference" 类似的错误,要查看相关目录下的Makefile是不是用obj-$(变量) 改成obj-y 强制编就可以了,怀疑是那个变量没传过来,建Kconfig建的不对,没和Makefile联系起来。
==========================================================================
printk 输出级别
==========================================================================
下面是两个printk函数的例子,一个是调试消息,一个是临界消息:
printk(KERN_DEBUG "Here I am: %s:%i/n", _ _FILE_ _, _ _LINE_ _);
printk(KERN_CRIT "I'm trashed; giving up on %p/n", ptr);
There are eight possible loglevel strings, defined in the header ; we list them in order of decreasing severity:
在头文件 <linux/kernel.h>中共定义了八个可用的记录级;我们下面按其严重性倒序列出:
KERN_EMERG
Used for emergency messages, usually those that precede a crash.
用于突发性事件的消息,通常在系统崩溃之前报告此类消息。
KERN_ALERT
A situation requiring immediate action.
在需要立即操作的情况下使用此消息。
KERN_CRIT
Critical conditions, often related to serious hardware or software failures.
用于临界条件下,通常遇到严重的硬软件错误时使用此消息。
KERN_ERR
Used to report error conditions; device drivers often use KERN_ERR to report hardware difficulties.
用于报告错误条件;设备驱动经常使用KERN_ERR报告硬件难题。
KERN_WARNING
Warnings about problematic situations that do not, in themselves, create serious problems with the system.
是关于问题状况的警告,一般这些状况不会引起系统的严重问题。
KERN_NOTICE
Situations that are normal, but still worthy of note. A number of security-related conditions are reported at this level.
该级别较为普通,但仍然值得注意。许多与安全性相关的情况会在这个级别被报告。
KERN_INFO
Informational messages. Many drivers print information about the hardware they find at startup time at this level.
信息消息。许多驱动程序在启动时刻用它来输出获得的硬件信息。
KERN_DEBUG
Used for debugging messages.
用于输出调试信息
================================================================================
================================================================================
注意:在编译过程中在sys.c中会提示找不到你的API函数(API函数在别的文件中定义,然后EXPORT_SYMBOL,在sys.c中extern),原因是你的定义API的文件编译成了模块,没有编译到内核,改为obj-y即可。